1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-06 12:02:40 +03:00

Add custom notification handling for MSC3401 call events (#2720)

This commit is contained in:
Šimon Brandner
2022-10-06 16:40:30 +02:00
committed by GitHub
parent a1b046b5d8
commit 6e5326f9c8
3 changed files with 142 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
import * as utils from "../test-utils/test-utils";
import { PushProcessor } from "../../src/pushprocessor";
import { EventType, MatrixClient, MatrixEvent } from "../../src";
import { IActionsObject, PushProcessor } from "../../src/pushprocessor";
import { EventType, IContent, MatrixClient, MatrixEvent } from "../../src";
describe('NotificationService', function() {
const testUserId = "@ali:matrix.org";
@@ -336,4 +336,102 @@ describe('NotificationService', function() {
enabled: true,
}, testEvent)).toBe(true);
});
describe("performCustomEventHandling()", () => {
const getActionsForEvent = (prevContent: IContent, content: IContent): IActionsObject => {
testEvent = utils.mkEvent({
type: "org.matrix.msc3401.call",
room: testRoomId,
user: "@alice:foo",
skey: "state_key",
event: true,
content: content,
prev_content: prevContent,
});
return pushProcessor.actionsForEvent(testEvent);
};
const assertDoesNotify = (actions: IActionsObject): void => {
expect(actions.notify).toBeTruthy();
expect(actions.tweaks.sound).toBeTruthy();
expect(actions.tweaks.highlight).toBeFalsy();
};
const assertDoesNotNotify = (actions: IActionsObject): void => {
expect(actions.notify).toBeFalsy();
expect(actions.tweaks.sound).toBeFalsy();
expect(actions.tweaks.highlight).toBeFalsy();
};
it.each(
["m.ring", "m.prompt"],
)("should notify when new group call event appears with %s intent", (intent: string) => {
assertDoesNotify(getActionsForEvent({}, {
"m.intent": intent,
"m.type": "m.voice",
"m.name": "Call",
}));
});
it("should notify when a call is un-terminated", () => {
assertDoesNotify(getActionsForEvent({
"m.intent": "m.ring",
"m.type": "m.voice",
"m.name": "Call",
"m.terminated": "All users left",
}, {
"m.intent": "m.ring",
"m.type": "m.voice",
"m.name": "Call",
}));
});
it("should not notify when call is terminated", () => {
assertDoesNotNotify(getActionsForEvent({
"m.intent": "m.ring",
"m.type": "m.voice",
"m.name": "Call",
}, {
"m.intent": "m.ring",
"m.type": "m.voice",
"m.name": "Call",
"m.terminated": "All users left",
}));
});
it("should ignore with m.room intent", () => {
assertDoesNotNotify(getActionsForEvent({}, {
"m.intent": "m.room",
"m.type": "m.voice",
"m.name": "Call",
}));
});
describe("ignoring non-relevant state changes", () => {
it("should ignore intent changes", () => {
assertDoesNotNotify(getActionsForEvent({
"m.intent": "m.ring",
"m.type": "m.voice",
"m.name": "Call",
}, {
"m.intent": "m.ring",
"m.type": "m.video",
"m.name": "Call",
}));
});
it("should ignore name changes", () => {
assertDoesNotNotify(getActionsForEvent({
"m.intent": "m.ring",
"m.type": "m.voice",
"m.name": "Call",
}, {
"m.intent": "m.ring",
"m.type": "m.voice",
"m.name": "New call",
}));
});
});
});
});