Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/@types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,28 @@ export const UNSIGNED_THREAD_ID_FIELD = new UnstableValue("thread_id", "org.matr
*/
export const UNSIGNED_MEMBERSHIP_FIELD = new NamespacedValue("membership", "io.element.msc4115.membership");


/**
* https://github.com/matrix-org/matrix-spec-proposals/pull/4354
*
* @experimental
*/
export const STICKY_EVENT_FIELD = new NamespacedValue(null, "msc4354_sticky");

/**
* https://github.com/matrix-org/matrix-spec-proposals/pull/4354
*
* @experimental
*/
export const STICKY_EVENT_KEY_FIELD = new NamespacedValue(null, "msc4354_sticky_key");

/**
* https://github.com/matrix-org/matrix-spec-proposals/pull/4354
*
* @experimental
*/
export const STICKY_EVENT_DURATION_TTL_MS = new NamespacedValue(null, "msc4354_sticky_duration_ttl_ms")

/**
* Mapped type from event type to content type for all specified non-state room events.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
RoomCreateTypeField,
RoomType,
type StateEvents,
STICKY_EVENT_KEY_FIELD,
type TimelineEvents,
UNSTABLE_MSC3088_ENABLED,
UNSTABLE_MSC3088_PURPOSE,
Expand Down Expand Up @@ -3443,7 +3444,7 @@
delayOpts: SendDelayedEventRequestOpts,
threadId: string | null,
eventType: K,
content: TimelineEvents[K] & { msc4354_sticky_key: string },
content: TimelineEvents[K] & { [STICKY_EVENT_KEY_FIELD.name]: string },
txnId?: string,
): Promise<SendDelayedEventResponse> {
if (!(await this.doesServerSupportUnstableFeature(UNSTABLE_MSC4140_DELAYED_EVENTS))) {
Expand Down Expand Up @@ -4288,9 +4289,9 @@
);
})
.then((res: IMessagesResponse) => {
const matrixEvents = res.chunk.map(this.getEventMapper());

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.

Check failure on line 4292 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IRoomEvent, index: number, array: IRoomEvent[]) => MatrixEvent'.
if (res.state) {
const stateEvents = res.state.map(this.getEventMapper());

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.

Check failure on line 4294 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IStateEvent, index: number, array: IStateEvent[]) => MatrixEvent'.
room.currentState.setUnknownStateEvents(stateEvents);
}

Expand Down Expand Up @@ -4385,7 +4386,7 @@
}

const mapper = this.getEventMapper();
const event = mapper(res.event);

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4389 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.
if (event.isRelation(THREAD_RELATION_TYPE.name)) {
this.logger.warn("Tried loading a regular timeline at the position of a thread event");
return undefined;
Expand All @@ -4394,18 +4395,18 @@
// Order events from most recent to oldest (reverse-chronological).
// We start with the last event, since that's the point at which we have known state.
// events_after is already backwards; events_before is forwards.
...res.events_after.reverse().map(mapper),

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4398 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.
event,
...res.events_before.map(mapper),

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4400 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.
];

// Here we handle non-thread timelines only, but still process any thread events to populate thread summaries.
let timeline = timelineSet.getTimelineForEvent(events[0].getId());
if (timeline) {
timeline.getState(EventTimeline.BACKWARDS)!.setUnknownStateEvents(res.state.map(mapper));

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4406 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.
} else {
timeline = timelineSet.addTimeline();
timeline.initialiseState(res.state.map(mapper));

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4409 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.
timeline.getState(EventTimeline.FORWARDS)!.paginationToken = res.end;
}

Expand Down Expand Up @@ -4454,7 +4455,7 @@
// TODO: we should implement a backoff (as per scrollback()) to deal more nicely with HTTP errors.
const res = await this.http.authedRequest<IContextResponse>(Method.Get, path, params);
const mapper = this.getEventMapper();
const event = mapper(res.event);

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

Check failure on line 4458 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'IEventWithRoomId' is not assignable to parameter of type 'Partial<IEvent>'.

if (!timelineSet.canContain(event)) {
return undefined;
Expand Down Expand Up @@ -4498,10 +4499,10 @@
// Here we handle non-thread timelines only, but still process any thread events to populate thread summaries.
let timeline = timelineSet.getTimelineForEvent(event.getId());
if (timeline) {
timeline.getState(EventTimeline.BACKWARDS)!.setUnknownStateEvents(res.state.map(mapper));

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4502 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.
} else {
timeline = timelineSet.addTimeline();
timeline.initialiseState(res.state.map(mapper));

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / ESLint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.

Check failure on line 4505 in src/client.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Argument of type 'EventMapper' is not assignable to parameter of type '(value: IEventWithRoomId, index: number, array: IEventWithRoomId[]) => MatrixEvent'.
}

timelineSet.addEventsToTimeline(events, true, false, timeline, resNewer.next_batch);
Expand Down
4 changes: 2 additions & 2 deletions src/matrixrtc/CallMembership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { type LivekitFocusSelection } from "./LivekitTransport.ts";
import { slotDescriptionToId, slotIdToDescription, type SlotDescription } from "./MatrixRTCSession.ts";
import type { RTCCallIntent, Transport } from "./types.ts";
import { type IContent, type MatrixEvent } from "../models/event.ts";
import { type RelationType } from "../@types/event.ts";
import { STICKY_EVENT_KEY_FIELD, type RelationType } from "../@types/event.ts";
import { logger } from "../logger.ts";

/**
Expand All @@ -47,7 +47,7 @@ export interface RtcMembershipData {
};
"rtc_transports": Transport[];
"versions": string[];
"msc4354_sticky_key"?: string;
[STICKY_EVENT_KEY_FIELD.name]?: string;
"sticky_key"?: string;
}

Expand Down
13 changes: 8 additions & 5 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
ToDeviceMessageId,
UNSIGNED_THREAD_ID_FIELD,
UNSIGNED_MEMBERSHIP_FIELD,
STICKY_EVENT_DURATION_TTL_MS,
STICKY_EVENT_FIELD,
} from "../@types/event.ts";
import { deepSortedObjectEntries, internaliseString } from "../utils.ts";
import { type RoomMember } from "./room-member.ts";
Expand Down Expand Up @@ -75,7 +77,7 @@ export interface IUnsigned {
"transaction_id"?: string;
"invite_room_state"?: StrippedState[];
"m.relations"?: Record<RelationType | string, any>; // No common pattern for aggregated relations
"msc4354_sticky_duration_ttl_ms"?: number;
[STICKY_EVENT_DURATION_TTL_MS.name]?: number;
[UNSIGNED_THREAD_ID_FIELD.name]?: string;
}

Expand All @@ -97,7 +99,7 @@ export interface IEvent {
membership?: Membership;
unsigned: IUnsigned;
redacts?: string;
msc4354_sticky?: { duration_ms: number };
[STICKY_EVENT_FIELD.name]?: { duration_ms: number };
}

export interface IAggregatedRelation {
Expand Down Expand Up @@ -1771,13 +1773,14 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
* `duration_ms` is safely bounded to a hour.
*/
public get unstableStickyInfo(): { duration_ms: number; duration_ttl_ms?: number } | undefined {
if (!this.event.msc4354_sticky?.duration_ms) {
const stickyInfo = (this.event[STICKY_EVENT_FIELD.name] ?? this.event[STICKY_EVENT_FIELD.unstable!]) as { duration_ms: number }|undefined;
if (!stickyInfo?.duration_ms) {
return undefined;
}
return {
duration_ms: Math.min(MAX_STICKY_DURATION_MS, this.event.msc4354_sticky.duration_ms),
duration_ms: Math.min(MAX_STICKY_DURATION_MS, stickyInfo.duration_ms),
// This is assumed to be bounded server-side.
duration_ttl_ms: this.event.unsigned?.msc4354_sticky_duration_ttl_ms,
duration_ttl_ms: this.event.unsigned?.[STICKY_EVENT_DURATION_TTL_MS.name] ?? this.event.unsigned?.[STICKY_EVENT_DURATION_TTL_MS.unstable!],
};
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/models/room-sticky-events.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { STICKY_EVENT_KEY_FIELD } from "src/matrix.ts";
import { logger as loggerInstance } from "../logger.ts";
import { type MatrixEvent } from "./event.ts";
import { TypedEventEmitter } from "./typed-event-emitter.ts";
Expand Down Expand Up @@ -78,14 +79,14 @@ export class RoomStickyEventsStore extends TypedEventEmitter<RoomStickyEventsEve
* and the previous event it may have replaced.
*/
private addStickyEvent(event: MatrixEvent): { added: true; prevEvent?: StickyMatrixEvent } | { added: false } {
const stickyKey = event.getContent().msc4354_sticky_key;
const stickyKey = event.getContent()[STICKY_EVENT_KEY_FIELD.name] ?? event.getContent()[STICKY_EVENT_KEY_FIELD.unstable!];
if (typeof stickyKey !== "string" && stickyKey !== undefined) {
throw new Error(`${event.getId()} is missing msc4354_sticky_key`);
throw new Error(`${event.getId()} is missing ${STICKY_EVENT_KEY_FIELD.name}`);
}

// With this we have the guarantee, that all events in stickyEventsMap are correctly formatted
if (event.unstableStickyExpiresAt === undefined) {
throw new Error(`${event.getId()} is missing msc4354_sticky.duration_ms`);
throw new Error(`${event.getId()} is missing ${STICKY_EVENT_KEY_FIELD.name}.duration_ms`);
}
const sender = event.getSender();
const type = event.getType();
Expand Down
23 changes: 14 additions & 9 deletions src/sync-accumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { logger } from "./logger.ts";
import { deepCopy } from "./utils.ts";
import { MAX_STICKY_DURATION_MS, type IContent, type IUnsigned } from "./models/event.ts";
import { type IRoomSummary } from "./models/room-summary.ts";
import { type EventType } from "./@types/event.ts";
import { STICKY_EVENT_FIELD, STICKY_EVENT_KEY_FIELD, type EventType } from "./@types/event.ts";
import { UNREAD_THREAD_NOTIFICATIONS } from "./@types/sync.ts";
import { ReceiptAccumulator } from "./receipt-accumulator.ts";
import { type OlmEncryptionInfo } from "./crypto-api/index.ts";
Expand Down Expand Up @@ -77,8 +77,8 @@ export interface ITimeline {
}

type StickyEventFields = {
msc4354_sticky: { duration_ms: number };
content: { msc4354_sticky_key?: string };
[STICKY_EVENT_FIELD.name]: { duration_ms: number };
content: { [STICKY_EVENT_KEY_FIELD.name]?: string };
};

export type IStickyEvent = IRoomEvent & StickyEventFields;
Expand All @@ -94,7 +94,7 @@ export interface IJoinedRoom {
// 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
"msc4354_sticky"?: ISticky; // https://github.com/matrix-org/matrix-spec-proposals/pull/4354
[STICKY_EVENT_FIELD.name]: ISticky; // https://github.com/matrix-org/matrix-spec-proposals/pull/4354
"timeline": ITimeline;
"ephemeral": IEphemeral;
"account_data": IAccountData;
Expand Down Expand Up @@ -570,18 +570,23 @@ export class SyncAccumulator {

// We want this to be fast, so don't worry about duplicate events here. The RoomStickyEventsStore will
// process these events into the correct mapped order.
if (data.msc4354_sticky?.events) {
const stickyEventData = (data.sticky ?? data['msc4354_sticky']) as ISticky;
if (stickyEventData?.events.length) {
currentData._stickyEvents = currentData._stickyEvents.concat(
data.msc4354_sticky.events.map((event) => {
stickyEventData.events.map((event) => {
// If `duration_ms` exceeds the spec limit of a hour, we cap it.
const cappedDuration = Math.min(event.msc4354_sticky.duration_ms, MAX_STICKY_DURATION_MS);
const duration = event['sticky_event']?.duration_ms ?? event['msc4354_sticky']?.duration_ms;
if (typeof duration !== "number") {
return null;
}
const cappedDuration = Math.min(duration, MAX_STICKY_DURATION_MS);
// If `origin_server_ts` claims to have been from the future, we still bound it to now.
const createdTs = Math.min(event.origin_server_ts, now);
return {
event,
expiresTs: cappedDuration + createdTs,
};
}),
}).filter(e => e !== null),
);
}

Expand Down Expand Up @@ -659,7 +664,7 @@ export class SyncAccumulator {
"msc4354_sticky": roomData._stickyEvents?.length
? {
events: roomData._stickyEvents.map((e) => e.event),
}
} satisfies ISticky
: undefined,
};
// Add account data
Expand Down
5 changes: 3 additions & 2 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
type ResetTimelineCallback,
} from "./client.ts";
import {
ISticky,
type IEphemeral,
type IInvitedRoom,
type IInviteState,
Expand All @@ -58,7 +59,7 @@ import {
import { MatrixEvent } from "./models/event.ts";
import { type MatrixError, Method } from "./http-api/index.ts";
import { type ISavedSync } from "./store/index.ts";
import { EventType } from "./@types/event.ts";
import { EventType, STICKY_EVENT_FIELD } from "./@types/event.ts";
import { type IPushRules } from "./@types/PushRules.ts";
import { type IMarkerFoundOptions, RoomStateEvent } from "./models/room-state.ts";
import { RoomMemberEvent } from "./models/room-member.ts";
Expand Down Expand Up @@ -1221,7 +1222,7 @@ export class SyncApi {
const timelineEvents = this.mapSyncEventsFormat(joinObj.timeline, room, false);
const ephemeralEvents = this.mapSyncEventsFormat(joinObj.ephemeral);
const accountDataEvents = this.mapSyncEventsFormat(joinObj.account_data);
const stickyEvents = this.mapSyncEventsFormat(joinObj.msc4354_sticky);
const stickyEvents = this.mapSyncEventsFormat((joinObj[STICKY_EVENT_FIELD.name] ?? joinObj[STICKY_EVENT_FIELD.unstable!]) as ISticky);

// If state_after is present, this is the events that form the state at the end of the timeline block and
// regular timeline events do *not* count towards state. If it's not present, then the state is formed by
Expand Down
Loading