Ignore activity in TAC (#12269)

This commit is contained in:
Florian Duros 2024-02-21 13:19:25 +01:00 committed by GitHub
parent 6d55ce0217
commit d9a20b00e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 60 deletions

View file

@ -96,6 +96,12 @@ function computeUnreadThreadRooms(mxClient: MatrixClient, msc3946ProcessDynamicP
if (VisibilityProvider.instance.isRoomVisible(room) && doesRoomHaveUnreadThreads(room)) { if (VisibilityProvider.instance.isRoomVisible(room) && doesRoomHaveUnreadThreads(room)) {
// Get the greatest notification level of all rooms // Get the greatest notification level of all rooms
const notificationLevel = getThreadNotificationLevel(room); const notificationLevel = getThreadNotificationLevel(room);
// If the room has an activity notification or less, we ignore it
if (notificationLevel <= NotificationLevel.Activity) {
continue;
}
if (notificationLevel > greatestNotificationLevel) { if (notificationLevel > greatestNotificationLevel) {
greatestNotificationLevel = notificationLevel; greatestNotificationLevel = notificationLevel;
} }

View file

@ -111,17 +111,13 @@ describe("ThreadsActivityCentre", () => {
expect(getTACMenu()).toBeInTheDocument(); expect(getTACMenu()).toBeInTheDocument();
}); });
it("should render a room with a activity in the TAC", async () => { it("should not render a room with a activity in the TAC", async () => {
cli.getVisibleRooms = jest.fn().mockReturnValue([roomWithActivity]); cli.getVisibleRooms = jest.fn().mockReturnValue([roomWithActivity]);
renderTAC(); renderTAC();
await userEvent.click(getTACButton()); await userEvent.click(getTACButton());
const tacRows = screen.getAllByRole("menuitem"); // We should not render the room with activity
expect(tacRows.length).toEqual(1); expect(() => screen.getAllByRole("menuitem")).toThrow();
getByText(tacRows[0], "Just activity");
expect(tacRows[0].getElementsByClassName("mx_NotificationBadge").length).toEqual(1);
expect(tacRows[0].getElementsByClassName("mx_NotificationBadge_level_notification").length).toEqual(0);
}); });
it("should render a room with a regular notification in the TAC", async () => { it("should render a room with a regular notification in the TAC", async () => {

View file

@ -2,7 +2,7 @@
exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] = ` exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] = `
<div <div
aria-labelledby="radix-13" aria-labelledby="radix-12"
aria-orientation="vertical" aria-orientation="vertical"
class="_menu_1x5h1_17" class="_menu_1x5h1_17"
data-align="end" data-align="end"
@ -11,7 +11,7 @@ exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] =
data-side="right" data-side="right"
data-state="open" data-state="open"
dir="ltr" dir="ltr"
id="radix-14" id="radix-13"
role="menu" role="menu"
style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); pointer-events: auto;" style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); pointer-events: auto;"
tabindex="-1" tabindex="-1"
@ -121,61 +121,13 @@ exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] =
/> />
</div> </div>
</button> </button>
<button
class="mx_ThreadsActivityRow _item_1bcsk_17 _interactive_1bcsk_36"
data-kind="primary"
data-orientation="vertical"
data-radix-collection-item=""
role="menuitem"
tabindex="-1"
>
<div
class="_icon_1bcsk_44"
>
<span
class="_avatar_k41ul_17 mx_BaseAvatar _avatar-imageless_k41ul_60"
data-color="6"
data-testid="avatar-img"
data-type="round"
role="presentation"
style="--cpd-avatar-size: 32px;"
>
J
</span>
</div>
<span
class="_typography_yh5dq_162 _font-body-md-medium_yh5dq_69 _label_1bcsk_53"
>
Just activity
</span>
<svg
aria-hidden="true"
class="_nav-hint_1bcsk_60"
fill="currentColor"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M8.7 17.3a.948.948 0 0 1-.275-.7.95.95 0 0 1 .275-.7l3.9-3.9-3.9-3.9a.948.948 0 0 1-.275-.7.95.95 0 0 1 .275-.7.948.948 0 0 1 .7-.275.95.95 0 0 1 .7.275l4.6 4.6c.1.1.17.208.213.325.041.117.062.242.062.375s-.02.258-.063.375a.876.876 0 0 1-.212.325l-4.6 4.6a.948.948 0 0 1-.7.275.948.948 0 0 1-.7-.275Z"
/>
</svg>
<div
class="mx_NotificationBadge mx_NotificationBadge_visible mx_NotificationBadge_dot"
>
<span
class="mx_NotificationBadge_count"
/>
</div>
</button>
</div> </div>
</div> </div>
`; `;
exports[`ThreadsActivityCentre should match snapshot when empty 1`] = ` exports[`ThreadsActivityCentre should match snapshot when empty 1`] = `
<div <div
aria-labelledby="radix-20" aria-labelledby="radix-18"
aria-orientation="vertical" aria-orientation="vertical"
class="_menu_1x5h1_17" class="_menu_1x5h1_17"
data-align="end" data-align="end"
@ -184,7 +136,7 @@ exports[`ThreadsActivityCentre should match snapshot when empty 1`] = `
data-side="right" data-side="right"
data-state="open" data-state="open"
dir="ltr" dir="ltr"
id="radix-21" id="radix-19"
role="menu" role="menu"
style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); pointer-events: auto;" style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); pointer-events: auto;"
tabindex="-1" tabindex="-1"

View file

@ -51,6 +51,28 @@ describe("useUnreadThreadRooms", () => {
expect(rooms.length).toEqual(0); expect(rooms.length).toEqual(0);
}); });
it("an activity notification is ignored", async () => {
const notifThreadInfo = await populateThread({
room: room,
client: client,
authorId: "@foo:bar",
participantUserIds: ["@fee:bar"],
});
room.setThreadUnreadNotificationCount(notifThreadInfo.thread.id, NotificationCountType.Total, 0);
client.getVisibleRooms = jest.fn().mockReturnValue([room]);
const wrapper = ({ children }: { children: React.ReactNode }) => (
<MatrixClientContext.Provider value={client}>{children}</MatrixClientContext.Provider>
);
const { result } = renderHook(() => useUnreadThreadRooms(true), { wrapper });
const { greatestNotificationLevel, rooms } = result.current;
expect(greatestNotificationLevel).toBe(NotificationLevel.None);
expect(rooms.length).toEqual(0);
});
it("a notification and a highlight summarise to a highlight", async () => { it("a notification and a highlight summarise to a highlight", async () => {
const notifThreadInfo = await populateThread({ const notifThreadInfo = await populateThread({
room: room, room: room,
@ -107,7 +129,7 @@ describe("useUnreadThreadRooms", () => {
const { result } = renderHook(() => useUnreadThreadRooms(true), { wrapper }); const { result } = renderHook(() => useUnreadThreadRooms(true), { wrapper });
expect(result.current.greatestNotificationLevel).toBe(NotificationLevel.Activity); expect(result.current.greatestNotificationLevel).toBe(NotificationLevel.None);
act(() => { act(() => {
room.setThreadUnreadNotificationCount(notifThreadInfo.thread.id, NotificationCountType.Highlight, 1); room.setThreadUnreadNotificationCount(notifThreadInfo.thread.id, NotificationCountType.Highlight, 1);