Update calls to addEventToTimeline and addLiveEvents for new signature

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2024-11-06 14:55:21 +00:00
parent a355292a7f
commit 044eaf7eb5
No known key found for this signature in database
GPG key ID: A2B008A5F49F5D0D
34 changed files with 166 additions and 131 deletions

View file

@ -104,7 +104,11 @@ class FilePanel extends React.Component<IProps, IState> {
} }
if (!this.state.timelineSet.eventIdToTimeline(ev.getId()!)) { if (!this.state.timelineSet.eventIdToTimeline(ev.getId()!)) {
this.state.timelineSet.addEventToTimeline(ev, timeline, false); this.state.timelineSet.addEventToTimeline(ev, timeline, {
fromCache: false,
addToState: false,
toStartOfTimeline: false,
});
} }
} }

View file

@ -820,7 +820,11 @@ export default class EventIndex extends EventEmitter {
// Add the events to the timeline of the file panel. // Add the events to the timeline of the file panel.
matrixEvents.forEach((e) => { matrixEvents.forEach((e) => {
if (!timelineSet.eventIdToTimeline(e.getId()!)) { if (!timelineSet.eventIdToTimeline(e.getId()!)) {
timelineSet.addEventToTimeline(e, timeline, direction == EventTimeline.BACKWARDS); timelineSet.addEventToTimeline(e, timeline, {
toStartOfTimeline: direction == EventTimeline.BACKWARDS,
fromCache: false,
addToState: false,
});
} }
}); });

View file

@ -109,7 +109,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
localRoom.targets = targets; localRoom.targets = targets;
localRoom.updateMyMembership(KnownMembership.Join); localRoom.updateMyMembership(KnownMembership.Join);
localRoom.addLiveEvents(events); localRoom.addLiveEvents(events, { addToState: true });
localRoom.currentState.setStateEvents(events); localRoom.currentState.setStateEvents(events);
localRoom.name = localRoom.getDefaultRoomName(client.getUserId()!); localRoom.name = localRoom.getDefaultRoomName(client.getUserId()!);
client.store.storeRoom(localRoom); client.store.storeRoom(localRoom);

View file

@ -44,17 +44,20 @@ export class MockedCall extends Call {
} }
public static create(room: Room, id: string) { public static create(room: Room, id: string) {
room.addLiveEvents([ room.addLiveEvents(
mkEvent({ [
event: true, mkEvent({
type: this.EVENT_TYPE, event: true,
room: room.roomId, type: this.EVENT_TYPE,
user: "@alice:example.org", room: room.roomId,
content: { "m.type": "m.video", "m.intent": "m.prompt" }, user: "@alice:example.org",
skey: id, content: { "m.type": "m.video", "m.intent": "m.prompt" },
ts: Date.now(), skey: id,
}), ts: Date.now(),
]); }),
],
{ addToState: true },
);
// @ts-ignore deliberately calling a private method // @ts-ignore deliberately calling a private method
// Let CallStore know that a call might now exist // Let CallStore know that a call might now exist
CallStore.instance.updateRoom(room); CallStore.instance.updateRoom(room);
@ -81,17 +84,20 @@ export class MockedCall extends Call {
public destroy() { public destroy() {
// Terminate the call for good measure // Terminate the call for good measure
this.room.addLiveEvents([ this.room.addLiveEvents(
mkEvent({ [
event: true, mkEvent({
type: MockedCall.EVENT_TYPE, event: true,
room: this.room.roomId, type: MockedCall.EVENT_TYPE,
user: "@alice:example.org", room: this.room.roomId,
content: { ...this.event.getContent(), "m.terminated": "Call ended" }, user: "@alice:example.org",
skey: this.widget.id, content: { ...this.event.getContent(), "m.terminated": "Call ended" },
ts: Date.now(), skey: this.widget.id,
}), ts: Date.now(),
]); }),
],
{ addToState: true },
);
super.destroy(); super.destroy();
} }

View file

@ -157,6 +157,6 @@ export const populateThread = async ({
// that it is already loaded, and send the events again to the room // that it is already loaded, and send the events again to the room
// so they are added to the thread timeline. // so they are added to the thread timeline.
ret.thread.initialEventsFetched = true; ret.thread.initialEventsFetched = true;
await room.addLiveEvents(ret.events); await room.addLiveEvents(ret.events, { addToState: false });
return ret; return ret;
}; };

View file

@ -624,8 +624,7 @@ describe("Notifier", () => {
content: { body: "this is a thread root" }, content: { body: "this is a thread root" },
}), }),
testRoom.threadsTimelineSets[0]!.getLiveTimeline(), testRoom.threadsTimelineSets[0]!.getLiveTimeline(),
false, { toStartOfTimeline: false, fromCache: false, addToState: true },
false,
); );
expect(fn).not.toHaveBeenCalled(); expect(fn).not.toHaveBeenCalled();

View file

@ -147,7 +147,7 @@ describe("RoomNotifs test", () => {
const itShouldCountPredecessorHighlightWhenThereIsAPredecessorInTheCreateEvent = (): void => { const itShouldCountPredecessorHighlightWhenThereIsAPredecessorInTheCreateEvent = (): void => {
it("and there is a predecessor in the create event, it should count predecessor highlight", () => { it("and there is a predecessor in the create event, it should count predecessor highlight", () => {
room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)]); room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)], { addToState: true });
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8);
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(7); expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(7);
@ -157,7 +157,7 @@ describe("RoomNotifs test", () => {
const itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent = (): void => { const itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent = (): void => {
it("and there is a predecessor event, it should count predecessor highlight", () => { it("and there is a predecessor event, it should count predecessor highlight", () => {
client.getVisibleRooms(); client.getVisibleRooms();
room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)]); room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)], { addToState: true });
upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]); upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8);
@ -185,7 +185,7 @@ describe("RoomNotifs test", () => {
itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent(); itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent();
it("and there is only a predecessor event, it should not count predecessor highlight", () => { it("and there is only a predecessor event, it should not count predecessor highlight", () => {
room.addLiveEvents([mkCreateEvent()]); room.addLiveEvents([mkCreateEvent()], { addToState: true });
upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]); upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2);
@ -204,7 +204,7 @@ describe("RoomNotifs test", () => {
itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent(); itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent();
it("and there is only a predecessor event, it should count predecessor highlight", () => { it("and there is only a predecessor event, it should count predecessor highlight", () => {
room.addLiveEvents([mkCreateEvent()]); room.addLiveEvents([mkCreateEvent()], { addToState: true });
upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]); upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8);
@ -212,7 +212,7 @@ describe("RoomNotifs test", () => {
}); });
it("and there is an unknown room in the predecessor event, it should not count predecessor highlight", () => { it("and there is an unknown room in the predecessor event, it should not count predecessor highlight", () => {
room.addLiveEvents([mkCreateEvent()]); room.addLiveEvents([mkCreateEvent()], { addToState: true });
upsertRoomStateEvents(room, [mkPredecessorEvent("!unknon:example.com")]); upsertRoomStateEvents(room, [mkPredecessorEvent("!unknon:example.com")]);
expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2);

View file

@ -138,7 +138,7 @@ describe("Unread", () => {
room: roomId, room: roomId,
content: {}, content: {},
}); });
room.addLiveEvents([event]); room.addLiveEvents([event], { addToState: true });
// Don't care about the code path of hidden events. // Don't care about the code path of hidden events.
mocked(haveRendererForEvent).mockClear().mockReturnValue(true); mocked(haveRendererForEvent).mockClear().mockReturnValue(true);
@ -157,7 +157,7 @@ describe("Unread", () => {
content: {}, content: {},
}); });
// Only for timeline events. // Only for timeline events.
room.addLiveEvents([event]); room.addLiveEvents([event], { addToState: true });
expect(doesRoomHaveUnreadMessages(room, false)).toBe(false); expect(doesRoomHaveUnreadMessages(room, false)).toBe(false);
}); });
@ -201,7 +201,7 @@ describe("Unread", () => {
content: {}, content: {},
}); });
// Only for timeline events. // Only for timeline events.
room.addLiveEvents([event2]); room.addLiveEvents([event2], { addToState: true });
expect(doesRoomHaveUnreadMessages(room, false)).toBe(true); expect(doesRoomHaveUnreadMessages(room, false)).toBe(true);
}); });
@ -403,7 +403,7 @@ describe("Unread", () => {
redactedEvent.makeRedacted(redactedEvent, room); redactedEvent.makeRedacted(redactedEvent, room);
console.log("Event Id", redactedEvent.getId()); console.log("Event Id", redactedEvent.getId());
// Only for timeline events. // Only for timeline events.
room.addLiveEvents([redactedEvent]); room.addLiveEvents([redactedEvent], { addToState: true });
expect(doesRoomHaveUnreadMessages(room, true)).toBe(true); expect(doesRoomHaveUnreadMessages(room, true)).toBe(true);
expect(logger.warn).toHaveBeenCalledWith( expect(logger.warn).toHaveBeenCalledWith(
@ -448,7 +448,7 @@ describe("Unread", () => {
room: roomId, room: roomId,
content: {}, content: {},
}); });
room.addLiveEvents([event]); room.addLiveEvents([event], { addToState: true });
}); });
it("an unthreaded receipt for the event makes the room read", () => { it("an unthreaded receipt for the event makes the room read", () => {
@ -502,7 +502,7 @@ describe("Unread", () => {
ts: 100, ts: 100,
currentUserId: myId, currentUserId: myId,
}); });
room.addLiveEvents(events); room.addLiveEvents(events, { addToState: true });
threadEvent = events[1]; threadEvent = events[1];
}); });
@ -555,7 +555,7 @@ describe("Unread", () => {
room: roomId, room: roomId,
content: {}, content: {},
}); });
room.addLiveEvents([event]); room.addLiveEvents([event], { addToState: true });
// It still returns false // It still returns false
expect(doesRoomHaveUnreadThreads(room)).toBe(false); expect(doesRoomHaveUnreadThreads(room)).toBe(false);

View file

@ -249,15 +249,19 @@ describe("RoomView", () => {
cli.isRoomEncrypted.mockReturnValue(true); cli.isRoomEncrypted.mockReturnValue(true);
// and fake an encryption event into the room to prompt it to re-check // and fake an encryption event into the room to prompt it to re-check
room.addLiveEvents([ room.addLiveEvents(
new MatrixEvent({ [
type: "m.room.encryption", new MatrixEvent({
sender: cli.getUserId()!, type: "m.room.encryption",
content: {}, sender: cli.getUserId()!,
event_id: "someid", content: {},
room_id: room.roomId, event_id: "someid",
}), room_id: room.roomId,
]); state_key: "",
}),
],
{ addToState: true },
);
// URL previews should now be disabled // URL previews should now be disabled
expect(roomViewInstance.state.showUrlPreview).toBe(false); expect(roomViewInstance.state.showUrlPreview).toBe(false);
@ -440,7 +444,7 @@ describe("RoomView", () => {
skey: id, skey: id,
ts, ts,
}); });
room.addLiveEvents([widgetEvent]); room.addLiveEvents([widgetEvent], { addToState: true });
room.currentState.setStateEvents([widgetEvent]); room.currentState.setStateEvents([widgetEvent]);
cli.emit(RoomStateEvent.Events, widgetEvent, room.currentState, null); cli.emit(RoomStateEvent.Events, widgetEvent, room.currentState, null);
await flushPromises(); await flushPromises();

View file

@ -209,11 +209,11 @@ describe("ThreadPanel", () => {
return event ? Promise.resolve(event) : Promise.reject(); return event ? Promise.resolve(event) : Promise.reject();
}); });
const [allThreads, myThreads] = room.threadsTimelineSets; const [allThreads, myThreads] = room.threadsTimelineSets;
allThreads!.addLiveEvent(otherThread.rootEvent); allThreads!.addLiveEvent(otherThread.rootEvent, { addToState: true });
allThreads!.addLiveEvent(mixedThread.rootEvent); allThreads!.addLiveEvent(mixedThread.rootEvent, { addToState: true });
allThreads!.addLiveEvent(ownThread.rootEvent); allThreads!.addLiveEvent(ownThread.rootEvent, { addToState: true });
myThreads!.addLiveEvent(mixedThread.rootEvent); myThreads!.addLiveEvent(mixedThread.rootEvent, { addToState: true });
myThreads!.addLiveEvent(ownThread.rootEvent); myThreads!.addLiveEvent(ownThread.rootEvent, { addToState: true });
let events: EventData[] = []; let events: EventData[] = [];
const renderResult = render(<TestThreadPanel />); const renderResult = render(<TestThreadPanel />);
@ -259,7 +259,7 @@ describe("ThreadPanel", () => {
return event ? Promise.resolve(event) : Promise.reject(); return event ? Promise.resolve(event) : Promise.reject();
}); });
const [allThreads] = room.threadsTimelineSets; const [allThreads] = room.threadsTimelineSets;
allThreads!.addLiveEvent(otherThread.rootEvent); allThreads!.addLiveEvent(otherThread.rootEvent, { addToState: true });
let events: EventData[] = []; let events: EventData[] = [];
const renderResult = render(<TestThreadPanel />); const renderResult = render(<TestThreadPanel />);

View file

@ -66,7 +66,7 @@ const mkTimeline = (room: Room, events: MatrixEvent[]): [EventTimeline, EventTim
getPendingEvents: () => [] as MatrixEvent[], getPendingEvents: () => [] as MatrixEvent[],
} as unknown as EventTimelineSet; } as unknown as EventTimelineSet;
const timeline = new EventTimeline(timelineSet); const timeline = new EventTimeline(timelineSet);
events.forEach((event) => timeline.addEvent(event, { toStartOfTimeline: false })); events.forEach((event) => timeline.addEvent(event, { toStartOfTimeline: false, addToState: true }));
return [timeline, timelineSet]; return [timeline, timelineSet];
}; };
@ -150,9 +150,11 @@ const setupPagination = (
mocked(client).paginateEventTimeline.mockImplementation(async (tl, { backwards }) => { mocked(client).paginateEventTimeline.mockImplementation(async (tl, { backwards }) => {
if (tl === timeline) { if (tl === timeline) {
if (backwards) { if (backwards) {
forEachRight(previousPage ?? [], (event) => tl.addEvent(event, { toStartOfTimeline: true })); forEachRight(previousPage ?? [], (event) =>
tl.addEvent(event, { toStartOfTimeline: true, addToState: true }),
);
} else { } else {
(nextPage ?? []).forEach((event) => tl.addEvent(event, { toStartOfTimeline: false })); (nextPage ?? []).forEach((event) => tl.addEvent(event, { toStartOfTimeline: false, addToState: true }));
} }
// Prevent any further pagination attempts in this direction // Prevent any further pagination attempts in this direction
tl.setPaginationToken(null, backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS); tl.setPaginationToken(null, backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS);
@ -256,7 +258,7 @@ describe("TimelinePanel", () => {
describe("and reading the timeline", () => { describe("and reading the timeline", () => {
beforeEach(async () => { beforeEach(async () => {
await renderTimelinePanel(); await renderTimelinePanel();
timelineSet.addLiveEvent(ev1, {}); timelineSet.addLiveEvent(ev1, { addToState: true });
await flushPromises(); await flushPromises();
// @ts-ignore // @ts-ignore
@ -285,11 +287,11 @@ describe("TimelinePanel", () => {
}); });
it("and forgetting the read markers, should send the stored marker again", async () => { it("and forgetting the read markers, should send the stored marker again", async () => {
timelineSet.addLiveEvent(ev2, {}); timelineSet.addLiveEvent(ev2, { addToState: true });
// Add the event to the room as well as the timeline, so we can find it when we // Add the event to the room as well as the timeline, so we can find it when we
// call findEventById in getEventReadUpTo. This is odd because in our test // call findEventById in getEventReadUpTo. This is odd because in our test
// setup, timelineSet is not actually the timelineSet of the room. // setup, timelineSet is not actually the timelineSet of the room.
await room.addLiveEvents([ev2], {}); await room.addLiveEvents([ev2], { addToState: true });
room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]); room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]);
await timelinePanel.forgetReadMarker(); await timelinePanel.forgetReadMarker();
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev2.getId()); expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev2.getId());
@ -315,7 +317,7 @@ describe("TimelinePanel", () => {
it("should send a fully read marker and a private receipt", async () => { it("should send a fully read marker and a private receipt", async () => {
await renderTimelinePanel(); await renderTimelinePanel();
timelineSet.addLiveEvent(ev1, {}); timelineSet.addLiveEvent(ev1, { addToState: true });
await flushPromises(); await flushPromises();
// @ts-ignore // @ts-ignore
@ -361,7 +363,7 @@ describe("TimelinePanel", () => {
it("should send receipts but no fully_read when reading the thread timeline", async () => { it("should send receipts but no fully_read when reading the thread timeline", async () => {
await renderTimelinePanel(); await renderTimelinePanel();
timelineSet.addLiveEvent(threadEv1, {}); timelineSet.addLiveEvent(threadEv1, { addToState: true });
await flushPromises(); await flushPromises();
// @ts-ignore // @ts-ignore
@ -871,7 +873,9 @@ describe("TimelinePanel", () => {
// @ts-ignore // @ts-ignore
thread.fetchEditsWhereNeeded = () => Promise.resolve(); thread.fetchEditsWhereNeeded = () => Promise.resolve();
await thread.addEvent(reply1, false, true); await thread.addEvent(reply1, false, true);
await allThreads.getLiveTimeline().addEvent(thread.rootEvent!, { toStartOfTimeline: true }); await allThreads
.getLiveTimeline()
.addEvent(thread.rootEvent!, { toStartOfTimeline: true, addToState: true });
const replyToEvent = jest.spyOn(thread, "replyToEvent", "get"); const replyToEvent = jest.spyOn(thread, "replyToEvent", "get");
const dom = render( const dom = render(
@ -907,7 +911,9 @@ describe("TimelinePanel", () => {
// @ts-ignore // @ts-ignore
realThread.fetchEditsWhereNeeded = () => Promise.resolve(); realThread.fetchEditsWhereNeeded = () => Promise.resolve();
await realThread.addEvent(reply1, true); await realThread.addEvent(reply1, true);
await allThreads.getLiveTimeline().addEvent(realThread.rootEvent!, { toStartOfTimeline: true }); await allThreads
.getLiveTimeline()
.addEvent(realThread.rootEvent!, { toStartOfTimeline: true, addToState: true });
const replyToEvent = jest.spyOn(realThread, "replyToEvent", "get"); const replyToEvent = jest.spyOn(realThread, "replyToEvent", "get");
// @ts-ignore // @ts-ignore
@ -968,7 +974,9 @@ describe("TimelinePanel", () => {
events.push(rootEvent); events.push(rootEvent);
events.forEach((event) => timelineSet.getLiveTimeline().addEvent(event, { toStartOfTimeline: true })); events.forEach((event) =>
timelineSet.getLiveTimeline().addEvent(event, { toStartOfTimeline: true, addToState: true }),
);
const roomMembership = mkMembership({ const roomMembership = mkMembership({
mship: KnownMembership.Join, mship: KnownMembership.Join,
@ -988,7 +996,10 @@ describe("TimelinePanel", () => {
jest.spyOn(roomState, "getMember").mockReturnValue(member); jest.spyOn(roomState, "getMember").mockReturnValue(member);
jest.spyOn(timelineSet.getLiveTimeline(), "getState").mockReturnValue(roomState); jest.spyOn(timelineSet.getLiveTimeline(), "getState").mockReturnValue(roomState);
timelineSet.addEventToTimeline(roomMembership, timelineSet.getLiveTimeline(), { toStartOfTimeline: false }); timelineSet.addEventToTimeline(roomMembership, timelineSet.getLiveTimeline(), {
toStartOfTimeline: false,
addToState: true,
});
for (const event of events) { for (const event of events) {
jest.spyOn(event, "isDecryptionFailure").mockReturnValue(true); jest.spyOn(event, "isDecryptionFailure").mockReturnValue(true);

View file

@ -127,7 +127,7 @@ describe("RoomGeneralContextMenu", () => {
user: "@user:id", user: "@user:id",
ts: 1000, ts: 1000,
}); });
room.addLiveEvents([event], {}); room.addLiveEvents([event], { addToState: true });
const { container } = getComponent({}); const { container } = getComponent({});

View file

@ -141,16 +141,19 @@ describe("InviteDialog", () => {
jest.clearAllMocks(); jest.clearAllMocks();
room = new Room(roomId, mockClient, mockClient.getSafeUserId()); room = new Room(roomId, mockClient, mockClient.getSafeUserId());
room.addLiveEvents([ room.addLiveEvents(
mkMessage({ [
msg: "Hello", mkMessage({
relatesTo: undefined, msg: "Hello",
event: true, relatesTo: undefined,
room: roomId, event: true,
user: mockClient.getSafeUserId(), room: roomId,
ts: Date.now(), user: mockClient.getSafeUserId(),
}), ts: Date.now(),
]); }),
],
{ addToState: true },
);
room.currentState.setStateEvents([ room.currentState.setStateEvents([
mkRoomCreateEvent(bobId, roomId), mkRoomCreateEvent(bobId, roomId),
mkMembership({ mkMembership({

View file

@ -86,7 +86,7 @@ describe("<Pill>", () => {
room: room1Id, room: room1Id,
msg: "Room 1 Message", msg: "Room 1 Message",
}); });
room1.addLiveEvents([room1Message]); room1.addLiveEvents([room1Message], { addToState: true });
room2 = new Room(room2Id, client, user1Id); room2 = new Room(room2Id, client, user1Id);
room2.currentState.setStateEvents([mkRoomMemberJoinEvent(user2Id, room2Id)]); room2.currentState.setStateEvents([mkRoomMemberJoinEvent(user2Id, room2Id)]);

View file

@ -41,7 +41,7 @@ describe("<RoomTopic/>", () => {
ts: 123, ts: 123,
event: true, event: true,
}); });
room.addLiveEvents([topicEvent]); room.addLiveEvents([topicEvent], { addToState: true });
return room; return room;
} }

View file

@ -165,7 +165,7 @@ describe("UnreadNotificationBadge", () => {
}, },
ts: 5, ts: 5,
}); });
room.addLiveEvents([event]); room.addLiveEvents([event], { addToState: true });
const { container } = render(getComponent(THREAD_ID)); const { container } = render(getComponent(THREAD_ID));
expect(container.querySelector(".mx_NotificationBadge_dot")).toBeTruthy(); expect(container.querySelector(".mx_NotificationBadge_dot")).toBeTruthy();

View file

@ -579,7 +579,7 @@ describe("RoomHeader", () => {
state_key: "", state_key: "",
room_id: room.roomId, room_id: room.roomId,
}); });
room.addLiveEvents([joinRuleEvent]); room.addLiveEvents([joinRuleEvent], { addToState: true });
render(<RoomHeader room={room} />, getWrapper()); render(<RoomHeader room={room} />, getWrapper());

View file

@ -915,7 +915,7 @@ describe("<Notifications />", () => {
user: "@alice:example.org", user: "@alice:example.org",
ts: 1, ts: 1,
}); });
await room.addLiveEvents([message]); await room.addLiveEvents([message], { addToState: true });
const { container } = await getComponentAndWait(); const { container } = await getComponentAndWait();
const clearNotificationEl = getByTestId(container, "clear-notifications"); const clearNotificationEl = getByTestId(container, "clear-notifications");

View file

@ -716,7 +716,7 @@ describe("<Notifications />", () => {
user: "@alice:example.org", user: "@alice:example.org",
ts: 1, ts: 1,
}); });
room.addLiveEvents([message]); room.addLiveEvents([message], { addToState: true });
room.setUnreadNotificationCount(NotificationCountType.Total, 1); room.setUnreadNotificationCount(NotificationCountType.Total, 1);
const user = userEvent.setup(); const user = userEvent.setup();

View file

@ -88,7 +88,7 @@ describe("pickFactory", () => {
client.getUserId()!, client.getUserId()!,
client.deviceId!, client.deviceId!,
); );
room.addLiveEvents([voiceBroadcastStartedEvent]); room.addLiveEvents([voiceBroadcastStartedEvent], { addToState: true });
voiceBroadcastStoppedEvent = mkVoiceBroadcastInfoStateEvent( voiceBroadcastStoppedEvent = mkVoiceBroadcastInfoStateEvent(
roomId, roomId,
VoiceBroadcastInfoState.Stopped, VoiceBroadcastInfoState.Stopped,

View file

@ -119,7 +119,7 @@ const setUpClientRoomAndStores = (): {
skey: stateKey, skey: stateKey,
content: content as IContent, content: content as IContent,
}); });
room.addLiveEvents([event]); room.addLiveEvents([event], { addToState: true });
return { event_id: event.getId()! }; return { event_id: event.getId()! };
}); });

View file

@ -202,6 +202,7 @@ describe("MemberListStore", () => {
function addEventToRoom(room: Room, ev: MatrixEvent) { function addEventToRoom(room: Room, ev: MatrixEvent) {
room.getLiveTimeline().addEvent(ev, { room.getLiveTimeline().addEvent(ev, {
toStartOfTimeline: false, toStartOfTimeline: false,
addToState: true,
}); });
} }

View file

@ -397,7 +397,7 @@ describe("RoomViewStore", function () {
mockClient.getSafeUserId(), mockClient.getSafeUserId(),
"ABC123", "ABC123",
); );
room2.addLiveEvents([broadcastEvent]); room2.addLiveEvents([broadcastEvent], { addToState: true });
stores.voiceBroadcastPlaybacksStore.getByInfoEvent(broadcastEvent, mockClient); stores.voiceBroadcastPlaybacksStore.getByInfoEvent(broadcastEvent, mockClient);
dis.dispatch({ action: Action.ViewRoom, room_id: roomId2 }); dis.dispatch({ action: Action.ViewRoom, room_id: roomId2 });

View file

@ -35,7 +35,7 @@ describe("MessagePreviewStore", () => {
event: MatrixEvent, event: MatrixEvent,
fireAction = true, fireAction = true,
): Promise<void> { ): Promise<void> {
room.addLiveEvents([event]); room.addLiveEvents([event], { addToState: true });
if (fireAction) { if (fireAction) {
// @ts-ignore private access // @ts-ignore private access
await store.onAction({ await store.onAction({

View file

@ -47,11 +47,11 @@ describe("RecentAlgorithm", () => {
room.getMyMembership = () => KnownMembership.Join; room.getMyMembership = () => KnownMembership.Join;
room.addLiveEvents([event1]); room.addLiveEvents([event1], { addToState: true });
expect(algorithm.getLastTs(room, "@jane:matrix.org")).toBe(5); expect(algorithm.getLastTs(room, "@jane:matrix.org")).toBe(5);
expect(algorithm.getLastTs(room, "@john:matrix.org")).toBe(5); expect(algorithm.getLastTs(room, "@john:matrix.org")).toBe(5);
room.addLiveEvents([event2]); room.addLiveEvents([event2], { addToState: true });
expect(algorithm.getLastTs(room, "@jane:matrix.org")).toBe(10); expect(algorithm.getLastTs(room, "@jane:matrix.org")).toBe(10);
expect(algorithm.getLastTs(room, "@john:matrix.org")).toBe(10); expect(algorithm.getLastTs(room, "@john:matrix.org")).toBe(10);
@ -94,8 +94,8 @@ describe("RecentAlgorithm", () => {
event: true, event: true,
}); });
room1.addLiveEvents([evt]); room1.addLiveEvents([evt], { addToState: true });
room2.addLiveEvents([evt2]); room2.addLiveEvents([evt2], { addToState: true });
expect(algorithm.sortRooms([room2, room1], DefaultTagID.Untagged)).toEqual([room1, room2]); expect(algorithm.sortRooms([room2, room1], DefaultTagID.Untagged)).toEqual([room1, room2]);
}); });
@ -115,7 +115,7 @@ describe("RecentAlgorithm", () => {
event: true, event: true,
}); });
room1.addLiveEvents([evt]); room1.addLiveEvents([evt], { addToState: true });
expect(algorithm.sortRooms([room2, room1], DefaultTagID.Untagged)).toEqual([room2, room1]); expect(algorithm.sortRooms([room2, room1], DefaultTagID.Untagged)).toEqual([room2, room1]);
@ -127,7 +127,7 @@ describe("RecentAlgorithm", () => {
ts: 12, ts: 12,
}); });
room1.addLiveEvents(events); room1.addLiveEvents(events, { addToState: true });
}); });
it("orders rooms based on thread replies too", () => { it("orders rooms based on thread replies too", () => {
@ -145,7 +145,7 @@ describe("RecentAlgorithm", () => {
ts: 12, ts: 12,
length: 5, length: 5,
}); });
room1.addLiveEvents(events1); room1.addLiveEvents(events1, { addToState: true });
const { events: events2 } = mkThread({ const { events: events2 } = mkThread({
room: room2, room: room2,
@ -155,7 +155,7 @@ describe("RecentAlgorithm", () => {
ts: 14, ts: 14,
length: 10, length: 10,
}); });
room2.addLiveEvents(events2); room2.addLiveEvents(events2, { addToState: true });
expect(algorithm.sortRooms([room1, room2], DefaultTagID.Untagged)).toEqual([room2, room1]); expect(algorithm.sortRooms([room1, room2], DefaultTagID.Untagged)).toEqual([room2, room1]);
@ -169,7 +169,7 @@ describe("RecentAlgorithm", () => {
// replies are 1ms after each other // replies are 1ms after each other
ts: 50, ts: 50,
}); });
room1.addLiveEvents([threadReply]); room1.addLiveEvents([threadReply], { addToState: true });
expect(algorithm.sortRooms([room1, room2], DefaultTagID.Untagged)).toEqual([room1, room2]); expect(algorithm.sortRooms([room1, room2], DefaultTagID.Untagged)).toEqual([room1, room2]);
}); });

View file

@ -70,7 +70,7 @@ describe("ReactionEventPreview", () => {
room: roomId, room: roomId,
}); });
room.getUnfilteredTimelineSet().addLiveEvent(message, {}); room.getUnfilteredTimelineSet().addLiveEvent(message, { addToState: true });
const event = mkEvent({ const event = mkEvent({
event: true, event: true,
@ -107,7 +107,7 @@ describe("ReactionEventPreview", () => {
room: roomId, room: roomId,
}); });
room.getUnfilteredTimelineSet().addLiveEvent(message, {}); room.getUnfilteredTimelineSet().addLiveEvent(message, { addToState: true });
const event = mkEvent({ const event = mkEvent({
event: true, event: true,

View file

@ -29,7 +29,7 @@ describe("useTopic", () => {
event: true, event: true,
}); });
room.addLiveEvents([topic]); room.addLiveEvents([topic], { addToState: true });
function RoomTopic() { function RoomTopic() {
const topic = useTopic(room); const topic = useTopic(room);
@ -52,7 +52,7 @@ describe("useTopic", () => {
}); });
act(() => { act(() => {
room.addLiveEvents([updatedTopic]); room.addLiveEvents([updatedTopic], { addToState: true });
}); });
expect(screen.queryByText("New topic")).toBeInTheDocument(); expect(screen.queryByText("New topic")).toBeInTheDocument();

View file

@ -593,18 +593,21 @@ describe("HTMLExport", () => {
it("should not make /messages requests when exporting 'Current Timeline'", async () => { it("should not make /messages requests when exporting 'Current Timeline'", async () => {
client.createMessagesRequest.mockRejectedValue(new Error("Should never be called")); client.createMessagesRequest.mockRejectedValue(new Error("Should never be called"));
room.addLiveEvents([ room.addLiveEvents(
new MatrixEvent({ [
event_id: `$eventId`, new MatrixEvent({
type: EventType.RoomMessage, event_id: `$eventId`,
sender: client.getSafeUserId(), type: EventType.RoomMessage,
origin_server_ts: 123456789, sender: client.getSafeUserId(),
content: { origin_server_ts: 123456789,
msgtype: "m.text", content: {
body: `testing testing`, msgtype: "m.text",
}, body: `testing testing`,
}), },
]); }),
],
{ addToState: true },
);
const exporter = new HTMLExporter( const exporter = new HTMLExporter(
room, room,

View file

@ -121,7 +121,7 @@ describe("notifications", () => {
user: USER_ID, user: USER_ID,
msg: "Hello", msg: "Hello",
}); });
room.addLiveEvents([message]); room.addLiveEvents([message], { addToState: true });
sendReadReceiptSpy = jest.spyOn(client, "sendReadReceipt").mockResolvedValue({}); sendReadReceiptSpy = jest.spyOn(client, "sendReadReceipt").mockResolvedValue({});
jest.spyOn(client, "getRooms").mockReturnValue([room]); jest.spyOn(client, "getRooms").mockReturnValue([room]);
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => { jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
@ -187,7 +187,7 @@ describe("notifications", () => {
user: USER_ID, user: USER_ID,
ts: 1, ts: 1,
}); });
room.addLiveEvents([message]); room.addLiveEvents([message], { addToState: true });
room.setUnreadNotificationCount(NotificationCountType.Total, 1); room.setUnreadNotificationCount(NotificationCountType.Total, 1);
await clearAllNotifications(client); await clearAllNotifications(client);
@ -202,7 +202,7 @@ describe("notifications", () => {
user: USER_ID, user: USER_ID,
ts: 1, ts: 1,
}); });
room.addLiveEvents([message]); room.addLiveEvents([message], { addToState: true });
room.setUnreadNotificationCount(NotificationCountType.Total, 1); room.setUnreadNotificationCount(NotificationCountType.Total, 1);
jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false); jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false);

View file

@ -85,7 +85,7 @@ describe("VoiceBroadcastBody", () => {
deviceId, deviceId,
infoEvent, infoEvent,
); );
room.addEventsToTimeline([infoEvent], true, room.getLiveTimeline()); room.addEventsToTimeline([infoEvent], true, true, room.getLiveTimeline());
testRecording = new VoiceBroadcastRecording(infoEvent, client); testRecording = new VoiceBroadcastRecording(infoEvent, client);
testPlayback = new VoiceBroadcastPlayback(infoEvent, client, new VoiceBroadcastRecordingsStore()); testPlayback = new VoiceBroadcastPlayback(infoEvent, client, new VoiceBroadcastRecordingsStore());
mocked(VoiceBroadcastRecordingBody).mockImplementation(({ recording }): ReactElement | null => { mocked(VoiceBroadcastRecordingBody).mockImplementation(({ recording }): ReactElement | null => {
@ -127,7 +127,7 @@ describe("VoiceBroadcastBody", () => {
describe("when there is a stopped voice broadcast", () => { describe("when there is a stopped voice broadcast", () => {
beforeEach(() => { beforeEach(() => {
room.addEventsToTimeline([stoppedEvent], true, room.getLiveTimeline()); room.addEventsToTimeline([stoppedEvent], true, true, room.getLiveTimeline());
renderVoiceBroadcast(); renderVoiceBroadcast();
}); });
@ -148,7 +148,7 @@ describe("VoiceBroadcastBody", () => {
describe("and the recordings ends", () => { describe("and the recordings ends", () => {
beforeEach(() => { beforeEach(() => {
act(() => { act(() => {
room.addEventsToTimeline([stoppedEvent], true, room.getLiveTimeline()); room.addEventsToTimeline([stoppedEvent], true, true, room.getLiveTimeline());
}); });
}); });

View file

@ -243,7 +243,7 @@ describe("VoiceBroadcastPlayback", () => {
beforeEach(async () => { beforeEach(async () => {
infoEvent = mkInfoEvent(VoiceBroadcastInfoState.Resumed); infoEvent = mkInfoEvent(VoiceBroadcastInfoState.Resumed);
createChunkEvents(); createChunkEvents();
room.addLiveEvents([infoEvent]); room.addLiveEvents([infoEvent], { addToState: true });
playback = await mkPlayback(); playback = await mkPlayback();
}); });
@ -331,7 +331,7 @@ describe("VoiceBroadcastPlayback", () => {
infoEvent = mkInfoEvent(VoiceBroadcastInfoState.Resumed); infoEvent = mkInfoEvent(VoiceBroadcastInfoState.Resumed);
createChunkEvents(); createChunkEvents();
setUpChunkEvents([chunk2Event, chunk1Event]); setUpChunkEvents([chunk2Event, chunk1Event]);
room.addLiveEvents([infoEvent, chunk1Event, chunk2Event]); room.addLiveEvents([infoEvent, chunk1Event, chunk2Event], { addToState: true });
room.relations.aggregateChildEvent(chunk2Event); room.relations.aggregateChildEvent(chunk2Event);
room.relations.aggregateChildEvent(chunk1Event); room.relations.aggregateChildEvent(chunk1Event);
playback = await mkPlayback(); playback = await mkPlayback();
@ -372,7 +372,7 @@ describe("VoiceBroadcastPlayback", () => {
describe("and an event with the same transaction Id occurs", () => { describe("and an event with the same transaction Id occurs", () => {
beforeEach(() => { beforeEach(() => {
room.addLiveEvents([chunk2BEvent]); room.addLiveEvents([chunk2BEvent], { addToState: true });
room.relations.aggregateChildEvent(chunk2BEvent); room.relations.aggregateChildEvent(chunk2BEvent);
}); });
@ -404,7 +404,7 @@ describe("VoiceBroadcastPlayback", () => {
infoEvent, infoEvent,
2, 2,
); );
room.addLiveEvents([stoppedEvent]); room.addLiveEvents([stoppedEvent], { addToState: true });
room.relations.aggregateChildEvent(stoppedEvent); room.relations.aggregateChildEvent(stoppedEvent);
chunk2Playback.emit(PlaybackState.Stopped); chunk2Playback.emit(PlaybackState.Stopped);
}); });
@ -426,7 +426,7 @@ describe("VoiceBroadcastPlayback", () => {
infoEvent, infoEvent,
3, 3,
); );
room.addLiveEvents([stoppedEvent]); room.addLiveEvents([stoppedEvent], { addToState: true });
room.relations.aggregateChildEvent(stoppedEvent); room.relations.aggregateChildEvent(stoppedEvent);
chunk2Playback.emit(PlaybackState.Stopped); chunk2Playback.emit(PlaybackState.Stopped);
}); });
@ -435,7 +435,7 @@ describe("VoiceBroadcastPlayback", () => {
describe("and the next chunk arrives", () => { describe("and the next chunk arrives", () => {
beforeEach(() => { beforeEach(() => {
room.addLiveEvents([chunk3Event]); room.addLiveEvents([chunk3Event], { addToState: true });
room.relations.aggregateChildEvent(chunk3Event); room.relations.aggregateChildEvent(chunk3Event);
}); });
@ -521,7 +521,7 @@ describe("VoiceBroadcastPlayback", () => {
createChunkEvents(); createChunkEvents();
// use delayed first chunk here to simulate loading time // use delayed first chunk here to simulate loading time
setUpChunkEvents([chunk2Event, deplayedChunk1Event, chunk3Event]); setUpChunkEvents([chunk2Event, deplayedChunk1Event, chunk3Event]);
room.addLiveEvents([infoEvent, deplayedChunk1Event, chunk2Event, chunk3Event]); room.addLiveEvents([infoEvent, deplayedChunk1Event, chunk2Event, chunk3Event], { addToState: true });
playback = await mkPlayback(true); playback = await mkPlayback(true);
}); });

View file

@ -32,7 +32,7 @@ describe("hasRoomLiveVoiceBroadcast", () => {
startedEvent?: MatrixEvent, startedEvent?: MatrixEvent,
): MatrixEvent => { ): MatrixEvent => {
const infoEvent = mkVoiceBroadcastInfoStateEvent(room.roomId, state, userId, deviceId, startedEvent); const infoEvent = mkVoiceBroadcastInfoStateEvent(room.roomId, state, userId, deviceId, startedEvent);
room.addLiveEvents([infoEvent]); room.addLiveEvents([infoEvent], { addToState: true });
room.currentState.setStateEvents([infoEvent]); room.currentState.setStateEvents([infoEvent]);
room.relations.aggregateChildEvent(infoEvent); room.relations.aggregateChildEvent(infoEvent);
return infoEvent; return infoEvent;

View file

@ -31,7 +31,7 @@ const mkRelatedEvent = (
}, },
user: client.getSafeUserId(), user: client.getSafeUserId(),
}); });
room.addLiveEvents([event]); room.addLiveEvents([event], { addToState: true });
return event; return event;
}; };
@ -65,7 +65,7 @@ describe("isRelatedToVoiceBroadcast", () => {
user: client.getSafeUserId(), user: client.getSafeUserId(),
}); });
room.addLiveEvents([broadcastEvent, nonBroadcastEvent]); room.addLiveEvents([broadcastEvent, nonBroadcastEvent], { addToState: true });
}); });
it("should return true if related (reference) to a broadcast event", () => { it("should return true if related (reference) to a broadcast event", () => {

View file

@ -67,7 +67,7 @@ describe("retrieveStartedInfoEvent", () => {
it("when the room contains the event, it should return it", async () => { it("when the room contains the event, it should return it", async () => {
const startEvent = mkStartEvent(); const startEvent = mkStartEvent();
const stopEvent = mkStopEvent(startEvent); const stopEvent = mkStopEvent(startEvent);
room.addLiveEvents([startEvent]); room.addLiveEvents([startEvent], { addToState: true });
expect(await retrieveStartedInfoEvent(stopEvent, client)).toBe(startEvent); expect(await retrieveStartedInfoEvent(stopEvent, client)).toBe(startEvent);
}); });