Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy committed Nov 8, 2024
1 parent f010962 commit f8574e9
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions spec/integ/crypto/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,

const syncResponse = getSyncResponse(["@bob:xyz"]);
// Every 2 messages in the room, the session should be rotated
syncResponse.rooms[Category.Join][ROOM_ID].state.events[0].content = {
syncResponse.rooms[Category.Join][ROOM_ID].state!.events[0].content = {
algorithm: "m.megolm.v1.aes-sha2",
rotation_period_msgs: 2,
};
Expand Down Expand Up @@ -1383,7 +1383,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
const oneHourInMs = 60 * 60 * 1000;

// Every 1h the session should be rotated
syncResponse.rooms[Category.Join][ROOM_ID].state.events[0].content = {
syncResponse.rooms[Category.Join][ROOM_ID].state!.events[0].content = {
algorithm: "m.megolm.v1.aes-sha2",
rotation_period_ms: oneHourInMs,
};
Expand Down
8 changes: 4 additions & 4 deletions spec/integ/matrix-client-syncing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ describe("MatrixClient syncing", () => {
});

it("should resolve incoming invites from /sync", () => {
syncData.rooms.join[roomOne].state.events.push(
syncData.rooms.join[roomOne].state!.events.push(
utils.mkMembership({
room: roomOne,
mship: KnownMembership.Invite,
Expand Down Expand Up @@ -589,7 +589,7 @@ describe("MatrixClient syncing", () => {
name: "The Ghost",
}) as IMinimalEvent,
];
syncData.rooms.join[roomOne].state.events.push(
syncData.rooms.join[roomOne].state!.events.push(
utils.mkMembership({
room: roomOne,
mship: KnownMembership.Invite,
Expand Down Expand Up @@ -617,7 +617,7 @@ describe("MatrixClient syncing", () => {
name: "The Ghost",
}) as IMinimalEvent,
];
syncData.rooms.join[roomOne].state.events.push(
syncData.rooms.join[roomOne].state!.events.push(
utils.mkMembership({
room: roomOne,
mship: KnownMembership.Invite,
Expand All @@ -644,7 +644,7 @@ describe("MatrixClient syncing", () => {
});

it("should no-op if resolveInvitesToProfiles is not set", () => {
syncData.rooms.join[roomOne].state.events.push(
syncData.rooms.join[roomOne].state!.events.push(
utils.mkMembership({
room: roomOne,
mship: KnownMembership.Invite,
Expand Down
2 changes: 1 addition & 1 deletion spec/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function getSyncResponse(roomMembers: string[], roomId = TEST_ROOM_ID): I
};

for (let i = 0; i < roomMembers.length; i++) {
roomResponse.state.events.push(
roomResponse.state!.events.push(
mkMembershipCustom({
membership: KnownMembership.Join,
sender: roomMembers[i],
Expand Down
2 changes: 1 addition & 1 deletion src/models/event-timeline-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
// If we got to the end of the loop, insertIndex points at the end of
// the list.

timeline.insertEvent(event, insertIndex, roomState);
timeline.insertEvent(event, insertIndex, roomState, addToState);
this._eventIdToTimeline.set(eventId, timeline);

const data: IRoomTimelineData = {
Expand Down
4 changes: 2 additions & 2 deletions src/models/event-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,14 @@ export class EventTimeline {
*
* @internal
*/
public insertEvent(event: MatrixEvent, insertIndex: number, roomState: RoomState): void {
public insertEvent(event: MatrixEvent, insertIndex: number, roomState: RoomState, addToState: boolean): void {
const timelineSet = this.getTimelineSet();

if (timelineSet.room) {
EventTimeline.setEventMetadata(event, roomState, false);

// modify state but only on unfiltered timelineSets
if (event.isState() && timelineSet.room.getUnfilteredTimelineSet() === timelineSet) {
if (addToState && event.isState() && timelineSet.room.getUnfilteredTimelineSet() === timelineSet) {
roomState.setStateEvents([event], {});
// it is possible that the act of setting the state event means we
// can set more metadata (specifically sender/target props), so try
Expand Down
2 changes: 1 addition & 1 deletion src/models/room-member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class RoomMember extends TypedEventEmitter<RoomMemberEvent, RoomMemberEve
this.events.member = event;

const oldMembership = this.membership;
this.membership = event.getDirectionalContent().membership;
this.membership = event.getDirectionalContent().membership; // XXX debug?
if (this.membership === undefined) {
// logging to diagnose https://github.com/vector-im/element-web/issues/20962
// (logs event content, although only of membership events)
Expand Down
16 changes: 8 additions & 8 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
// see https://github.com/vector-im/vector-web/issues/2109

unfilteredLiveTimeline.getEvents().forEach(function (event) {
timelineSet.addLiveEvent(event, { addToState: true });
timelineSet.addLiveEvent(event, { addToState: false }); // Filtered timeline sets should not track state
});

// find the earliest unfiltered timeline
Expand Down Expand Up @@ -1995,7 +1995,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
if (filterType !== ThreadFilterType.My || currentUserParticipated) {
timelineSet.getLiveTimeline().addEvent(thread.rootEvent!, {
toStartOfTimeline: false,
addToState: true,
addToState: false,
});
}
});
Expand Down Expand Up @@ -2070,7 +2070,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
const opts = {
duplicateStrategy: DuplicateStrategy.Ignore,
fromCache: false,
addToState: true,
addToState: false,
roomState,
};
this.threadsTimelineSets[0]?.addLiveEvent(rootEvent, opts);
Expand Down Expand Up @@ -2193,7 +2193,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
duplicateStrategy: DuplicateStrategy.Replace,
fromCache: false,
roomState,
addToState: true,
addToState: false,
});
}
}
Expand Down Expand Up @@ -2385,12 +2385,12 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
duplicateStrategy: DuplicateStrategy.Replace,
fromCache: false,
roomState: this.currentState,
addToState: true,
addToState: false,
});
} else {
timelineSet.addEventToTimeline(thread.rootEvent, timelineSet.getLiveTimeline(), {
toStartOfTimeline,
addToState: true,
addToState: false,
});
}
}
Expand Down Expand Up @@ -2640,13 +2640,13 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
if (timelineSet.getFilter()!.filterRoomTimeline([event]).length) {
timelineSet.addEventToTimeline(event, timelineSet.getLiveTimeline(), {
toStartOfTimeline: false,
addToState: false,
addToState: false, // We don't support localEcho of state events yet
});
}
} else {
timelineSet.addEventToTimeline(event, timelineSet.getLiveTimeline(), {
toStartOfTimeline: false,
addToState: false,
addToState: false, // We don't support localEcho of state events yet
});
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/sync-accumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export interface ITimeline {

export interface IJoinedRoom {
"summary": IRoomSummary;
"state": IState;
// One of `state` or `state_after` is required.
"state"?: IState;
"org.matrix.msc4222.state_after"?: IState; // https://github.com/matrix-org/matrix-spec-proposals/pull/4222
"timeline": ITimeline;
"ephemeral": IEphemeral;
Expand Down Expand Up @@ -107,7 +108,8 @@ export interface IInvitedRoom {
}

export interface ILeftRoom {
"state": IState;
// One of `state` or `state_after` is required.
"state"?: IState;
"org.matrix.msc4222.state_after"?: IState;
"timeline": ITimeline;
"account_data": IAccountData;
Expand Down Expand Up @@ -660,7 +662,7 @@ export class SyncAccumulator {
// Push to both fields to provide downgrade compatibility in the sync accumulator db
// the code will prefer `state_after` if it is present
roomJson["org.matrix.msc4222.state_after"]?.events.push(ev);
roomJson.state.events.push(ev);
roomJson.state?.events.push(ev);
});
});
data.join[roomId] = roomJson;
Expand Down
2 changes: 1 addition & 1 deletion src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ export class SyncApi {
const events = this.mapSyncEventsFormat(leaveObj.timeline, room);
const accountDataEvents = this.mapSyncEventsFormat(leaveObj.account_data);

await this.injectRoomEvents(room, undefined, stateEvents, events);
await this.injectRoomEvents(room, stateEvents, undefined, events);
room.addAccountData(accountDataEvents);

room.recalculate();
Expand Down

0 comments on commit f8574e9

Please sign in to comment.