Skip to content

Commit

Permalink
fix: ignore subconversation message fail to decrypt system message (#…
Browse files Browse the repository at this point in the history
…3245) (#3246)

Co-authored-by: Jakub Żerko <iot.zerko@gmail.com>
  • Loading branch information
github-actions[bot] and Garzas authored Jan 24, 2025
1 parent 544ccea commit ab9c3ac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,20 @@ internal class NewMessageEventHandlerImpl(

is MLSMessageFailureResolution.InformUser -> {
eventLogger.logFailure(it, "protocol" to "MLS", "mlsOutcome" to "INFORM_USER")
applicationMessageHandler.handleDecryptionError(
eventId = event.id,
conversationId = event.conversationId,
messageInstant = event.messageInstant,
senderUserId = event.senderUserId,
senderClientId = ClientId(""), // TODO(mls): client ID not available for MLS messages
content = MessageContent.FailedDecryption(
isDecryptionResolved = false,
senderUserId = event.senderUserId
// messages from subconversations should not send a system message
if (event.subconversationId == null) {
applicationMessageHandler.handleDecryptionError(
eventId = event.id,
conversationId = event.conversationId,
messageInstant = event.messageInstant,
senderUserId = event.senderUserId,
senderClientId = ClientId(""), // TODO(mls): client ID not available for MLS messages
content = MessageContent.FailedDecryption(
isDecryptionResolved = false,
senderUserId = event.senderUserId
)
)
)
}
}

is MLSMessageFailureResolution.OutOfSync -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.wire.kalium.logic.data.event.EventEnvelope
import com.wire.kalium.logic.data.event.MemberLeaveReason
import com.wire.kalium.logic.data.featureConfig.AppLockModel
import com.wire.kalium.logic.data.featureConfig.Status
import com.wire.kalium.logic.data.id.SubconversationId
import com.wire.kalium.logic.data.user.Connection
import com.wire.kalium.logic.data.user.ConnectionState
import com.wire.kalium.logic.data.user.UserId
Expand Down Expand Up @@ -198,11 +199,12 @@ object TestEvent {
)

fun newMLSMessageEvent(
dateTime: Instant
dateTime: Instant,
subConversationId: SubconversationId? = null
) = Event.Conversation.NewMLSMessage(
"eventId",
TestConversation.ID,
null,
subConversationId,
TestUser.USER_ID,
dateTime,
"content".encodeBase64(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.wire.kalium.logic.ProteusFailure
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.SubconversationId
import com.wire.kalium.logic.data.message.MessageContent
import com.wire.kalium.logic.data.message.ProtoContent
import com.wire.kalium.logic.data.message.receipt.ReceiptType
Expand All @@ -35,7 +36,6 @@ import com.wire.kalium.logic.feature.message.ephemeral.EphemeralMessageDeletionH
import com.wire.kalium.logic.framework.TestEvent
import com.wire.kalium.logic.framework.TestUser
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.isRight
import com.wire.kalium.logic.sync.receiver.handler.legalhold.LegalHoldHandler
import com.wire.kalium.util.DateTimeUtil
import io.mockative.Mock
Expand Down Expand Up @@ -393,6 +393,33 @@ class NewMessageEventHandlerTest {
}.wasNotInvoked()
}

@Test
fun givenSubconversationId_whenHandlingInformUserFailure_thenShouldNotSendSystemMessage() = runTest {
val event = TestEvent.newMLSMessageEvent(
dateTime = DateTimeUtil.currentInstant(),
subConversationId = SubconversationId("subconversation-id")
)

val (arrangement, newMessageEventHandler) = Arrangement()
.apply {
withMLSUnpackerReturning(Either.Left(CoreFailure.Unknown(null)))
}
.arrange()

newMessageEventHandler.handleNewMLSMessage(event, TestEvent.liveDeliveryInfo)

coVerify {
arrangement.applicationMessageHandler.handleDecryptionError(
eventId = any(),
conversationId = any(),
messageInstant = any(),
senderUserId = any(),
senderClientId = any(),
content = any()
)
}.wasNotInvoked()
}

private class Arrangement {

@Mock
Expand Down

0 comments on commit ab9c3ac

Please sign in to comment.