You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
sliding sync: add invited|joined_count
This is critical for calculating client-side push rules correctly. Without it, the push processor may think rooms have a different number of members, resulting typically in annoying failure modes where rooms constantly make noises because the code thinks they are 1:1 rooms.
This commit is contained in:
@ -168,6 +168,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
const roomD = "!d_with_notif_count:localhost";
|
const roomD = "!d_with_notif_count:localhost";
|
||||||
const roomE = "!e_with_invite:localhost";
|
const roomE = "!e_with_invite:localhost";
|
||||||
const roomF = "!f_calc_room_name:localhost";
|
const roomF = "!f_calc_room_name:localhost";
|
||||||
|
const roomG = "!g_join_invite_counts:localhost";
|
||||||
const data: Record<string, MSC3575RoomData> = {
|
const data: Record<string, MSC3575RoomData> = {
|
||||||
[roomA]: {
|
[roomA]: {
|
||||||
name: "A",
|
name: "A",
|
||||||
@ -261,6 +262,18 @@ describe("SlidingSyncSdk", () => {
|
|||||||
],
|
],
|
||||||
initial: true,
|
initial: true,
|
||||||
},
|
},
|
||||||
|
[roomG]: {
|
||||||
|
name: "G",
|
||||||
|
required_state: [],
|
||||||
|
timeline: [
|
||||||
|
mkOwnStateEvent(EventType.RoomCreate, { creator: selfUserId }, ""),
|
||||||
|
mkOwnStateEvent(EventType.RoomMember, { membership: "join" }, selfUserId),
|
||||||
|
mkOwnStateEvent(EventType.RoomPowerLevels, { users: { [selfUserId]: 100 } }, ""),
|
||||||
|
],
|
||||||
|
joined_count: 5,
|
||||||
|
invited_count: 2,
|
||||||
|
initial: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
it("can be created with required_state and timeline", () => {
|
it("can be created with required_state and timeline", () => {
|
||||||
@ -299,6 +312,14 @@ describe("SlidingSyncSdk", () => {
|
|||||||
).toEqual(data[roomD].notification_count);
|
).toEqual(data[roomD].notification_count);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("can be created with an invited/joined_count", () => {
|
||||||
|
mockSlidingSync.emit(SlidingSyncEvent.RoomData, roomG, data[roomG]);
|
||||||
|
const gotRoom = client.getRoom(roomG);
|
||||||
|
expect(gotRoom).toBeDefined();
|
||||||
|
expect(gotRoom.getInvitedMemberCount()).toEqual(data[roomG].invited_count);
|
||||||
|
expect(gotRoom.getJoinedMemberCount()).toEqual(data[roomG].joined_count);
|
||||||
|
});
|
||||||
|
|
||||||
it("can be created with invite_state", () => {
|
it("can be created with invite_state", () => {
|
||||||
mockSlidingSync.emit(SlidingSyncEvent.RoomData, roomE, data[roomE]);
|
mockSlidingSync.emit(SlidingSyncEvent.RoomData, roomE, data[roomE]);
|
||||||
const gotRoom = client.getRoom(roomE);
|
const gotRoom = client.getRoom(roomE);
|
||||||
@ -374,6 +395,18 @@ describe("SlidingSyncSdk", () => {
|
|||||||
).toEqual(1);
|
).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("can update with a new joined_count", () => {
|
||||||
|
mockSlidingSync.emit(SlidingSyncEvent.RoomData, roomG, {
|
||||||
|
name: data[roomD].name,
|
||||||
|
required_state: [],
|
||||||
|
timeline: [],
|
||||||
|
joined_count: 1,
|
||||||
|
});
|
||||||
|
const gotRoom = client.getRoom(roomG);
|
||||||
|
expect(gotRoom).toBeDefined();
|
||||||
|
expect(gotRoom.getJoinedMemberCount()).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
// Regression test for a bug which caused the timeline entries to be out-of-order
|
// Regression test for a bug which caused the timeline entries to be out-of-order
|
||||||
// when the same room appears twice with different timeline limits. E.g appears in
|
// when the same room appears twice with different timeline limits. E.g appears in
|
||||||
// the list with timeline_limit:1 then appears again as a room subscription with
|
// the list with timeline_limit:1 then appears again as a room subscription with
|
||||||
|
@ -472,6 +472,13 @@ export class SlidingSyncSdk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Number.isInteger(roomData.invited_count)) {
|
||||||
|
room.currentState.setInvitedMemberCount(roomData.invited_count);
|
||||||
|
}
|
||||||
|
if (Number.isInteger(roomData.joined_count)) {
|
||||||
|
room.currentState.setJoinedMemberCount(roomData.joined_count);
|
||||||
|
}
|
||||||
|
|
||||||
if (roomData.invite_state) {
|
if (roomData.invite_state) {
|
||||||
const inviteStateEvents = mapEvents(this.client, room.roomId, roomData.invite_state);
|
const inviteStateEvents = mapEvents(this.client, room.roomId, roomData.invite_state);
|
||||||
this.processRoomEvents(room, inviteStateEvents);
|
this.processRoomEvents(room, inviteStateEvents);
|
||||||
|
@ -84,6 +84,8 @@ export interface MSC3575RoomData {
|
|||||||
timeline: (IRoomEvent | IStateEvent)[];
|
timeline: (IRoomEvent | IStateEvent)[];
|
||||||
notification_count?: number;
|
notification_count?: number;
|
||||||
highlight_count?: number;
|
highlight_count?: number;
|
||||||
|
joined_count?: number;
|
||||||
|
invited_count?: number;
|
||||||
invite_state?: IStateEvent[];
|
invite_state?: IStateEvent[];
|
||||||
initial?: boolean;
|
initial?: boolean;
|
||||||
limited?: boolean;
|
limited?: boolean;
|
||||||
|
Reference in New Issue
Block a user