From 11a037d9cffa54119ee349247ae16aabe5001e43 Mon Sep 17 00:00:00 2001 From: "marc.sirisak" Date: Thu, 5 Dec 2024 17:26:46 +0100 Subject: [PATCH] TCHAP: remove notification power levels changes --- patches/tchap-modifications.json | 6 +++ src/Unread.ts | 1 + test/unit-tests/tchap/Unread-test.ts | 68 ++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 test/unit-tests/tchap/Unread-test.ts diff --git a/patches/tchap-modifications.json b/patches/tchap-modifications.json index 61b80c3fbd..fbfb4f3548 100644 --- a/patches/tchap-modifications.json +++ b/patches/tchap-modifications.json @@ -125,5 +125,11 @@ "files": [ "src/components/views/settings/PowerLevelSelector.tsx" ] + }, + "remove-notification-powerlevel-change": { + "issue": "https://github.com/tchapgouv/tchap-web-v4/issues/1176", + "files": [ + "src/Unread.ts" + ] } } \ No newline at end of file diff --git a/src/Unread.ts b/src/Unread.ts index 06d2344938..560837dd2e 100644 --- a/src/Unread.ts +++ b/src/Unread.ts @@ -36,6 +36,7 @@ export function eventTriggersUnreadCount(client: MatrixClient, ev: MatrixEvent): case EventType.RoomServerAcl: case M_BEACON.name: case M_BEACON.altName: + case EventType.RoomPowerLevels: // :TCHAP: remove-notification-powerlevel-change return false; } diff --git a/test/unit-tests/tchap/Unread-test.ts b/test/unit-tests/tchap/Unread-test.ts new file mode 100644 index 0000000000..855b8d65fd --- /dev/null +++ b/test/unit-tests/tchap/Unread-test.ts @@ -0,0 +1,68 @@ +/* +Copyright 2024 New Vector Ltd. +Copyright 2022 The Matrix.org Foundation C.I.C. + +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only +Please see LICENSE files in the repository root for full details. +*/ + +import { mocked } from "jest-mock"; +import { MatrixEvent, EventType } from "matrix-js-sdk/src/matrix"; + +import { haveRendererForEvent } from "~tchap-web/src/events/EventTileFactory"; +import { stubClient } from "~tchap-web/test/test-utils"; +import { eventTriggersUnreadCount } from "~tchap-web/src/Unread"; +import { MatrixClientPeg } from "~tchap-web/src/MatrixClientPeg"; + +jest.mock("~tchap-web/src/events/EventTileFactory", () => ({ + haveRendererForEvent: jest.fn(), +})); + +describe("Unread", () => { + // A different user. + const aliceId = "@alice:server.org"; + stubClient(); + const client = MatrixClientPeg.safeGet(); + + // :TCHAP: remove-notification-powerlevel-change + describe("Don't show power levels change in notification", () => { + // setup events + const powerLevelEvent = new MatrixEvent({ + type: EventType.RoomPowerLevels, + sender: client.getUserId()!, + }); + + beforeEach(() => { + jest.clearAllMocks(); + mocked(haveRendererForEvent).mockClear().mockReturnValue(false); + }); + + it("returns false when the event was sent by the current user", () => { + expect(eventTriggersUnreadCount(client, powerLevelEvent)).toBe(false); + // returned early before checking renderer + expect(haveRendererForEvent).not.toHaveBeenCalled(); + }); + + const noUnreadEventTypes = [ + EventType.RoomMember, + EventType.RoomThirdPartyInvite, + EventType.CallAnswer, + EventType.CallHangup, + EventType.RoomCanonicalAlias, + EventType.RoomServerAcl, + EventType.RoomPowerLevels, + ]; + + it.each(noUnreadEventTypes)( + "returns false without checking for renderer for events with type %s", + (eventType) => { + const event = new MatrixEvent({ + type: eventType, + sender: aliceId, + }); + expect(eventTriggersUnreadCount(client, event)).toBe(false); + expect(haveRendererForEvent).not.toHaveBeenCalled(); + }, + ); + }); +});