TimelineWindow
Defined in: src/timeline-window.ts:53
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TimelineWindow(
client,timelineSet,opts?):TimelineWindow
Defined in: src/timeline-window.ts:87
Construct a TimelineWindow.
This abstracts the separate timelines in a [Room](/messaging-js/reference/client/classes/room/) into a single iterable thing. It keeps track of the start and endpoints of the window, which can be advanced with the help of pagination requests.
Before the window is useful, it must be initialised by calling [TimelineWindow#load](/messaging-js/reference/client/classes/timelinewindow/#load).
Note that the window will not automatically extend itself when new events are received from /sync; you should arrange to call [TimelineWindow#paginate](/messaging-js/reference/client/classes/timelinewindow/#paginate) on [RoomEvent.Timeline](/messaging-js/reference/client/enumerations/roomevent/#timeline) events.
Note that constructing an instance of this class for a room adds a listener for RoomEvent.Timeline events which is never removed. In theory this should not cause a leak since the EventEmitter uses weak mappings.
Parameters
Section titled “Parameters”client
Section titled “client”DigitalWorldClient to be used for context/pagination requests.
timelineSet
Section titled “timelineSet”The timelineSet to track
IOpts = {}
Configuration options for this window
Returns
Section titled “Returns”TimelineWindow
Methods
Section titled “Methods”canPaginate()
Section titled “canPaginate()”canPaginate(
direction):boolean
Defined in: src/timeline-window.ts:230
Check if this window can be extended
This returns true if we either have more events, or if we have a pagination token which means we can paginate in that direction. It does not necessarily mean that there are more events available in that direction at this time.
Parameters
Section titled “Parameters”direction
Section titled “direction”EventTimeline.BACKWARDS to check if we can paginate backwards; EventTimeline.FORWARDS to check if we can go forwards
Returns
Section titled “Returns”boolean
true if we can paginate in the given direction
extend()
Section titled “extend()”extend(
direction,size):boolean
Defined in: src/timeline-window.ts:176
Try to extend the window using events that are already in the underlying TimelineIndex.
Parameters
Section titled “Parameters”direction
Section titled “direction”EventTimeline.BACKWARDS to try extending it backwards; EventTimeline.FORWARDS to try extending it forwards.
number
number of events to try to extend by.
Returns
Section titled “Returns”boolean
true if the window was extended, false otherwise.
getEvents()
Section titled “getEvents()”getEvents():
DigitalWorldEvent[]
Defined in: src/timeline-window.ts:386
Get a list of the events currently in the window
Returns
Section titled “Returns”the events in the window
getTimelineIndex()
Section titled “getTimelineIndex()”getTimelineIndex(
direction):TimelineIndex|null
Defined in: src/timeline-window.ts:156
Get the TimelineIndex of the window in the given direction.
Parameters
Section titled “Parameters”direction
Section titled “direction”EventTimeline.BACKWARDS to get the TimelineIndex at the start of the window; EventTimeline.FORWARDS to get the TimelineIndex at the end.
Returns
Section titled “Returns”TimelineIndex | null
The requested timeline index if one exists, null otherwise.
load()
Section titled “load()”load(
initialEventId?,initialWindowSize?):Promise<void>
Defined in: src/timeline-window.ts:103
Initialise the window to point at a given event, or the live timeline
Parameters
Section titled “Parameters”initialEventId?
Section titled “initialEventId?”string
If given, the window will contain the given event
initialWindowSize?
Section titled “initialWindowSize?”number = 20
Size of the initial window
Returns
Section titled “Returns”Promise<void>
paginate()
Section titled “paginate()”paginate(
direction,size,makeRequest?,requestLimit?):Promise<boolean>
Defined in: src/timeline-window.ts:275
Attempt to extend the window
Parameters
Section titled “Parameters”direction
Section titled “direction”EventTimeline.BACKWARDS to extend the window backwards (towards older events); EventTimeline.FORWARDS to go forwards.
number
number of events to try to extend by. If fewer than this number are immediately available, then we return immediately rather than making an API call.
makeRequest?
Section titled “makeRequest?”boolean = true
whether we should make API calls to fetch further events if we don’t have any at all. (This has no effect if the room already knows about additional events in the relevant direction, even if there are fewer than ‘size’ of them, as we will just return those we already know about.)
requestLimit?
Section titled “requestLimit?”number = DEFAULT_PAGINATE_LOOP_LIMIT
limit for the number of API requests we should make.
Returns
Section titled “Returns”Promise<boolean>
Promise which resolves to a boolean which is true if more events were successfully retrieved.
unpaginate()
Section titled “unpaginate()”unpaginate(
delta,startOfTimeline):void
Defined in: src/timeline-window.ts:353
Remove delta events from the start or end of the timeline.
Parameters
Section titled “Parameters”number
number of events to remove from the timeline
startOfTimeline
Section titled “startOfTimeline”boolean
if events should be removed from the start of the timeline.
Returns
Section titled “Returns”void