Skip to content

Commit

Permalink
Merge pull request #280 from nordeck/nic/fix/3461-changes_in_meeting_…
Browse files Browse the repository at this point in the history
…details_updates_other_widgets

PB-3461 changes in meeting details updates other widgets
  • Loading branch information
nurjinjafar authored Sep 28, 2023
2 parents 5a2328f + 53d22cf commit bcca276
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-rabbits-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nordeck/matrix-meetings-bot': patch
---

Provide a base32_room_id50 template parameter for widget urls that can for example be used to template the pad-id of Etherpad.
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ The following content is available:

- `room_id`: the ID of the current room.
- `base32_room_id`: the base32 encoded room id as needed for Jitsi.
- `base32_room_id50`: the base32 encoded room id with max character limit of 50 as needed for Etherpad.
- `title`: the title of the meeting (=the room name).
- `uuid`: a random UUID.
- `encodeURIComponent()`: a function to encode any value to make it URL-safe
Expand Down
4 changes: 4 additions & 0 deletions matrix-meetings-bot/src/IEventContentParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { v4 as uuiv4 } from 'uuid';
export interface IEventContentParams {
room_id?: string;
base32_room_id?: string;
base32_room_id50?: string;
title?: string;
uuid?: string;
}
Expand All @@ -32,11 +33,14 @@ class EventContentParamsHelper {
const base32RoomId = roomId
? base32.stringify(Buffer.from(roomId), { pad: false })
: undefined;
// etherpad has limitations of max 50 characters on pad names.
const base32RoomId50 = base32RoomId?.slice(0, 50);
const nonNullTitle = title || '';

return {
room_id: roomId,
base32_room_id: base32RoomId,
base32_room_id50: base32RoomId50,
title: nonNullTitle,
uuid: uuiv4(),
};
Expand Down
1 change: 0 additions & 1 deletion matrix-meetings-bot/src/service/MeetingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ export class MeetingService {
),
);
}

for (const widgetId of room.meeting.widgetIds) {
const widgetEventContent = room.widgetEventById(widgetId)?.content;
promises.push(
Expand Down
68 changes: 68 additions & 0 deletions matrix-meetings-bot/test/EventContentParams.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2023 Nordeck IT + Consulting GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
IEventContentParams,
eventContentParams,
} from '../src/IEventContentParams';

describe('EventContentParamsHelper', () => {
test('should create an instance with room_id and title', () => {
const params: IEventContentParams = eventContentParams.newInstance(
'roomId123',
'Sample Title',
);

expect(params.room_id).toBe('roomId123');
expect(params.title).toBe('Sample Title');
expect(params.base32_room_id).toBe('OJXW63KJMQYTEMY');
expect(params.base32_room_id50).toBe('OJXW63KJMQYTEMY');
expect(params.base32_room_id50?.length).toBeLessThanOrEqual(50);
expect(params.uuid).toBeDefined();
});

test('should create an instance with undefined room_id and empty title', () => {
const params: IEventContentParams = eventContentParams.newInstance(
undefined,
'',
);

expect(params.room_id).toBeUndefined();
expect(params.title).toBe('');
expect(params.base32_room_id).toBeUndefined();
expect(params.base32_room_id50).toBeUndefined();
expect(params.uuid).toBeDefined();
});

test('should truncate base32_room_id to 50 characters if longer', () => {
const longRoomId = 'a'.repeat(60); // Create a roomId longer than 50 characters
const params: IEventContentParams = eventContentParams.newInstance(
longRoomId,
'Sample Title',
);

expect(params.room_id).toBe(longRoomId);
expect(params.title).toBe('Sample Title');
expect(params.base32_room_id).toBe(
'MFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLB',
);
expect(params.base32_room_id50).toBe(
'MFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMFQWCYLBMF',
);
expect(params.base32_room_id50?.length).toBe(50); // Ensure it's truncated to 50 characters
expect(params.uuid).toBeDefined();
});
});
3 changes: 2 additions & 1 deletion matrix-meetings-bot/test/EventContentRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('EventContentRenderer', () => {
const params: IEventContentParams = {
room_id: 'room1',
base32_room_id: 'room1',
base32_room_id50: 'roomId50',
title: 'Demo Room',
};

Expand Down Expand Up @@ -94,7 +95,7 @@ describe('EventContentRenderer', () => {
expect(json).toStrictEqual({
id: 'etherpad',
type: 'm.etherpad',
url: 'https://some_url/p/room1?matrix_display_name=$matrix_display_name&matrix_avatar_url=$matrix_avatar_url&matrix_user_id=$matrix_user_id&matrix_room_id=$matrix_room_id&theme=$theme&showChat=false',
url: 'https://some_url/p/roomId50?matrix_display_name=$matrix_display_name&matrix_avatar_url=$matrix_avatar_url&matrix_user_id=$matrix_user_id&matrix_room_id=$matrix_room_id&theme=$theme&showChat=false',
name: '',
});
});
Expand Down
2 changes: 1 addition & 1 deletion matrix-meetings-bot/test/conf/test_default_events.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"type": "im.vector.modular.widgets",
"content": {
"type": "m.etherpad",
"url": "https://some_url/p/{{#encodeURIComponent}}{{base32_room_id}}{{/encodeURIComponent}}?matrix_display_name=$matrix_display_name&matrix_avatar_url=$matrix_avatar_url&matrix_user_id=$matrix_user_id&matrix_room_id=$matrix_room_id&theme=$theme&showChat=false",
"url": "https://some_url/p/{{#encodeURIComponent}}{{base32_room_id50}}{{/encodeURIComponent}}?matrix_display_name=$matrix_display_name&matrix_avatar_url=$matrix_avatar_url&matrix_user_id=$matrix_user_id&matrix_room_id=$matrix_room_id&theme=$theme&showChat=false",
"name": "{{appConfig.etherpad_name}}"
}
},
Expand Down

0 comments on commit bcca276

Please sign in to comment.