Typed Event Emitter class which can act as a Base Model for all our model and communication events. This makes it much easier for us to distinguish between events, as we now need to properly type this, so that our events are not stringly-based and prone to silly typos.

Type parameters:

  • Events - List of all events emitted by this TypedEventEmitter. Normally an enum type.
  • Arguments - A ListenerMap type providing mappings from event names to listener types.
  • SuperclassArguments - TODO: not really sure. Alternative listener mappings, I think? But only honoured for .emit?

Hierarchy (view full)

Constructors

  • 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.

    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.

    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.

    In order that we can find events from their ids later, we also maintain a map from event_id to timeline and index.

    Parameters

    • room: undefined | Room

      Room for this timelineSet. May be null for non-room cases, such as the notification timeline.

    • opts: IOpts = {}

      Options inherited from Room.

    • Optionalclient: MatrixClient

      the Matrix client which owns this EventTimelineSet, can be omitted if room is specified.

    • Optionalthread: Thread

      the thread to which this timeline set relates.

    • threadListType: null | ThreadFilterType = null

      the type of thread list represented, if any (e.g., All threads or My threads)

    Returns EventTimelineSet

Properties

room: undefined | Room

Room for this timelineSet. May be null for non-room cases, such as the notification timeline.

thread?: Thread

the thread to which this timeline set relates.

threadListType: null | ThreadFilterType = null

the type of thread list represented, if any (e.g., All threads or My threads)

Methods

  • Add events to a timeline

    Will fire "Room.timeline" for each event added.

    Parameters

    • events: MatrixEvent[]

      A list of events to add.

    • toStartOfTimeline: boolean

      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 last element of 'events'.

    • timeline: EventTimeline

      timeline to add events to.

    • OptionalpaginationToken: null | string

      token for the next batch of events

    Returns void

    Fires RoomEvent.Timeline

  • 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.

    Parameters

    • event: MatrixEvent

      the event to check whether it belongs to this timeline set.

    Returns boolean

    whether the event belongs to this timeline set.

    Error if room was not set when constructing this timeline set.

  • Determine where two events appear in the timeline relative to one another

    Parameters

    • eventId1: string

      The id of the first event

    • eventId2: string

      The id of the second event

    Returns null | number

    -1 if eventId1 precedes eventId2, and +1 eventId1 succeeds eventId2. 0 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).

  • Synchronously calls each of the listeners registered for the event named event, in the order they were registered, passing the supplied arguments to each.

    Type Parameters

    Parameters

    Returns boolean

    true if the event had listeners, false otherwise.

  • Synchronously calls each of the listeners registered for the event namedeventName, in the order they were registered, passing the supplied arguments to each.

    Returns true if the event had listeners, false otherwise.

    import EventEmitter from 'node:events';
    const myEmitter = new EventEmitter();

    // First listener
    myEmitter.on('event', function firstListener() {
    console.log('Helloooo! first listener');
    });
    // Second listener
    myEmitter.on('event', function secondListener(arg1, arg2) {
    console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
    });
    // Third listener
    myEmitter.on('event', function thirdListener(...args) {
    const parameters = args.join(', ');
    console.log(`event with parameters ${parameters} in third listener`);
    });

    console.log(myEmitter.listeners('event'));

    myEmitter.emit('event', 1, 2, 3, 4, 5);

    // Prints:
    // [
    // [Function: firstListener],
    // [Function: secondListener],
    // [Function: thirdListener]
    // ]
    // Helloooo! first listener
    // event with parameters 1, 2 in second listener
    // event with parameters 1, 2, 3, 4, 5 in third listener

    Type Parameters

    Parameters

    Returns boolean

    v0.1.26

  • Get the list of pending sent events for this timelineSet's room, filtered by the timelineSet's filter if appropriate.

    Returns MatrixEvent[]

    A list of the sent events waiting for remote echo.

    If opts.pendingEventOrdering was not 'detached'

  • Replaces event with ID oldEventId with one with newEventId, if oldEventId is recognised. Otherwise, add to the live timeline. Used to handle remote echos.

    Parameters

    • localEvent: MatrixEvent

      the new event to be added to the timeline

    • oldEventId: string

      the ID of the original event

    • newEventId: string

      the ID of the replacement event

    Returns void

    Fires RoomEvent.Timeline

  • Internal

    Insert event to the given timeline, and emit Room.timeline. Assumes we have already checked we don't know about this event.

    TEMPORARY: until we have recursive relations, we need this function to exist to allow us to insert events in timeline order, which is our best guess for Sync Order. This is a copy of addEventToTimeline above, modified to insert the event after the event it relates to, and before any event with a later timestamp. This is our best guess at Sync Order.

    Will fire "Room.timeline" for each event added.

    Parameters

    Returns void

    Fires RoomEvent.Timeline

  • Adds the listener function to the end of the listeners array for the event named event.

    No checks are made to see if the listener has already been added. Multiple calls passing the same combination of event and listener will result in the listener being added, and called, multiple times.

    By default, event listeners are invoked in the order they are added. The prependListener method can be used as an alternative to add the event listener to the beginning of the listeners array.

    Type Parameters

    Parameters

    Returns this

    a reference to the EventEmitter, so that calls can be chained.

  • Removes all listeners, or those of the specified event.

    It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

    Parameters

    Returns this

    a reference to the EventEmitter, so that calls can be chained.

  • Track a new event as if it were in the same timeline as an old event, replacing it.

    Parameters

    • oldEventId: string

      event ID of the original event

    • newEventId: string

      event ID of the replacement event

    Returns void

  • Reset the live timeline, and start a new one.

    This is used when /sync returns a 'limited' timeline.

    Parameters

    • OptionalbackPaginationToken: string

      token for back-paginating the new timeline

    • OptionalforwardPaginationToken: string

      token for forward-paginating the old live timeline, if absent or null, all timelines are reset.

    Returns void

  • Set the filter object this timeline set is filtered on (passed to the server when paginating via /messages).

    Parameters

    • Optionalfilter: Filter

      the filter for this timelineSet

    Returns void