Skip to content

Commit

Permalink
Merge pull request #1178 from tchapgouv/1179-remove-notification-powe…
Browse files Browse the repository at this point in the history
…rlevels

TCHAP: remove notification power levels changes
  • Loading branch information
MarcWadai authored Dec 9, 2024
2 parents b68ff01 + 11a037d commit b8ab31b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
6 changes: 6 additions & 0 deletions patches/tchap-modifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
1 change: 1 addition & 0 deletions src/Unread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
68 changes: 68 additions & 0 deletions test/unit-tests/tchap/Unread-test.ts
Original file line number Diff line number Diff line change
@@ -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();
},
);
});
});

0 comments on commit b8ab31b

Please sign in to comment.