Skip to content

Commit

Permalink
feat: check if call epoch change event was fired by parent conversati…
Browse files Browse the repository at this point in the history
…on (#14788)

* feat: check if call epoch change event was fired by parent conversation

* refactor: inject conversationState directly to mlsConference module method

* chore: add comments
  • Loading branch information
PatrykBuniX committed Mar 7, 2023
1 parent 1209baa commit 9814a3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/script/calling/mlsConference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {constructFullyQualifiedClientId} from '@wireapp/core/lib/util/fullyQuali

import {SubconversationEpochInfoMember} from './CallingRepository';

import {ConversationState} from '../conversation/ConversationState';

const KEY_LENGTH = 32;

const generateSubconversationMembers = async (
Expand Down Expand Up @@ -89,7 +91,7 @@ export const getSubconversationEpochInfo = async (
};

export const subscribeToEpochUpdates = async (
{mlsService}: {mlsService: MLSService},
{mlsService, conversationState}: {mlsService: MLSService; conversationState: ConversationState},
conversationId: QualifiedId,
onEpochUpdate: (info: {
members: SubconversationEpochInfoMember[];
Expand All @@ -104,11 +106,26 @@ export const subscribeToEpochUpdates = async (

const forwardNewEpoch = async ({groupId, epoch}: {groupId: string; epoch: number}) => {
if (groupId !== subconversationGroupId) {
return;
// if the epoch update did not happen in the subconversation directly, check if it happened in the parent conversation
const parentConversation = conversationState.findConversationByGroupId(groupId);
if (!parentConversation) {
return;
}

const foundSubconversationGroupId = await mlsService.getGroupIdFromConversationId?.(
parentConversation.qualifiedId,
SUBCONVERSATION_ID.CONFERENCE,
);

// if the conference subconversation of parent conversation is not known, ignore the epoch update
if (foundSubconversationGroupId !== subconversationGroupId) {
return;
}
}

const {keyLength, secretKey, members} = await getSubconversationEpochInfo({mlsService}, conversationId);
onEpochUpdate({epoch: Number(epoch), keyLength, secretKey, members});

return onEpochUpdate({epoch: Number(epoch), keyLength, secretKey, members});
};

mlsService.on('newEpoch', forwardNewEpoch);
Expand Down
4 changes: 2 additions & 2 deletions src/script/view_model/CallingViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class CallingViewModel {

if (conversation.isUsingMLSProtocol) {
const unsubscribe = await subscribeToEpochUpdates(
{mlsService: this.mlsService},
{mlsService: this.mlsService, conversationState: this.conversationState},
conversation.qualifiedId,
({epoch, keyLength, secretKey, members}) => {
this.callingRepository.setEpochInfo(conversation.qualifiedId, {epoch, keyLength, secretKey}, members);
Expand All @@ -176,7 +176,7 @@ export class CallingViewModel {

const joinOngoingMlsConference = async (call: Call) => {
const unsubscribe = await subscribeToEpochUpdates(
{mlsService: this.mlsService},
{mlsService: this.mlsService, conversationState: this.conversationState},
call.conversationId,
({epoch, keyLength, secretKey, members}) => {
this.callingRepository.setEpochInfo(call.conversationId, {epoch, keyLength, secretKey}, members);
Expand Down

0 comments on commit 9814a3d

Please sign in to comment.