Skip to content

Commit 7fedcaf

Browse files
toger5Half-Shot
authored andcommitted
use sticky events from the timeline
Signed-off-by: Timo K <[email protected]>
1 parent ab8d315 commit 7fedcaf

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/models/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface IEvent {
9696
membership?: Membership;
9797
unsigned: IUnsigned;
9898
redacts?: string;
99-
sticky?: number;
99+
msc4354_sticky?: number;
100100
}
101101

102102
export interface IAggregatedRelation {

src/models/room.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,7 +3454,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
34543454
private getNextStickyExpiryTs(): number | null {
34553455
let nextExpiry = null;
34563456
for (const event of this.stickyEventsMap.values()) {
3457-
const expiry = event.getTs() + event.event.sticky!;
3457+
const expiry = event.getTs() + event.event.msc4354_sticky!;
34583458
if (nextExpiry === null || expiry < nextExpiry) {
34593459
nextExpiry = expiry;
34603460
}
@@ -3467,7 +3467,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
34673467
for (const [key, event] of this.stickyEventsMap.entries()) {
34683468
const creationTs = event.getTs();
34693469
// we only added items with `sticky` into this map so we can assert non-null here
3470-
if (now > creationTs + event.event.sticky!) {
3470+
if (now > creationTs + event.event.msc4354_sticky!) {
34713471
toRemove.push(key);
34723472
}
34733473
}

src/sync.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,13 @@ export class SyncApi {
14051405
// we deliberately don't add accountData to the timeline
14061406
room.addAccountData(accountDataEvents);
14071407

1408-
room.addStickyEvents(stickyEvents);
1408+
// events from the sticky section of the sync come first (those are the ones that would be skipped due to gappy syncs)
1409+
// hence we consider them as older.
1410+
// and we add the events from the timeline at the end (newer)
1411+
const stickyEventsAndStickyEventsFromTheTimeline = stickyEvents.concat(
1412+
timelineEvents.filter((e) => e.event.msc4354_sticky !== undefined),
1413+
);
1414+
room.addStickyEvents(stickyEventsAndStickyEventsFromTheTimeline);
14091415

14101416
room.recalculate();
14111417
if (joinObj.isBrandNewRoom) {

0 commit comments

Comments
 (0)