From a2b86ff5f6c232c3cc0a9868db3c8e2b62893b80 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 15 Dec 2023 11:38:42 +0100 Subject: [PATCH] Fixed outgoing message file upload display --- .../ui/main/chat/model/MessageModel.kt | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt b/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt index ae411a40b..f12377e55 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt @@ -201,6 +201,8 @@ class MessageModel @WorkerThread constructor( offset: Int, total: Int ) { + if (message.isOutgoing) return + val model = downloadingFileModel if (model != null) { val percent = ((offset * 100.0) / total).toInt() // Conversion from int to double and back to int is required @@ -371,25 +373,14 @@ class MessageModel @WorkerThread constructor( filesContentCount += 1 val name = content.name ?: "" if (name.isNotEmpty()) { - val fileModel = FileModel(name, name, content.fileSize.toLong(), true) { model -> - Log.d("$TAG Starting downloading content for file [${model.fileName}]") - - if (content.filePath.orEmpty().isEmpty()) { - val contentName = content.name - if (contentName != null) { - val isImage = FileUtils.isExtensionImage(contentName) - val file = FileUtils.getFileStoragePath(contentName, isImage) - content.filePath = file.path - Log.i( - "$TAG File [$contentName] will be downloaded at [${content.filePath}]" - ) - - model.downloadProgress.postValue(0) - downloadingFileModel = model - chatMessage.downloadContent(content) - } else { - Log.e("$TAG Content name is null, can't download it!") - } + val fileModel = if (isOutgoing && chatMessage.isFileTransferInProgress) { + val path = content.filePath ?: "" + FileModel(path, name, content.fileSize.toLong(), false) { model -> + onContentClicked?.invoke(model.file) + } + } else { + FileModel(name, name, content.fileSize.toLong(), true) { model -> + downloadContent(model, content) } } filesPath.add(fileModel) @@ -407,13 +398,38 @@ class MessageModel @WorkerThread constructor( filesList.postValue(filesPath) if (!displayableContentFound) { // Temporary workaround to prevent empty bubbles - Log.w("$TAG No displayable content found, generating text based description") val describe = LinphoneUtils.getTextDescribingMessage(chatMessage) + Log.w( + "$TAG No displayable content found, generating text based description [$describe]" + ) val spannable = Spannable.Factory.getInstance().newSpannable(describe) text.postValue(spannable) } } + @WorkerThread + private fun downloadContent(model: FileModel, content: Content) { + Log.d("$TAG Starting downloading content for file [${model.fileName}]") + + if (content.filePath.orEmpty().isEmpty()) { + val contentName = content.name + if (contentName != null) { + val isImage = FileUtils.isExtensionImage(contentName) + val file = FileUtils.getFileStoragePath(contentName, isImage) + content.filePath = file.path + Log.i( + "$TAG File [$contentName] will be downloaded at [${content.filePath}]" + ) + + model.downloadProgress.postValue(0) + downloadingFileModel = model + chatMessage.downloadContent(content) + } else { + Log.e("$TAG Content name is null, can't download it!") + } + } + } + @WorkerThread private fun updateReactionsList() { var reactionsList = ""