summaryrefslogtreecommitdiff
path: root/includes/external/matrix/node_modules/matrix-js-sdk/lib/models/event-timeline-set.d.ts
blob: 88bddd61b558790bd583f99c990842e83f9c498f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import { EventTimeline, IAddEventOptions } from "./event-timeline";
import { MatrixEvent } from "./event";
import { Room, RoomEvent } from "./room";
import { Filter } from "../filter";
import { RoomState } from "./room-state";
import { TypedEventEmitter } from "./typed-event-emitter";
import { RelationsContainer } from "./relations-container";
import { MatrixClient } from "../client";
import { Thread, ThreadFilterType } from "./thread";
interface IOpts {
    timelineSupport?: boolean;
    filter?: Filter;
    pendingEvents?: boolean;
}
export declare enum DuplicateStrategy {
    Ignore = "ignore",
    Replace = "replace"
}
export interface IRoomTimelineData {
    timeline: EventTimeline;
    liveEvent?: boolean;
}
export interface IAddEventToTimelineOptions extends Pick<IAddEventOptions, "toStartOfTimeline" | "roomState" | "timelineWasEmpty"> {
    /** Whether the sync response came from cache */
    fromCache?: boolean;
}
export interface IAddLiveEventOptions extends Pick<IAddEventToTimelineOptions, "fromCache" | "roomState" | "timelineWasEmpty"> {
    /** Applies to events in the timeline only. If this is 'replace' then if a
     * duplicate is encountered, the event passed to this function will replace
     * the existing event in the timeline. If this is not specified, or is
     * 'ignore', then the event passed to this function will be ignored
     * entirely, preserving the existing event in the timeline. Events are
     * identical based on their event ID <b>only</b>. */
    duplicateStrategy?: DuplicateStrategy;
}
type EmittedEvents = RoomEvent.Timeline | RoomEvent.TimelineReset;
export type EventTimelineSetHandlerMap = {
    /**
     * Fires whenever the timeline in a room is updated.
     * @param event - The matrix event which caused this event to fire.
     * @param room - The room, if any, whose timeline was updated.
     * @param toStartOfTimeline - True if this event was added to the start
     * @param removed - True if this event has just been removed from the timeline
     * (beginning; oldest) of the timeline e.g. due to pagination.
     *
     * @param data - more data about the event
     *
     * @example
     * ```
     * matrixClient.on("Room.timeline",
     *                 function(event, room, toStartOfTimeline, removed, data) {
     *   if (!toStartOfTimeline && data.liveEvent) {
     *     var messageToAppend = room.timeline.[room.timeline.length - 1];
     *   }
     * });
     * ```
     */
    [RoomEvent.Timeline]: (event: MatrixEvent, room: Room | undefined, toStartOfTimeline: boolean | undefined, removed: boolean, data: IRoomTimelineData) => void;
    /**
     * Fires whenever the live timeline in a room is reset.
     *
     * When we get a 'limited' sync (for example, after a network outage), we reset
     * the live timeline to be empty before adding the recent events to the new
     * timeline. This event is fired after the timeline is reset, and before the
     * new events are added.
     *
     * @param room - The room whose live timeline was reset, if any
     * @param timelineSet - timelineSet room whose live timeline was reset
     * @param resetAllTimelines - True if all timelines were reset.
     */
    [RoomEvent.TimelineReset]: (room: Room | undefined, eventTimelineSet: EventTimelineSet, resetAllTimelines: boolean) => void;
};
export declare class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTimelineSetHandlerMap> {
    readonly room: Room | undefined;
    readonly thread?: Thread | undefined;
    readonly threadListType: ThreadFilterType | null;
    readonly relations: RelationsContainer;
    private readonly timelineSupport;
    private readonly displayPendingEvents;
    private liveTimeline;
    private timelines;
    private _eventIdToTimeline;
    private filter?;
    /**
     * Construct a set of EventTimeline objects, typically on behalf of a given
     * room.  A room may have multiple EventTimelineSets for different levels
     * of filtering.  The global notification list is also an EventTimelineSet, but
     * lacks a room.
     *
     * <p>This is an ordered sequence of timelines, which may or may not
     * be continuous. Each timeline lists a series of events, as well as tracking
     * the room state at the start and the end of the timeline (if appropriate).
     * It also tracks forward and backward pagination tokens, as well as containing
     * links to the next timeline in the sequence.
     *
     * <p>There is one special timeline - the 'live' timeline, which represents the
     * timeline to which events are being added in real-time as they are received
     * from the /sync API. Note that you should not retain references to this
     * timeline - even if it is the current timeline right now, it may not remain
     * so if the server gives us a timeline gap in /sync.
     *
     * <p>In order that we can find events from their ids later, we also maintain a
     * map from event_id to timeline and index.
     *
     * @param room - Room for this timelineSet. May be null for non-room cases, such as the
     * notification timeline.
     * @param opts - Options inherited from Room.
     * @param client - the Matrix client which owns this EventTimelineSet,
     * can be omitted if room is specified.
     * @param thread - the thread to which this timeline set relates.
     * @param isThreadTimeline - Whether this timeline set relates to a thread list timeline
     * (e.g., All threads or My threads)
     */
    constructor(room: Room | undefined, opts?: IOpts, client?: MatrixClient, thread?: Thread | undefined, threadListType?: ThreadFilterType | null);
    /**
     * Get all the timelines in this set
     * @returns the timelines in this set
     */
    getTimelines(): EventTimeline[];
    /**
     * Get the filter object this timeline set is filtered on, if any
     * @returns the optional filter for this timelineSet
     */
    getFilter(): Filter | undefined;
    /**
     * Set the filter object this timeline set is filtered on
     * (passed to the server when paginating via /messages).
     * @param filter - the filter for this timelineSet
     */
    setFilter(filter?: Filter): void;
    /**
     * Get the list of pending sent events for this timelineSet's room, filtered
     * by the timelineSet's filter if appropriate.
     *
     * @returns A list of the sent events
     * waiting for remote echo.
     *
     * @throws If `opts.pendingEventOrdering` was not 'detached'
     */
    getPendingEvents(): MatrixEvent[];
    /**
     * Get the live timeline for this room.
     *
     * @returns live timeline
     */
    getLiveTimeline(): EventTimeline;
    /**
     * Set the live timeline for this room.
     *
     * @returns live timeline
     */
    setLiveTimeline(timeline: EventTimeline): void;
    /**
     * Return the timeline (if any) this event is in.
     * @param eventId - the eventId being sought
     * @returns timeline
     */
    eventIdToTimeline(eventId: string): EventTimeline | undefined;
    /**
     * Track a new event as if it were in the same timeline as an old event,
     * replacing it.
     * @param oldEventId -  event ID of the original event
     * @param newEventId -  event ID of the replacement event
     */
    replaceEventId(oldEventId: string, newEventId: string): void;
    /**
     * Reset the live timeline, and start a new one.
     *
     * <p>This is used when /sync returns a 'limited' timeline.
     *
     * @param backPaginationToken -   token for back-paginating the new timeline
     * @param forwardPaginationToken - token for forward-paginating the old live timeline,
     * if absent or null, all timelines are reset.
     *
     * @remarks
     * Fires {@link RoomEvent.TimelineReset}
     */
    resetLiveTimeline(backPaginationToken?: string, forwardPaginationToken?: string): void;
    /**
     * Get the timeline which contains the given event, if any
     *
     * @param eventId -  event ID to look for
     * @returns timeline containing
     * the given event, or null if unknown
     */
    getTimelineForEvent(eventId?: string): EventTimeline | null;
    /**
     * Get an event which is stored in our timelines
     *
     * @param eventId -  event ID to look for
     * @returns the given event, or undefined if unknown
     */
    findEventById(eventId: string): MatrixEvent | undefined;
    /**
     * Add a new timeline to this timeline list
     *
     * @returns newly-created timeline
     */
    addTimeline(): EventTimeline;
    /**
     * Add events to a timeline
     *
     * <p>Will fire "Room.timeline" for each event added.
     *
     * @param events - A list of events to add.
     *
     * @param toStartOfTimeline -   True to add these events to the start
     * (oldest) instead of the end (newest) of the timeline. If true, the oldest
     * event will be the <b>last</b> element of 'events'.
     *
     * @param timeline -   timeline to
     *    add events to.
     *
     * @param paginationToken -   token for the next batch of events
     *
     * @remarks
     * Fires {@link RoomEvent.Timeline}
     *
     */
    addEventsToTimeline(events: MatrixEvent[], toStartOfTimeline: boolean, timeline: EventTimeline, paginationToken?: string | null): void;
    /**
     * Add an event to the end of this live timeline.
     *
     * @param event - Event to be added
     * @param options - addLiveEvent options
     */
    addLiveEvent(event: MatrixEvent, { duplicateStrategy, fromCache, roomState, timelineWasEmpty }: IAddLiveEventOptions): void;
    /**
     * @deprecated In favor of the overload with `IAddLiveEventOptions`
     */
    addLiveEvent(event: MatrixEvent, duplicateStrategy?: DuplicateStrategy, fromCache?: boolean, roomState?: RoomState): void;
    /**
     * Add event to the given timeline, and emit Room.timeline. Assumes
     * we have already checked we don't know about this event.
     *
     * Will fire "Room.timeline" for each event added.
     *
     * @param options - addEventToTimeline options
     *
     * @remarks
     * Fires {@link RoomEvent.Timeline}
     */
    addEventToTimeline(event: MatrixEvent, timeline: EventTimeline, { toStartOfTimeline, fromCache, roomState, timelineWasEmpty }: IAddEventToTimelineOptions): void;
    /**
     * @deprecated In favor of the overload with `IAddEventToTimelineOptions`
     */
    addEventToTimeline(event: MatrixEvent, timeline: EventTimeline, toStartOfTimeline: boolean, fromCache?: boolean, roomState?: RoomState): void;
    /**
     * Replaces event with ID oldEventId with one with newEventId, if oldEventId is
     * recognised.  Otherwise, add to the live timeline.  Used to handle remote echos.
     *
     * @param localEvent -     the new event to be added to the timeline
     * @param oldEventId -          the ID of the original event
     * @param newEventId -         the ID of the replacement event
     *
     * @remarks
     * Fires {@link RoomEvent.Timeline}
     */
    handleRemoteEcho(localEvent: MatrixEvent, oldEventId: string, newEventId: string): void;
    /**
     * Removes a single event from this room.
     *
     * @param eventId -  The id of the event to remove
     *
     * @returns the removed event, or null if the event was not found
     * in this room.
     */
    removeEvent(eventId: string): MatrixEvent | null;
    /**
     * Determine where two events appear in the timeline relative to one another
     *
     * @param eventId1 -   The id of the first event
     * @param eventId2 -   The id of the second event

     * @returns a number less than zero if eventId1 precedes eventId2, and
     *    greater than zero if eventId1 succeeds eventId2. zero if they are the
     *    same event; null if we can't tell (either because we don't know about one
     *    of the events, or because they are in separate timelines which don't join
     *    up).
     */
    compareEventOrdering(eventId1: string, eventId2: string): number | null;
    /**
     * Determine whether a given event can sanely be added to this event timeline set,
     * for timeline sets relating to a thread, only return true for events in the same
     * thread timeline, for timeline sets not relating to a thread only return true
     * for events which should be shown in the main room timeline.
     * Requires the `room` property to have been set at EventTimelineSet construction time.
     *
     * @param event - the event to check whether it belongs to this timeline set.
     * @throws Error if `room` was not set when constructing this timeline set.
     * @returns whether the event belongs to this timeline set.
     */
    canContain(event: MatrixEvent): boolean;
}
export {};
//# sourceMappingURL=event-timeline-set.d.ts.map