Class RoomState

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.

Hierarchy

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.

    Returns RoomState

Properties

_liveBeaconIds: string[] = []
beacons: Map<string, Beacon> = ...
displayNameToUserIds: Map<string, string[]> = ...
events: Map<string, Map<string, MatrixEvent>> = ...
invitedMemberCount: null | number = null
joinedMemberCount: null | number = null
members: Record<string, RoomMember> = {}
modified: number = -1
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.

Type declaration

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

sentinels: Record<string, RoomMember> = {}
summaryInvitedMemberCount: null | number = null
summaryJoinedMemberCount: null | number = null
tokenToInvite: Record<string, MatrixEvent> = {}
userIdsToDisplayNames: Record<string, string> = {}

Accessors

Methods

  • Find the predecessor room based on this room state.

    Returns

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

    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[];
    }

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

    Returns

    The m.room.member event or null

    Parameters

    • token: string

      The token

    Returns null | MatrixEvent

  • Returns the number of invited members in this room

    Returns

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

    Returns number

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

    Returns

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

    Returns number

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

    Returns

    The timestamp

    Returns number

  • Get a room member by their user ID.

    Returns

    The member or null if they do not exist.

    Parameters

    • userId: string

      The room member's user ID.

    Returns null | RoomMember

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

    Returns

    A list of RoomMembers.

    Parameters

    • excludedIds: string[]

      The user IDs to exclude.

    Returns RoomMember[]

  • Looks up a member by the given userId, and if it doesn't exist, create it and emit the RoomState.newMember event. This method makes sure the member is added to the members dictionary before emitting, as this is done from setStateEvents and setOutOfBandMember.

    Returns

    the member, existing or newly created.

    Remarks

    Fires NewMember

    Parameters

    • userId: string

      the id of the user to look up

    • event: MatrixEvent

      the membership event for the (new) member. Used to emit.

    Returns RoomMember

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

    Returns

    The member or null if they do not exist.

    Parameters

    • userId: string

      The room member's user ID.

    Returns null | RoomMember

  • Get state events from the state of the room.

    Returns

    A list of events if state_key was undefined, else a single event (or null if no match found).

    Parameters

    • eventType: string

      The event type of the state event.

    Returns MatrixEvent[]

  • Parameters

    • eventType: string
    • stateKey: string

    Returns null | MatrixEvent

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

    Returns

    An array of user IDs or an empty array.

    Parameters

    • displayName: string

      The display name to get user IDs from.

    Returns string[]

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

    Returns

    true if the given power level is sufficient

    Parameters

    • action: "ban" | "kick" | "redact"

      The type of power level to check

    • powerLevel: number

      The power level of the member

    Returns boolean

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

    Returns

    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.

    Parameters

    • stateEventType: string

      The type of state events to test

    • cli: MatrixClient

      The client to test permission for

    Returns boolean

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

    Returns

    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.

    Parameters

    • eventType: string

      The type of event to test

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

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

    Returns

    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.

    Parameters

    • eventType: string

      The type of event to test

    • userId: string

      The user ID of the user to test permission for

    • state: boolean

      If true, tests if the user may send a state event of this type. Otherwise tests whether they may send a regular event.

    Returns boolean

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

    Returns

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

    Parameters

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

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

    Returns

    true if the given used ID can redact given event

    Parameters

    • mxEvent: MatrixEvent

      The event to test permission for

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

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

    Returns

    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.

    Parameters

    • stateEventType: string

      The type of state events to test

    • userId: string

      The user ID of the user to test permission for

    Returns boolean

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

    Returns

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

    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

  • 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

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

    Returns boolean

  • Experimental

    Check liveness of room beacons emit RoomStateEvent.BeaconLiveness event

    Returns void

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

    Returns

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

    Returns boolean

  • 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

  • Add an array of one or more state MatrixEvents, overwriting any existing state with the same {type, stateKey} tuple. Will fire "RoomState.events" for every event added. May fire "RoomState.members" if there are m.room.member events. May fire "RoomStateEvent.Marker" if there are UNSTABLE_MSC2716_MARKER events.

    Remarks

    Fires Members Fires NewMember Fires Events Fires Marker

    Parameters

    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

  • Parameters

    • userId: string
    • displayName: string

    Returns void

Generated using TypeDoc