From 7611f05a8c0e55a33fba96ae17b9d412c6e3f6fd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:13:37 +0000 Subject: [PATCH] fix: delay outgoing message before sync is finished [#WPB-15141] (#3216) (#3220) Co-authored-by: Sergey Bakhtiarov --- .../com/wire/kalium/logic/feature/debug/DebugScope.kt | 3 ++- .../wire/kalium/logic/feature/message/MessageScope.kt | 3 ++- ...leteEphemeralMessageForSelfUserAsReceiverUseCase.kt | 9 ++++++++- ...EphemeralMessageForSelfUserAsReceiverUseCaseTest.kt | 10 +++++++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/debug/DebugScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/debug/DebugScope.kt index 6367488ad5f..f09b9c8c918 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/debug/DebugScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/debug/DebugScope.kt @@ -201,7 +201,8 @@ class DebugScope internal constructor( currentClientIdProvider = currentClientIdProvider, messageSender = messageSender, selfUserId = userId, - selfConversationIdProvider = selfConversationIdProvider + selfConversationIdProvider = selfConversationIdProvider, + syncManager = syncManager, ) private val deleteEphemeralMessageForSelfUserAsSender: DeleteEphemeralMessageForSelfUserAsSenderUseCaseImpl diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageScope.kt index 59566d18737..2a6129225bf 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MessageScope.kt @@ -436,7 +436,8 @@ class MessageScope internal constructor( currentClientIdProvider = currentClientIdProvider, messageSender = messageSender, selfUserId = selfUserId, - selfConversationIdProvider = selfConversationIdProvider + selfConversationIdProvider = selfConversationIdProvider, + syncManager = syncManager, ) val getSearchedConversationMessagePosition: GetSearchedConversationMessagePositionUseCase diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/ephemeral/DeleteEphemeralMessageForSelfUserAsReceiverUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/ephemeral/DeleteEphemeralMessageForSelfUserAsReceiverUseCase.kt index 1105f1a24af..04d703071e7 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/ephemeral/DeleteEphemeralMessageForSelfUserAsReceiverUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/ephemeral/DeleteEphemeralMessageForSelfUserAsReceiverUseCase.kt @@ -37,6 +37,7 @@ import com.wire.kalium.logic.functional.foldToEitherWhileRight import com.wire.kalium.logic.functional.onFailure import com.wire.kalium.logic.functional.onSuccess import com.wire.kalium.logic.kaliumLogger +import com.wire.kalium.logic.sync.SyncManager import kotlinx.datetime.Clock /** @@ -60,7 +61,8 @@ internal class DeleteEphemeralMessageForSelfUserAsReceiverUseCaseImpl( private val currentClientIdProvider: CurrentClientIdProvider, private val messageSender: MessageSender, private val selfUserId: UserId, - private val selfConversationIdProvider: SelfConversationIdProvider + private val selfConversationIdProvider: SelfConversationIdProvider, + private val syncManager: SyncManager, ) : DeleteEphemeralMessageForSelfUserAsReceiverUseCase { override suspend fun invoke(conversationId: ConversationId, messageId: String): Either = @@ -78,6 +80,11 @@ internal class DeleteEphemeralMessageForSelfUserAsReceiverUseCaseImpl( conversationId, currentClientId ).flatMap { + + // Wait until the sync is complete to avoid sending message with + // potentially invalid epoch + syncManager.waitUntilLive() + sendDeleteMessageToOriginalSender( message.id, message.conversationId, diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/message/ephemeral/DeleteEphemeralMessageForSelfUserAsReceiverUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/message/ephemeral/DeleteEphemeralMessageForSelfUserAsReceiverUseCaseTest.kt index a3eb57969ef..7850762a63c 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/message/ephemeral/DeleteEphemeralMessageForSelfUserAsReceiverUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/message/ephemeral/DeleteEphemeralMessageForSelfUserAsReceiverUseCaseTest.kt @@ -23,8 +23,8 @@ import com.wire.kalium.logic.data.message.AssetContent import com.wire.kalium.logic.data.message.Message import com.wire.kalium.logic.data.message.MessageContent import com.wire.kalium.logic.data.message.MessageEncryptionAlgorithm -import com.wire.kalium.logic.data.message.MessageTarget import com.wire.kalium.logic.data.user.UserId +import com.wire.kalium.logic.data.message.MessageTarget import com.wire.kalium.logic.feature.message.ephemeral.DeleteEphemeralMessageForSelfUserAsReceiverUseCase import com.wire.kalium.logic.feature.message.ephemeral.DeleteEphemeralMessageForSelfUserAsReceiverUseCaseImpl import com.wire.kalium.logic.functional.Either @@ -32,6 +32,8 @@ import com.wire.kalium.logic.util.arrangement.MessageSenderArrangement import com.wire.kalium.logic.util.arrangement.MessageSenderArrangementImpl import com.wire.kalium.logic.util.arrangement.SelfConversationIdProviderArrangement import com.wire.kalium.logic.util.arrangement.SelfConversationIdProviderArrangementImpl +import com.wire.kalium.logic.util.arrangement.SyncManagerArrangement +import com.wire.kalium.logic.util.arrangement.SyncManagerArrangementImpl import com.wire.kalium.logic.util.arrangement.provider.CurrentClientIdProviderArrangement import com.wire.kalium.logic.util.arrangement.provider.CurrentClientIdProviderArrangementImpl import com.wire.kalium.logic.util.arrangement.repository.AssetRepositoryArrangement @@ -163,7 +165,8 @@ class DeleteEphemeralMessageForSelfUserAsReceiverUseCaseTest { MessageRepositoryArrangement by MessageRepositoryArrangementImpl(), MessageSenderArrangement by MessageSenderArrangementImpl(), SelfConversationIdProviderArrangement by SelfConversationIdProviderArrangementImpl(), - AssetRepositoryArrangement by AssetRepositoryArrangementImpl() { + AssetRepositoryArrangement by AssetRepositoryArrangementImpl(), + SyncManagerArrangement by SyncManagerArrangementImpl() { private val useCase: DeleteEphemeralMessageForSelfUserAsReceiverUseCase = DeleteEphemeralMessageForSelfUserAsReceiverUseCaseImpl( @@ -172,7 +175,8 @@ class DeleteEphemeralMessageForSelfUserAsReceiverUseCaseTest { selfUserId = SELF_USER_ID, selfConversationIdProvider = selfConversationIdProvider, assetRepository = assetRepository, - currentClientIdProvider = currentClientIdProvider + currentClientIdProvider = currentClientIdProvider, + syncManager = syncManager, ) suspend fun arrange(block: suspend Arrangement.() -> Unit): Pair {