atagen

macltok

public
Star0
Watch0
2c7ca08237507e839b498f639987316309e3b843
3
ssh://brewery@pls.lobotomise.me:33/atagen/macltok.git

Blame: src/transport.rs

96fdf90aacd6atagen2026-09-08 08:24 UTC1
use std::{
121a56ce119datagen2026-10-24 06:42 UTC2
    collections::HashSet,
96fdf90aacd6atagen2026-09-08 08:24 UTC3
    fmt,
31ce2453c82fatagen2026-09-24 13:07 UTC4
    future::Future,
96fdf90aacd6atagen2026-09-08 08:24 UTC5
    pin::Pin,
121a56ce119datagen2026-10-24 06:42 UTC6
    sync::{Arc, Mutex},
96fdf90aacd6atagen2026-09-08 08:24 UTC7
    task::{Context, Poll},
96fdf90aacd6atagen2026-09-08 08:24 UTC8
};
96fdf90aacd6atagen2026-09-08 08:24 UTC9
96fdf90aacd6atagen2026-09-08 08:24 UTC10
use matrix_sdk::{Client, RoomMemberships};
96fdf90aacd6atagen2026-09-08 08:24 UTC11
use matrix_sdk_ui::{
96fdf90aacd6atagen2026-09-08 08:24 UTC12
    notification_client::{
96fdf90aacd6atagen2026-09-08 08:24 UTC13
        NotificationClient, NotificationProcessSetup, NotificationStatus, RawNotificationEvent,
96fdf90aacd6atagen2026-09-08 08:24 UTC14
    },
31ce2453c82fatagen2026-09-24 13:07 UTC15
    spaces::{SpaceRoomList, SpaceService, room_list::SpaceRoomListPaginationState},
96fdf90aacd6atagen2026-09-08 08:24 UTC16
    sync_service::SyncService,
96fdf90aacd6atagen2026-09-08 08:24 UTC17
};
96fdf90aacd6atagen2026-09-08 08:24 UTC18
use ruma::{
5d2974de5826atagen2026-10-08 11:29 UTC19
    EventId, OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedRoomOrAliasId,
31ce2453c82fatagen2026-09-24 13:07 UTC20
    OwnedServerName, OwnedTransactionId, OwnedUserId, RoomId, UserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC21
    events::{
31ce2453c82fatagen2026-09-24 13:07 UTC22
        AnyGlobalAccountDataEventContent, AnyRoomAccountDataEvent, AnyRoomAccountDataEventContent,
31ce2453c82fatagen2026-09-24 13:07 UTC23
        GlobalAccountDataEventType, RoomAccountDataEventType,
96fdf90aacd6atagen2026-09-08 08:24 UTC24
    },
96fdf90aacd6atagen2026-09-08 08:24 UTC25
    serde::Raw,
96fdf90aacd6atagen2026-09-08 08:24 UTC26
};
96fdf90aacd6atagen2026-09-08 08:24 UTC27
use tokio::sync::{OnceCell, mpsc, oneshot, watch};
96fdf90aacd6atagen2026-09-08 08:24 UTC28
96fdf90aacd6atagen2026-09-08 08:24 UTC29
use crate::{
31ce2453c82fatagen2026-09-24 13:07 UTC30
    AccountCommand, AttachmentUpload, Command, CommandOutput, ConnectionState, CreateRoomOptions,
17e042fbc331atagen2026-10-08 12:39 UTC31
    EncryptionCommand, EncryptionState, Error, ErrorKind, Event, EventRef, ImagePacks,
0291516d40b5atagen2026-10-22 08:31 UTC32
    InteractiveAuth, InteractiveAuthOutcome, LifecycleCommand, LinkPreview, Media, MediaCommand,
0291516d40b5atagen2026-10-22 08:31 UTC33
    MediaId, MediaLocation, MediaSize, MemberFilter, MemberSummary, MessageContent,
0291516d40b5atagen2026-10-22 08:31 UTC34
    MessageEditContent, NotificationCommand, OwnDevice, PowerLevelChanges, Profile,
0291516d40b5atagen2026-10-22 08:31 UTC35
    PushNotification, PushNotificationEvent, PushNotificationStatus, RoomCommand, RoomListFilter,
5b21b919d1e6atagen2026-09-27 11:47 UTC36
    RoomNotificationMode, RoomNotificationSettings, RoomPowerLevels, RoomSummary, SpaceChild,
5b21b919d1e6atagen2026-09-27 11:47 UTC37
    TimelineCommand, TimelineId, VerificationAction, VerificationTarget,
96fdf90aacd6atagen2026-09-08 08:24 UTC38
    encryption::encryption_state,
a250c7fa43fbatagen2026-09-26 13:35 UTC39
    engine::{MediaService, StoreLock},
96fdf90aacd6atagen2026-09-08 08:24 UTC40
    model::{PushNotificationRoom, PushNotificationSender},
0291516d40b5atagen2026-10-22 08:31 UTC41
    normalise::{image_packs, member_summary, room_summaries, space_child, url_previews_allowed},
96fdf90aacd6atagen2026-09-08 08:24 UTC42
};
96fdf90aacd6atagen2026-09-08 08:24 UTC43
96fdf90aacd6atagen2026-09-08 08:24 UTC44
#[derive(Clone)]
96fdf90aacd6atagen2026-09-08 08:24 UTC45
pub struct ClientHandle {
31ce2453c82fatagen2026-09-24 13:07 UTC46
    requests: mpsc::Sender<Request>,
96fdf90aacd6atagen2026-09-08 08:24 UTC47
    client: Client,
96fdf90aacd6atagen2026-09-08 08:24 UTC48
    connection: watch::Receiver<ConnectionState>,
96fdf90aacd6atagen2026-09-08 08:24 UTC49
    notification_client: Arc<OnceCell<NotificationClient>>,
96fdf90aacd6atagen2026-09-08 08:24 UTC50
    sync_service: Arc<SyncService>,
31ce2453c82fatagen2026-09-24 13:07 UTC51
    media: Arc<MediaService>,
31ce2453c82fatagen2026-09-24 13:07 UTC52
    spaces: Arc<OnceCell<SpaceService>>,
121a56ce119datagen2026-10-24 06:42 UTC53
    members_checked: Arc<Mutex<HashSet<OwnedRoomId>>>,
a250c7fa43fbatagen2026-09-26 13:35 UTC54
    _store_lock: Option<Arc<StoreLock>>,
96fdf90aacd6atagen2026-09-08 08:24 UTC55
}
96fdf90aacd6atagen2026-09-08 08:24 UTC56
96fdf90aacd6atagen2026-09-08 08:24 UTC57
impl fmt::Debug for ClientHandle {
96fdf90aacd6atagen2026-09-08 08:24 UTC58
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
96fdf90aacd6atagen2026-09-08 08:24 UTC59
        formatter
96fdf90aacd6atagen2026-09-08 08:24 UTC60
            .debug_struct("ClientHandle")
96fdf90aacd6atagen2026-09-08 08:24 UTC61
            .finish_non_exhaustive()
96fdf90aacd6atagen2026-09-08 08:24 UTC62
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC63
}
96fdf90aacd6atagen2026-09-08 08:24 UTC64
31ce2453c82fatagen2026-09-24 13:07 UTC65
/// a command's answer. drop it if you don't care, the command still runs
31ce2453c82fatagen2026-09-24 13:07 UTC66
#[derive(Debug)]
31ce2453c82fatagen2026-09-24 13:07 UTC67
#[must_use = "dropping it is fine but then you'll never know"]
31ce2453c82fatagen2026-09-24 13:07 UTC68
pub struct Pending(oneshot::Receiver<Result<CommandOutput, Error>>);
31ce2453c82fatagen2026-09-24 13:07 UTC69
31ce2453c82fatagen2026-09-24 13:07 UTC70
impl Future for Pending {
31ce2453c82fatagen2026-09-24 13:07 UTC71
    type Output = Result<CommandOutput, Error>;
31ce2453c82fatagen2026-09-24 13:07 UTC72
31ce2453c82fatagen2026-09-24 13:07 UTC73
    fn poll(mut self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output> {
31ce2453c82fatagen2026-09-24 13:07 UTC74
        Pin::new(&mut self.0)
31ce2453c82fatagen2026-09-24 13:07 UTC75
            .poll(context)
31ce2453c82fatagen2026-09-24 13:07 UTC76
            .map(|result| result.unwrap_or_else(|_| Err(Error::interrupted())))
31ce2453c82fatagen2026-09-24 13:07 UTC77
    }
31ce2453c82fatagen2026-09-24 13:07 UTC78
}
31ce2453c82fatagen2026-09-24 13:07 UTC79
96fdf90aacd6atagen2026-09-08 08:24 UTC80
impl ClientHandle {
f12377bce9b9atagen2026-09-26 12:32 UTC81
    /// current credentials, it holds secrets. the engine saves it for you unless the
f12377bce9b9atagen2026-09-26 12:32 UTC82
    /// session was built `without_persistence`
62fe32759529atagen2026-09-26 08:50 UTC83
    #[cfg(any(feature = "sqlite", feature = "indexeddb"))]
96fdf90aacd6atagen2026-09-08 08:24 UTC84
    pub fn session_record(&self) -> Result<crate::SessionRecord, crate::AccountError> {
96fdf90aacd6atagen2026-09-08 08:24 UTC85
        crate::account::session_record(&self.client)
96fdf90aacd6atagen2026-09-08 08:24 UTC86
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC87
5b21b919d1e6atagen2026-09-27 11:47 UTC88
    /// the bearer token. it rotates on every refresh so ask again after a 401 rather than
5b21b919d1e6atagen2026-09-27 11:47 UTC89
    /// keeping it, and keep it in memory and away from all but the homeserver's media endpoints
5b21b919d1e6atagen2026-09-27 11:47 UTC90
    pub fn access_token(&self) -> Option<String> {
5b21b919d1e6atagen2026-09-27 11:47 UTC91
        self.client.access_token()
5b21b919d1e6atagen2026-09-27 11:47 UTC92
    }
5b21b919d1e6atagen2026-09-27 11:47 UTC93
31ce2453c82fatagen2026-09-24 13:07 UTC94
    /// queue a command, waiting for room in the queue if there isn't any
31ce2453c82fatagen2026-09-24 13:07 UTC95
    pub async fn send(&self, command: Command) -> Result<Pending, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC96
        let (request, pending) = Request::new(command);
31ce2453c82fatagen2026-09-24 13:07 UTC97
        self.requests
31ce2453c82fatagen2026-09-24 13:07 UTC98
            .send(request)
96fdf90aacd6atagen2026-09-08 08:24 UTC99
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC100
            .map_err(|_| Error::interrupted())?;
31ce2453c82fatagen2026-09-24 13:07 UTC101
        Ok(pending)
31ce2453c82fatagen2026-09-24 13:07 UTC102
    }
31ce2453c82fatagen2026-09-24 13:07 UTC103
31ce2453c82fatagen2026-09-24 13:07 UTC104
    /// queue a command or fail with `QueueFull` right now
31ce2453c82fatagen2026-09-24 13:07 UTC105
    pub fn try_send(&self, command: Command) -> Result<Pending, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC106
        let (request, pending) = Request::new(command);
31ce2453c82fatagen2026-09-24 13:07 UTC107
        self.requests
31ce2453c82fatagen2026-09-24 13:07 UTC108
            .try_send(request)
31ce2453c82fatagen2026-09-24 13:07 UTC109
            .map_err(|error| match error {
31ce2453c82fatagen2026-09-24 13:07 UTC110
                mpsc::error::TrySendError::Full(_) => {
31ce2453c82fatagen2026-09-24 13:07 UTC111
                    Error::new(ErrorKind::QueueFull, "the command queue is full")
31ce2453c82fatagen2026-09-24 13:07 UTC112
                }
31ce2453c82fatagen2026-09-24 13:07 UTC113
                mpsc::error::TrySendError::Closed(_) => Error::interrupted(),
31ce2453c82fatagen2026-09-24 13:07 UTC114
            })?;
31ce2453c82fatagen2026-09-24 13:07 UTC115
        Ok(pending)
31ce2453c82fatagen2026-09-24 13:07 UTC116
    }
31ce2453c82fatagen2026-09-24 13:07 UTC117
31ce2453c82fatagen2026-09-24 13:07 UTC118
    /// queue a command and wait for its answer. timeline sends answer once the
31ce2453c82fatagen2026-09-24 13:07 UTC119
    /// sdk send queue has them, delivery shows up later as the item's send state
31ce2453c82fatagen2026-09-24 13:07 UTC120
    pub async fn execute(&self, command: Command) -> Result<CommandOutput, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC121
        self.send(command).await?.await
31ce2453c82fatagen2026-09-24 13:07 UTC122
    }
31ce2453c82fatagen2026-09-24 13:07 UTC123
31ce2453c82fatagen2026-09-24 13:07 UTC124
    async fn run(&self, command: Command) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC125
        self.execute(command).await.map(drop)
31ce2453c82fatagen2026-09-24 13:07 UTC126
    }
31ce2453c82fatagen2026-09-24 13:07 UTC127
31ce2453c82fatagen2026-09-24 13:07 UTC128
    async fn run_for_room(&self, command: RoomCommand) -> Result<OwnedRoomId, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC129
        match self.execute(Command::Room(command)).await? {
31ce2453c82fatagen2026-09-24 13:07 UTC130
            CommandOutput::Room(room_id) => Ok(room_id),
31ce2453c82fatagen2026-09-24 13:07 UTC131
            output => Err(Error::new(
31ce2453c82fatagen2026-09-24 13:07 UTC132
                ErrorKind::Other,
31ce2453c82fatagen2026-09-24 13:07 UTC133
                format!("expected a room but got {output:?}"),
31ce2453c82fatagen2026-09-24 13:07 UTC134
            )),
31ce2453c82fatagen2026-09-24 13:07 UTC135
        }
31ce2453c82fatagen2026-09-24 13:07 UTC136
    }
31ce2453c82fatagen2026-09-24 13:07 UTC137
31ce2453c82fatagen2026-09-24 13:07 UTC138
    pub async fn shutdown(&self) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC139
        self.run(Command::Lifecycle(LifecycleCommand::Shutdown))
31ce2453c82fatagen2026-09-24 13:07 UTC140
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC141
    }
31ce2453c82fatagen2026-09-24 13:07 UTC142
31ce2453c82fatagen2026-09-24 13:07 UTC143
    pub async fn logout(&self) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC144
        self.run(Command::Account(AccountCommand::Logout)).await
96fdf90aacd6atagen2026-09-08 08:24 UTC145
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC146
96fdf90aacd6atagen2026-09-08 08:24 UTC147
    pub async fn delete_devices(
96fdf90aacd6atagen2026-09-08 08:24 UTC148
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC149
        device_ids: Vec<OwnedDeviceId>,
96fdf90aacd6atagen2026-09-08 08:24 UTC150
        auth: Option<InteractiveAuth>,
31ce2453c82fatagen2026-09-24 13:07 UTC151
    ) -> Result<InteractiveAuthOutcome, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC152
        match self
31ce2453c82fatagen2026-09-24 13:07 UTC153
            .run(Command::Account(AccountCommand::DeleteDevices {
96fdf90aacd6atagen2026-09-08 08:24 UTC154
                device_ids,
96fdf90aacd6atagen2026-09-08 08:24 UTC155
                auth,
31ce2453c82fatagen2026-09-24 13:07 UTC156
            }))
96fdf90aacd6atagen2026-09-08 08:24 UTC157
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC158
        {
31ce2453c82fatagen2026-09-24 13:07 UTC159
            Ok(()) => Ok(InteractiveAuthOutcome::Completed),
31ce2453c82fatagen2026-09-24 13:07 UTC160
            Err(Error {
31ce2453c82fatagen2026-09-24 13:07 UTC161
                challenge: Some(challenge),
31ce2453c82fatagen2026-09-24 13:07 UTC162
                ..
31ce2453c82fatagen2026-09-24 13:07 UTC163
            }) => Ok(InteractiveAuthOutcome::Challenge(*challenge)),
31ce2453c82fatagen2026-09-24 13:07 UTC164
            Err(error) => Err(error),
31ce2453c82fatagen2026-09-24 13:07 UTC165
        }
96fdf90aacd6atagen2026-09-08 08:24 UTC166
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC167
96fdf90aacd6atagen2026-09-08 08:24 UTC168
    pub async fn rename_device(
96fdf90aacd6atagen2026-09-08 08:24 UTC169
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC170
        device_id: OwnedDeviceId,
96fdf90aacd6atagen2026-09-08 08:24 UTC171
        display_name: impl Into<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC172
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC173
        self.run(Command::Account(AccountCommand::RenameDevice {
96fdf90aacd6atagen2026-09-08 08:24 UTC174
            device_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC175
            display_name: display_name.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC176
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC177
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC178
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC179
31ce2453c82fatagen2026-09-24 13:07 UTC180
    pub async fn set_global_account_data(
31ce2453c82fatagen2026-09-24 13:07 UTC181
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC182
        event_type: GlobalAccountDataEventType,
31ce2453c82fatagen2026-09-24 13:07 UTC183
        content: Raw<AnyGlobalAccountDataEventContent>,
31ce2453c82fatagen2026-09-24 13:07 UTC184
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC185
        self.run(Command::Account(AccountCommand::SetAccountData {
31ce2453c82fatagen2026-09-24 13:07 UTC186
            event_type,
31ce2453c82fatagen2026-09-24 13:07 UTC187
            content,
31ce2453c82fatagen2026-09-24 13:07 UTC188
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC189
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC190
    }
31ce2453c82fatagen2026-09-24 13:07 UTC191
31ce2453c82fatagen2026-09-24 13:07 UTC192
    pub async fn set_room_account_data(
31ce2453c82fatagen2026-09-24 13:07 UTC193
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC194
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC195
        event_type: RoomAccountDataEventType,
31ce2453c82fatagen2026-09-24 13:07 UTC196
        content: Raw<AnyRoomAccountDataEventContent>,
31ce2453c82fatagen2026-09-24 13:07 UTC197
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC198
        self.run(Command::Room(RoomCommand::SetAccountData {
31ce2453c82fatagen2026-09-24 13:07 UTC199
            room_id,
31ce2453c82fatagen2026-09-24 13:07 UTC200
            event_type,
31ce2453c82fatagen2026-09-24 13:07 UTC201
            content,
31ce2453c82fatagen2026-09-24 13:07 UTC202
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC203
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC204
    }
31ce2453c82fatagen2026-09-24 13:07 UTC205
96fdf90aacd6atagen2026-09-08 08:24 UTC206
    pub async fn set_room_notification_mode(
96fdf90aacd6atagen2026-09-08 08:24 UTC207
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC208
        room_id: OwnedRoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC209
        mode: RoomNotificationMode,
31ce2453c82fatagen2026-09-24 13:07 UTC210
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC211
        self.run(Command::Notification(NotificationCommand::SetRoomMode {
96fdf90aacd6atagen2026-09-08 08:24 UTC212
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC213
            mode,
96fdf90aacd6atagen2026-09-08 08:24 UTC214
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC215
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC216
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC217
31ce2453c82fatagen2026-09-24 13:07 UTC218
    pub async fn reset_room_notification_mode(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC219
        self.run(Command::Notification(NotificationCommand::ResetRoomMode(
96fdf90aacd6atagen2026-09-08 08:24 UTC220
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC221
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC222
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC223
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC224
96fdf90aacd6atagen2026-09-08 08:24 UTC225
    pub async fn set_default_notification_mode(
96fdf90aacd6atagen2026-09-08 08:24 UTC226
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC227
        encrypted: bool,
96fdf90aacd6atagen2026-09-08 08:24 UTC228
        one_to_one: bool,
96fdf90aacd6atagen2026-09-08 08:24 UTC229
        mode: RoomNotificationMode,
31ce2453c82fatagen2026-09-24 13:07 UTC230
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC231
        self.run(Command::Notification(NotificationCommand::SetDefaultMode {
96fdf90aacd6atagen2026-09-08 08:24 UTC232
            encrypted,
96fdf90aacd6atagen2026-09-08 08:24 UTC233
            one_to_one,
96fdf90aacd6atagen2026-09-08 08:24 UTC234
            mode,
96fdf90aacd6atagen2026-09-08 08:24 UTC235
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC236
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC237
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC238
31ce2453c82fatagen2026-09-24 13:07 UTC239
    pub async fn add_notification_keyword(&self, keyword: impl Into<String>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC240
        self.run(Command::Notification(NotificationCommand::AddKeyword(
96fdf90aacd6atagen2026-09-08 08:24 UTC241
            keyword.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC242
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC243
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC244
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC245
96fdf90aacd6atagen2026-09-08 08:24 UTC246
    pub async fn remove_notification_keyword(
96fdf90aacd6atagen2026-09-08 08:24 UTC247
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC248
        keyword: impl Into<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC249
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC250
        self.run(Command::Notification(NotificationCommand::RemoveKeyword(
96fdf90aacd6atagen2026-09-08 08:24 UTC251
            keyword.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC252
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC253
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC254
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC255
31ce2453c82fatagen2026-09-24 13:07 UTC256
    pub async fn open_room(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC257
        self.run(Command::Room(RoomCommand::Open(room_id))).await
96fdf90aacd6atagen2026-09-08 08:24 UTC258
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC259
31ce2453c82fatagen2026-09-24 13:07 UTC260
    pub async fn close_room(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC261
        self.run(Command::Room(RoomCommand::Close(room_id))).await
96fdf90aacd6atagen2026-09-08 08:24 UTC262
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC263
96fdf90aacd6atagen2026-09-08 08:24 UTC264
    pub async fn open_thread(
96fdf90aacd6atagen2026-09-08 08:24 UTC265
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC266
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC267
        root_event_id: OwnedEventId,
31ce2453c82fatagen2026-09-24 13:07 UTC268
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC269
        self.run(Command::Timeline(TimelineCommand::OpenThread {
96fdf90aacd6atagen2026-09-08 08:24 UTC270
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC271
            root_event_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC272
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC273
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC274
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC275
96fdf90aacd6atagen2026-09-08 08:24 UTC276
    pub async fn close_thread(
96fdf90aacd6atagen2026-09-08 08:24 UTC277
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC278
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC279
        root_event_id: OwnedEventId,
31ce2453c82fatagen2026-09-24 13:07 UTC280
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC281
        self.run(Command::Timeline(TimelineCommand::CloseThread {
96fdf90aacd6atagen2026-09-08 08:24 UTC282
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC283
            root_event_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC284
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC285
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC286
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC287
31ce2453c82fatagen2026-09-24 13:07 UTC288
    pub async fn resync(&self, timeline_id: TimelineId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC289
        self.run(Command::Timeline(TimelineCommand::Resync { timeline_id }))
96fdf90aacd6atagen2026-09-08 08:24 UTC290
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC291
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC292
31ce2453c82fatagen2026-09-24 13:07 UTC293
    pub async fn paginate(&self, timeline_id: TimelineId, limit: u16) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC294
        self.run(Command::Timeline(TimelineCommand::Paginate {
31ce2453c82fatagen2026-09-24 13:07 UTC295
            timeline_id,
31ce2453c82fatagen2026-09-24 13:07 UTC296
            limit,
31ce2453c82fatagen2026-09-24 13:07 UTC297
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC298
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC299
    }
31ce2453c82fatagen2026-09-24 13:07 UTC300
31ce2453c82fatagen2026-09-24 13:07 UTC301
    pub async fn send_message(
96fdf90aacd6atagen2026-09-08 08:24 UTC302
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC303
        timeline_id: TimelineId,
31ce2453c82fatagen2026-09-24 13:07 UTC304
        content: MessageContent,
31ce2453c82fatagen2026-09-24 13:07 UTC305
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC306
        self.run(Command::Timeline(TimelineCommand::Send {
31ce2453c82fatagen2026-09-24 13:07 UTC307
            timeline_id,
31ce2453c82fatagen2026-09-24 13:07 UTC308
            content,
31ce2453c82fatagen2026-09-24 13:07 UTC309
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC310
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC311
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC312
31ce2453c82fatagen2026-09-24 13:07 UTC313
    pub async fn edit_message(
96fdf90aacd6atagen2026-09-08 08:24 UTC314
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC315
        timeline_id: TimelineId,
960ac0721079atagen2026-09-25 00:24 UTC316
        target: impl Into<EventRef>,
31ce2453c82fatagen2026-09-24 13:07 UTC317
        content: MessageEditContent,
31ce2453c82fatagen2026-09-24 13:07 UTC318
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC319
        self.run(Command::Timeline(TimelineCommand::Edit {
31ce2453c82fatagen2026-09-24 13:07 UTC320
            timeline_id,
960ac0721079atagen2026-09-25 00:24 UTC321
            target: target.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC322
            content,
31ce2453c82fatagen2026-09-24 13:07 UTC323
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC324
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC325
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC326
31ce2453c82fatagen2026-09-24 13:07 UTC327
    pub async fn redact(
96fdf90aacd6atagen2026-09-08 08:24 UTC328
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC329
        timeline_id: TimelineId,
960ac0721079atagen2026-09-25 00:24 UTC330
        target: impl Into<EventRef>,
31ce2453c82fatagen2026-09-24 13:07 UTC331
        reason: Option<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC332
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC333
        self.run(Command::Timeline(TimelineCommand::Redact {
31ce2453c82fatagen2026-09-24 13:07 UTC334
            timeline_id,
960ac0721079atagen2026-09-25 00:24 UTC335
            target: target.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC336
            reason,
31ce2453c82fatagen2026-09-24 13:07 UTC337
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC338
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC339
    }
31ce2453c82fatagen2026-09-24 13:07 UTC340
31ce2453c82fatagen2026-09-24 13:07 UTC341
    pub async fn toggle_reaction(
31ce2453c82fatagen2026-09-24 13:07 UTC342
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC343
        timeline_id: TimelineId,
960ac0721079atagen2026-09-25 00:24 UTC344
        target: impl Into<EventRef>,
31ce2453c82fatagen2026-09-24 13:07 UTC345
        key: impl Into<String>,
8fa8a7cde89catagen2026-10-08 12:39 UTC346
        shortcode: Option<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC347
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC348
        self.run(Command::Timeline(TimelineCommand::ToggleReaction {
31ce2453c82fatagen2026-09-24 13:07 UTC349
            timeline_id,
960ac0721079atagen2026-09-25 00:24 UTC350
            target: target.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC351
            key: key.into(),
8fa8a7cde89catagen2026-10-08 12:39 UTC352
            shortcode,
31ce2453c82fatagen2026-09-24 13:07 UTC353
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC354
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC355
    }
31ce2453c82fatagen2026-09-24 13:07 UTC356
31ce2453c82fatagen2026-09-24 13:07 UTC357
    pub async fn mark_read(
31ce2453c82fatagen2026-09-24 13:07 UTC358
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC359
        timeline_id: TimelineId,
31ce2453c82fatagen2026-09-24 13:07 UTC360
        event_id: OwnedEventId,
31ce2453c82fatagen2026-09-24 13:07 UTC361
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC362
        self.run(Command::Timeline(TimelineCommand::MarkRead {
31ce2453c82fatagen2026-09-24 13:07 UTC363
            timeline_id,
31ce2453c82fatagen2026-09-24 13:07 UTC364
            event_id,
31ce2453c82fatagen2026-09-24 13:07 UTC365
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC366
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC367
    }
31ce2453c82fatagen2026-09-24 13:07 UTC368
31ce2453c82fatagen2026-09-24 13:07 UTC369
    pub async fn set_typing(&self, room_id: OwnedRoomId, typing: bool) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC370
        self.run(Command::Room(RoomCommand::SetTyping { room_id, typing }))
96fdf90aacd6atagen2026-09-08 08:24 UTC371
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC372
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC373
38c4caecdb3datagen2026-09-26 13:35 UTC374
    pub async fn prepare_to_send(&self, room_id: OwnedRoomId) -> Result<(), Error> {
38c4caecdb3datagen2026-09-26 13:35 UTC375
        self.run(Command::Room(RoomCommand::PrepareToSend(room_id)))
38c4caecdb3datagen2026-09-26 13:35 UTC376
            .await
38c4caecdb3datagen2026-09-26 13:35 UTC377
    }
38c4caecdb3datagen2026-09-26 13:35 UTC378
31ce2453c82fatagen2026-09-24 13:07 UTC379
    pub async fn join_room(
96fdf90aacd6atagen2026-09-08 08:24 UTC380
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC381
        room: OwnedRoomOrAliasId,
31ce2453c82fatagen2026-09-24 13:07 UTC382
        via: Vec<OwnedServerName>,
31ce2453c82fatagen2026-09-24 13:07 UTC383
    ) -> Result<OwnedRoomId, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC384
        self.run_for_room(RoomCommand::Join { room, via }).await
31ce2453c82fatagen2026-09-24 13:07 UTC385
    }
31ce2453c82fatagen2026-09-24 13:07 UTC386
31ce2453c82fatagen2026-09-24 13:07 UTC387
    pub async fn leave_room(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC388
        self.run(Command::Room(RoomCommand::Leave(room_id))).await
31ce2453c82fatagen2026-09-24 13:07 UTC389
    }
31ce2453c82fatagen2026-09-24 13:07 UTC390
31ce2453c82fatagen2026-09-24 13:07 UTC391
    pub async fn forget_room(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC392
        self.run(Command::Room(RoomCommand::Forget(room_id))).await
31ce2453c82fatagen2026-09-24 13:07 UTC393
    }
31ce2453c82fatagen2026-09-24 13:07 UTC394
31ce2453c82fatagen2026-09-24 13:07 UTC395
    pub async fn accept_invite(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC396
        self.run(Command::Room(RoomCommand::AcceptInvite(room_id)))
31ce2453c82fatagen2026-09-24 13:07 UTC397
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC398
    }
31ce2453c82fatagen2026-09-24 13:07 UTC399
31ce2453c82fatagen2026-09-24 13:07 UTC400
    pub async fn reject_invite(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC401
        self.run(Command::Room(RoomCommand::RejectInvite(room_id)))
96fdf90aacd6atagen2026-09-08 08:24 UTC402
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC403
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC404
96fdf90aacd6atagen2026-09-08 08:24 UTC405
    pub async fn invite_user(
96fdf90aacd6atagen2026-09-08 08:24 UTC406
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC407
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC408
        user_id: OwnedUserId,
31ce2453c82fatagen2026-09-24 13:07 UTC409
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC410
        self.run(Command::Room(RoomCommand::InviteUser { room_id, user_id }))
31ce2453c82fatagen2026-09-24 13:07 UTC411
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC412
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC413
96fdf90aacd6atagen2026-09-08 08:24 UTC414
    pub async fn kick_user(
96fdf90aacd6atagen2026-09-08 08:24 UTC415
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC416
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC417
        user_id: OwnedUserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC418
        reason: Option<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC419
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC420
        self.run(Command::Room(RoomCommand::KickUser {
96fdf90aacd6atagen2026-09-08 08:24 UTC421
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC422
            user_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC423
            reason,
96fdf90aacd6atagen2026-09-08 08:24 UTC424
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC425
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC426
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC427
96fdf90aacd6atagen2026-09-08 08:24 UTC428
    pub async fn ban_user(
96fdf90aacd6atagen2026-09-08 08:24 UTC429
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC430
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC431
        user_id: OwnedUserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC432
        reason: Option<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC433
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC434
        self.run(Command::Room(RoomCommand::BanUser {
96fdf90aacd6atagen2026-09-08 08:24 UTC435
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC436
            user_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC437
            reason,
96fdf90aacd6atagen2026-09-08 08:24 UTC438
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC439
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC440
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC441
96fdf90aacd6atagen2026-09-08 08:24 UTC442
    pub async fn unban_user(
96fdf90aacd6atagen2026-09-08 08:24 UTC443
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC444
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC445
        user_id: OwnedUserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC446
        reason: Option<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC447
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC448
        self.run(Command::Room(RoomCommand::UnbanUser {
96fdf90aacd6atagen2026-09-08 08:24 UTC449
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC450
            user_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC451
            reason,
96fdf90aacd6atagen2026-09-08 08:24 UTC452
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC453
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC454
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC455
96fdf90aacd6atagen2026-09-08 08:24 UTC456
    pub async fn set_power_levels(
96fdf90aacd6atagen2026-09-08 08:24 UTC457
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC458
        room_id: OwnedRoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC459
        changes: PowerLevelChanges,
31ce2453c82fatagen2026-09-24 13:07 UTC460
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC461
        self.run(Command::Room(RoomCommand::SetPowerLevels {
96fdf90aacd6atagen2026-09-08 08:24 UTC462
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC463
            changes,
96fdf90aacd6atagen2026-09-08 08:24 UTC464
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC465
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC466
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC467
96fdf90aacd6atagen2026-09-08 08:24 UTC468
    pub async fn set_user_power_level(
96fdf90aacd6atagen2026-09-08 08:24 UTC469
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC470
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC471
        user_id: OwnedUserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC472
        level: i64,
31ce2453c82fatagen2026-09-24 13:07 UTC473
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC474
        self.run(Command::Room(RoomCommand::SetUserPowerLevel {
96fdf90aacd6atagen2026-09-08 08:24 UTC475
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC476
            user_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC477
            level,
96fdf90aacd6atagen2026-09-08 08:24 UTC478
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC479
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC480
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC481
31ce2453c82fatagen2026-09-24 13:07 UTC482
    pub async fn create_room(&self, options: CreateRoomOptions) -> Result<OwnedRoomId, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC483
        self.run_for_room(RoomCommand::Create(options)).await
96fdf90aacd6atagen2026-09-08 08:24 UTC484
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC485
31ce2453c82fatagen2026-09-24 13:07 UTC486
    /// hands back the existing dm with them if there is one
31ce2453c82fatagen2026-09-24 13:07 UTC487
    pub async fn create_direct(&self, user_id: OwnedUserId) -> Result<OwnedRoomId, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC488
        self.run_for_room(RoomCommand::CreateDirect(user_id)).await
96fdf90aacd6atagen2026-09-08 08:24 UTC489
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC490
96fdf90aacd6atagen2026-09-08 08:24 UTC491
    pub async fn cancel_send(
96fdf90aacd6atagen2026-09-08 08:24 UTC492
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC493
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC494
        transaction_id: OwnedTransactionId,
31ce2453c82fatagen2026-09-24 13:07 UTC495
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC496
        self.run(Command::Room(RoomCommand::CancelSend {
96fdf90aacd6atagen2026-09-08 08:24 UTC497
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC498
            transaction_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC499
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC500
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC501
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC502
96fdf90aacd6atagen2026-09-08 08:24 UTC503
    pub async fn retry_send(
96fdf90aacd6atagen2026-09-08 08:24 UTC504
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC505
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC506
        transaction_id: OwnedTransactionId,
31ce2453c82fatagen2026-09-24 13:07 UTC507
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC508
        self.run(Command::Room(RoomCommand::RetrySend {
96fdf90aacd6atagen2026-09-08 08:24 UTC509
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC510
            transaction_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC511
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC512
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC513
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC514
31ce2453c82fatagen2026-09-24 13:07 UTC515
    pub async fn upload(&self, upload: AttachmentUpload) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC516
        self.run(Command::Media(MediaCommand::Upload(upload))).await
96fdf90aacd6atagen2026-09-08 08:24 UTC517
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC518
31ce2453c82fatagen2026-09-24 13:07 UTC519
    pub async fn recover(&self, recovery_key: impl Into<String>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC520
        self.run(Command::Encryption(EncryptionCommand::Recover(
31ce2453c82fatagen2026-09-24 13:07 UTC521
            recovery_key.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC522
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC523
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC524
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC525
31ce2453c82fatagen2026-09-24 13:07 UTC526
    pub async fn create_key_backup(&self) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC527
        self.run(Command::Encryption(EncryptionCommand::CreateKeyBackup))
31ce2453c82fatagen2026-09-24 13:07 UTC528
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC529
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC530
31ce2453c82fatagen2026-09-24 13:07 UTC531
    pub async fn enable_key_backup(&self) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC532
        self.run(Command::Encryption(EncryptionCommand::EnableKeyBackup))
31ce2453c82fatagen2026-09-24 13:07 UTC533
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC534
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC535
31ce2453c82fatagen2026-09-24 13:07 UTC536
    pub async fn disable_key_backup(&self, delete_from_server: bool) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC537
        self.run(Command::Encryption(EncryptionCommand::DisableKeyBackup {
31ce2453c82fatagen2026-09-24 13:07 UTC538
            delete_from_server,
31ce2453c82fatagen2026-09-24 13:07 UTC539
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC540
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC541
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC542
31ce2453c82fatagen2026-09-24 13:07 UTC543
    pub async fn recover_key_backup(&self, recovery_key: impl Into<String>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC544
        self.run(Command::Encryption(EncryptionCommand::RecoverKeyBackup(
31ce2453c82fatagen2026-09-24 13:07 UTC545
            recovery_key.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC546
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC547
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC548
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC549
31ce2453c82fatagen2026-09-24 13:07 UTC550
    pub async fn start_verification(&self, target: VerificationTarget) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC551
        self.run(Command::Encryption(EncryptionCommand::StartVerification(
31ce2453c82fatagen2026-09-24 13:07 UTC552
            target,
31ce2453c82fatagen2026-09-24 13:07 UTC553
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC554
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC555
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC556
31ce2453c82fatagen2026-09-24 13:07 UTC557
    pub async fn verify(&self, action: VerificationAction) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC558
        self.run(Command::Encryption(EncryptionCommand::Verify(action)))
31ce2453c82fatagen2026-09-24 13:07 UTC559
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC560
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC561
5d2974de5826atagen2026-10-08 11:29 UTC562
    /// bytes for an avatar, or for media a retained timeline showed you. concurrent asks share
5d2974de5826atagen2026-10-08 11:29 UTC563
    /// one download
31ce2453c82fatagen2026-09-24 13:07 UTC564
    pub async fn media(&self, media_id: &MediaId, size: MediaSize) -> Result<Media, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC565
        self.media.timeline_media(media_id, size).await
31ce2453c82fatagen2026-09-24 13:07 UTC566
    }
31ce2453c82fatagen2026-09-24 13:07 UTC567
5b21b919d1e6atagen2026-09-27 11:47 UTC568
    /// where `media` would fetch from, for a host streaming big files itself. the byte cap
5b21b919d1e6atagen2026-09-27 11:47 UTC569
    /// doesn't apply since nothing is buffered
5b21b919d1e6atagen2026-09-27 11:47 UTC570
    pub async fn media_source(
5b21b919d1e6atagen2026-09-27 11:47 UTC571
        &self,
5b21b919d1e6atagen2026-09-27 11:47 UTC572
        media_id: &MediaId,
5b21b919d1e6atagen2026-09-27 11:47 UTC573
        size: MediaSize,
5b21b919d1e6atagen2026-09-27 11:47 UTC574
    ) -> Result<MediaLocation, Error> {
5b21b919d1e6atagen2026-09-27 11:47 UTC575
        self.media.media_location(media_id, size).await
5b21b919d1e6atagen2026-09-27 11:47 UTC576
    }
5b21b919d1e6atagen2026-09-27 11:47 UTC577
31ce2453c82fatagen2026-09-24 13:07 UTC578
    /// the space graph builds on first use and then keeps itself current
31ce2453c82fatagen2026-09-24 13:07 UTC579
    async fn spaces(&self) -> &SpaceService {
31ce2453c82fatagen2026-09-24 13:07 UTC580
        self.spaces
31ce2453c82fatagen2026-09-24 13:07 UTC581
            .get_or_init(|| SpaceService::new(self.client.clone()))
31ce2453c82fatagen2026-09-24 13:07 UTC582
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC583
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC584
96fdf90aacd6atagen2026-09-08 08:24 UTC585
    pub async fn rooms(&self) -> Vec<RoomSummary> {
31ce2453c82fatagen2026-09-24 13:07 UTC586
        room_summaries(&self.client, self.spaces().await).await
96fdf90aacd6atagen2026-09-08 08:24 UTC587
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC588
17e042fbc331atagen2026-10-08 12:39 UTC589
    pub async fn image_packs(&self) -> Result<ImagePacks, Error> {
17e042fbc331atagen2026-10-08 12:39 UTC590
        image_packs(&self.client).await
17e042fbc331atagen2026-10-08 12:39 UTC591
    }
17e042fbc331atagen2026-10-08 12:39 UTC592
0291516d40b5atagen2026-10-22 08:31 UTC593
    /// the homeserver's preview of a page, `None` when it has none. the homeserver sees every
0291516d40b5atagen2026-10-22 08:31 UTC594
    /// url asked about, so a host decides whether encrypted rooms ask at all
0291516d40b5atagen2026-10-22 08:31 UTC595
    pub async fn url_preview(&self, url: &str) -> Result<Option<LinkPreview>, Error> {
0291516d40b5atagen2026-10-22 08:31 UTC596
        self.media.url_preview(url).await
0291516d40b5atagen2026-10-22 08:31 UTC597
    }
0291516d40b5atagen2026-10-22 08:31 UTC598
0291516d40b5atagen2026-10-22 08:31 UTC599
    /// whether the room and the user's settings let link previews show here
0291516d40b5atagen2026-10-22 08:31 UTC600
    pub async fn url_previews_allowed(&self, room_id: &RoomId) -> Result<bool, Error> {
0291516d40b5atagen2026-10-22 08:31 UTC601
        url_previews_allowed(&self.room(room_id)?).await
0291516d40b5atagen2026-10-22 08:31 UTC602
    }
0291516d40b5atagen2026-10-22 08:31 UTC603
31ce2453c82fatagen2026-09-24 13:07 UTC604
    /// browse a space the way the server sees it, rooms you haven't joined included
31ce2453c82fatagen2026-09-24 13:07 UTC605
    pub async fn space_hierarchy(&self, space_id: OwnedRoomId) -> SpaceHierarchy {
31ce2453c82fatagen2026-09-24 13:07 UTC606
        SpaceHierarchy(SpaceRoomList::new(self.client.clone(), space_id).await)
31ce2453c82fatagen2026-09-24 13:07 UTC607
    }
31ce2453c82fatagen2026-09-24 13:07 UTC608
31ce2453c82fatagen2026-09-24 13:07 UTC609
    pub async fn own_profile(&self) -> Result<Profile, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC610
        let user_id = self
31ce2453c82fatagen2026-09-24 13:07 UTC611
            .client
31ce2453c82fatagen2026-09-24 13:07 UTC612
            .user_id()
31ce2453c82fatagen2026-09-24 13:07 UTC613
            .ok_or_else(|| Error::new(ErrorKind::Unauthenticated, "the client is not logged in"))?
31ce2453c82fatagen2026-09-24 13:07 UTC614
            .to_owned();
31ce2453c82fatagen2026-09-24 13:07 UTC615
        let response = self
31ce2453c82fatagen2026-09-24 13:07 UTC616
            .client
31ce2453c82fatagen2026-09-24 13:07 UTC617
            .account()
31ce2453c82fatagen2026-09-24 13:07 UTC618
            .fetch_user_profile()
31ce2453c82fatagen2026-09-24 13:07 UTC619
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC620
            .map_err(|source| Error::from_sdk("fetching the profile failed", source))?;
31ce2453c82fatagen2026-09-24 13:07 UTC621
        profile(user_id, &response)
31ce2453c82fatagen2026-09-24 13:07 UTC622
    }
31ce2453c82fatagen2026-09-24 13:07 UTC623
31ce2453c82fatagen2026-09-24 13:07 UTC624
    pub async fn user_profile(&self, user_id: &UserId) -> Result<Profile, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC625
        let response = self
31ce2453c82fatagen2026-09-24 13:07 UTC626
            .client
31ce2453c82fatagen2026-09-24 13:07 UTC627
            .account()
31ce2453c82fatagen2026-09-24 13:07 UTC628
            .fetch_user_profile_of(user_id)
31ce2453c82fatagen2026-09-24 13:07 UTC629
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC630
            .map_err(|source| Error::from_sdk("fetching the profile failed", source))?;
31ce2453c82fatagen2026-09-24 13:07 UTC631
        profile(user_id.to_owned(), &response)
31ce2453c82fatagen2026-09-24 13:07 UTC632
    }
31ce2453c82fatagen2026-09-24 13:07 UTC633
31ce2453c82fatagen2026-09-24 13:07 UTC634
    pub async fn set_display_name(&self, name: Option<String>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC635
        self.run(Command::Account(AccountCommand::SetDisplayName(name)))
31ce2453c82fatagen2026-09-24 13:07 UTC636
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC637
    }
31ce2453c82fatagen2026-09-24 13:07 UTC638
31ce2453c82fatagen2026-09-24 13:07 UTC639
    pub async fn set_avatar(&self, avatar: Option<OwnedMxcUri>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC640
        self.run(Command::Account(AccountCommand::SetAvatar(avatar)))
31ce2453c82fatagen2026-09-24 13:07 UTC641
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC642
    }
31ce2453c82fatagen2026-09-24 13:07 UTC643
31ce2453c82fatagen2026-09-24 13:07 UTC644
    pub async fn upload_avatar(
31ce2453c82fatagen2026-09-24 13:07 UTC645
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC646
        mimetype: impl Into<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC647
        bytes: Vec<u8>,
31ce2453c82fatagen2026-09-24 13:07 UTC648
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC649
        self.run(Command::Account(AccountCommand::UploadAvatar {
31ce2453c82fatagen2026-09-24 13:07 UTC650
            mimetype: mimetype.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC651
            bytes,
31ce2453c82fatagen2026-09-24 13:07 UTC652
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC653
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC654
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC655
31ce2453c82fatagen2026-09-24 13:07 UTC656
    pub async fn rooms_filtered(&self, filter: &RoomListFilter) -> Vec<RoomSummary> {
31ce2453c82fatagen2026-09-24 13:07 UTC657
        let matcher = filter.matcher();
96fdf90aacd6atagen2026-09-08 08:24 UTC658
        self.rooms()
96fdf90aacd6atagen2026-09-08 08:24 UTC659
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC660
            .into_iter()
31ce2453c82fatagen2026-09-24 13:07 UTC661
            .filter(|room| matcher.matches(room))
96fdf90aacd6atagen2026-09-08 08:24 UTC662
            .collect()
96fdf90aacd6atagen2026-09-08 08:24 UTC663
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC664
31ce2453c82fatagen2026-09-24 13:07 UTC665
    pub async fn devices(&self) -> Result<Vec<OwnDevice>, Error> {
96fdf90aacd6atagen2026-09-08 08:24 UTC666
        let current_device_id = self.client.device_id();
96fdf90aacd6atagen2026-09-08 08:24 UTC667
        Ok(self
96fdf90aacd6atagen2026-09-08 08:24 UTC668
            .client
96fdf90aacd6atagen2026-09-08 08:24 UTC669
            .devices()
96fdf90aacd6atagen2026-09-08 08:24 UTC670
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC671
            .map_err(|source| Error::from_http("listing devices failed", source))?
96fdf90aacd6atagen2026-09-08 08:24 UTC672
            .devices
96fdf90aacd6atagen2026-09-08 08:24 UTC673
            .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC674
            .map(|device| OwnDevice {
96fdf90aacd6atagen2026-09-08 08:24 UTC675
                current: current_device_id == Some(device.device_id.as_ref()),
96fdf90aacd6atagen2026-09-08 08:24 UTC676
                device_id: device.device_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC677
                display_name: device.display_name,
96fdf90aacd6atagen2026-09-08 08:24 UTC678
                last_seen_ip: device.last_seen_ip,
96fdf90aacd6atagen2026-09-08 08:24 UTC679
                last_seen_timestamp_ms: device.last_seen_ts.map(|timestamp| timestamp.get().into()),
96fdf90aacd6atagen2026-09-08 08:24 UTC680
            })
96fdf90aacd6atagen2026-09-08 08:24 UTC681
            .collect())
96fdf90aacd6atagen2026-09-08 08:24 UTC682
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC683
31ce2453c82fatagen2026-09-24 13:07 UTC684
    fn room(&self, room_id: &RoomId) -> Result<matrix_sdk::Room, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC685
        self.client
31ce2453c82fatagen2026-09-24 13:07 UTC686
            .get_room(room_id)
31ce2453c82fatagen2026-09-24 13:07 UTC687
            .ok_or_else(Error::room_unknown)
31ce2453c82fatagen2026-09-24 13:07 UTC688
    }
31ce2453c82fatagen2026-09-24 13:07 UTC689
96fdf90aacd6atagen2026-09-08 08:24 UTC690
    pub async fn room_notification_settings(
96fdf90aacd6atagen2026-09-08 08:24 UTC691
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC692
        room_id: &RoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC693
    ) -> Result<Option<RoomNotificationSettings>, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC694
        let room = self.room(room_id)?;
96fdf90aacd6atagen2026-09-08 08:24 UTC695
        let custom = room.user_defined_notification_mode().await;
96fdf90aacd6atagen2026-09-08 08:24 UTC696
        let mode = match custom {
96fdf90aacd6atagen2026-09-08 08:24 UTC697
            Some(mode) => mode,
96fdf90aacd6atagen2026-09-08 08:24 UTC698
            None => match room.notification_mode().await {
96fdf90aacd6atagen2026-09-08 08:24 UTC699
                Some(mode) => mode,
96fdf90aacd6atagen2026-09-08 08:24 UTC700
                None => return Ok(None),
96fdf90aacd6atagen2026-09-08 08:24 UTC701
            },
96fdf90aacd6atagen2026-09-08 08:24 UTC702
        };
96fdf90aacd6atagen2026-09-08 08:24 UTC703
        Ok(Some(RoomNotificationSettings {
96fdf90aacd6atagen2026-09-08 08:24 UTC704
            mode: crate::normalise::notification_mode(mode),
96fdf90aacd6atagen2026-09-08 08:24 UTC705
            custom: custom.is_some(),
96fdf90aacd6atagen2026-09-08 08:24 UTC706
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC707
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC708
96fdf90aacd6atagen2026-09-08 08:24 UTC709
    pub async fn notification_keywords(&self) -> Vec<String> {
96fdf90aacd6atagen2026-09-08 08:24 UTC710
        self.client
96fdf90aacd6atagen2026-09-08 08:24 UTC711
            .notification_settings()
96fdf90aacd6atagen2026-09-08 08:24 UTC712
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC713
            .enabled_keywords()
96fdf90aacd6atagen2026-09-08 08:24 UTC714
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC715
            .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC716
            .collect()
96fdf90aacd6atagen2026-09-08 08:24 UTC717
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC718
96fdf90aacd6atagen2026-09-08 08:24 UTC719
    pub async fn resolve_push_notification(
96fdf90aacd6atagen2026-09-08 08:24 UTC720
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC721
        room_id: &RoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC722
        event_id: &EventId,
31ce2453c82fatagen2026-09-24 13:07 UTC723
    ) -> Result<PushNotificationStatus, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC724
        let notification_failed = |source| {
31ce2453c82fatagen2026-09-24 13:07 UTC725
            Error::with_source(
31ce2453c82fatagen2026-09-24 13:07 UTC726
                ErrorKind::Other,
31ce2453c82fatagen2026-09-24 13:07 UTC727
                "resolving the push notification failed",
31ce2453c82fatagen2026-09-24 13:07 UTC728
                source,
31ce2453c82fatagen2026-09-24 13:07 UTC729
            )
31ce2453c82fatagen2026-09-24 13:07 UTC730
        };
96fdf90aacd6atagen2026-09-08 08:24 UTC731
        let client = self
96fdf90aacd6atagen2026-09-08 08:24 UTC732
            .notification_client
96fdf90aacd6atagen2026-09-08 08:24 UTC733
            .get_or_try_init(|| async {
96fdf90aacd6atagen2026-09-08 08:24 UTC734
                NotificationClient::new(
96fdf90aacd6atagen2026-09-08 08:24 UTC735
                    self.client.clone(),
96fdf90aacd6atagen2026-09-08 08:24 UTC736
                    NotificationProcessSetup::SingleProcess {
96fdf90aacd6atagen2026-09-08 08:24 UTC737
                        sync_service: self.sync_service.clone(),
96fdf90aacd6atagen2026-09-08 08:24 UTC738
                    },
96fdf90aacd6atagen2026-09-08 08:24 UTC739
                )
96fdf90aacd6atagen2026-09-08 08:24 UTC740
                .await
96fdf90aacd6atagen2026-09-08 08:24 UTC741
            })
96fdf90aacd6atagen2026-09-08 08:24 UTC742
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC743
            .map_err(notification_failed)?;
96fdf90aacd6atagen2026-09-08 08:24 UTC744
        let status = client
96fdf90aacd6atagen2026-09-08 08:24 UTC745
            .get_notification(room_id, event_id)
96fdf90aacd6atagen2026-09-08 08:24 UTC746
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC747
            .map_err(notification_failed)?;
96fdf90aacd6atagen2026-09-08 08:24 UTC748
        Ok(normalise_push_notification(room_id, event_id, status))
96fdf90aacd6atagen2026-09-08 08:24 UTC749
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC750
96fdf90aacd6atagen2026-09-08 08:24 UTC751
    pub async fn members(
96fdf90aacd6atagen2026-09-08 08:24 UTC752
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC753
        room_id: &RoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC754
        filter: MemberFilter,
31ce2453c82fatagen2026-09-24 13:07 UTC755
    ) -> Result<Vec<MemberSummary>, Error> {
121a56ce119datagen2026-10-24 06:42 UTC756
        let room = self.room(room_id)?;
121a56ce119datagen2026-10-24 06:42 UTC757
        // stores have been seen with members_synced persisted over a partial
121a56ce119datagen2026-10-24 06:42 UTC758
        // roster, and the sdk never asks /members again once it's set
121a56ce119datagen2026-10-24 06:42 UTC759
        if self.members_checked.lock().unwrap().insert(room_id.to_owned()) {
121a56ce119datagen2026-10-24 06:42 UTC760
            room.mark_members_missing();
121a56ce119datagen2026-10-24 06:42 UTC761
        }
121a56ce119datagen2026-10-24 06:42 UTC762
        list_members(&room, filter).await
121a56ce119datagen2026-10-24 06:42 UTC763
    }
121a56ce119datagen2026-10-24 06:42 UTC764
121a56ce119datagen2026-10-24 06:42 UTC765
    /// drop the cached roster for a room and fetch /members again
121a56ce119datagen2026-10-24 06:42 UTC766
    pub async fn refresh_members(
121a56ce119datagen2026-10-24 06:42 UTC767
        &self,
121a56ce119datagen2026-10-24 06:42 UTC768
        room_id: &RoomId,
121a56ce119datagen2026-10-24 06:42 UTC769
        filter: MemberFilter,
121a56ce119datagen2026-10-24 06:42 UTC770
    ) -> Result<Vec<MemberSummary>, Error> {
121a56ce119datagen2026-10-24 06:42 UTC771
        let room = self.room(room_id)?;
121a56ce119datagen2026-10-24 06:42 UTC772
        room.mark_members_missing();
121a56ce119datagen2026-10-24 06:42 UTC773
        self.members_checked.lock().unwrap().insert(room_id.to_owned());
121a56ce119datagen2026-10-24 06:42 UTC774
        list_members(&room, filter).await
96fdf90aacd6atagen2026-09-08 08:24 UTC775
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC776
31ce2453c82fatagen2026-09-24 13:07 UTC777
    pub async fn room_power_levels(&self, room_id: &RoomId) -> Result<RoomPowerLevels, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC778
        let levels = self
31ce2453c82fatagen2026-09-24 13:07 UTC779
            .room(room_id)?
96fdf90aacd6atagen2026-09-08 08:24 UTC780
            .power_levels()
96fdf90aacd6atagen2026-09-08 08:24 UTC781
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC782
            .map_err(|source| Error::from_sdk("reading power levels failed", source.into()))?;
96fdf90aacd6atagen2026-09-08 08:24 UTC783
        Ok(RoomPowerLevels {
96fdf90aacd6atagen2026-09-08 08:24 UTC784
            ban: levels.ban.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC785
            invite: levels.invite.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC786
            kick: levels.kick.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC787
            redact: levels.redact.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC788
            events_default: levels.events_default.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC789
            state_default: levels.state_default.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC790
            users_default: levels.users_default.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC791
            room_notification: levels.notifications.room.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC792
            users: levels
96fdf90aacd6atagen2026-09-08 08:24 UTC793
                .users
96fdf90aacd6atagen2026-09-08 08:24 UTC794
                .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC795
                .map(|(user_id, level)| (user_id, level.into()))
96fdf90aacd6atagen2026-09-08 08:24 UTC796
                .collect(),
96fdf90aacd6atagen2026-09-08 08:24 UTC797
            events: levels
96fdf90aacd6atagen2026-09-08 08:24 UTC798
                .events
96fdf90aacd6atagen2026-09-08 08:24 UTC799
                .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC800
                .map(|(event_type, level)| (event_type.to_string(), level.into()))
96fdf90aacd6atagen2026-09-08 08:24 UTC801
                .collect(),
5a52012c9b1datagen2026-09-24 23:45 UTC802
            creators: levels
5a52012c9b1datagen2026-09-24 23:45 UTC803
                .rules
5a52012c9b1datagen2026-09-24 23:45 UTC804
                .privileged_creators
5a52012c9b1datagen2026-09-24 23:45 UTC805
                .into_iter()
5a52012c9b1datagen2026-09-24 23:45 UTC806
                .flatten()
5a52012c9b1datagen2026-09-24 23:45 UTC807
                .collect(),
96fdf90aacd6atagen2026-09-08 08:24 UTC808
        })
96fdf90aacd6atagen2026-09-08 08:24 UTC809
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC810
96fdf90aacd6atagen2026-09-08 08:24 UTC811
    pub async fn pending_send_ids(
96fdf90aacd6atagen2026-09-08 08:24 UTC812
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC813
        room_id: &RoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC814
    ) -> Result<Vec<OwnedTransactionId>, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC815
        let (echoes, _) = self
31ce2453c82fatagen2026-09-24 13:07 UTC816
            .room(room_id)?
96fdf90aacd6atagen2026-09-08 08:24 UTC817
            .send_queue()
96fdf90aacd6atagen2026-09-08 08:24 UTC818
            .subscribe()
96fdf90aacd6atagen2026-09-08 08:24 UTC819
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC820
            .map_err(|source| {
31ce2453c82fatagen2026-09-24 13:07 UTC821
                Error::with_source(ErrorKind::Store, "reading the send queue failed", source)
31ce2453c82fatagen2026-09-24 13:07 UTC822
            })?;
96fdf90aacd6atagen2026-09-08 08:24 UTC823
        Ok(echoes
96fdf90aacd6atagen2026-09-08 08:24 UTC824
            .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC825
            .filter(|echo| {
96fdf90aacd6atagen2026-09-08 08:24 UTC826
                matches!(
96fdf90aacd6atagen2026-09-08 08:24 UTC827
                    echo.content,
96fdf90aacd6atagen2026-09-08 08:24 UTC828
                    matrix_sdk::send_queue::LocalEchoContent::Event { .. }
96fdf90aacd6atagen2026-09-08 08:24 UTC829
                )
96fdf90aacd6atagen2026-09-08 08:24 UTC830
            })
96fdf90aacd6atagen2026-09-08 08:24 UTC831
            .map(|echo| echo.transaction_id)
96fdf90aacd6atagen2026-09-08 08:24 UTC832
            .collect())
96fdf90aacd6atagen2026-09-08 08:24 UTC833
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC834
96fdf90aacd6atagen2026-09-08 08:24 UTC835
    pub async fn global_account_data(
96fdf90aacd6atagen2026-09-08 08:24 UTC836
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC837
        event_type: GlobalAccountDataEventType,
31ce2453c82fatagen2026-09-24 13:07 UTC838
    ) -> Result<Option<Raw<AnyGlobalAccountDataEventContent>>, Error> {
96fdf90aacd6atagen2026-09-08 08:24 UTC839
        self.client
96fdf90aacd6atagen2026-09-08 08:24 UTC840
            .account()
96fdf90aacd6atagen2026-09-08 08:24 UTC841
            .account_data_raw(event_type)
96fdf90aacd6atagen2026-09-08 08:24 UTC842
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC843
            .map_err(|source| Error::from_sdk("reading account data failed", source))
96fdf90aacd6atagen2026-09-08 08:24 UTC844
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC845
96fdf90aacd6atagen2026-09-08 08:24 UTC846
    pub async fn room_account_data(
96fdf90aacd6atagen2026-09-08 08:24 UTC847
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC848
        room_id: &RoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC849
        event_type: RoomAccountDataEventType,
31ce2453c82fatagen2026-09-24 13:07 UTC850
    ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC851
        self.room(room_id)?
31ce2453c82fatagen2026-09-24 13:07 UTC852
            .account_data(event_type)
96fdf90aacd6atagen2026-09-08 08:24 UTC853
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC854
            .map_err(|source| Error::from_sdk("reading room account data failed", source))
96fdf90aacd6atagen2026-09-08 08:24 UTC855
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC856
96fdf90aacd6atagen2026-09-08 08:24 UTC857
    #[must_use]
96fdf90aacd6atagen2026-09-08 08:24 UTC858
    pub fn connection_state(&self) -> watch::Receiver<ConnectionState> {
96fdf90aacd6atagen2026-09-08 08:24 UTC859
        self.connection.clone()
96fdf90aacd6atagen2026-09-08 08:24 UTC860
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC861
96fdf90aacd6atagen2026-09-08 08:24 UTC862
    #[must_use]
96fdf90aacd6atagen2026-09-08 08:24 UTC863
    pub fn encryption_state(&self) -> Option<EncryptionState> {
96fdf90aacd6atagen2026-09-08 08:24 UTC864
        let device_id = self.client.device_id()?.to_owned();
96fdf90aacd6atagen2026-09-08 08:24 UTC865
        let encryption = self.client.encryption();
96fdf90aacd6atagen2026-09-08 08:24 UTC866
        Some(encryption_state(
96fdf90aacd6atagen2026-09-08 08:24 UTC867
            device_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC868
            encryption.recovery().state(),
96fdf90aacd6atagen2026-09-08 08:24 UTC869
            encryption.verification_state().get(),
96fdf90aacd6atagen2026-09-08 08:24 UTC870
            encryption.backups().state(),
96fdf90aacd6atagen2026-09-08 08:24 UTC871
        ))
96fdf90aacd6atagen2026-09-08 08:24 UTC872
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC873
}
96fdf90aacd6atagen2026-09-08 08:24 UTC874
31ce2453c82fatagen2026-09-24 13:07 UTC875
/// one space's hierarchy, a page at a time. hold on to it while you browse, it remembers where it got to
31ce2453c82fatagen2026-09-24 13:07 UTC876
pub struct SpaceHierarchy(SpaceRoomList);
31ce2453c82fatagen2026-09-24 13:07 UTC877
31ce2453c82fatagen2026-09-24 13:07 UTC878
impl fmt::Debug for SpaceHierarchy {
31ce2453c82fatagen2026-09-24 13:07 UTC879
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
31ce2453c82fatagen2026-09-24 13:07 UTC880
        formatter
31ce2453c82fatagen2026-09-24 13:07 UTC881
            .debug_struct("SpaceHierarchy")
31ce2453c82fatagen2026-09-24 13:07 UTC882
            .finish_non_exhaustive()
31ce2453c82fatagen2026-09-24 13:07 UTC883
    }
31ce2453c82fatagen2026-09-24 13:07 UTC884
}
31ce2453c82fatagen2026-09-24 13:07 UTC885
31ce2453c82fatagen2026-09-24 13:07 UTC886
impl SpaceHierarchy {
31ce2453c82fatagen2026-09-24 13:07 UTC887
    /// fetches the next page. a no-op once the end is reached or while a page is in flight
31ce2453c82fatagen2026-09-24 13:07 UTC888
    pub async fn paginate(&self) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC889
        self.0.paginate().await.map_err(|source| {
31ce2453c82fatagen2026-09-24 13:07 UTC890
            Error::with_source(
31ce2453c82fatagen2026-09-24 13:07 UTC891
                ErrorKind::Server,
31ce2453c82fatagen2026-09-24 13:07 UTC892
                "fetching the space hierarchy failed",
31ce2453c82fatagen2026-09-24 13:07 UTC893
                source,
31ce2453c82fatagen2026-09-24 13:07 UTC894
            )
31ce2453c82fatagen2026-09-24 13:07 UTC895
        })
31ce2453c82fatagen2026-09-24 13:07 UTC896
    }
31ce2453c82fatagen2026-09-24 13:07 UTC897
31ce2453c82fatagen2026-09-24 13:07 UTC898
    /// everything fetched so far, the space itself excluded
31ce2453c82fatagen2026-09-24 13:07 UTC899
    pub async fn rooms(&self) -> Vec<SpaceChild> {
31ce2453c82fatagen2026-09-24 13:07 UTC900
        self.0.rooms().await.into_iter().map(space_child).collect()
31ce2453c82fatagen2026-09-24 13:07 UTC901
    }
31ce2453c82fatagen2026-09-24 13:07 UTC902
31ce2453c82fatagen2026-09-24 13:07 UTC903
    #[must_use]
31ce2453c82fatagen2026-09-24 13:07 UTC904
    pub fn end_reached(&self) -> bool {
31ce2453c82fatagen2026-09-24 13:07 UTC905
        matches!(
31ce2453c82fatagen2026-09-24 13:07 UTC906
            self.0.pagination_state(),
31ce2453c82fatagen2026-09-24 13:07 UTC907
            SpaceRoomListPaginationState::Idle { end_reached: true }
31ce2453c82fatagen2026-09-24 13:07 UTC908
        )
31ce2453c82fatagen2026-09-24 13:07 UTC909
    }
31ce2453c82fatagen2026-09-24 13:07 UTC910
}
31ce2453c82fatagen2026-09-24 13:07 UTC911
31ce2453c82fatagen2026-09-24 13:07 UTC912
fn profile(
31ce2453c82fatagen2026-09-24 13:07 UTC913
    user_id: OwnedUserId,
31ce2453c82fatagen2026-09-24 13:07 UTC914
    response: &ruma::api::client::profile::get_profile::v3::Response,
31ce2453c82fatagen2026-09-24 13:07 UTC915
) -> Result<Profile, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC916
    use ruma::api::client::profile::{AvatarUrl, DisplayName};
31ce2453c82fatagen2026-09-24 13:07 UTC917
    let malformed = |source| {
31ce2453c82fatagen2026-09-24 13:07 UTC918
        Error::with_source(
31ce2453c82fatagen2026-09-24 13:07 UTC919
            ErrorKind::Server,
31ce2453c82fatagen2026-09-24 13:07 UTC920
            "the server sent a malformed profile",
31ce2453c82fatagen2026-09-24 13:07 UTC921
            source,
31ce2453c82fatagen2026-09-24 13:07 UTC922
        )
31ce2453c82fatagen2026-09-24 13:07 UTC923
    };
31ce2453c82fatagen2026-09-24 13:07 UTC924
    Ok(Profile {
31ce2453c82fatagen2026-09-24 13:07 UTC925
        user_id,
31ce2453c82fatagen2026-09-24 13:07 UTC926
        display_name: response.get_static::<DisplayName>().map_err(malformed)?,
5d2974de5826atagen2026-10-08 11:29 UTC927
        avatar: response
5d2974de5826atagen2026-10-08 11:29 UTC928
            .get_static::<AvatarUrl>()
5d2974de5826atagen2026-10-08 11:29 UTC929
            .map_err(malformed)?
5d2974de5826atagen2026-10-08 11:29 UTC930
            .as_deref()
5d2974de5826atagen2026-10-08 11:29 UTC931
            .map(MediaId::plain),
31ce2453c82fatagen2026-09-24 13:07 UTC932
    })
31ce2453c82fatagen2026-09-24 13:07 UTC933
}
31ce2453c82fatagen2026-09-24 13:07 UTC934
31ce2453c82fatagen2026-09-24 13:07 UTC935
#[derive(Debug)]
31ce2453c82fatagen2026-09-24 13:07 UTC936
pub(crate) struct Request {
96fdf90aacd6atagen2026-09-08 08:24 UTC937
    pub(crate) command: Command,
31ce2453c82fatagen2026-09-24 13:07 UTC938
    pub(crate) reply: Responder,
31ce2453c82fatagen2026-09-24 13:07 UTC939
}
31ce2453c82fatagen2026-09-24 13:07 UTC940
31ce2453c82fatagen2026-09-24 13:07 UTC941
impl Request {
31ce2453c82fatagen2026-09-24 13:07 UTC942
    fn new(command: Command) -> (Self, Pending) {
31ce2453c82fatagen2026-09-24 13:07 UTC943
        let (reply, pending) = oneshot::channel();
31ce2453c82fatagen2026-09-24 13:07 UTC944
        (
31ce2453c82fatagen2026-09-24 13:07 UTC945
            Self {
31ce2453c82fatagen2026-09-24 13:07 UTC946
                command,
31ce2453c82fatagen2026-09-24 13:07 UTC947
                reply: Responder(reply),
31ce2453c82fatagen2026-09-24 13:07 UTC948
            },
31ce2453c82fatagen2026-09-24 13:07 UTC949
            Pending(pending),
31ce2453c82fatagen2026-09-24 13:07 UTC950
        )
31ce2453c82fatagen2026-09-24 13:07 UTC951
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC952
}
96fdf90aacd6atagen2026-09-08 08:24 UTC953
31ce2453c82fatagen2026-09-24 13:07 UTC954
/// whoever holds this owes the caller an answer. dropping it answers `Interrupted`
96fdf90aacd6atagen2026-09-08 08:24 UTC955
#[derive(Debug)]
31ce2453c82fatagen2026-09-24 13:07 UTC956
pub(crate) struct Responder(oneshot::Sender<Result<CommandOutput, Error>>);
31ce2453c82fatagen2026-09-24 13:07 UTC957
31ce2453c82fatagen2026-09-24 13:07 UTC958
impl Responder {
31ce2453c82fatagen2026-09-24 13:07 UTC959
    pub(crate) fn send(self, result: Result<CommandOutput, Error>) {
31ce2453c82fatagen2026-09-24 13:07 UTC960
        if let Err(error) = &result {
31ce2453c82fatagen2026-09-24 13:07 UTC961
            tracing::debug!(%error, kind = ?error.kind, "command failed");
31ce2453c82fatagen2026-09-24 13:07 UTC962
        }
31ce2453c82fatagen2026-09-24 13:07 UTC963
        let _ = self.0.send(result);
31ce2453c82fatagen2026-09-24 13:07 UTC964
    }
31ce2453c82fatagen2026-09-24 13:07 UTC965
31ce2453c82fatagen2026-09-24 13:07 UTC966
    pub(crate) fn done(self, result: Result<(), Error>) {
31ce2453c82fatagen2026-09-24 13:07 UTC967
        self.send(result.map(|()| CommandOutput::Done));
31ce2453c82fatagen2026-09-24 13:07 UTC968
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC969
}
96fdf90aacd6atagen2026-09-08 08:24 UTC970
96fdf90aacd6atagen2026-09-08 08:24 UTC971
#[derive(Debug)]
96fdf90aacd6atagen2026-09-08 08:24 UTC972
pub struct EventStream {
96fdf90aacd6atagen2026-09-08 08:24 UTC973
    events: mpsc::Receiver<Event>,
96fdf90aacd6atagen2026-09-08 08:24 UTC974
}
96fdf90aacd6atagen2026-09-08 08:24 UTC975
96fdf90aacd6atagen2026-09-08 08:24 UTC976
impl EventStream {
96fdf90aacd6atagen2026-09-08 08:24 UTC977
    pub async fn recv(&mut self) -> Option<Event> {
96fdf90aacd6atagen2026-09-08 08:24 UTC978
        self.events.recv().await
96fdf90aacd6atagen2026-09-08 08:24 UTC979
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC980
96fdf90aacd6atagen2026-09-08 08:24 UTC981
    pub fn try_recv(&mut self) -> Result<Event, mpsc::error::TryRecvError> {
96fdf90aacd6atagen2026-09-08 08:24 UTC982
        self.events.try_recv()
96fdf90aacd6atagen2026-09-08 08:24 UTC983
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC984
}
96fdf90aacd6atagen2026-09-08 08:24 UTC985
96fdf90aacd6atagen2026-09-08 08:24 UTC986
impl futures_util::Stream for EventStream {
96fdf90aacd6atagen2026-09-08 08:24 UTC987
    type Item = Event;
96fdf90aacd6atagen2026-09-08 08:24 UTC988
96fdf90aacd6atagen2026-09-08 08:24 UTC989
    fn poll_next(mut self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Option<Self::Item>> {
96fdf90aacd6atagen2026-09-08 08:24 UTC990
        self.events.poll_recv(context)
96fdf90aacd6atagen2026-09-08 08:24 UTC991
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC992
}
96fdf90aacd6atagen2026-09-08 08:24 UTC993
96fdf90aacd6atagen2026-09-08 08:24 UTC994
#[derive(Debug)]
96fdf90aacd6atagen2026-09-08 08:24 UTC995
pub(crate) struct DriverPort {
31ce2453c82fatagen2026-09-24 13:07 UTC996
    requests: mpsc::Receiver<Request>,
96fdf90aacd6atagen2026-09-08 08:24 UTC997
    events: mpsc::Sender<Event>,
96fdf90aacd6atagen2026-09-08 08:24 UTC998
    connection: watch::Sender<ConnectionState>,
96fdf90aacd6atagen2026-09-08 08:24 UTC999
}
96fdf90aacd6atagen2026-09-08 08:24 UTC1000
96fdf90aacd6atagen2026-09-08 08:24 UTC1001
#[derive(Clone, Debug)]
96fdf90aacd6atagen2026-09-08 08:24 UTC1002
pub(crate) struct EventSender(mpsc::Sender<Event>);
96fdf90aacd6atagen2026-09-08 08:24 UTC1003
96fdf90aacd6atagen2026-09-08 08:24 UTC1004
impl EventSender {
96fdf90aacd6atagen2026-09-08 08:24 UTC1005
    pub(crate) async fn send(&self, event: Event) -> Result<(), SendEventError> {
31ce2453c82fatagen2026-09-24 13:07 UTC1006
        self.0.send(event).await.map_err(|_| SendEventError)
96fdf90aacd6atagen2026-09-08 08:24 UTC1007
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1008
411bc1c78b65atagen2026-10-22 07:39 UTC1009
    pub(crate) async fn reserve(&self) -> Result<mpsc::Permit<'_, Event>, SendEventError> {
411bc1c78b65atagen2026-10-22 07:39 UTC1010
        self.0.reserve().await.map_err(|_| SendEventError)
411bc1c78b65atagen2026-10-22 07:39 UTC1011
    }
411bc1c78b65atagen2026-10-22 07:39 UTC1012
31ce2453c82fatagen2026-09-24 13:07 UTC1013
    /// resolves once every `EventStream` is gone
96fdf90aacd6atagen2026-09-08 08:24 UTC1014
    pub(crate) async fn closed(&self) {
96fdf90aacd6atagen2026-09-08 08:24 UTC1015
        self.0.closed().await;
96fdf90aacd6atagen2026-09-08 08:24 UTC1016
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1017
}
96fdf90aacd6atagen2026-09-08 08:24 UTC1018
96fdf90aacd6atagen2026-09-08 08:24 UTC1019
impl DriverPort {
96fdf90aacd6atagen2026-09-08 08:24 UTC1020
    pub(crate) fn event_sender(&self) -> EventSender {
96fdf90aacd6atagen2026-09-08 08:24 UTC1021
        EventSender(self.events.clone())
96fdf90aacd6atagen2026-09-08 08:24 UTC1022
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1023
96fdf90aacd6atagen2026-09-08 08:24 UTC1024
    pub(crate) fn connection_sender(&self) -> watch::Sender<ConnectionState> {
96fdf90aacd6atagen2026-09-08 08:24 UTC1025
        self.connection.clone()
96fdf90aacd6atagen2026-09-08 08:24 UTC1026
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1027
31ce2453c82fatagen2026-09-24 13:07 UTC1028
    pub(crate) async fn recv(&mut self) -> Option<Request> {
31ce2453c82fatagen2026-09-24 13:07 UTC1029
        self.requests.recv().await
96fdf90aacd6atagen2026-09-08 08:24 UTC1030
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1031
5a52012c9b1datagen2026-09-24 23:45 UTC1032
    pub(crate) fn try_recv(&mut self) -> Option<Request> {
5a52012c9b1datagen2026-09-24 23:45 UTC1033
        self.requests.try_recv().ok()
5a52012c9b1datagen2026-09-24 23:45 UTC1034
    }
5a52012c9b1datagen2026-09-24 23:45 UTC1035
31ce2453c82fatagen2026-09-24 13:07 UTC1036
    pub(crate) fn close(&mut self) {
31ce2453c82fatagen2026-09-24 13:07 UTC1037
        self.requests.close();
96fdf90aacd6atagen2026-09-08 08:24 UTC1038
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1039
}
96fdf90aacd6atagen2026-09-08 08:24 UTC1040
31ce2453c82fatagen2026-09-24 13:07 UTC1041
#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
31ce2453c82fatagen2026-09-24 13:07 UTC1042
#[error("the event receiver has closed")]
31ce2453c82fatagen2026-09-24 13:07 UTC1043
pub(crate) struct SendEventError;
96fdf90aacd6atagen2026-09-08 08:24 UTC1044
96fdf90aacd6atagen2026-09-08 08:24 UTC1045
#[must_use]
96fdf90aacd6atagen2026-09-08 08:24 UTC1046
pub(crate) fn transport_pair(
96fdf90aacd6atagen2026-09-08 08:24 UTC1047
    client: Client,
96fdf90aacd6atagen2026-09-08 08:24 UTC1048
    sync_service: Arc<SyncService>,
31ce2453c82fatagen2026-09-24 13:07 UTC1049
    media: Arc<MediaService>,
a250c7fa43fbatagen2026-09-26 13:35 UTC1050
    store_lock: Option<Arc<StoreLock>>,
96fdf90aacd6atagen2026-09-08 08:24 UTC1051
    command_capacity: usize,
96fdf90aacd6atagen2026-09-08 08:24 UTC1052
    event_capacity: usize,
96fdf90aacd6atagen2026-09-08 08:24 UTC1053
) -> (ClientHandle, DriverPort, EventStream) {
31ce2453c82fatagen2026-09-24 13:07 UTC1054
    let (request_tx, request_rx) = mpsc::channel(command_capacity);
96fdf90aacd6atagen2026-09-08 08:24 UTC1055
    let (event_tx, event_rx) = mpsc::channel(event_capacity);
96fdf90aacd6atagen2026-09-08 08:24 UTC1056
    let (connection_tx, connection_rx) = watch::channel(ConnectionState::Idle);
96fdf90aacd6atagen2026-09-08 08:24 UTC1057
    (
96fdf90aacd6atagen2026-09-08 08:24 UTC1058
        ClientHandle {
31ce2453c82fatagen2026-09-24 13:07 UTC1059
            requests: request_tx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1060
            client,
96fdf90aacd6atagen2026-09-08 08:24 UTC1061
            connection: connection_rx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1062
            notification_client: Arc::new(OnceCell::new()),
96fdf90aacd6atagen2026-09-08 08:24 UTC1063
            sync_service,
31ce2453c82fatagen2026-09-24 13:07 UTC1064
            media,
31ce2453c82fatagen2026-09-24 13:07 UTC1065
            spaces: Arc::new(OnceCell::new()),
121a56ce119datagen2026-10-24 06:42 UTC1066
            members_checked: Arc::default(),
a250c7fa43fbatagen2026-09-26 13:35 UTC1067
            _store_lock: store_lock,
96fdf90aacd6atagen2026-09-08 08:24 UTC1068
        },
96fdf90aacd6atagen2026-09-08 08:24 UTC1069
        DriverPort {
31ce2453c82fatagen2026-09-24 13:07 UTC1070
            requests: request_rx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1071
            events: event_tx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1072
            connection: connection_tx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1073
        },
96fdf90aacd6atagen2026-09-08 08:24 UTC1074
        EventStream { events: event_rx },
96fdf90aacd6atagen2026-09-08 08:24 UTC1075
    )
96fdf90aacd6atagen2026-09-08 08:24 UTC1076
}
96fdf90aacd6atagen2026-09-08 08:24 UTC1077
121a56ce119datagen2026-10-24 06:42 UTC1078
async fn list_members(
121a56ce119datagen2026-10-24 06:42 UTC1079
    room: &matrix_sdk::Room,
121a56ce119datagen2026-10-24 06:42 UTC1080
    filter: MemberFilter,
121a56ce119datagen2026-10-24 06:42 UTC1081
) -> Result<Vec<MemberSummary>, Error> {
121a56ce119datagen2026-10-24 06:42 UTC1082
    let memberships = match filter {
121a56ce119datagen2026-10-24 06:42 UTC1083
        MemberFilter::Active => RoomMemberships::ACTIVE,
121a56ce119datagen2026-10-24 06:42 UTC1084
        MemberFilter::Joined => RoomMemberships::JOIN,
121a56ce119datagen2026-10-24 06:42 UTC1085
        MemberFilter::Invited => RoomMemberships::INVITE,
121a56ce119datagen2026-10-24 06:42 UTC1086
        MemberFilter::Banned => RoomMemberships::BAN,
121a56ce119datagen2026-10-24 06:42 UTC1087
        MemberFilter::Left => RoomMemberships::LEAVE,
121a56ce119datagen2026-10-24 06:42 UTC1088
        // An empty mask is the SDK's unfiltered wildcard: it matches every
121a56ce119datagen2026-10-24 06:42 UTC1089
        // membership, including custom states that `all()` would exclude.
121a56ce119datagen2026-10-24 06:42 UTC1090
        MemberFilter::All => RoomMemberships::empty(),
121a56ce119datagen2026-10-24 06:42 UTC1091
    };
121a56ce119datagen2026-10-24 06:42 UTC1092
    Ok(room
121a56ce119datagen2026-10-24 06:42 UTC1093
        .members(memberships)
121a56ce119datagen2026-10-24 06:42 UTC1094
        .await
121a56ce119datagen2026-10-24 06:42 UTC1095
        .map_err(|source| Error::from_sdk("listing members failed", source))?
121a56ce119datagen2026-10-24 06:42 UTC1096
        .into_iter()
121a56ce119datagen2026-10-24 06:42 UTC1097
        .map(member_summary)
121a56ce119datagen2026-10-24 06:42 UTC1098
        .collect())
121a56ce119datagen2026-10-24 06:42 UTC1099
}
121a56ce119datagen2026-10-24 06:42 UTC1100
96fdf90aacd6atagen2026-09-08 08:24 UTC1101
fn normalise_push_notification(
96fdf90aacd6atagen2026-09-08 08:24 UTC1102
    room_id: &RoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC1103
    event_id: &EventId,
96fdf90aacd6atagen2026-09-08 08:24 UTC1104
    status: NotificationStatus,
96fdf90aacd6atagen2026-09-08 08:24 UTC1105
) -> PushNotificationStatus {
96fdf90aacd6atagen2026-09-08 08:24 UTC1106
    match status {
96fdf90aacd6atagen2026-09-08 08:24 UTC1107
        NotificationStatus::Event(item) => {
96fdf90aacd6atagen2026-09-08 08:24 UTC1108
            let event = match &item.raw_event {
96fdf90aacd6atagen2026-09-08 08:24 UTC1109
                RawNotificationEvent::Timeline(event) => {
96fdf90aacd6atagen2026-09-08 08:24 UTC1110
                    PushNotificationEvent::Timeline(event.clone())
96fdf90aacd6atagen2026-09-08 08:24 UTC1111
                }
96fdf90aacd6atagen2026-09-08 08:24 UTC1112
                RawNotificationEvent::Invite(event) => PushNotificationEvent::Invite(event.clone()),
96fdf90aacd6atagen2026-09-08 08:24 UTC1113
            };
96fdf90aacd6atagen2026-09-08 08:24 UTC1114
            PushNotificationStatus::Event(Box::new(PushNotification {
96fdf90aacd6atagen2026-09-08 08:24 UTC1115
                event_id: event_id.to_owned(),
96fdf90aacd6atagen2026-09-08 08:24 UTC1116
                event,
96fdf90aacd6atagen2026-09-08 08:24 UTC1117
                sender: PushNotificationSender {
96fdf90aacd6atagen2026-09-08 08:24 UTC1118
                    user_id: item.event.sender().to_owned(),
96fdf90aacd6atagen2026-09-08 08:24 UTC1119
                    display_name: item.sender_display_name,
5d2974de5826atagen2026-10-08 11:29 UTC1120
                    avatar_url: item.sender_avatar_url.as_deref().map(MediaId::plain),
96fdf90aacd6atagen2026-09-08 08:24 UTC1121
                    name_ambiguous: item.is_sender_name_ambiguous,
96fdf90aacd6atagen2026-09-08 08:24 UTC1122
                },
96fdf90aacd6atagen2026-09-08 08:24 UTC1123
                room: PushNotificationRoom {
96fdf90aacd6atagen2026-09-08 08:24 UTC1124
                    room_id: room_id.to_owned(),
96fdf90aacd6atagen2026-09-08 08:24 UTC1125
                    name: item.room_computed_display_name,
5d2974de5826atagen2026-10-08 11:29 UTC1126
                    avatar_url: item.room_avatar_url.as_deref().map(MediaId::plain),
96fdf90aacd6atagen2026-09-08 08:24 UTC1127
                    canonical_alias: item
96fdf90aacd6atagen2026-09-08 08:24 UTC1128
                        .room_canonical_alias
96fdf90aacd6atagen2026-09-08 08:24 UTC1129
                        .as_deref()
96fdf90aacd6atagen2026-09-08 08:24 UTC1130
                        .and_then(|alias| alias.parse().ok()),
96fdf90aacd6atagen2026-09-08 08:24 UTC1131
                    topic: item.room_topic,
96fdf90aacd6atagen2026-09-08 08:24 UTC1132
                    encrypted: item.is_room_encrypted,
96fdf90aacd6atagen2026-09-08 08:24 UTC1133
                    direct: item.room_is_dm,
96fdf90aacd6atagen2026-09-08 08:24 UTC1134
                    joined_members_count: item.joined_members_count,
96fdf90aacd6atagen2026-09-08 08:24 UTC1135
                    service_members: item
96fdf90aacd6atagen2026-09-08 08:24 UTC1136
                        .service_members
96fdf90aacd6atagen2026-09-08 08:24 UTC1137
                        .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC1138
                        .filter_map(|user_id| user_id.parse().ok())
96fdf90aacd6atagen2026-09-08 08:24 UTC1139
                        .collect(),
96fdf90aacd6atagen2026-09-08 08:24 UTC1140
                    active_service_members_count: item.active_service_members_count,
96fdf90aacd6atagen2026-09-08 08:24 UTC1141
                    space: item.is_space,
96fdf90aacd6atagen2026-09-08 08:24 UTC1142
                },
96fdf90aacd6atagen2026-09-08 08:24 UTC1143
                noisy: item.is_noisy,
96fdf90aacd6atagen2026-09-08 08:24 UTC1144
                has_mention: item.has_mention,
96fdf90aacd6atagen2026-09-08 08:24 UTC1145
                thread_id: item.thread_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC1146
            }))
96fdf90aacd6atagen2026-09-08 08:24 UTC1147
        }
96fdf90aacd6atagen2026-09-08 08:24 UTC1148
        NotificationStatus::EventNotFound => PushNotificationStatus::NotFound,
96fdf90aacd6atagen2026-09-08 08:24 UTC1149
        NotificationStatus::EventFilteredOut => PushNotificationStatus::FilteredOut,
96fdf90aacd6atagen2026-09-08 08:24 UTC1150
        NotificationStatus::EventRedacted => PushNotificationStatus::Redacted,
96fdf90aacd6atagen2026-09-08 08:24 UTC1151
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1152
}