Skip to content

Commit

Permalink
feat: SystemMessage about MLS verified conversation (#2104)
Browse files Browse the repository at this point in the history
  • Loading branch information
borichellow authored Sep 29, 2023
1 parent 0cfeb18 commit 91c2b37
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,18 @@ sealed interface Message {
typeKey to "conversationDegradedMLS"
)

is MessageContent.ConversationVerifiedMLS -> mutableMapOf(
typeKey to "conversationVerifiedMLS"
)

is MessageContent.ConversationDegradedProteus -> mutableMapOf(
typeKey to "conversationDegradedProteus"
)

is MessageContent.ConversationVerifiedProteus -> mutableMapOf(
typeKey to "conversationVerifiedProteus"
)

is MessageContent.FederationStopped.ConnectionRemoved -> mutableMapOf(
typeKey to "federationConnectionRemoved"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,10 @@ sealed class MessageContent {

object HistoryLost : System()
object ConversationCreated : System()
object ConversationDegradedMLS : System()
object ConversationDegradedProteus : System()
data object ConversationDegradedMLS : System()
data object ConversationVerifiedMLS : System()
data object ConversationDegradedProteus : System()
data object ConversationVerifiedProteus : System()
sealed class FederationStopped : System() {
data class Removed(val domain: String) : FederationStopped()
data class ConnectionRemoved(val domainList: List<String>) : FederationStopped()
Expand Down Expand Up @@ -344,6 +346,8 @@ fun MessageContent?.getType() = when (this) {
is MessageContent.FederationStopped.ConnectionRemoved -> "Federation.ConnectionRemoved"
is MessageContent.FederationStopped.Removed -> "Federation.Removed"
is MessageContent.Unknown -> "Unknown"
MessageContent.ConversationVerifiedMLS -> "ConversationVerification.Verified.MLS"
MessageContent.ConversationVerifiedProteus -> "ConversationVerification.Verified.Proteus"
null -> "null"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class MessageMapperImpl(
message.id,
message.date
)

else -> LocalNotificationMessage.SelfDeleteMessage(
message.id,
message.date
Expand Down Expand Up @@ -257,6 +258,8 @@ class MessageMapperImpl(
MessageEntity.ContentType.CONVERSATION_DEGRADED_PREOTEUS -> null
MessageEntity.ContentType.COMPOSITE -> null
MessageEntity.ContentType.FEDERATION -> null
MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS -> null
MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS -> null
}
}

Expand Down Expand Up @@ -362,7 +365,9 @@ class MessageMapperImpl(
is MessageEntityContent.ConversationCreated -> MessageContent.ConversationCreated
is MessageEntityContent.MLSWrongEpochWarning -> MessageContent.MLSWrongEpochWarning
is MessageEntityContent.ConversationDegradedMLS -> MessageContent.ConversationDegradedMLS
is MessageEntityContent.ConversationVerifiedMLS -> MessageContent.ConversationVerifiedMLS
is MessageEntityContent.ConversationDegradedProteus -> MessageContent.ConversationDegradedProteus
is MessageEntityContent.ConversationVerifiedProteus -> MessageContent.ConversationVerifiedProteus
is MessageEntityContent.Federation -> when (type) {
MessageEntity.FederationType.DELETE -> MessageContent.FederationStopped.Removed(domainList.first())
MessageEntity.FederationType.CONNECTION_REMOVED -> MessageContent.FederationStopped.ConnectionRemoved(domainList)
Expand Down Expand Up @@ -576,4 +581,7 @@ fun MessageContent.System.toMessageEntityContent(): MessageEntityContent.System
listOf(domain),
MessageEntity.FederationType.DELETE
)

MessageContent.ConversationVerifiedMLS -> MessageEntityContent.ConversationVerifiedMLS
MessageContent.ConversationVerifiedProteus -> MessageEntityContent.ConversationVerifiedProteus
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ internal class PersistMessageUseCaseImpl(
is MessageContent.ConversationCreated -> false
is MessageContent.MLSWrongEpochWarning -> false
MessageContent.ConversationDegradedMLS -> false
MessageContent.ConversationVerifiedMLS -> false
MessageContent.ConversationDegradedProteus -> false
MessageContent.ConversationVerifiedProteus -> false
is MessageContent.Composite -> true
is MessageContent.ButtonAction -> false
is MessageContent.ButtonActionConfirmation -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ internal class MLSConversationsVerificationStatusesHandlerImpl(

conversationRepository.updateVerificationStatus(newStatus, conversation.conversation.id)

if (newStatus == VerificationStatus.DEGRADED) {
notifyUserAboutStateChanges(conversation.conversation.id, VerificationStatus.DEGRADED)
if (newStatus == VerificationStatus.DEGRADED || newStatus == VerificationStatus.VERIFIED) {
notifyUserAboutStateChanges(conversation.conversation.id, newStatus)
}
}

Expand All @@ -91,8 +91,9 @@ internal class MLSConversationsVerificationStatusesHandlerImpl(
conversationId: ConversationId,
updatedStatus: VerificationStatus
) {
// TODO notify about verified too
val content = MessageContent.ConversationDegradedMLS
val content = if (updatedStatus == VerificationStatus.VERIFIED) MessageContent.ConversationVerifiedMLS
else MessageContent.ConversationDegradedMLS

val conversationDegradedMessage = Message.System(
id = uuid4().toString(),
content = content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
verify(arrangement.persistMessageUseCase)
.suspendFunction(arrangement.persistMessageUseCase::invoke)
.with(anyInstanceOf(Message.System::class))
.wasNotInvoked()
.wasInvoked(once)
}

private fun arrange(block: Arrangement.() -> Unit) = Arrangement(block).arrange()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ sealed interface MessageEntity {
val isSelfMessage: Boolean
val expireAfterMs: Long?
val selfDeletionStartDate: Instant?

data class Regular(
override val id: String,
override val conversationId: QualifiedIDEntity,
Expand Down Expand Up @@ -190,8 +191,8 @@ sealed interface MessageEntity {
TEXT, ASSET, KNOCK, MEMBER_CHANGE, MISSED_CALL, RESTRICTED_ASSET,
CONVERSATION_RENAMED, UNKNOWN, FAILED_DECRYPTION, REMOVED_FROM_TEAM, CRYPTO_SESSION_RESET,
NEW_CONVERSATION_RECEIPT_MODE, CONVERSATION_RECEIPT_MODE_CHANGED, HISTORY_LOST, CONVERSATION_MESSAGE_TIMER_CHANGED,
CONVERSATION_CREATED, MLS_WRONG_EPOCH_WARNING, CONVERSATION_DEGRADED_MLS, CONVERSATION_DEGRADED_PREOTEUS,
COMPOSITE, FEDERATION
CONVERSATION_CREATED, MLS_WRONG_EPOCH_WARNING, CONVERSATION_DEGRADED_MLS, CONVERSATION_DEGRADED_PREOTEUS, CONVERSATION_VERIFIED_MLS,
CONVERSATION_VERIFIED_PREOTEUS, COMPOSITE, FEDERATION
}

enum class MemberChangeType {
Expand Down Expand Up @@ -326,8 +327,10 @@ sealed class MessageEntityContent {
data class ConversationMessageTimerChanged(val messageTimer: Long?) : System()
object HistoryLost : System()
object ConversationCreated : System()
object ConversationDegradedMLS : System()
object ConversationDegradedProteus : System()
data object ConversationDegradedMLS : System()
data object ConversationVerifiedMLS : System()
data object ConversationDegradedProteus : System()
data object ConversationVerifiedProteus : System()
data class Federation(val domainList: List<String>, val type: MessageEntity.FederationType) : System()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,18 @@ internal class MessageInsertExtensionImpl(
/* no-op */
}

is MessageEntityContent.ConversationVerifiedMLS -> {
/* no-op */
}

is MessageEntityContent.ConversationDegradedProteus -> {
/* no-op */
}

is MessageEntityContent.ConversationVerifiedProteus -> {
/* no-op */
}

is MessageEntityContent.Federation -> {
messagesQueries.insertFederationTerminatedMessage(
message_id = message.id,
Expand Down Expand Up @@ -292,12 +300,13 @@ internal class MessageInsertExtensionImpl(
is MessageEntityContent.MemberChange,
is MessageEntityContent.NewConversationReceiptMode,
is MessageEntityContent.Federation,
MessageEntityContent.ConversationDegradedMLS,
MessageEntityContent.ConversationVerifiedMLS,
MessageEntityContent.ConversationDegradedProteus,
MessageEntityContent.ConversationVerifiedProteus,
is MessageEntityContent.TeamMemberRemoved -> {
/* no-op */
}

MessageEntityContent.ConversationDegradedMLS -> TODO()
MessageEntityContent.ConversationDegradedProteus -> TODO()
}
}
}
Expand Down Expand Up @@ -383,5 +392,7 @@ internal class MessageInsertExtensionImpl(
is MessageEntityContent.ConversationDegradedProteus -> MessageEntity.ContentType.CONVERSATION_DEGRADED_PREOTEUS
is MessageEntityContent.Composite -> MessageEntity.ContentType.COMPOSITE
is MessageEntityContent.Federation -> MessageEntity.ContentType.FEDERATION
MessageEntityContent.ConversationVerifiedMLS -> MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS
MessageEntityContent.ConversationVerifiedProteus -> MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ object MessageMapper {
MessageEntity.ContentType.UNKNOWN -> MessagePreviewEntityContent.Unknown
MessageEntity.ContentType.FAILED_DECRYPTION -> MessagePreviewEntityContent.Unknown
MessageEntity.ContentType.CRYPTO_SESSION_RESET -> MessagePreviewEntityContent.CryptoSessionReset
MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS -> MessagePreviewEntityContent.Unknown
MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS -> MessagePreviewEntityContent.Unknown
}
}

Expand Down Expand Up @@ -561,6 +563,8 @@ object MessageMapper {
MessageEntity.ContentType.MLS_WRONG_EPOCH_WARNING -> MessageEntityContent.MLSWrongEpochWarning
MessageEntity.ContentType.CONVERSATION_DEGRADED_MLS -> MessageEntityContent.ConversationDegradedMLS
MessageEntity.ContentType.CONVERSATION_DEGRADED_PREOTEUS -> MessageEntityContent.ConversationDegradedProteus
MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS -> MessageEntityContent.ConversationVerifiedMLS
MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS -> MessageEntityContent.ConversationVerifiedProteus
MessageEntity.ContentType.FEDERATION -> MessageEntityContent.Federation(
domainList = federationDomainList.requireField("federationDomainList"),
type = federationType.requireField("federationType")
Expand Down

0 comments on commit 91c2b37

Please sign in to comment.