Class: EventTimeline

models/event-timeline~EventTimeline

new EventTimeline(eventTimelineSet)

Construct a new EventTimeline

An EventTimeline represents a contiguous sequence of events in a room.

As well as keeping track of the events themselves, it stores the state of the room at the beginning and end of the timeline, and pagination tokens for going backwards and forwards in the timeline.

In order that clients can meaningfully maintain an index into a timeline, the EventTimeline object tracks a 'baseIndex'. This starts at zero, but is incremented when events are prepended to the timeline. The index of an event relative to baseIndex therefore remains constant.

Once a timeline joins up with its neighbour, they are linked together into a doubly-linked list.

Parameters:
Name Type Description
eventTimelineSet EventTimelineSet the set of timelines this is part of
Source:

Members

(static) BACKWARDS

Symbolic constant for methods which take a 'direction' argument: refers to the start of the timeline, or backwards in time.
Source:

(static) FORWARDS

Symbolic constant for methods which take a 'direction' argument: refers to the end of the timeline, or forwards in time.
Source:

Methods

(static) setEventMetadata(event, stateContext, toStartOfTimeline)

Static helper method to set sender and target properties
Parameters:
Name Type Description
event MatrixEvent the event whose metadata is to be set
stateContext RoomState the room state to be queried
toStartOfTimeline bool if true the event's forwardLooking flag is set false
Source:

addEvent(event, atStart)

Add a new event to the timeline, and update the state
Parameters:
Name Type Description
event MatrixEvent new event
atStart boolean true to insert new event at the start
Source:

getBaseIndex() → {number}

Get the base index.

This is an index which is incremented when events are prepended to the timeline. An individual event therefore stays at the same index in the array relative to the base index (although note that a given event's index may well be less than the base index, thus giving that event a negative relative index).

Source:
Returns:
Type
number

getEvents() → {Array.<MatrixEvent>}

Get the list of events in this context
Source:
Returns:
An array of MatrixEvents
Type
Array.<MatrixEvent>

getFilter() → {Filter}

Get the filter for this timeline's timelineSet (if any)
Source:
Returns:
filter
Type
Filter

getNeighbouringTimeline(direction) → (nullable) {EventTimeline}

Get the next timeline in the series
Parameters:
Name Type Description
direction string EventTimeline.BACKWARDS to get the previous timeline; EventTimeline.FORWARDS to get the next timeline.
Source:
Returns:
previous or following timeline, if they have been joined up.
Type
EventTimeline

getPaginationToken(direction) → (nullable) {string}

Get a pagination token
Parameters:
Name Type Description
direction string EventTimeline.BACKWARDS to get the pagination token for going backwards in time; EventTimeline.FORWARDS to get the pagination token for going forwards in time.
Source:
Returns:
pagination token
Type
string

getRoomId() → {string}

Get the ID of the room for this timeline
Source:
Returns:
room ID
Type
string

getState(direction) → {RoomState}

Get the room state at the start/end of the timeline
Parameters:
Name Type Description
direction string EventTimeline.BACKWARDS to get the state at the start of the timeline; EventTimeline.FORWARDS to get the state at the end of the timeline.
Source:
Returns:
state at the start/end of the timeline
Type
RoomState

getTimelineSet() → {EventTimelineSet}

Get the timelineSet for this timeline
Source:
Returns:
timelineSet
Type
EventTimelineSet

initialiseState(stateEvents)

Initialise the start and end state with the given events

This can only be called before any events are added.

Parameters:
Name Type Description
stateEvents Array.<MatrixEvent> list of state events to initialise the state with.
Source:
Throws:
if an attempt is made to call this after addEvent is called.
Type
Error

removeEvent(eventId) → (nullable) {MatrixEvent}

Remove an event from the timeline
Parameters:
Name Type Description
eventId string ID of event to be removed
Source:
Returns:
removed event, or null if not found
Type
MatrixEvent

setNeighbouringTimeline(neighbour, direction)

Set the next timeline in the series
Parameters:
Name Type Description
neighbour EventTimeline previous/following timeline
direction string EventTimeline.BACKWARDS to set the previous timeline; EventTimeline.FORWARDS to set the next timeline.
Source:
Throws:
if an attempt is made to set the neighbouring timeline when it is already set.
Type
Error

setPaginationToken(tokennullable, direction)

Set a pagination token
Parameters:
Name Type Attributes Description
token string <nullable>
pagination token
direction string EventTimeline.BACKWARDS to set the pagination token for going backwards in time; EventTimeline.FORWARDS to set the pagination token for going forwards in time.
Source:

toString() → {string}

Return a string to identify this timeline, for debugging
Source:
Returns:
name for this timeline
Type
string