Using onFileTransferTerminated instead of relying on FileTransferDone chat message state

This commit is contained in:
Sylvain Berfini 2026-01-05 15:58:18 +01:00
parent 50aa053c19
commit a897c127e5

View file

@ -219,27 +219,13 @@ class MessageModel
private val chatMessageListener = object : ChatMessageListenerStub() {
@WorkerThread
override fun onMsgStateChanged(message: ChatMessage, messageState: ChatMessage.State?) {
Log.i("$TAG Chat message [${message.messageId}] state changed to [$messageState]")
if (messageState != ChatMessage.State.FileTransferDone && messageState != ChatMessage.State.FileTransferInProgress) {
statusIcon.postValue(LinphoneUtils.getChatIconResId(chatMessage.state))
if (messageState == ChatMessage.State.Displayed) {
isRead = chatMessage.isRead
}
} else if (messageState == ChatMessage.State.FileTransferDone) {
Log.i("$TAG File transfer is done")
transferringFileModel?.updateTransferProgress(-1)
transferringFileModel = null
if (!allFilesDownloaded) {
computeContentsList()
} else {
for (content in message.contents) {
if (content.isVoiceRecording) {
Log.i("$TAG File transfer done, updating voice record info")
computeVoiceRecordContent(content)
break
}
}
}
}
isInError.postValue(messageState == ChatMessage.State.NotDelivered)
}
@ -247,22 +233,7 @@ class MessageModel
@WorkerThread
override fun onFileTransferTerminated(message: ChatMessage, content: Content) {
Log.i("$TAG File [${content.name}] from message [${message.messageId}] transfer terminated")
// Never do auto media export for ephemeral messages!
if (corePreferences.makePublicMediaFilesDownloaded && !message.isEphemeral) {
val path = content.filePath
if (path.isNullOrEmpty()) return
val mime = "${content.type}/${content.subtype}"
val mimeType = FileUtils.getMimeType(mime)
when (mimeType) {
FileUtils.MimeType.Image, FileUtils.MimeType.Video, FileUtils.MimeType.Audio -> {
Log.i("$TAG Exporting file path [$path] to the native media gallery")
onFileToExportToNativeGallery?.invoke(path)
}
else -> {}
}
}
fileTransferTerminated(message, content)
}
@WorkerThread
@ -1067,4 +1038,37 @@ class MessageModel
"$TAG Found voice record with path [$voiceRecordPath] and duration [$formattedDuration]"
)
}
@WorkerThread
private fun fileTransferTerminated(message: ChatMessage, content: Content) {
// Never do auto media export for ephemeral messages!
if (corePreferences.makePublicMediaFilesDownloaded && !message.isEphemeral) {
val path = content.filePath
if (path.isNullOrEmpty()) return
val mime = "${content.type}/${content.subtype}"
val mimeType = FileUtils.getMimeType(mime)
when (mimeType) {
FileUtils.MimeType.Image, FileUtils.MimeType.Video, FileUtils.MimeType.Audio -> {
Log.i("$TAG Exporting file path [$path] to the native media gallery")
onFileToExportToNativeGallery?.invoke(path)
}
else -> {}
}
}
transferringFileModel?.updateTransferProgress(-1)
transferringFileModel = null
if (!allFilesDownloaded) {
computeContentsList()
} else {
for (content in message.contents) {
if (content.isVoiceRecording) {
Log.i("$TAG File transfer done, updating voice record info")
computeVoiceRecordContent(content)
break
}
}
}
}
}