Class User

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

Constructors

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 prependListener method can be used as an alternative to add the event listener to the beginning of the listeners array.

    Type Parameters

    Parameters

    Returns User

    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 User

    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 User

    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

  • Update this User with the given presence event. May fire "User.presence", "User.avatarUrl" and/or "User.displayName" if this event updates this user's properties.

    Parameters

    Returns void

    Remarks

    Fires Presence Fires DisplayName Fires AvatarUrl

  • 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

Generated using TypeDoc