pub enum Room {
    Joined(Joined),
    Left(Left),
    Invited(Invited),
}
Expand description

An enum that abstracts over the different states a room can be in.

Variants

Joined(Joined)

The room in the join state.

Left(Left)

The room in the left state.

Invited(Invited)

The room in the invited state.

Methods from Deref<Target = Common>

Get the inner client saved in this room instance.

Returns the client this room is part of.

Gets the avatar of this room, if set.

Returns the avatar. If a thumbnail is requested no guarantee on the size of the image is given.

Arguments
  • format - The desired format of the avatar.
Example
let client = Client::new(homeserver).await.unwrap();
client.login(user, "password", None, None).await.unwrap();
let room_id = room_id!("!roomid:example.com");
let room = client.get_joined_room(&room_id).unwrap();
if let Some(avatar) = room.avatar(MediaFormat::File).await.unwrap() {
    std::fs::write("avatar.png", avatar);
}

Sends a request to /_matrix/client/r0/rooms/{room_id}/messages and returns a Messages struct that contains a chunk of room and state events (RoomEvent and AnyStateEvent).

With the encryption feature, messages are decrypted if possible. If decryption fails for an individual message, that message is returned undecrypted.

Examples
use matrix_sdk::{room::MessagesOptions, Client};

let options =
    MessagesOptions::backward().from("t47429-4392820_219380_26003_2265");

let mut client = Client::new(homeserver).await.unwrap();
let room = client.get_joined_room(room_id!("!roomid:example.com")).unwrap();
assert!(room.messages(options).await.is_ok());

Register a handler for events of a specific type, within this room.

This method works the same way as Client::add_event_handler, except that the handler will only be called for events within this room. See that method for more details on event handler functions.

room.add_event_handler(hdl) is equivalent to client.add_room_event_handler(room_id, hdl). Use whichever one is more convenient in your use case.

Fetch the event with the given EventId in this room.

Sync the member list with the server.

This method will de-duplicate requests if it is called multiple times in quick succession, in that case the return value will be None.

Get active members for this room, includes invited, joined members.

Note: This method will fetch the members from the homeserver if the member list isn’t synchronized due to member lazy loading. Because of that, it might panic if it isn’t run on a tokio thread.

Use active_members_no_sync() if you want a method that doesn’t do any requests.

Get active members for this room, includes invited, joined members.

Note: This method will not fetch the members from the homeserver if the member list isn’t synchronized due to member lazy loading. Thus, members could be missing from the list.

Use active_members() if you want to ensure to always get the full member list.

Get all the joined members of this room.

Note: This method will fetch the members from the homeserver if the member list isn’t synchronized due to member lazy loading. Because of that it might panic if it isn’t run on a tokio thread.

Use joined_members_no_sync() if you want a method that doesn’t do any requests.

Get all the joined members of this room.

Note: This method will not fetch the members from the homeserver if the member list isn’t synchronized due to member lazy loading. Thus, members could be missing from the list.

Use joined_members() if you want to ensure to always get the full member list.

Get a specific member of this room.

Note: This method will fetch the members from the homeserver if the member list isn’t synchronized due to member lazy loading. Because of that it might panic if it isn’t run on a tokio thread.

Use get_member_no_sync() if you want a method that doesn’t do any requests.

Arguments
  • user_id - The ID of the user that should be fetched out of the store.

Get a specific member of this room.

Note: This method will not fetch the members from the homeserver if the member list isn’t synchronized due to member lazy loading. Thus, members could be missing.

Use get_member() if you want to ensure to always have the full member list to chose from.

Arguments
  • user_id - The ID of the user that should be fetched out of the store.

Get all members for this room, includes invited, joined and left members.

Note: This method will fetch the members from the homeserver if the member list isn’t synchronized due to member lazy loading. Because of that it might panic if it isn’t run on a tokio thread.

Use members_no_sync() if you want a method that doesn’t do any requests.

Get all members for this room, includes invited, joined and left members.

Note: This method will not fetch the members from the homeserver if the member list isn’t synchronized due to member lazy loading. Thus, members could be missing.

Use members() if you want to ensure to always get the full member list.

Get all state events of a given type in this room.

Get all state events of a given statically-known type in this room.

Example
use matrix_sdk::ruma::{
    events::room::member::SyncRoomMemberEvent, serde::Raw,
};

let room_members: Vec<Raw<SyncRoomMemberEvent>> =
    room.get_state_events_static().await?;

Get a specific state event in this room.

Get a specific state event of statically-known type with an empty state key in this room.

Example
use matrix_sdk::ruma::events::room::power_levels::SyncRoomPowerLevelsEvent;

let power_levels: SyncRoomPowerLevelsEvent = room
    .get_state_event_static()
    .await?
    .expect("every room has a power_levels event")
    .deserialize()?;

Get a specific state event of statically-known type in this room.

Example
use matrix_sdk::ruma::{
    events::room::member::SyncRoomMemberEvent, serde::Raw, user_id,
};

let member_event: Option<Raw<SyncRoomMemberEvent>> = room
    .get_state_event_static_for_key(user_id!("@alice:example.org"))
    .await?;

Get account data in this room.

Get account data of statically-known type in this room.

Example
use matrix_sdk::ruma::events::fully_read::FullyReadEventContent;

match room.account_data_static::<FullyReadEventContent>().await? {
    Some(fully_read) => {
        println!("Found read marker: {:?}", fully_read.deserialize()?)
    }
    None => println!("No read marker for this room"),
}
Available on crate feature e2e-encryption only.

Check if all members of this room are verified and all their devices are verified.

Returns true if all devices in the room are verified, otherwise false.

Adds a tag to the room, or updates it if it already exists.

Returns the [create_tag::v3::Response] from the server.

Arguments
  • tag - The tag to add or update.

  • tag_info - Information about the tag, generally containing the order parameter.

Example
use matrix_sdk::ruma::events::tag::TagInfo;

if let Some(room) = client.get_joined_room(&room_id) {
    let mut tag_info = TagInfo::new();
    tag_info.order = Some(0.9);
    let user_tag = UserTagName::from_str("u.work")?;

    room.set_tag(TagName::User(user_tag), tag_info).await?;
}

Removes a tag from the room.

Returns the [delete_tag::v3::Response] from the server.

Arguments
  • tag - The tag to remove.

Sets whether this room is a DM.

When setting this room as DM, it will be marked as DM for all active members of the room. When unsetting this room as DM, it will be unmarked as DM for all users, not just the members.

Arguments
  • is_direct - Whether to mark this room as direct.
Available on crate feature e2e-encryption only.

Tries to decrypt a room event.

Arguments
  • event - The room event to be decrypted.

Returns the decrypted event.

Get a list of servers that should know this room.

Uses the synced members of the room and the suggested routing algorithm from the Matrix spec.

Returns at most three servers.

Get a matrix.to permalink to this room.

If this room has an alias, we use it. Otherwise, we try to use the synced members in the room for routing the room ID.

Get a matrix: permalink to this room.

If this room has an alias, we use it. Otherwise, we try to use the synced members in the room for routing the room ID.

Arguments
  • join - Whether the user should join the room.

Get a matrix.to permalink to an event in this room.

We try to use the synced members in the room for routing the room ID.

Note: This method does not check if the given event ID is actually part of this room. It needs to be checked before calling this method otherwise the permalink won’t work.

Arguments
  • event_id - The ID of the event.

Get a matrix: permalink to an event in this room.

We try to use the synced members in the room for routing the room ID.

Note: This method does not check if the given event ID is actually part of this room. It needs to be checked before calling this method otherwise the permalink won’t work.

Arguments
  • event_id - The ID of the event.

Methods from Deref<Target = BaseRoom>

Get the unique room id of the room.

Get our own user id.

Get the type of the room.

Whether this room’s RoomType is m.space.

Get the unread notification counts.

Check if the room has it’s members fully synced.

Members might be missing if lazy member loading was enabled for the sync.

Returns true if no members are missing, false otherwise.

Get the prev_batch token that was received from the last sync. May be None if the last sync contained the full room history.

Get the avatar url of this room.

Get the canonical alias of this room.

Get the canonical alias of this room.

Get the m.room.create content of this room.

This usually isn’t optional but some servers might not send an m.room.create event as the first event for a given room, thus this can be optional.

It can also be redacted in current room versions, leaving only the creator field.

Is this room considered a direct message.

If this room is a direct message, get the members that we’re sharing the room with.

Note: The member list might have been modified in the meantime and the targets might not even be in the room anymore. This setting should only be considered as guidance.

Is the room encrypted.

Get the m.room.encryption content that enabled end to end encryption in the room.

Get the guest access policy of this room.

Get the history visibility policy of this room.

Is the room considered to be public.

Get the join rule policy of this room.

Get the maximum power level that this room contains.

This is useful if one wishes to normalize the power levels, e.g. from 0-100 where 100 would be the max power level.

Get the m.room.name of this room.

Has the room been tombstoned.

Get the m.room.tombstone content of this room if there is one.

Get the topic of the room.

Calculate the canonical display name of the room, taking into account its name, aliases and members.

The display name is calculated according to this algorithm.

Get the list of users ids that are considered to be joined members of this room.

Get the all RoomMembers of this room that are known to the store.

Get the list of RoomMembers that are considered to be joined members of this room.

Get the list of RoomMembers that are considered to be joined or invited members of this room.

Clone the inner RoomInfo

Update the summary with given RoomInfo

Get the RoomMember with the given user_id.

Returns None if the member was never part of this room, otherwise return a RoomMember that can be in a joined, invited, left, banned state.

Get the Tags for this room.

Get the read receipt as a EventId and Receipt tuple for the given user_id in this room.

Get the read receipts as a list of UserId and Receipt tuples for the given event_id in this room.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

This event handler context argument is only applicable to room-specific events.

Trying to use it in the event handler for another event, for example a global account data or presence event, will result in the event handler being skipped and an error getting logged.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more