Skip to content

Commit

Permalink
fix: Migration message not shown in 1:1 conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine committed Sep 27, 2024
1 parent ba79287 commit acd3182
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,8 @@ class UserSessionScope internal constructor(
conversationGroupRepository,
conversationRepository,
messageRepository,
userRepository
userRepository,
systemMessageInserter
)
private val oneOnOneResolver: OneOnOneResolver
get() = OneOnOneResolverImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.wire.kalium.logic.data.conversation.ConversationGroupRepository
import com.wire.kalium.logic.data.conversation.ConversationRepository
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.message.MessageRepository
import com.wire.kalium.logic.data.message.SystemMessageInserter
import com.wire.kalium.logic.data.user.OtherUser
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.data.user.type.isTeammate
Expand All @@ -44,7 +45,8 @@ internal class OneOnOneMigratorImpl(
private val conversationGroupRepository: ConversationGroupRepository,
private val conversationRepository: ConversationRepository,
private val messageRepository: MessageRepository,
private val userRepository: UserRepository
private val userRepository: UserRepository,
private val systemMessageInserter: SystemMessageInserter
) : OneOnOneMigrator {

override suspend fun migrateToProteus(user: OtherUser): Either<CoreFailure, ConversationId> =
Expand Down Expand Up @@ -87,6 +89,12 @@ internal class OneOnOneMigratorImpl(
userId = user.id
).map {
mlsConversation
}.also {
systemMessageInserter.insertProtocolChangedSystemMessage(
conversationId = mlsConversation,
senderUserId = user.id,
protocol = Conversation.Protocol.MLS
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ class OneOnOneMigratorTest {
coVerify {
arrangement.messageRepository.moveMessagesToAnotherConversation(any(), any())
}.wasNotInvoked()

coVerify {
arrangement.systemMessageInserter.insertProtocolChangedSystemMessage(any(), any(), any())
}.wasNotInvoked()
}

@Test
Expand All @@ -141,7 +145,7 @@ class OneOnOneMigratorTest {
)
val failure = CoreFailure.MissingClientRegistration

val (_, oneOnOneMigrator) = arrange {
val (arrangement, oneOnOneMigrator) = arrange {
withResolveConversationReturning(Either.Left(failure))
}

Expand Down Expand Up @@ -171,6 +175,10 @@ class OneOnOneMigratorTest {
coVerify {
arrangement.userRepository.updateActiveOneOnOneConversation(any(), any())
}.wasNotInvoked()

coVerify {
arrangement.systemMessageInserter.insertProtocolChangedSystemMessage(any(), any(), any())
}.wasNotInvoked()
}

@Test
Expand Down Expand Up @@ -212,6 +220,10 @@ class OneOnOneMigratorTest {
coVerify {
arrangement.messageRepository.moveMessagesToAnotherConversation(eq(originalConversationId), eq(resolvedConversationId))
}.wasInvoked(exactly = once)

coVerify {
arrangement.systemMessageInserter.insertProtocolChangedSystemMessage(any(), any(), any())
}.wasInvoked(exactly = once)
}

@Test
Expand All @@ -234,6 +246,10 @@ class OneOnOneMigratorTest {
coVerify {
arrangement.userRepository.updateActiveOneOnOneConversation(eq(user.id), eq(resolvedConversationId))
}.wasInvoked(exactly = once)

coVerify {
arrangement.systemMessageInserter.insertProtocolChangedSystemMessage(any(), any(), any())
}.wasInvoked(exactly = once)
}

private class Arrangement(private val block: suspend Arrangement.() -> Unit) :
Expand All @@ -249,7 +265,8 @@ class OneOnOneMigratorTest {
conversationGroupRepository = conversationGroupRepository,
conversationRepository = conversationRepository,
messageRepository = messageRepository,
userRepository = userRepository
userRepository = userRepository,
systemMessageInserter = systemMessageInserter
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.wire.kalium.logic.StorageFailure
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.message.Message
import com.wire.kalium.logic.data.message.MessageRepository
import com.wire.kalium.logic.data.message.SystemMessageInserter
import com.wire.kalium.logic.data.notification.LocalNotification
import com.wire.kalium.logic.functional.Either
import io.mockative.Mock
Expand All @@ -37,6 +38,9 @@ internal interface MessageRepositoryArrangement {
@Mock
val messageRepository: MessageRepository

@Mock
val systemMessageInserter: SystemMessageInserter

suspend fun withGetMessageById(
result: Either<StorageFailure, Message>,
messageID: Matcher<String> = AnyMatcher(valueOf()),
Expand Down Expand Up @@ -68,6 +72,8 @@ internal open class MessageRepositoryArrangementImpl : MessageRepositoryArrangem
@Mock
override val messageRepository: MessageRepository = mock(MessageRepository::class)

override val systemMessageInserter = mock(SystemMessageInserter::class)

override suspend fun withGetMessageById(
result: Either<StorageFailure, Message>,
messageID: Matcher<String>,
Expand Down

0 comments on commit acd3182

Please sign in to comment.