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: refresh self protocols on team refresh #15897

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions src/script/self/SelfRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,25 @@ describe('SelfRepository', () => {
expect(selfRepository.refreshSelfSupportedProtocols).toHaveBeenCalled();
});

it('refreshes self supported protocols on team refresh', async () => {
const selfRepository = await testFactory.exposeSelfActors();

const selfUser = selfRepository['userState'].self()!;

const initialProtocols = [ConversationProtocol.PROTEUS];
selfUser.supportedProtocols(initialProtocols);

const evaluatedProtocols = [ConversationProtocol.PROTEUS, ConversationProtocol.MLS];

jest.spyOn(selfRepository, 'evaluateSelfSupportedProtocols').mockResolvedValueOnce(evaluatedProtocols);
jest.spyOn(selfRepository['selfService'], 'putSupportedProtocols');

await act(async () => selfRepository['teamRepository'].emit('teamRefreshed'));

expect(selfUser.supportedProtocols()).toEqual(evaluatedProtocols);
expect(selfRepository['selfService'].putSupportedProtocols).toHaveBeenCalledWith(evaluatedProtocols);
});

it('refreshes self supported protocols after mls feature is enabled', async () => {
const selfRepository = await testFactory.exposeSelfActors();

Expand Down
1 change: 1 addition & 0 deletions src/script/self/SelfRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class SelfRepository {
// It's possible that they have removed proteus client, and now all their clients are mls-capable.
amplify.subscribe(WebAppEvents.CLIENT.REMOVE, this.refreshSelfSupportedProtocols);

teamRepository.on('teamRefreshed', this.refreshSelfSupportedProtocols);
teamRepository.on('featureUpdated', ({event, prevFeatureList}) => {
if (event.name === FEATURE_KEY.MLS) {
void this.handleMLSFeatureUpdate(event.data, prevFeatureList?.[FEATURE_KEY.MLS]);
Expand Down
2 changes: 2 additions & 0 deletions src/script/team/TeamRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Events = {
prevFeatureList?: FeatureList;
event: TeamFeatureConfigurationUpdateEvent;
};
teamRefreshed: void;
};

export class TeamRepository extends TypedEventEmitter<Events> {
Expand Down Expand Up @@ -156,6 +157,7 @@ export class TeamRepository extends TypedEventEmitter<Events> {
try {
await this.getTeam();
await this.updateFeatureConfig();
this.emit('teamRefreshed');
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: maybe we could narrow down the scope of this event to just featureConfigUpdated and move it to the updateFeatureConfig function (this way we are sure this event will emit even if we just update the config and not the entire team). WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updateFeatureConfig is called every time any of the feature is updated though, so we would refresh protocols too often in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hummm I see. ok then, fine for now 👍

} catch (error) {
this.logger.error(error);
}
Expand Down
Loading