From 09a6cfb68bae006adc52269b0d1135461854390b Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 5 Feb 2025 15:51:36 +0100 Subject: [PATCH] avoid duplicated messages after sending It could happen that when sending a message it was received on server but if the servers response is not received, the retry was triggered in the talk app. This sometimes happened when internet connection was not the best. Best would be that messages with the same referenceId would be refused on server side, but this won't be the case for now. So messages with the same referenceId are NOT refused as this would be too much overhead as there would be additional queries on server for every received message) For now, the automatic retry logic is just removed so duplicated messages won't be created automatically. However it's still possible to manually trigger the retry via button. In this case it is not guaranteed that there won't be duplicates. Signed-off-by: Marcel Hibbe --- .../chat/data/network/OfflineFirstChatRepository.kt | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt index e2e05ae924..bea8a9a029 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt @@ -44,7 +44,6 @@ import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.retryWhen import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import java.io.IOException @@ -839,14 +838,6 @@ class OfflineFirstChatRepository @Inject constructor( emit(Result.success(chatMessageModel)) } - .retryWhen { cause, attempt -> - if (cause is IOException && attempt < SEND_MESSAGE_RETRY_ATTEMPTS) { - delay(SEND_MESSAGE_RETRY_DELAY) - return@retryWhen true - } else { - return@retryWhen false - } - } .catch { e -> Log.e(TAG, "Error when sending message", e) @@ -1038,7 +1029,5 @@ class OfflineFirstChatRepository @Inject constructor( private const val DELAY_TO_ENSURE_MESSAGES_ARE_ADDED: Long = 100 private const val DEFAULT_MESSAGES_LIMIT = 100 private const val MILLIES = 1000 - private const val SEND_MESSAGE_RETRY_ATTEMPTS = 3 - private const val SEND_MESSAGE_RETRY_DELAY: Long = 2000 } }