import { type MatrixEvent } from "./event.ts"; import { TypedEventEmitter } from "./typed-event-emitter.ts"; export declare enum RoomStickyEventsEvent { Update = "RoomStickyEvents.Update" } export type StickyMatrixEvent = MatrixEvent & { /** * When the event actually expires, preferring the server-provided TTL. * This differs by homeserver and client and should be used for expiry only. * * @experimental Part of MSC4354. */ unstableStickyExpiresAt: number; /** * When the sender's homeserver intended the event to expire. This is stable across * different homeservers and clients and should be used for ordering only. * * @experimental Part of MSC4354. */ unstableStickyIntendedExpiresAt: number; }; export type RoomStickyEventsMap = { /** * Fires when any sticky event changes happen in a room. * @param added Any new sticky events with no predecessor events (matching sender, type, and sticky_key) * @param updated Any sticky events that supersede an existing event (matching sender, type, and sticky_key) * @param removed The events that were removed from the map due to expiry. */ [RoomStickyEventsEvent.Update]: (added: StickyMatrixEvent[], updated: { current: StickyMatrixEvent; previous: StickyMatrixEvent; }[], removed: StickyMatrixEvent[]) => void; }; /** * Tracks sticky events on behalf of one room, and fires an event * whenever a sticky event is updated or replaced. */ export declare class RoomStickyEventsStore extends TypedEventEmitter { /** * Sticky event map is a nested map of: * eventType -> `content.sticky_key sender` -> StickyMatrixEvent[] * * The events are ordered descendingly by intended expiry, tie breaking on the event ID, so that the first * event in the array will always be the "current" one. */ private readonly stickyEventsMap; /** * These are sticky events that have no sticky key and therefore exist outside the tuple * system above. They are just held in this Set until they expire. */ private readonly unkeyedStickyEvents; private stickyEventTimer?; private nextStickyEventExpiryTs; /** * Sort two sticky events by intended expiry, tie breaking on the event ID. This assumes the sticky events have * the same `type`, `sticky_key` and `sender`. * * @returns A positive value if event A was intended to expire sooner, or a negative value if event B was. */ private static sortStickyEvent; /** * Check whether a sticky event has expired. * @param event The sticky event to check. * @param now The current time in milliseconds since the epoch. * @returns True if the event has expired, false otherwise. */ private static isExpired; /** * Generate the correct key for an event to be found in the inner maps of `stickyEventsMap`. * @param stickyKey The sticky key of an event. * @param sender The sender of the event. */ private static stickyMapKey; /** * Get all sticky events that are currently active. * @returns An iterable set of events. * @yields {@link StickyMatrixEvent} */ getStickyEvents(): Iterable; /** * Get an active sticky event that match the given `type`, `sender`, and `stickyKey` * @param type The event `type`. * @param sender The sender of the sticky event. * @param stickyKey The sticky key used by the event. * @returns A matching active sticky event, or undefined. */ getKeyedStickyEvent(sender: string, type: string, stickyKey: string): StickyMatrixEvent | undefined; /** * Get active sticky events without a sticky key that match the given `type` and `sender`. * @param type The event `type`. * @param sender The sender of the sticky event. * @returns An array of matching sticky events. */ getUnkeyedStickyEvent(sender: string, type: string): StickyMatrixEvent[]; /** * Adds a sticky event into the local sticky event map. * * NOTE: This will not cause `RoomEvent.StickyEvents` to be emitted. * * @throws If the `event` does not contain valid sticky data. * @param event The MatrixEvent that contains sticky data. * @returns An object describing whether the event was added to the map, * and the previous event it may have replaced. */ private addStickyEvent; /** * Adds the event to the map once it has been decrypted, emitting `RoomEvent.StickyEvents` at that point. * * Decryption may fail because the keys haven't arrived yet, in which case we keep waiting. An event that * is never decrypted simply never enters the map. */ private addStickyEventOnceDecrypted; /** * Add a series of sticky events, emitting `RoomEvent.StickyEvents` if any * changes were made. * @param events A set of new sticky events. */ addStickyEvents(events: MatrixEvent[]): void; /** * Schedule the sticky event expiry timer. The timer will * run immediately if an event has already expired. */ private scheduleStickyTimer; /** * Clean out any expired sticky events. */ private readonly cleanExpiredStickyEvents; /** * Handles incoming event redactions. Checks the sticky map * for any active sticky events being redacted. * @param redactedEvent The MatrixEvent OR event ID of the event being redacted. MAY not be a sticky event. */ handleRedaction(redactedEvent: MatrixEvent | string): void; /** * Remove a redacted event from an entry of the keyed sticky map, emitting * `RoomEvent.StickyEvents` if this changes the "current" event of that entry. * @param eventType The event `type` of the redacted event. * @param mapKey The inner map key of the redacted event, see {@link stickyMapKey}. * @param redactEventId The ID of the redacted event. */ private removeKeyedStickyEvent; /** * Clear all events and stop the timer from firing. */ clear(): void; } //# sourceMappingURL=room-sticky-events.d.ts.map