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

Bot sends a message when a single meeting is edited. #319

Merged
merged 16 commits into from
Oct 19, 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
5 changes: 5 additions & 0 deletions .changeset/chatty-papayas-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nordeck/matrix-meetings-bot': minor
---

Bot sends a message when a single meeting is edited.
7 changes: 6 additions & 1 deletion e2e/src/openXchange.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ test.describe('OpenXchange', () => {

await expect(
aliceElementWebPage.locateChatMessageInRoom(
/10\/04\/2040 10:30 AM CEST to 10\/04\/2040 11:00 AM CEST/,
/October 4, 2040, 10:30 – 11:00 AM GMT\+2/,
),
).toBeVisible();
await expect(
aliceElementWebPage.locateChatMessageInRoom(
/\(previously: October 3, 2040, 10:30 – 11:00 AM GMT\+2\)/,
),
).toBeVisible();

Expand Down
23 changes: 23 additions & 0 deletions e2e/src/recurringMeetings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ test.describe('Recurring Meetings', () => {
aliceMeetingsWidgetPage.getMeeting('My Meeting', '10/04/2040')
.meetingTimeRangeText,
).toHaveText('10:30 AM – 11:30 AM. Recurrence: Every day for 5 times');

await aliceElementWebPage.switchToRoom('My Meeting');

await expect(
aliceElementWebPage.locateChatMessageInRoom(
/A single meeting from a meeting series is moved to October 9, 2040, 10:40 – 11:40 AM GMT\+2/,
),
).toBeVisible();

await expect(
aliceElementWebPage.locateChatMessageInRoom(
/\(previously: October 3, 2040, 10:30 – 11:30 AM GMT\+2/,
),
).toBeVisible();
});

test('should covert a recurring meeting into a single meeting', async ({
Expand Down Expand Up @@ -372,6 +386,7 @@ test.describe('Recurring Meetings', () => {
});

test('should delete a single recurring meeting', async ({
aliceElementWebPage,
aliceMeetingsWidgetPage,
}) => {
await aliceMeetingsWidgetPage.setDateFilter([2040, 10, 1], [2040, 10, 9]);
Expand Down Expand Up @@ -404,6 +419,14 @@ test.describe('Recurring Meetings', () => {
await expect(
aliceMeetingsWidgetPage.getMeeting('My Meeting').card,
).toHaveCount(4);

await aliceElementWebPage.switchToRoom('My Meeting');

await expect(
aliceElementWebPage.locateChatMessageInRoom(
/A single meeting from a meeting series on October 3, 2040, 10:30 – 11:30 AM GMT\+2 is deleted/,
),
).toBeVisible();
});

// TODO: Delete starting from
Expand Down
1 change: 0 additions & 1 deletion matrix-meetings-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"luxon": "^3.3.0",
"matrix-bot-sdk": "^0.6.6",
"mime-types": "^2.1.35",
"moment-timezone": "^0.5.43",
"mustache": "^4.2.0",
"nestjs-pino": "^3.5.0",
"node-fetch": "^2.7.0",
Expand Down
3 changes: 3 additions & 0 deletions matrix-meetings-bot/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import i18next from 'i18next';
import i18nextBackend from 'i18next-fs-backend';
import { Settings } from 'luxon';
import 'reflect-metadata';
import { registerDateRangeFormatter } from './src/dateRangeFormatter';
import translationDe from './src/static/locales/de/translation.json';
import translationEn from './src/static/locales/en/translation.json';

Expand All @@ -36,6 +37,8 @@ i18next.use(i18nextBackend).init({
},
});

registerDateRangeFormatter(i18next);

// We want our tests to be in a reproducible time zone, always resulting in
// the same results, independent from where they are run.
Settings.defaultZone = 'UTC';
Expand Down
12 changes: 6 additions & 6 deletions matrix-meetings-bot/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
NestModule,
} from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import i18next, { TFunction } from 'i18next';
import i18next from 'i18next';
import i18nextFsBackend from 'i18next-fs-backend';
import i18nextMiddleware from 'i18next-http-middleware';
import {
Expand All @@ -49,6 +49,7 @@ import { HealthCheckController } from './controller/HealthCheckController';
import { MeetingController } from './controller/MeetingController';
import { WelcomeWorkflowController } from './controller/WelcomeWorkflowController';
import { WidgetController } from './controller/WidgetController';
import { registerDateRangeFormatter } from './dateRangeFormatter';
import { RoomMatrixEventsReader } from './io/RoomMatrixEventsReader';
import { WidgetLayoutConfigReader } from './io/WidgetLayoutConfigReader';
import { MatrixClientProxyHandler } from './matrix/MatrixClientProxyHandler';
Expand Down Expand Up @@ -170,12 +171,10 @@ const appRuntimeContextFactory: FactoryProvider<Promise<AppRuntimeContext>> = {
inject: [MatrixClient],
};

const i18nFactory: FactoryProvider<Promise<TFunction>> = {
const i18nFactory: FactoryProvider<void> = {
provide: ModuleProviderToken.I18N,
useFactory: async (
appRuntimeContext: AppRuntimeContext,
): Promise<TFunction> => {
return i18next
useFactory: (appRuntimeContext: AppRuntimeContext): void => {
i18next
.use(i18nextFsBackend)
.use(i18nextMiddleware.LanguageDetector)
.init({
Expand All @@ -191,6 +190,7 @@ const i18nFactory: FactoryProvider<Promise<TFunction>> = {
},
preload: appRuntimeContext.supportedLngs,
});
registerDateRangeFormatter(i18next);
},
inject: [AppRuntimeContext],
};
Expand Down
16 changes: 13 additions & 3 deletions matrix-meetings-bot/src/client/MeetingClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,19 @@ describe('MeetingClient', () => {
type: 'net.nordeck.meetings.metadata',
content: {
creator: '@user-id:example',
start_time: '2020-05-07T10:00:00+02:00',
end_time: '2020-05-07T11:00:00+02:00',
auto_deletion_offset: 60,
calendar: [
{
uid: expect.any(String),
dtstart: {
tzid: 'UTC',
value: '20200507T080000',
},
dtend: { tzid: 'UTC', value: '20200507T090000' },
},
],
force_deletion_at: new Date(
'2020-05-07T12:00:00+02:00',
).getTime(),
},
},
],
Expand Down
34 changes: 8 additions & 26 deletions matrix-meetings-bot/src/client/MeetingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ import { MeetingType } from '../model/MeetingType';
import { Room } from '../model/Room';
import { RoomEventName } from '../model/RoomEventName';
import { StateEventName } from '../model/StateEventName';
import {
getForceDeletionTime,
getMeetingEndTime,
getMeetingStartTime,
} from '../shared';
import { getForceDeletionTime } from '../shared';
import { templateHelper } from '../util/TemplateHelper';
import { extractOxRrule } from '../util/extractOxRrule';
import { migrateMeetingTime } from '../util/migrateMeetingTime';
Expand Down Expand Up @@ -180,14 +176,12 @@ export class MeetingClient {
userContext.userId,
);

const meetingStartTime = getMeetingStartTime(
meetingCreate.start_time,
meetingCreate.calendar,
);

const meetingEndTime = getMeetingEndTime(
meetingCreate.end_time,
meetingCreate.calendar,
// change data model if meeting is in old format
const externalRrule = extractOxRrule(meetingCreate);
const calendar = migrateMeetingTime(
meetingCreate,
externalRrule,
undefined,
);

const memberEventsWithReason: DeepReadonlyArray<
Expand All @@ -198,9 +192,7 @@ export class MeetingClient {
const { textReason, htmlReason } = templateHelper.makeInviteReasons(
{
description: meetingCreate.description,
startTime: meetingStartTime,
endTime: meetingEndTime,
calendar: meetingCreate.calendar,
calendar,
},
userContext,
se.state_key === userContext.userId ? undefined : displayname,
Expand Down Expand Up @@ -241,19 +233,9 @@ export class MeetingClient {
params,
);

// change data model if meeting is OX with non-empty rrules
const { start_time, end_time, calendar } = migrateMeetingTime(
meetingCreate,
extractOxRrule(meetingCreate),
);

const meetingsMetadataEventContent: IMeetingsMetadataEventContent = {
start_time,
end_time,
calendar,
force_deletion_at: getForceDeletionTime(autoDeletionOffset, calendar),
auto_deletion_offset:
calendar === undefined ? autoDeletionOffset : undefined,
creator: userContext.userId,
external_data: meetingCreate.external_data,
};
Expand Down
33 changes: 33 additions & 0 deletions matrix-meetings-bot/src/dateFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.
*/

export const fullLongDateFormat = {
hour: 'numeric',
minute: 'numeric',
month: 'long',
year: 'numeric',
day: 'numeric',
timeZoneName: 'short',
};

export const fullNumericDateFormat = {
hour: 'numeric',
minute: 'numeric',
month: 'numeric',
year: 'numeric',
day: 'numeric',
timeZoneName: 'short',
};
30 changes: 30 additions & 0 deletions matrix-meetings-bot/src/dateRangeFormatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2022 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 { i18n } from 'i18next';

export function registerDateRangeFormatter(i18n: i18n) {
i18n.services.formatter?.add(
'daterange',
(value: Date[], lng: string | undefined, options) => {
const [start, end] = value;

const formatter = new Intl.DateTimeFormat(lng, { ...options });
// @ts-ignore: DateTimeFormat#formatRange will be available in TypeScript >4.7.2
return formatter.formatRange(start, end);
},
);
}
4 changes: 1 addition & 3 deletions matrix-meetings-bot/src/model/IMeeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export interface IMeeting {
roomId: string;
title: string;
description: string;
startTime: string;
endTime: string;
calendar?: CalendarEntryDto[];
calendar: CalendarEntryDto[];
widgetIds: string[];
participants: string[];
autoDeletionOffset?: number;
Expand Down
11 changes: 7 additions & 4 deletions matrix-meetings-bot/src/model/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { ICreationContent } from '../matrix/dto/ICreationContent';
import { EncryptionEventContent } from '../matrix/event/EncryptionEventContent';
import { IStateEvent } from '../matrix/event/IStateEvent';
import { getMeetingEndTime, getMeetingStartTime } from '../shared';
import { migrateMeetingTime } from '../util/migrateMeetingTime';
import { IMeeting } from './IMeeting';
import { IMeetingsMetadataEventContent } from './IMeetingsMetadataEventContent';
import { IRoom } from './IRoom';
Expand Down Expand Up @@ -92,9 +92,12 @@ export class Room implements IRoom {
roomId: this._room_id,
creator: content.creator,
parentRoomId: spaceParent?.state_key,
startTime: getMeetingStartTime(content.start_time, content.calendar),
endTime: getMeetingEndTime(content.end_time, content.calendar),
calendar: content.calendar,
calendar:
content.calendar ??
migrateMeetingTime({
start_time: content.start_time,
end_time: content.end_time,
}),
autoDeletionOffset: content.auto_deletion_offset,
title: (
this.roomEventsByName(StateEventName.M_ROOM_NAME_EVENT)[0]
Expand Down
Loading
Loading