Skip to content

Commit

Permalink
refactor code for generating uuid
Browse files Browse the repository at this point in the history
Signed-off-by: nurjinn jafar <[email protected]>
  • Loading branch information
nurjinjafar committed Sep 22, 2023
1 parent a3257ab commit b18619b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 4 additions & 2 deletions matrix-meetings-bot/src/IEventContentParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { base32 } from 'rfc4648';
import { v4 as uuiv4 } from 'uuid';

export interface IEventContentParams {
room_id?: string;
Expand All @@ -32,13 +31,16 @@ class EventContentParamsHelper {
const base32RoomId = roomId
? base32.stringify(Buffer.from(roomId), { pad: false })
: undefined;
const base32AsUuid = roomId
? base32.stringify(Buffer.from(roomId), { pad: true }).slice(0, 25)
: undefined;
const nonNullTitle = title || '';

return {
room_id: roomId,
base32_room_id: base32RoomId,
title: nonNullTitle,
uuid: uuiv4(),
uuid: base32AsUuid,
};
}
}
Expand Down
15 changes: 6 additions & 9 deletions matrix-meetings-bot/src/client/WidgetClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export class WidgetClient {
roomTitle: string | undefined,
widgetId: string,
eventContent: IWidgetContent | undefined,
widgetStateKey?: string,
): Promise<void> {
if (!this.isCustomConfiguredWidget(widgetId)) return;

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

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

Expand Down
2 changes: 0 additions & 2 deletions matrix-meetings-bot/src/service/MeetingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ export class MeetingService {
newMeeting.title,
widgetId,
widgetEventContent,
room.widgetEventById(widgetId)?.state_key,
),
);
}
Expand Down Expand Up @@ -601,7 +600,6 @@ export class MeetingService {
room.meeting.title,
widgetId,
widgetEventContent,
room.widgetEventById(widgetId)?.state_key,
),
);
}
Expand Down
9 changes: 6 additions & 3 deletions matrix-meetings-bot/test/MeetingService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1771,20 +1771,23 @@ describe('test relevant functionality of MeetingService', () => {
const e = StateEventName.IM_VECTOR_MODULAR_WIDGETS_EVENT;
verify(
clientMock.sendStateEvent(parentId, e, anything(), anything()),
).times(3);
).times(4);

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

// verify removed whiteboard
expect(callInfo(2, SendStateEventParameter.StateKey, e)).toBe(
expect(callInfo(3, SendStateEventParameter.StateKey, e)).toBe(
'whiteboard',
);
expect(callInfo(2, SendStateEventParameter.Content, e)).toStrictEqual({});
expect(callInfo(3, SendStateEventParameter.Content, e)).toStrictEqual({});
});

test('no layout config', async () => {
Expand Down

0 comments on commit b18619b

Please sign in to comment.