User class

Represents a user in the context of a Matrix room, not a global user profile.

This class extends StrippedStateEvent to handle room-specific user state, including membership status, display name, and avatar within that room. The user information is derived from room member state events.

For example, a user may have different display names or avatars in different rooms, and this class represents that room-specific view of the user rather than their global profile.

Inheritance
Available extensions

Constructors

User(String id, {String? membership, String? displayName, String? avatarUrl, DateTime? originServerTs, required Room room})
factory
User.fromState({required String stateKey, Map<String, Object?> content = const {}, required String typeKey, required String senderId, required Room room, DateTime? originServerTs, Map<String, Object?>? prevContent})

Properties

avatarUrl Uri?
The avatar if the user has one.
no setter
canBan bool
Whether the client is able to ban/unban this user.
no setter
canChangePowerLevel bool
no setter
canChangeUserPowerLevel bool
Whether the client is allowed to change the power level of this user. Please be aware that you can only set the power level to at least your own!
no setter
canKick bool
Whether the client is able to kick this user.
no setter
content Map<String, Object?>
getter/setter pairinherited
currentPresence Future<CachedPresence>
no setter
displayName String?
The displayname of the user if the user has set one.
no setter
hashCode int
The hash code for this object.
no setteroverride
id String
The full qualified Matrix ID in the format @username:server.abc.
no setter
membership Membership
The membership status of the user. One of: join invite leave ban
no setter
mention String
Get the mention text to use in a plain text body to mention this specific user in this specific room
no setter
mentionFragments Set<String>
Get the mention fragments for this user.
no setter
originServerTs DateTime?
final
parsedForwardedRoomKeyContent ForwardedRoomKeyContent

Available on BasicEvent, provided by the ForwardedRoomKeyContentBasicEventExtension extension

no setter
parsedImagePackContent ImagePackContent

Available on BasicEvent, provided by the ImagePackContentBasicEventExtension extension

no setter
parsedRoomEncryptedContent RoomEncryptedContent

Available on BasicEvent, provided by the RoomEncryptedContentBasicEventExtension extension

no setter
parsedRoomEncryptionContent RoomEncryptionContent

Available on BasicEvent, provided by the RoomEncryptionContentBasicEventExtension extension

no setter
parsedRoomKeyContent RoomKeyContent

Available on BasicEvent, provided by the RoomKeyContentBasicEventExtension extension

no setter
parsedRoomKeyRequestContent RoomKeyRequestContent

Available on BasicEvent, provided by the RoomKeyRequestContentBasicEventExtension extension

no setter
parsedSecretStorageDefaultKeyContent SecretStorageDefaultKeyContent

Available on BasicEvent, provided by the SecretStorageDefaultKeyContentBasicEventExtension extension

no setter
parsedSecretStorageKeyContent SecretStorageKeyContent

Available on BasicEvent, provided by the SecretStorageKeyContentBasicEventExtension extension

no setter
parsedTombstoneContent TombstoneContent

Available on BasicEvent, provided by the TombstoneContentBasicEventExtension extension

no setter
powerLevel int
Returns the power level of this user.
no setter
presence Presence?
The newest presence of this user if there is any and null if not.
no setter
prevContent Map<String, Object?>?
final
room Room
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
senderId String
getter/setter pairinherited
stateKey String?
getter/setter pairinherited
type String
getter/setter pairinherited

Methods

asUser(Room room) User

Available on StrippedStateEvent, provided by the FromStrippedStateEventExtension extension

ban() Future<void>
Call the Matrix API to ban this user from this room.
calcDisplayname({bool? formatLocalpart, bool? mxidLocalPartFallback, MatrixLocalizations i18n = const MatrixDefaultLocalizations()}) String
Returns the displayname or the local part of the Matrix ID if the user has no displayname. If formatLocalpart is true, then the localpart will be formatted in the way, that all "_" characters are becomming white spaces and the first character of each word becomes uppercase. If mxidLocalPartFallback is true, then the local part of the mxid will be shown if there is no other displayname available. If not then this will return "Unknown user".
fetchCurrentPresence() Future<CachedPresence>
The newest presence of this user if there is any. Fetches it from the database first and then from the server if necessary or returns offline.
kick() Future<void>
Call the Matrix API to kick this user from this room.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setPower(int power) Future<void>
Call the Matrix API to change the power level of this user.
startDirectChat({bool? enableEncryption, List<StateEvent>? initialState, bool waitForSync = true}) Future<String>
Returns an existing direct chat ID with this user or creates a new one. Returns null on error.
toJson() Map<String, Object?>
inherited
toString() String
A string representation of this object.
inherited
unban() Future<void>
Call the Matrix API to unban this banned user from this room.

Operators

operator ==(Object other) bool
The equality operator.
override