atagen

macltok

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

Blame: src/transport.rs

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