Add thread notification with server assistance (MSC3773) (#9400)
Co-authored-by: Janne Mareike Koschinski <janne@kuschku.de>
This commit is contained in:
parent
d4f1c573ad
commit
9eb4f8d723
22 changed files with 1014 additions and 142 deletions
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixEventEvent, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { MatrixEventEvent, MatrixEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { stubClient } from "../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
|
@ -24,12 +24,16 @@ import * as testUtils from "../../test-utils";
|
|||
import { NotificationStateEvents } from "../../../src/stores/notifications/NotificationState";
|
||||
|
||||
describe("RoomNotificationState", () => {
|
||||
stubClient();
|
||||
const client = MatrixClientPeg.get();
|
||||
let testRoom: Room;
|
||||
let client: MatrixClient;
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
testRoom = testUtils.mkStubRoom("$aroomid", "Test room", client);
|
||||
});
|
||||
|
||||
it("Updates on event decryption", () => {
|
||||
const testRoom = testUtils.mkStubRoom("$aroomid", "Test room", client);
|
||||
|
||||
const roomNotifState = new RoomNotificationState(testRoom as any as Room);
|
||||
const listener = jest.fn();
|
||||
roomNotifState.addListener(NotificationStateEvents.Update, listener);
|
||||
|
@ -40,4 +44,9 @@ describe("RoomNotificationState", () => {
|
|||
client.emit(MatrixEventEvent.Decrypted, testEvent);
|
||||
expect(listener).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("removes listeners", () => {
|
||||
const roomNotifState = new RoomNotificationState(testRoom as any as Room);
|
||||
expect(() => roomNotifState.destroy()).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
|
60
test/stores/notifications/RoomNotificationStateStore-test.ts
Normal file
60
test/stores/notifications/RoomNotificationStateStore-test.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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 { PendingEventOrdering } from "matrix-js-sdk/src/client";
|
||||
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
import { RoomNotificationStateStore } from "../../../src/stores/notifications/RoomNotificationStateStore";
|
||||
import { stubClient } from "../../test-utils";
|
||||
|
||||
describe("RoomNotificationStateStore", () => {
|
||||
const ROOM_ID = "!roomId:example.org";
|
||||
|
||||
let room;
|
||||
let client;
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
room = new Room(ROOM_ID, client, client.getUserId(), {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not use legacy thread notification store", () => {
|
||||
client.canSupport.set(Feature.ThreadUnreadNotifications, ServerSupport.Stable);
|
||||
expect(RoomNotificationStateStore.instance.getThreadsRoomState(room)).toBeNull();
|
||||
});
|
||||
|
||||
it("use legacy thread notification store", () => {
|
||||
client.canSupport.set(Feature.ThreadUnreadNotifications, ServerSupport.Unsupported);
|
||||
expect(RoomNotificationStateStore.instance.getThreadsRoomState(room)).not.toBeNull();
|
||||
});
|
||||
|
||||
it("does not use legacy thread notification store", () => {
|
||||
client.canSupport.set(Feature.ThreadUnreadNotifications, ServerSupport.Stable);
|
||||
RoomNotificationStateStore.instance.getRoomState(room);
|
||||
expect(RoomNotificationStateStore.instance.getThreadsRoomState(room)).toBeNull();
|
||||
});
|
||||
|
||||
it("use legacy thread notification store", () => {
|
||||
client.canSupport.set(Feature.ThreadUnreadNotifications, ServerSupport.Unsupported);
|
||||
RoomNotificationStateStore.instance.getRoomState(room);
|
||||
expect(RoomNotificationStateStore.instance.getThreadsRoomState(room)).not.toBeNull();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue