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

Some refactoring

parent 2f59e9e2
......@@ -69,11 +69,11 @@ data class MessageViewModel(val context: Context,
}
}
message.attachments?.let {
if (it.isEmpty() || it[0] == null) return@let
if (it[0] is FileAttachment) {
val attachment = it[0] as FileAttachment
message.attachments?.let { attachments ->
val attachment = attachments.firstOrNull()
if (attachments.isEmpty() || attachment == null) return@let
when (attachment) {
is FileAttachment -> {
baseUrl?.let {
attachmentUrl = attachmentUrl("${baseUrl.value}${attachment.url}")
attachmentTitle = attachment.title
......@@ -85,8 +85,8 @@ data class MessageViewModel(val context: Context,
else -> null
}
}
} else if (it[0] is MessageAttachment) {
val attachment = it[0] as MessageAttachment
}
is MessageAttachment -> {
attachmentType = AttachmentType.Message
attachmentMessageText = attachment.text ?: ""
attachmentMessageAuthor = attachment.author ?: ""
......@@ -94,6 +94,7 @@ data class MessageViewModel(val context: Context,
attachmentTimestamp = attachment.timestamp
}
}
}
content = getContent(context)
}
......@@ -114,6 +115,9 @@ data class MessageViewModel(val context: Context,
}
}
/**
* Get the original message as a String.
*/
fun getOriginalMessage() = message.message
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