Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix bug not displaying asset messages correctly #518

Merged
merged 7 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,15 @@ class ConversationViewModel @Inject constructor(
}
}

private suspend fun fromMessageModelToMessageContent(message: Message): MessageContent =
private suspend fun fromMessageModelToMessageContent(message: Message): MessageContent? =
when (val content = message.content) {
is Asset -> mapToMessageUI(content.value, message.conversationId, message.id)
is Text -> TextMessage(messageBody = MessageBody(content.value))
else -> TextMessage(messageBody = MessageBody((content as? Text)?.value ?: "content is not available"))
}

private suspend fun mapToMessageUI(assetContent: AssetContent, conversationId: ConversationId, messageId: String): MessageContent {
private suspend fun mapToMessageUI(assetContent: AssetContent, conversationId: ConversationId, messageId: String): MessageContent? {
with(assetContent) {
val assetId = remoteData.assetId

// TODO: To be changed once the error behavior has been defined with product
if (assetId.isEmpty()) return TextMessage(messageBody = MessageBody("The asset message could not be downloaded correctly"))
saleniuk marked this conversation as resolved.
Show resolved Hide resolved

val (imgWidth, imgHeight) = when (val md = metadata) {
is Image -> md.width to md.height
else -> 0 to 0
Expand All @@ -287,12 +282,17 @@ class ConversationViewModel @Inject constructor(
)

// It's a generic Asset Message so let's not download it yet
else -> AssetMessage(
assetName = name ?: "",
assetExtension = name?.split(".")?.last() ?: "",
assetId = remoteData.assetId,
assetSizeInBytes = sizeInBytes
)
else -> {
return if (remoteData.assetId.isNotEmpty()) {
AssetMessage(
assetName = name ?: "",
assetExtension = name?.split(".")?.last() ?: "",
assetId = remoteData.assetId,
assetSizeInBytes = sizeInBytes
)
// On the first asset message received, the asset ID is null, so we filter it out until the second updates it
} else null
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private fun Username(username: String) {
}

@Composable
private fun MessageContent(messageContent: MessageContent, onAssetClick: (String) -> Unit) {
private fun MessageContent(messageContent: MessageContent?, onAssetClick: (String) -> Unit) {
when (messageContent) {
is MessageContent.ImageMessage -> MessageImage(
rawImgData = messageContent.rawImgData,
Expand All @@ -145,6 +145,7 @@ private fun MessageContent(messageContent: MessageContent, onAssetClick: (String
assetSizeInBytes = messageContent.assetSizeInBytes,
onAssetClick = { onAssetClick(messageContent.assetId) }
)
else -> {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class MessageViewWrapper(
val user: User,
val messageSource: MessageSource = MessageSource.CurrentUser,
val messageHeader: MessageHeader,
val messageContent: MessageContent,
val messageContent: MessageContent?,
) {
val isDeleted: Boolean = messageHeader.messageStatus == MessageStatus.Deleted

Expand Down