From 1da26b5cd199650f77bf3f62a60d84b9add5e270 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 Jan 2025 10:16:45 +0000 Subject: [PATCH] Fix issue with sentinels being incorrect on m.room.member events (#4609) * Fix issue with sentinels being incorrect on m.room.member events Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Simplify change Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- spec/unit/event-timeline-set.spec.ts | 26 +++++++++++++++ src/client.ts | 4 +-- src/models/event-timeline.ts | 22 +------------ src/models/event.ts | 49 ++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 24 deletions(-) diff --git a/spec/unit/event-timeline-set.spec.ts b/spec/unit/event-timeline-set.spec.ts index 61b30edb36d..352e882130c 100644 --- a/spec/unit/event-timeline-set.spec.ts +++ b/spec/unit/event-timeline-set.spec.ts @@ -23,6 +23,7 @@ import { EventTimelineSet, EventType, Filter, + KnownMembership, MatrixClient, MatrixEvent, MatrixEventEvent, @@ -138,6 +139,31 @@ describe("EventTimelineSet", () => { expect(eventsInLiveTimeline.length).toStrictEqual(1); expect(eventsInLiveTimeline[0]).toStrictEqual(duplicateMessageEvent); }); + + it("should set event.target after applying the membership state update", () => { + const eventTimelineSet = room.getUnfilteredTimelineSet(); + + const ev1 = utils.mkMembership({ + room: roomId, + mship: KnownMembership.Invite, + user: "@sender:server", + skey: userA, + event: true, + }); + const ev2 = utils.mkMembership({ + room: roomId, + mship: KnownMembership.Join, + user: userA, + skey: userA, + name: "This is my displayname", + event: true, + }); + + eventTimelineSet.addLiveEvent(ev1, { addToState: true }); + expect(ev1.target?.name).toBe(userA); + eventTimelineSet.addLiveEvent(ev2, { addToState: true }); + expect(ev2.target?.name).toBe("This is my displayname"); + }); }); describe("addEventToTimeline", () => { diff --git a/src/client.ts b/src/client.ts index eea8faa708f..0e49b16091c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -7348,10 +7348,8 @@ export class MatrixClient extends TypedEventEmitter void; [MatrixEventEvent.Replaced]: (event: MatrixEvent) => void; [MatrixEventEvent.RelationsCreated]: (relationType: string, eventType: string) => void; + [MatrixEventEvent.SentinelUpdated]: () => void; } & Pick; export class MatrixEvent extends TypedEventEmitter { @@ -328,6 +331,7 @@ export class MatrixEvent extends TypedEventEmitter