Skip to content

Commit

Permalink
fix: delay outgoing message before sync is finished [#WPB-15141] (#3216
Browse files Browse the repository at this point in the history
…) (#3220)

Co-authored-by: Sergey Bakhtiarov <[email protected]>
  • Loading branch information
github-actions[bot] and sbakhtiarov authored Jan 15, 2025
1 parent 76697f1 commit 7611f05
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ class DebugScope internal constructor(
currentClientIdProvider = currentClientIdProvider,
messageSender = messageSender,
selfUserId = userId,
selfConversationIdProvider = selfConversationIdProvider
selfConversationIdProvider = selfConversationIdProvider,
syncManager = syncManager,
)

private val deleteEphemeralMessageForSelfUserAsSender: DeleteEphemeralMessageForSelfUserAsSenderUseCaseImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ class MessageScope internal constructor(
currentClientIdProvider = currentClientIdProvider,
messageSender = messageSender,
selfUserId = selfUserId,
selfConversationIdProvider = selfConversationIdProvider
selfConversationIdProvider = selfConversationIdProvider,
syncManager = syncManager,
)

val getSearchedConversationMessagePosition: GetSearchedConversationMessagePositionUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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<CoreFailure, Unit> =
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ 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
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
Expand Down Expand Up @@ -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(
Expand All @@ -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<Arrangement, DeleteEphemeralMessageForSelfUserAsReceiverUseCase> {
Expand Down

0 comments on commit 7611f05

Please sign in to comment.