Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TeamRepository): Prevent removal of MLS from supported protocols if it was previously supported #18797

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I'm reading it well, but this should be based on the client capability to support MLS, not the configuration of the team

}

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 && teamSupportedProtocols?.length > 0) {
return [...new Set([...teamSupportedProtocols, ConversationProtocol.MLS])];
}

// 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
Loading