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 new User. A User must have an ID and can optionally have extra information associated with it.

    Parameters

    • userId: string

      Required. The ID of this user.

    Returns User

    Deprecated

    use User.createUser

Properties

avatarUrl?: string

The 'avatar_url' of the user if known.

currentlyActive: boolean = false

Whether we should consider lastActiveAgo to be an approximation and that the user should be seen as active 'now'

displayName?: string

The 'displayname' of the user if known.

events: {
    presence?: MatrixEvent;
    profile?: MatrixEvent;
} = {}

The events describing this user.

Type declaration

lastActiveAgo: number = 0

Timestamp (ms since the epoch) for when we last received presence data for this user. We can subtract lastActiveAgo from this to approximate an absolute value for when a user was last active.

lastPresenceTs: number = 0

The time elapsed in ms since the user interacted proactively with the server, or we saw a message from the user

modified: number = -1
presence: string = "offline"

The presence enum if known.

presenceStatusMsg?: string

The presence status message if known.

rawDisplayName?: string
userId: string

Required. The ID of this user.

Methods

  • Get the absolute timestamp when this User was last known active on the server. It is NOT accurate if this.currentlyActive is true.

    Returns number

    The timestamp

  • Get the timestamp when this User was last updated. This timestamp is updated when this User receives a new Presence event which has updated a property on this object. It is updated before firing events.

    Returns number

    The timestamp

  • 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 TypedEventEmitter#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 the listener function to the beginning 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.

    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.

  • Manually set this user's avatar URL. No event is emitted in response to this as there is no underlying MatrixEvent to emit with.

    Parameters

    • Optional url: string

      The new avatar URL.

    Returns void

  • Manually set this user's display name. No event is emitted in response to this as there is no underlying MatrixEvent to emit with.

    Parameters

    • name: string

      The new display name.

    Returns void

  • Manually set this user's non-disambiguated display name. No event is emitted in response to this as there is no underlying MatrixEvent to emit with.

    Parameters

    • Optional name: string

      The new display name.

    Returns void

  • Update the last modified time to the current time.

    Returns void

  • Construct a new User whose events will also emit on MatrixClient. A User must have an ID and can optionally have extra information associated with it.

    Parameters

    • userId: string

      Required. The ID of this user.

    • client: MatrixClient

      An instance of MatrixClient object

    Returns User

    User object with reEmitter setup on client

Generated using TypeDoc