Skip to content

Commit

Permalink
runfix: don't try joining mixed conversations twice
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykBuniX committed Jun 23, 2023
1 parent 82e834d commit b7fed06
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/script/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {Configuration} from '../Config';
import {ConnectionRepository} from '../connection/ConnectionRepository';
import {ConnectionService} from '../connection/ConnectionService';
import {ConversationRepository} from '../conversation/ConversationRepository';
import {isMLSConversation} from '../conversation/ConversationSelectors';
import {ConversationService} from '../conversation/ConversationService';
import {MessageRepository} from '../conversation/MessageRepository';
import {CryptographyRepository} from '../cryptography/CryptographyRepository';
Expand Down Expand Up @@ -431,8 +432,10 @@ export class App {
if (supportsMLS()) {
// Once all the messages have been processed and the message sending queue freed we can now:

const mlsConversations = conversations.filter(isMLSConversation);

//join all the mls groups we're member of and have not yet joined (eg. we were not send welcome message)
await initMLSConversations(conversations, this.core);
await initMLSConversations(mlsConversations, this.core);

//add the potential `self` and `team` conversations
await registerUninitializedSelfAndTeamConversations(conversations, selfUser, clientEntity().id, this.core);
Expand Down
25 changes: 14 additions & 11 deletions src/script/mls/MLSConversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import {useMLSConversationState} from './mlsConversationState';

import {ConversationRepository} from '../conversation/ConversationRepository';
import {
isMLSCapableConversation,
isMLSConversation,
isSelfConversation,
isTeamConversation,
MLSCapableConversation,
Expand All @@ -47,13 +45,15 @@ type MLSConversationRepository = Pick<
* @param conversations - all the conversations that the user is part of
* @param core - the instance of the core
*/
export async function initMLSConversations(conversations: Conversation[], core: Account): Promise<void> {
export async function initMLSConversations(
mlsCapableConversations: MLSCapableConversation[],
core: Account,
): Promise<void> {
const mlsService = core.service?.mls;
if (!mlsService) {
throw new Error('MLS service not available');
}

const mlsCapableConversations = conversations.filter(isMLSCapableConversation);
await joinNewMLSConversations(mlsCapableConversations, core);

return mlsService.schedulePeriodicKeyMaterialRenewals(mlsCapableConversations.map(({groupId}) => groupId));
Expand Down Expand Up @@ -104,21 +104,24 @@ async function joinNewMLSConversations(conversations: MLSCapableConversation[],
* @param core instance of the core
*/
export async function registerUninitializedSelfAndTeamConversations(
conversations: Conversation[],
mlsConversations: MLSConversation[],
selfUser: User,
selfClientId: string,
core: Account,
): Promise<void> {
const uninitializedConversations = conversations.filter(
(conversation): conversation is MLSConversation =>
isMLSConversation(conversation) &&
conversation.epoch === 0 &&
(isSelfConversation(conversation) || isTeamConversation(conversation)),
const mlsService = core.service?.mls;

if (!mlsService) {
throw new Error('MLS service not available');
}

const uninitializedConversations = mlsConversations.filter(
conversation => conversation.epoch === 0 && (isSelfConversation(conversation) || isTeamConversation(conversation)),
);

await Promise.all(
uninitializedConversations.map(conversation =>
core.service?.mls.registerConversation(conversation.groupId, [selfUser.qualifiedId], {
mlsService.registerConversation(conversation.groupId, [selfUser.qualifiedId], {
user: selfUser,
client: selfClientId,
}),
Expand Down

0 comments on commit b7fed06

Please sign in to comment.