Skip to content
Open
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
11 changes: 9 additions & 2 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface IUnsigned {
"invite_room_state"?: StrippedState[];
"m.relations"?: Record<RelationType | string, any>; // No common pattern for aggregated relations
"msc4354_sticky_duration_ttl_ms"?: number;
"msc4354_sticky_ttl_start_ms"?: number;
[UNSIGNED_THREAD_ID_FIELD.name]?: string;
"membership"?: Membership;
"io.element.msc4115.membership"?: Membership;
Expand Down Expand Up @@ -463,7 +464,10 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
this.reEmitter = new TypedReEmitter(this);
if (this.unstableStickyInfo) {
if (this.unstableStickyInfo.duration_ttl_ms) {
this.unstableStickyExpiresAt = now + this.unstableStickyInfo.duration_ttl_ms;
const established = this.unstableStickyInfo?.ttl_start_ms ?? now;
const elapsed = now - established;
const remainingTtl = this.unstableStickyInfo.duration_ttl_ms - elapsed;
this.unstableStickyExpiresAt = now + remainingTtl;
} else {
// Bound the timestamp so it doesn't come from the future.
this.unstableStickyExpiresAt = Math.min(now, this.getTs()) + this.unstableStickyInfo.duration_ms;
Expand Down Expand Up @@ -1768,14 +1772,17 @@ 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 {
public get unstableStickyInfo():
| { duration_ms: number; duration_ttl_ms?: number; ttl_start_ms?: number }
| undefined {
if (!this.event.msc4354_sticky?.duration_ms) {
return undefined;
}
return {
duration_ms: Math.min(MAX_STICKY_DURATION_MS, this.event.msc4354_sticky.duration_ms),
// This is assumed to be bounded server-side.
duration_ttl_ms: this.event.unsigned?.msc4354_sticky_duration_ttl_ms,
ttl_start_ms: this.event.unsigned?.msc4354_sticky_ttl_start_ms,
};
}
}
Expand Down
Loading