Skip to content

Commit 5ddd453

Browse files
Germainrichvdh
Germain
andauthored
Emit summary update event (#3687)
* Emit summary update event * Add documentation * Update RoomSummary event documentation Co-authored-by: Richard van der Hoff <[email protected]> --------- Co-authored-by: Richard van der Hoff <[email protected]>
1 parent 42d982d commit 5ddd453

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

spec/unit/room.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,21 @@ describe("Room", function () {
12021202
room.recalculate();
12031203
expect(room.name).toEqual("Empty room");
12041204
});
1205+
1206+
it("emits an update event", function () {
1207+
const spy = jest.fn();
1208+
const summary = {
1209+
"m.heroes": [],
1210+
"m.invited_member_count": 1,
1211+
};
1212+
1213+
room.once(RoomEvent.Summary, spy);
1214+
1215+
room.setSummary(summary);
1216+
room.recalculate();
1217+
1218+
expect(spy).toHaveBeenCalledWith(summary);
1219+
});
12051220
});
12061221

12071222
describe("Room.recalculate => Room Name", function () {

src/models/room.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export enum RoomEvent {
146146
CurrentStateUpdated = "Room.CurrentStateUpdated",
147147
HistoryImportedWithinTimeline = "Room.historyImportedWithinTimeline",
148148
UnreadNotifications = "Room.UnreadNotifications",
149+
Summary = "Room.Summary",
149150
}
150151

151152
export type RoomEmittedEvents =
@@ -290,6 +291,14 @@ export type RoomEventHandlerMap = {
290291
[RoomEvent.HistoryImportedWithinTimeline]: (markerEvent: MatrixEvent, room: Room) => void;
291292
[RoomEvent.UnreadNotifications]: (unreadNotifications?: NotificationCount, threadId?: string) => void;
292293
[RoomEvent.TimelineRefresh]: (room: Room, eventTimelineSet: EventTimelineSet) => void;
294+
/**
295+
* Fires when a new room summary is returned by `/sync`.
296+
*
297+
* See https://spec.matrix.org/v1.8/client-server-api/#_matrixclientv3sync_roomsummary
298+
* for full details
299+
* @param summary - the room summary object
300+
*/
301+
[RoomEvent.Summary]: (summary: IRoomSummary) => void;
293302
[ThreadEvent.New]: (thread: Thread, toStartOfTimeline: boolean) => void;
294303
/**
295304
* Fires when a new poll instance is added to the room state
@@ -1499,6 +1508,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
14991508
return userId !== this.myUserId;
15001509
});
15011510
}
1511+
1512+
this.emit(RoomEvent.Summary, summary);
15021513
}
15031514

15041515
/**

0 commit comments

Comments
 (0)