@@ -46,6 +46,7 @@ import {
4646 CONVERSATION_EVENT ,
4747 ConversationProtocolUpdateEvent ,
4848 ConversationAddPermissionUpdateEvent ,
49+ ConversationMLSResetEvent ,
4950} from '@wireapp/api-client/lib/event' ;
5051import { BackendErrorLabel } from '@wireapp/api-client/lib/http/' ;
5152import type { BackendError } from '@wireapp/api-client/lib/http/' ;
@@ -1110,9 +1111,15 @@ export class ConversationRepository {
11101111 return this . updateConversations ( this . conversationState . archivedConversations ( ) ) ;
11111112 }
11121113
1113- private async updateConversationFromBackend ( conversationEntity : Conversation ) {
1114+ private async updateConversationFromBackend ( conversationEntity : Conversation ) : Promise < void > {
11141115 const conversationData = await this . conversationService . getConversationById ( conversationEntity ) ;
1115- const { name, message_timer, type} = conversationData ;
1116+ const { name, message_timer, type, group_id : groupId , epoch} = conversationData ;
1117+
1118+ if ( groupId && typeof epoch === 'number' ) {
1119+ ConversationMapper . updateProperties ( conversationEntity , { groupId, epoch} ) ;
1120+ }
1121+
1122+ ConversationMapper . updateProperties ( conversationEntity , { name, type} ) ;
11161123 ConversationMapper . updateProperties ( conversationEntity , { name, type} ) ;
11171124 ConversationMapper . updateSelfStatus ( conversationEntity , { message_timer} ) ;
11181125 }
@@ -2791,9 +2798,9 @@ export class ConversationRepository {
27912798 * @returns Resolves with updated conversation entity
27922799 */
27932800 private async refreshConversationProtocolProperties ( conversation : Conversation ) {
2794- //refetch the conversation to get all new fields (groupId, ciphersuite, epoch and new protocol)
2801+ // refetch the conversation to get all new fields (groupId, ciphersuite, epoch and new protocol)
27952802 const remoteConversationData = await this . conversationService . getConversationById ( conversation . qualifiedId ) ;
2796- //update fields that came after protocol update
2803+ // update fields that came after protocol update
27972804 const { cipher_suite : cipherSuite , epoch, group_id : newGroupId , protocol : newProtocol } = remoteConversationData ;
27982805 const updatedConversation = ConversationMapper . updateProperties ( conversation , {
27992806 cipherSuite,
@@ -3192,7 +3199,11 @@ export class ConversationRepository {
31923199
31933200 const inSelfConversation = this . conversationState . isSelfConversation ( conversationId ) ;
31943201 if ( inSelfConversation ) {
3195- const typesInSelfConversation = [ CONVERSATION_EVENT . MEMBER_UPDATE , ClientEvent . CONVERSATION . MESSAGE_HIDDEN ] ;
3202+ const typesInSelfConversation = [
3203+ CONVERSATION_EVENT . MEMBER_UPDATE ,
3204+ CONVERSATION_EVENT . MLS_RESET ,
3205+ ClientEvent . CONVERSATION . MESSAGE_HIDDEN ,
3206+ ] ;
31963207
31973208 const isExpectedType = typesInSelfConversation . includes ( type ) ;
31983209 if ( ! isExpectedType ) {
@@ -3406,6 +3417,9 @@ export class ConversationRepository {
34063417 case CONVERSATION_EVENT . MLS_WELCOME_MESSAGE :
34073418 return this . onMLSWelcomeMessage ( conversationEntity ) ;
34083419
3420+ case CONVERSATION_EVENT . MLS_RESET :
3421+ return this . onMLSResetMessage ( conversationEntity , eventJson ) ;
3422+
34093423 case ClientEvent . CONVERSATION . ASSET_ADD :
34103424 return this . onAssetAdd ( conversationEntity , eventJson ) ;
34113425
@@ -4101,6 +4115,28 @@ export class ConversationRepository {
41014115 await this . resolve1To1Conversation ( otherUserId ) ;
41024116 }
41034117
4118+ /**
4119+ * A user has reset an MLS Conversation.
4120+ * This means group id and epoch have changed, so we need to
4121+ * update the conversation to the latest group id and epoch.
4122+ *
4123+ * @param conversationEntity Conversation entity user has received a welcome message in
4124+ * @returns Resolves when the event was handled
4125+ */
4126+ private async onMLSResetMessage ( conversationEntity : Conversation , eventJson : ConversationMLSResetEvent ) {
4127+ try {
4128+ if ( ! isMLSConversation ( conversationEntity ) ) {
4129+ return ;
4130+ }
4131+
4132+ await this . core . service ?. conversation . wipeMLSConversation ( eventJson . data . group_id ) ;
4133+
4134+ await this . refreshConversationProtocolProperties ( conversationEntity ) ;
4135+ } catch ( error ) {
4136+ this . logger . error ( `Failed to reset MLS conversation ${ conversationEntity . id } ` , error ) ;
4137+ }
4138+ }
4139+
41044140 /**
41054141 * A user started or stopped typing in a conversation.
41064142 *
0 commit comments