atagen

macltok

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