Skip to content

Commit

Permalink
feat(TeamRepository): Prevent removal of MLS from supported protocols…
Browse files Browse the repository at this point in the history
… if it was previously supported
  • Loading branch information
przemvs committed Feb 25, 2025
1 parent 43dd3af commit 9b2d334
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions src/script/team/TeamRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

import {ConversationRolesList, ConversationProtocol} from '@wireapp/api-client/lib/conversation';
import {ConversationProtocol, ConversationRolesList} from '@wireapp/api-client/lib/conversation';
import type {
TeamConversationDeleteEvent,
TeamDeleteEvent,
Expand All @@ -26,7 +26,7 @@ import type {
TeamMemberLeaveEvent,
} from '@wireapp/api-client/lib/event';
import {TEAM_EVENT} from '@wireapp/api-client/lib/event/TeamEvent';
import {FeatureStatus, FeatureList, FEATURE_KEY} from '@wireapp/api-client/lib/team/feature/';
import {FEATURE_KEY, FeatureList, FeatureStatus} from '@wireapp/api-client/lib/team/feature/';
import type {PermissionsData} from '@wireapp/api-client/lib/team/member/PermissionsData';
import type {TeamData} from '@wireapp/api-client/lib/team/team/TeamData';
import {QualifiedId} from '@wireapp/api-client/lib/user';
Expand Down Expand Up @@ -57,12 +57,14 @@ import {NOTIFICATION_HANDLING_STATE} from '../event/NotificationHandlingState';
import {IntegrationMapper} from '../integration/IntegrationMapper';
import {ServiceEntity} from '../integration/ServiceEntity';
import {scheduleRecurringTask, updateRemoteConfigLogger} from '../lifecycle/updateRemoteConfigs';
import {MLSMigrationStatus, getMLSMigrationStatus} from '../mls/MLSMigration/migrationStatus';
import {getMLSMigrationStatus, MLSMigrationStatus} from '../mls/MLSMigration/migrationStatus';
import {APIClient} from '../service/APIClientSingleton';
import {ROLE, ROLE as TEAM_ROLE, roleFromTeamPermissions} from '../user/UserPermission';
import {UserRepository} from '../user/UserRepository';
import {UserState} from '../user/UserState';

export const HAS_PERSISTED_SUPPORTED_PROTOCOLS = 'HAS_PERSISTED_SUPPORTED_PROTOCOLS';

export interface AccountInfo {
accentID: number;
availability?: Availability.Type;
Expand All @@ -87,6 +89,8 @@ export class TeamRepository extends TypedEventEmitter<Events> {
private readonly assetRepository: AssetRepository;
private backendSupportsMLS: boolean | null = null;

private hasPersistedSupportedProtocols: boolean = localStorage.getItem(HAS_PERSISTED_SUPPORTED_PROTOCOLS) === 'true';

constructor(
userRepository: UserRepository,
assetRepository: AssetRepository,
Expand Down Expand Up @@ -120,6 +124,10 @@ export class TeamRepository extends TypedEventEmitter<Events> {
);
}

private updatePersistedSupportedProtocols() {
localStorage.setItem(HAS_PERSISTED_SUPPORTED_PROTOCOLS, 'true');
}

/**
* Will init the team configuration and all the team members from the contact list.
* @param teamId the Id of the team to init
Expand All @@ -134,6 +142,17 @@ export class TeamRepository extends TypedEventEmitter<Events> {

this.teamState.teamFeatures(newFeatureList);

if (newFeatureList[FEATURE_KEY.MLS]?.config?.supportedProtocols?.includes(ConversationProtocol.MLS)) {
this.updatePersistedSupportedProtocols();
}

if (this.hasPersistedSupportedProtocols && newFeatureList?.[FEATURE_KEY.MLS]?.config.supportedProtocols) {
newFeatureList[FEATURE_KEY.MLS].config.supportedProtocols = [
ConversationProtocol.MLS,
ConversationProtocol.PROTEUS,
];
}

if (!teamId) {
return {team: undefined, features: {}, members: []};
}
Expand All @@ -157,6 +176,22 @@ export class TeamRepository extends TypedEventEmitter<Events> {
const prevFeatureList = this.teamState.teamFeatures();
const newFeatureList = await this.teamService.getAllTeamFeatures();

if (
this.hasPersistedSupportedProtocols &&
prevFeatureList?.[FEATURE_KEY.MLS]?.config.supportedProtocols &&
newFeatureList?.[FEATURE_KEY.MLS]?.config.supportedProtocols
) {
prevFeatureList[FEATURE_KEY.MLS].config.supportedProtocols = [
ConversationProtocol.MLS,
ConversationProtocol.PROTEUS,
];

newFeatureList[FEATURE_KEY.MLS].config.supportedProtocols = [
ConversationProtocol.MLS,
ConversationProtocol.PROTEUS,
];
}

this.teamState.teamFeatures(newFeatureList);

this.emit('featureConfigUpdated', {prevFeatureList, newFeatureList});
Expand All @@ -165,6 +200,8 @@ export class TeamRepository extends TypedEventEmitter<Events> {
!prevFeatureList?.[FEATURE_KEY.MLS]?.config.supportedProtocols.includes(ConversationProtocol.MLS) &&
newFeatureList?.[FEATURE_KEY.MLS]?.config.supportedProtocols.includes(ConversationProtocol.MLS)
) {
this.updatePersistedSupportedProtocols();

PrimaryModal.show(PrimaryModal.type.CONFIRM, {
primaryAction: {
action: () => window.location.reload(),
Expand Down Expand Up @@ -502,6 +539,10 @@ export class TeamRepository extends TypedEventEmitter<Events> {

const teamSupportedProtocols = mlsFeature.config.supportedProtocols;

if (this.hasPersistedSupportedProtocols) {
return [...teamSupportedProtocols, ConversationProtocol.MLS];

Check failure on line 543 in src/script/team/TeamRepository.ts

View workflow job for this annotation

GitHub Actions / test

TeamRepository › getTeamSupportedProtocols › returns proteus if supported protocols field does not exist on mls feature

TypeError: teamSupportedProtocols is not iterable at TeamRepository.teamSupportedProtocols [as getTeamSupportedProtocols] (src/script/team/TeamRepository.ts:543:18) at Object.getTeamSupportedProtocols (src/script/team/TeamRepository.test.ts:194:34)
}

// For old teams (created on some older backend versions) supportedProtocols field might not exist or be empty,
// we fallback to proteus in this case.
return teamSupportedProtocols && teamSupportedProtocols.length > 0
Expand Down

0 comments on commit 9b2d334

Please sign in to comment.