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 room state.

    Room State represents the state of the room at a given point. It can be mutated by adding state events to it. There are two types of room member associated with a state event: normal member objects (accessed via getMember/getMembers) which mutate with the state to represent the current state of that room/user, e.g. the object returned by getMember('@bob:example.com') will mutate to get a different display name if Bob later changes his display name in the room. There are also 'sentinel' members (accessed via getSentinelMember). These also represent the state of room members at the point in time represented by the RoomState object, but unlike objects from getMember, sentinel objects will always represent the room state as at the time getSentinelMember was called, so if Bob subsequently changes his display name, a room member object previously acquired with getSentinelMember will still have his old display name. Calling getSentinelMember again after the display name change will return a new RoomMember object with Bob's new display name.

    Parameters

    • roomId: string

      Optional. The ID of the room which has this state. If none is specified it just tracks paginationTokens, useful for notifTimelineSet

    • oobMemberFlags: {
          status: OobStatus;
      } = ...

      Optional. The state of loading out of bound members. As the timeline might get reset while they are loading, this state needs to be inherited and shared when the room state is cloned for the new timeline. This should only be passed from clone.

    • isStartTimelineState: boolean = false

      Optional. This state is marked as a start state. This is used to skip state insertions that are in the wrong order. The order is determined by the replaces_state id.

      Example: A current state events replaces_state value is 1. Trying to insert a state event with event_id 1 in its place would fail if isStartTimelineState = false.

      A current state events event_id is 2. Trying to insert a state event where its replaces_state value is 2 would fail if isStartTimelineState = true.

    Returns RoomState

Properties

beacons: Map<string, Beacon> = ...
events: Map<string, Map<string, MatrixEvent>> = ...
isStartTimelineState: boolean = false

Optional. This state is marked as a start state. This is used to skip state insertions that are in the wrong order. The order is determined by the replaces_state id.

Example: A current state events replaces_state value is 1. Trying to insert a state event with event_id 1 in its place would fail if isStartTimelineState = false.

A current state events event_id is 2. Trying to insert a state event where its replaces_state value is 2 would fail if isStartTimelineState = true.

members: Record<string, RoomMember> = {}
paginationToken: null | string = null
roomId: string

Optional. The ID of the room which has this state. If none is specified it just tracks paginationTokens, useful for notifTimelineSet

Accessors

Methods

  • 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

  • Find the predecessor room based on this room state.

    Parameters

    • msc3946ProcessDynamicPredecessor: boolean = false

      if true, look for an m.room.predecessor state event and use it if found (MSC3946).

    Returns null | {
        eventId?: string;
        roomId: string;
        viaServers?: string[];
    }

    null if this room has no predecessor. Otherwise, returns the roomId, last eventId and viaServers of the predecessor room.

    If msc3946ProcessDynamicPredecessor is true, use m.predecessor events as well as m.room.create events to find predecessors.

    Note: if an m.predecessor event is used, eventId may be undefined since last_known_event_id is optional.

    Note: viaServers may be undefined, and will definitely be undefined if this predecessor comes from a RoomCreate event (rather than a RoomPredecessor, which has the optional via_servers property).

  • Returns the number of invited members in this room

    Returns number

    The number of members in this room whose membership is 'invite'

  • Get the m.room.member event which has the given third party invite token.

    Parameters

    • token: string

      The token

    Returns null | MatrixEvent

    The m.room.member event or null

  • Returns the number of joined members in this room This method caches the result.

    Returns number

    The number of members in this room whose membership is 'join'

  • Get the timestamp when this room state was last updated. This timestamp is updated when this object has received new state events.

    Returns number

    The timestamp

  • Get all RoomMembers in this room, excluding the user IDs provided.

    Parameters

    • excludedIds: string[]

      The user IDs to exclude.

    Returns RoomMember[]

    A list of RoomMembers.

  • Get a room member whose properties will not change with this room state. You typically want this if you want to attach a RoomMember to a MatrixEvent which may no longer be represented correctly by Room.currentState or Room.oldState. The term 'sentinel' refers to the fact that this RoomMember is an unchanging guardian for state at this particular point in time.

    Parameters

    • userId: string

      The room member's user ID.

    Returns null | RoomMember

    The member or null if they do not exist.

  • Get state events from the state of the room.

    Parameters

    • eventType: string

      The event type of the state event.

    Returns MatrixEvent[]

    A list of events

  • Get state events from the state of the room.

    Parameters

    • eventType: string

      The event type of the state event.

    • stateKey: string

      The state_key of the state event.

    Returns null | MatrixEvent

    A single event (or null if no match found).

  • Get user IDs with the specified or similar display names.

    Parameters

    • displayName: string

      The display name to get user IDs from.

    Returns string[]

    An array of user IDs or an empty array.

  • Returns true if the given power level is sufficient for action

    Parameters

    Returns boolean

    true if the given power level is sufficient

  • Mark this room state as having failed to fetch out-of-band members

    Returns void

  • Mark this room state as waiting for out-of-band members, ensuring it doesn't ask for them to be requested again through needsOutOfBandMembers

    Returns void

  • Returns true if the given MatrixClient has permission to send a state event of type stateEventType into this room.

    Parameters

    • stateEventType: string

      The type of state events to test

    • cli: MatrixClient

      The client to test permission for

    Returns boolean

    true if the given client should be permitted to send the given type of state event into this room, according to the room's state.

  • Returns true if the given user ID has permission to send a normal event of type eventType into this room.

    Parameters

    • eventType: string

      The type of event to test

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

    true if the given user ID should be permitted to send the given type of event into this room, according to the room's state.

  • Short-form for maySendEvent('m.room.message', userId)

    Parameters

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

    true if the given user ID should be permitted to send message events into the given room.

  • Returns true if userId is in room, event is not redacted and either sender of mxEvent or has power level sufficient to redact events other than their own.

    Parameters

    • mxEvent: MatrixEvent

      The event to test permission for

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

    true if the given used ID can redact given event

  • Returns true if the given user ID has permission to send a state event of type stateEventType into this room.

    Parameters

    • stateEventType: string

      The type of state events to test

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

    true if the given user ID should be permitted to send the given type of state event into this room, according to the room's state.

  • Returns true if the given user ID has permission to trigger notification of type notifLevelKey

    Parameters

    • notifLevelKey: string

      The level of notification to test (eg. 'room')

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

    true if the given user ID has permission to trigger a notification of this type.

  • Get the out-of-band members loading state, whether loading is needed or not. Note that loading might be in progress and hence isn't needed.

    Returns boolean

    whether or not the members of this room need to be loaded

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

  • Adds a one-time listener function for the event named event. The next time event is triggered, this listener is removed and then invoked.

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

    By default, event listeners are invoked in the order they are added. The prependOnceListener 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.

  • Check if loading of out-of-band-members has completed

    Returns boolean

    true if the full membership list of this room has been loaded. False if it is not started or is in progress.

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

  • Set the amount of invited members in this room

    Parameters

    • count: number

      the amount of invited members

    Returns void

  • Set the joined member count explicitly (like from summary part of the sync response)

    Parameters

    • count: number

      the amount of joined members

    Returns void

  • Sets the loaded out-of-band members.

    Parameters

    • stateEvents: MatrixEvent[]

      array of membership state events

    Returns void

  • Add previously unknown state events. When lazy loading members while back-paginating, the relevant room state for the timeline chunk at the end of the chunk can be set with this method.

    Parameters

    Returns void