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

Some refactoring

parent 2f59e9e2
...@@ -69,29 +69,30 @@ data class MessageViewModel(val context: Context, ...@@ -69,29 +69,30 @@ 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
attachmentType = when (attachment) { attachmentType = when (attachment) {
is ImageAttachment -> AttachmentType.Image is ImageAttachment -> AttachmentType.Image
is VideoAttachment -> AttachmentType.Video is VideoAttachment -> AttachmentType.Video
is AudioAttachment -> AttachmentType.Audio is AudioAttachment -> AttachmentType.Audio
else -> null else -> null
}
} }
} }
} else if (it[0] is MessageAttachment) { is MessageAttachment -> {
val attachment = it[0] as MessageAttachment attachmentType = AttachmentType.Message
attachmentType = AttachmentType.Message attachmentMessageText = attachment.text ?: ""
attachmentMessageText = attachment.text ?: "" attachmentMessageAuthor = attachment.author ?: ""
attachmentMessageAuthor = attachment.author ?: "" attachmentMessageIcon = attachment.icon
attachmentMessageIcon = attachment.icon attachmentTimestamp = attachment.timestamp
attachmentTimestamp = attachment.timestamp }
} }
} }
...@@ -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