Add labs flag for Threads Activity Centre (#12137)

* Add `Thread Activity centre` labs flag

* Rename translation string

* Update supportedLevels

* Fix labs subsection test

* Update Threads Activity Centre label

* Make threads activity centre labs flag split out unread counts

Just shows notif & unread counts for main thread if the TAC is enabled.

* Fix tests

* Simpler fix

* Pass in & cache the status of the TAC labs flag

* Pass includeThreads as setting to doesRoomHaveUnreadMessages too

* Fix tests

---------

Co-authored-by: David Baker <dbkr@users.noreply.github.com>
This commit is contained in:
Florian Duros 2024-01-29 18:52:48 +01:00 committed by GitHub
parent a370a5cfa4
commit 77e1649f0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 111 additions and 56 deletions

View file

@ -109,16 +109,16 @@ describe("RoomNotifs test", () => {
});
it("counts room notification type", () => {
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(0);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(0);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(0);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(0);
});
it("counts notifications type", () => {
room.setUnreadNotificationCount(NotificationCountType.Total, 2);
room.setUnreadNotificationCount(NotificationCountType.Highlight, 1);
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(2);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(1);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(1);
});
describe("when there is a room predecessor", () => {
@ -156,8 +156,8 @@ describe("RoomNotifs test", () => {
it("and there is a predecessor in the create event, it should count predecessor highlight", () => {
room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(8);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(7);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(7);
});
};
@ -167,8 +167,8 @@ describe("RoomNotifs test", () => {
room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)]);
upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(8);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(7);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(7);
});
};
@ -195,8 +195,8 @@ describe("RoomNotifs test", () => {
room.addLiveEvents([mkCreateEvent()]);
upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(2);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(1);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(1);
});
});
@ -214,31 +214,31 @@ describe("RoomNotifs test", () => {
room.addLiveEvents([mkCreateEvent()]);
upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(8);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(7);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(7);
});
it("and there is an unknown room in the predecessor event, it should not count predecessor highlight", () => {
room.addLiveEvents([mkCreateEvent()]);
upsertRoomStateEvents(room, [mkPredecessorEvent("!unknon:example.com")]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(2);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(1);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(1);
});
});
});
it("counts thread notification type", () => {
expect(getUnreadNotificationCount(room, NotificationCountType.Total, THREAD_ID)).toBe(0);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, THREAD_ID)).toBe(0);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false, THREAD_ID)).toBe(0);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false, THREAD_ID)).toBe(0);
});
it("counts thread notifications type", () => {
room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total, 2);
room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight, 1);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, THREAD_ID)).toBe(2);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, THREAD_ID)).toBe(1);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false, THREAD_ID)).toBe(2);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false, THREAD_ID)).toBe(1);
});
});

View file

@ -152,7 +152,7 @@ describe("Unread", () => {
});
it("returns true for a room with no receipts", () => {
expect(doesRoomHaveUnreadMessages(room)).toBe(true);
expect(doesRoomHaveUnreadMessages(room, false)).toBe(true);
});
it("returns false for a room when the latest event was sent by the current user", () => {
@ -166,7 +166,7 @@ describe("Unread", () => {
// Only for timeline events.
room.addLiveEvents([event]);
expect(doesRoomHaveUnreadMessages(room)).toBe(false);
expect(doesRoomHaveUnreadMessages(room, false)).toBe(false);
});
it("returns false for a room when the read receipt is at the latest event", () => {
@ -183,7 +183,7 @@ describe("Unread", () => {
});
room.addReceipt(receipt);
expect(doesRoomHaveUnreadMessages(room)).toBe(false);
expect(doesRoomHaveUnreadMessages(room, false)).toBe(false);
});
it("returns true for a room when the read receipt is earlier than the latest event", () => {
@ -210,7 +210,7 @@ describe("Unread", () => {
// Only for timeline events.
room.addLiveEvents([event2]);
expect(doesRoomHaveUnreadMessages(room)).toBe(true);
expect(doesRoomHaveUnreadMessages(room, false)).toBe(true);
});
it("returns true for a room with an unread message in a thread", async () => {
@ -247,7 +247,7 @@ describe("Unread", () => {
// Create a thread as a different user.
await populateThread({ room, client, authorId: myId, participantUserIds: [aliceId] });
expect(doesRoomHaveUnreadMessages(room)).toBe(true);
expect(doesRoomHaveUnreadMessages(room, true)).toBe(true);
});
it("returns false for a room when the latest thread event was sent by the current user", async () => {
@ -268,7 +268,7 @@ describe("Unread", () => {
// Create a thread as the current user.
await populateThread({ room, client, authorId: myId, participantUserIds: [myId] });
expect(doesRoomHaveUnreadMessages(room)).toBe(false);
expect(doesRoomHaveUnreadMessages(room, true)).toBe(false);
});
it("returns false for a room with read thread messages", async () => {
@ -308,7 +308,7 @@ describe("Unread", () => {
});
room.addReceipt(receipt);
expect(doesRoomHaveUnreadMessages(room)).toBe(false);
expect(doesRoomHaveUnreadMessages(room, true)).toBe(false);
});
it("returns true for a room when read receipt is not on the latest thread messages", async () => {
@ -348,7 +348,7 @@ describe("Unread", () => {
});
room.addReceipt(receipt);
expect(doesRoomHaveUnreadMessages(room)).toBe(true);
expect(doesRoomHaveUnreadMessages(room, true)).toBe(true);
});
it("returns true when the event for a thread receipt can't be found", async () => {
@ -394,7 +394,7 @@ describe("Unread", () => {
});
room.addReceipt(receipt);
expect(doesRoomHaveUnreadMessages(room)).toBe(true);
expect(doesRoomHaveUnreadMessages(room, true)).toBe(true);
});
});
@ -412,7 +412,7 @@ describe("Unread", () => {
// Only for timeline events.
room.addLiveEvents([redactedEvent]);
expect(doesRoomHaveUnreadMessages(room)).toBe(true);
expect(doesRoomHaveUnreadMessages(room, true)).toBe(true);
expect(logger.warn).toHaveBeenCalledWith(
"Falling back to unread room because of no read receipt or counting message found",
{

View file

@ -812,8 +812,11 @@ function createRoom(info: IRoomCreationInfo) {
const userId = client.getUserId()!;
if (info.isDm) {
client.getAccountData = (eventType) => {
expect(eventType).toEqual("m.direct");
return mkDirectEvent(roomId, userId, info.userIds);
if (eventType === "m.direct") {
return mkDirectEvent(roomId, userId, info.userIds);
} else {
return undefined;
}
};
}

View file

@ -47,7 +47,7 @@ describe("<VideoRoomChatButton />", () => {
};
const mockRoomNotificationState = (room: Room, level: NotificationLevel): RoomNotificationState => {
const roomNotificationState = new RoomNotificationState(room);
const roomNotificationState = new RoomNotificationState(room, false);
// @ts-ignore ugly mocking
roomNotificationState._level = level;

View file

@ -60,7 +60,7 @@ describe("<LabsUserSettingsTab />", () => {
// non-beta labs section
expect(screen.getByText("Early previews")).toBeInTheDocument();
const labsSections = container.getElementsByClassName("mx_SettingsSubsection");
expect(labsSections).toHaveLength(9);
expect(labsSections).toHaveLength(10);
});
describe("Rust crypto setting", () => {

View file

@ -125,6 +125,7 @@ describe("RoomNotificationStateStore", function () {
ret.getPendingEvents = jest.fn().mockReturnValue([]);
ret.isSpaceRoom = jest.fn().mockReturnValue(false);
ret.getUnreadNotificationCount = jest.fn().mockReturnValue(numUnreads);
ret.getRoomUnreadNotificationCount = jest.fn().mockReturnValue(numUnreads);
return ret;
}
});

View file

@ -81,7 +81,7 @@ describe("RoomNotificationState", () => {
}
it("Updates on event decryption", () => {
const roomNotifState = new RoomNotificationState(room);
const roomNotifState = new RoomNotificationState(room, true);
const listener = jest.fn();
roomNotifState.addListener(NotificationStateEvents.Update, listener);
const testEvent = {
@ -93,12 +93,12 @@ describe("RoomNotificationState", () => {
});
it("removes listeners", () => {
const roomNotifState = new RoomNotificationState(room);
const roomNotifState = new RoomNotificationState(room, false);
expect(() => roomNotifState.destroy()).not.toThrow();
});
it("suggests an 'unread' ! if there are unsent messages", () => {
const roomNotifState = new RoomNotificationState(room);
const roomNotifState = new RoomNotificationState(room, false);
const event = mkEvent({
event: true,
@ -115,7 +115,7 @@ describe("RoomNotificationState", () => {
});
it("suggests nothing if the room is muted", () => {
const roomNotifState = new RoomNotificationState(room);
const roomNotifState = new RoomNotificationState(room, false);
muteRoom(room);
setUnreads(room, 1234, 0);
@ -127,7 +127,7 @@ describe("RoomNotificationState", () => {
});
it("suggests a red ! if the user has been invited to a room", () => {
const roomNotifState = new RoomNotificationState(room);
const roomNotifState = new RoomNotificationState(room, false);
room.updateMyMembership("invite"); // emit
@ -137,7 +137,7 @@ describe("RoomNotificationState", () => {
});
it("returns a proper count and color for regular unreads", () => {
const roomNotifState = new RoomNotificationState(room);
const roomNotifState = new RoomNotificationState(room, false);
setUnreads(room, 4321, 0);
room.updateMyMembership("join"); // emit
@ -148,7 +148,7 @@ describe("RoomNotificationState", () => {
});
it("returns a proper count and color for highlights", () => {
const roomNotifState = new RoomNotificationState(room);
const roomNotifState = new RoomNotificationState(room, false);
setUnreads(room, 0, 69);
room.updateMyMembership("join"); // emit
@ -159,7 +159,7 @@ describe("RoomNotificationState", () => {
});
it("includes threads", async () => {
const roomNotifState = new RoomNotificationState(room);
const roomNotifState = new RoomNotificationState(room, true);
room.timeline.push(
new MatrixEvent({