Commit 692b65f3 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Some refactoring

parent 2f59e9e2
...@@ -69,11 +69,11 @@ data class MessageViewModel(val context: Context, ...@@ -69,11 +69,11 @@ data class MessageViewModel(val context: Context,
} }
} }
message.attachments?.let { message.attachments?.let { attachments ->
if (it.isEmpty() || it[0] == null) return@let val attachment = attachments.firstOrNull()
if (attachments.isEmpty() || attachment == null) return@let
if (it[0] is FileAttachment) { when (attachment) {
val attachment = it[0] as FileAttachment is FileAttachment -> {
baseUrl?.let { baseUrl?.let {
attachmentUrl = attachmentUrl("${baseUrl.value}${attachment.url}") attachmentUrl = attachmentUrl("${baseUrl.value}${attachment.url}")
attachmentTitle = attachment.title attachmentTitle = attachment.title
...@@ -85,8 +85,8 @@ data class MessageViewModel(val context: Context, ...@@ -85,8 +85,8 @@ data class MessageViewModel(val context: Context,
else -> null else -> null
} }
} }
} else if (it[0] is MessageAttachment) { }
val attachment = it[0] as MessageAttachment is MessageAttachment -> {
attachmentType = AttachmentType.Message attachmentType = AttachmentType.Message
attachmentMessageText = attachment.text ?: "" attachmentMessageText = attachment.text ?: ""
attachmentMessageAuthor = attachment.author ?: "" attachmentMessageAuthor = attachment.author ?: ""
...@@ -94,6 +94,7 @@ data class MessageViewModel(val context: Context, ...@@ -94,6 +94,7 @@ data class MessageViewModel(val context: Context,
attachmentTimestamp = attachment.timestamp attachmentTimestamp = attachment.timestamp
} }
} }
}
content = getContent(context) content = getContent(context)
} }
...@@ -114,6 +115,9 @@ data class MessageViewModel(val context: Context, ...@@ -114,6 +115,9 @@ data class MessageViewModel(val context: Context,
} }
} }
/**
* Get the original message as a String.
*/
fun getOriginalMessage() = message.message fun getOriginalMessage() = message.message
private fun getTime(timestamp: Long) = DateTimeHelper.getTime(DateTimeHelper.getLocalDateTime(timestamp)) private fun getTime(timestamp: Long) = DateTimeHelper.getTime(DateTimeHelper.getLocalDateTime(timestamp))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment