Skip to content

Commit

Permalink
refactor code for filtering etherpad based on statekey
Browse files Browse the repository at this point in the history
Signed-off-by: nurjinn jafar <[email protected]>
  • Loading branch information
nurjinjafar committed Sep 19, 2023
1 parent 74021bc commit a3257ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
15 changes: 9 additions & 6 deletions matrix-meetings-bot/src/client/WidgetClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class WidgetClient {
roomTitle: string | undefined,
widgetId: string,
eventContent: IWidgetContent | undefined,
widgetStateKey?: string,
): Promise<void> {
if (!this.isCustomConfiguredWidget(widgetId)) return;

Expand Down Expand Up @@ -166,12 +167,14 @@ export class WidgetClient {
);

if (!_.isEqual(eventContent, newEventContent)) {
await this.client.sendStateEvent(
roomId,
StateEventName.IM_VECTOR_MODULAR_WIDGETS_EVENT,
widgetId,
newEventContent,
);
if (widgetStateKey !== 'etherpad') {
await this.client.sendStateEvent(
roomId,
StateEventName.IM_VECTOR_MODULAR_WIDGETS_EVENT,
widgetId,
newEventContent,
);
}
}
}

Expand Down
9 changes: 3 additions & 6 deletions matrix-meetings-bot/src/service/MeetingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,15 @@ export class MeetingService {
),
);
}
const filteredWidgetIds = room.meeting.widgetIds.filter(
(widget) =>
widget.startsWith(WidgetType.COCKPIT) &&
widget.startsWith(WidgetType.BREAKOUT_SESSIONS),
);
for (const widgetId of filteredWidgetIds) {
for (const widgetId of room.meeting.widgetIds) {
const widgetEventContent = room.widgetEventById(widgetId)?.content;
promises.push(
this.widgetClient.createOrUpdateCustomConfiguredWidget(
room.id,
newMeeting.title,
widgetId,
widgetEventContent,
room.widgetEventById(widgetId)?.state_key,
),
);
}
Expand Down Expand Up @@ -605,6 +601,7 @@ export class MeetingService {
room.meeting.title,
widgetId,
widgetEventContent,
room.widgetEventById(widgetId)?.state_key,
),
);
}
Expand Down
17 changes: 10 additions & 7 deletions matrix-meetings-bot/test/MeetingService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ describe('test relevant functionality of MeetingService', () => {
); // ignores 'whiteboard-with-custom-content.id'
});

test('add 1 widget, then add another', async () => {
test('add 2 widgets, then add 2 other', async () => {
// room has a poll widget
// cockpit is there after the meeting room was created
const parentRoom: any = create_test_meeting(
Expand All @@ -1725,8 +1725,8 @@ describe('test relevant functionality of MeetingService', () => {
parentRoom,
);

// add whiteboard
const widgets = ['whiteboard'];
// add whiteboard & etherpad
const widgets = ['whiteboard', 'etherpad'];
await meetingService.handleWidgets(
userContext,
new MeetingWidgetsHandleDto(parentId, true, widgets),
Expand All @@ -1735,24 +1735,27 @@ describe('test relevant functionality of MeetingService', () => {
const e = StateEventName.IM_VECTOR_MODULAR_WIDGETS_EVENT;
verify(
clientMock.sendStateEvent(parentId, e, anything(), anything()),
).times(2);
).times(3);

expect(callInfo(0, SendStateEventParameter.Content, e).type).toBe(
'net.nordeck.poll',
); // updated poll
expect(callInfo(1, SendStateEventParameter.Content, e).type).toBe(
'net.nordeck.whiteboard',
); // added whiteboard
expect(callInfo(2, SendStateEventParameter.Content, e).type).toBe(
'm.etherpad',
); // added etherpad
});

test('add 2 widgets, then remove 1', async () => {
// room has 2 widgets
test('add 3 widgets, then remove 1', async () => {
// room has 3 widgets
// assume that there's no cockpit widget
const parentRoom: any = create_test_meeting(
CURRENT_USER,
PARENT_MEETING_ROOM_ID,
null,
['poll', 'whiteboard'],
['poll', 'whiteboard', 'etherpad'],
);
when(clientMock.getRoomState(PARENT_MEETING_ROOM_ID)).thenResolve(
parentRoom,
Expand Down

0 comments on commit a3257ab

Please sign in to comment.