atagen

macltok

public
Star0
Watch0
17e042fbc3316ffae2dc316cadbc20c8ce863a9d
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>,
31ce2453c82fatagen2026-09-24 13:07 UTC344
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC345
        self.run(Command::Timeline(TimelineCommand::ToggleReaction {
31ce2453c82fatagen2026-09-24 13:07 UTC346
            timeline_id,
960ac0721079atagen2026-09-25 00:24 UTC347
            target: target.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC348
            key: key.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC349
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC350
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC351
    }
31ce2453c82fatagen2026-09-24 13:07 UTC352
31ce2453c82fatagen2026-09-24 13:07 UTC353
    pub async fn mark_read(
31ce2453c82fatagen2026-09-24 13:07 UTC354
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC355
        timeline_id: TimelineId,
31ce2453c82fatagen2026-09-24 13:07 UTC356
        event_id: OwnedEventId,
31ce2453c82fatagen2026-09-24 13:07 UTC357
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC358
        self.run(Command::Timeline(TimelineCommand::MarkRead {
31ce2453c82fatagen2026-09-24 13:07 UTC359
            timeline_id,
31ce2453c82fatagen2026-09-24 13:07 UTC360
            event_id,
31ce2453c82fatagen2026-09-24 13:07 UTC361
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC362
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC363
    }
31ce2453c82fatagen2026-09-24 13:07 UTC364
31ce2453c82fatagen2026-09-24 13:07 UTC365
    pub async fn set_typing(&self, room_id: OwnedRoomId, typing: bool) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC366
        self.run(Command::Room(RoomCommand::SetTyping { room_id, typing }))
96fdf90aacd6atagen2026-09-08 08:24 UTC367
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC368
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC369
38c4caecdb3datagen2026-09-26 13:35 UTC370
    pub async fn prepare_to_send(&self, room_id: OwnedRoomId) -> Result<(), Error> {
38c4caecdb3datagen2026-09-26 13:35 UTC371
        self.run(Command::Room(RoomCommand::PrepareToSend(room_id)))
38c4caecdb3datagen2026-09-26 13:35 UTC372
            .await
38c4caecdb3datagen2026-09-26 13:35 UTC373
    }
38c4caecdb3datagen2026-09-26 13:35 UTC374
31ce2453c82fatagen2026-09-24 13:07 UTC375
    pub async fn join_room(
96fdf90aacd6atagen2026-09-08 08:24 UTC376
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC377
        room: OwnedRoomOrAliasId,
31ce2453c82fatagen2026-09-24 13:07 UTC378
        via: Vec<OwnedServerName>,
31ce2453c82fatagen2026-09-24 13:07 UTC379
    ) -> Result<OwnedRoomId, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC380
        self.run_for_room(RoomCommand::Join { room, via }).await
31ce2453c82fatagen2026-09-24 13:07 UTC381
    }
31ce2453c82fatagen2026-09-24 13:07 UTC382
31ce2453c82fatagen2026-09-24 13:07 UTC383
    pub async fn leave_room(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC384
        self.run(Command::Room(RoomCommand::Leave(room_id))).await
31ce2453c82fatagen2026-09-24 13:07 UTC385
    }
31ce2453c82fatagen2026-09-24 13:07 UTC386
31ce2453c82fatagen2026-09-24 13:07 UTC387
    pub async fn forget_room(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC388
        self.run(Command::Room(RoomCommand::Forget(room_id))).await
31ce2453c82fatagen2026-09-24 13:07 UTC389
    }
31ce2453c82fatagen2026-09-24 13:07 UTC390
31ce2453c82fatagen2026-09-24 13:07 UTC391
    pub async fn accept_invite(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC392
        self.run(Command::Room(RoomCommand::AcceptInvite(room_id)))
31ce2453c82fatagen2026-09-24 13:07 UTC393
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC394
    }
31ce2453c82fatagen2026-09-24 13:07 UTC395
31ce2453c82fatagen2026-09-24 13:07 UTC396
    pub async fn reject_invite(&self, room_id: OwnedRoomId) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC397
        self.run(Command::Room(RoomCommand::RejectInvite(room_id)))
96fdf90aacd6atagen2026-09-08 08:24 UTC398
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC399
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC400
96fdf90aacd6atagen2026-09-08 08:24 UTC401
    pub async fn invite_user(
96fdf90aacd6atagen2026-09-08 08:24 UTC402
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC403
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC404
        user_id: OwnedUserId,
31ce2453c82fatagen2026-09-24 13:07 UTC405
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC406
        self.run(Command::Room(RoomCommand::InviteUser { room_id, user_id }))
31ce2453c82fatagen2026-09-24 13:07 UTC407
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC408
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC409
96fdf90aacd6atagen2026-09-08 08:24 UTC410
    pub async fn kick_user(
96fdf90aacd6atagen2026-09-08 08:24 UTC411
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC412
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC413
        user_id: OwnedUserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC414
        reason: Option<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC415
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC416
        self.run(Command::Room(RoomCommand::KickUser {
96fdf90aacd6atagen2026-09-08 08:24 UTC417
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC418
            user_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC419
            reason,
96fdf90aacd6atagen2026-09-08 08:24 UTC420
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC421
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC422
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC423
96fdf90aacd6atagen2026-09-08 08:24 UTC424
    pub async fn ban_user(
96fdf90aacd6atagen2026-09-08 08:24 UTC425
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC426
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC427
        user_id: OwnedUserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC428
        reason: Option<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC429
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC430
        self.run(Command::Room(RoomCommand::BanUser {
96fdf90aacd6atagen2026-09-08 08:24 UTC431
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC432
            user_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC433
            reason,
96fdf90aacd6atagen2026-09-08 08:24 UTC434
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC435
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC436
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC437
96fdf90aacd6atagen2026-09-08 08:24 UTC438
    pub async fn unban_user(
96fdf90aacd6atagen2026-09-08 08:24 UTC439
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC440
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC441
        user_id: OwnedUserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC442
        reason: Option<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC443
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC444
        self.run(Command::Room(RoomCommand::UnbanUser {
96fdf90aacd6atagen2026-09-08 08:24 UTC445
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC446
            user_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC447
            reason,
96fdf90aacd6atagen2026-09-08 08:24 UTC448
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC449
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC450
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC451
96fdf90aacd6atagen2026-09-08 08:24 UTC452
    pub async fn set_power_levels(
96fdf90aacd6atagen2026-09-08 08:24 UTC453
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC454
        room_id: OwnedRoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC455
        changes: PowerLevelChanges,
31ce2453c82fatagen2026-09-24 13:07 UTC456
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC457
        self.run(Command::Room(RoomCommand::SetPowerLevels {
96fdf90aacd6atagen2026-09-08 08:24 UTC458
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC459
            changes,
96fdf90aacd6atagen2026-09-08 08:24 UTC460
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC461
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC462
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC463
96fdf90aacd6atagen2026-09-08 08:24 UTC464
    pub async fn set_user_power_level(
96fdf90aacd6atagen2026-09-08 08:24 UTC465
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC466
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC467
        user_id: OwnedUserId,
96fdf90aacd6atagen2026-09-08 08:24 UTC468
        level: i64,
31ce2453c82fatagen2026-09-24 13:07 UTC469
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC470
        self.run(Command::Room(RoomCommand::SetUserPowerLevel {
96fdf90aacd6atagen2026-09-08 08:24 UTC471
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC472
            user_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC473
            level,
96fdf90aacd6atagen2026-09-08 08:24 UTC474
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC475
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC476
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC477
31ce2453c82fatagen2026-09-24 13:07 UTC478
    pub async fn create_room(&self, options: CreateRoomOptions) -> Result<OwnedRoomId, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC479
        self.run_for_room(RoomCommand::Create(options)).await
96fdf90aacd6atagen2026-09-08 08:24 UTC480
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC481
31ce2453c82fatagen2026-09-24 13:07 UTC482
    /// hands back the existing dm with them if there is one
31ce2453c82fatagen2026-09-24 13:07 UTC483
    pub async fn create_direct(&self, user_id: OwnedUserId) -> Result<OwnedRoomId, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC484
        self.run_for_room(RoomCommand::CreateDirect(user_id)).await
96fdf90aacd6atagen2026-09-08 08:24 UTC485
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC486
96fdf90aacd6atagen2026-09-08 08:24 UTC487
    pub async fn cancel_send(
96fdf90aacd6atagen2026-09-08 08:24 UTC488
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC489
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC490
        transaction_id: OwnedTransactionId,
31ce2453c82fatagen2026-09-24 13:07 UTC491
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC492
        self.run(Command::Room(RoomCommand::CancelSend {
96fdf90aacd6atagen2026-09-08 08:24 UTC493
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC494
            transaction_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC495
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC496
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC497
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC498
96fdf90aacd6atagen2026-09-08 08:24 UTC499
    pub async fn retry_send(
96fdf90aacd6atagen2026-09-08 08:24 UTC500
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC501
        room_id: OwnedRoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC502
        transaction_id: OwnedTransactionId,
31ce2453c82fatagen2026-09-24 13:07 UTC503
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC504
        self.run(Command::Room(RoomCommand::RetrySend {
96fdf90aacd6atagen2026-09-08 08:24 UTC505
            room_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC506
            transaction_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC507
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC508
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC509
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC510
31ce2453c82fatagen2026-09-24 13:07 UTC511
    pub async fn upload(&self, upload: AttachmentUpload) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC512
        self.run(Command::Media(MediaCommand::Upload(upload))).await
96fdf90aacd6atagen2026-09-08 08:24 UTC513
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC514
31ce2453c82fatagen2026-09-24 13:07 UTC515
    pub async fn recover(&self, recovery_key: impl Into<String>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC516
        self.run(Command::Encryption(EncryptionCommand::Recover(
31ce2453c82fatagen2026-09-24 13:07 UTC517
            recovery_key.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC518
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC519
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC520
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC521
31ce2453c82fatagen2026-09-24 13:07 UTC522
    pub async fn create_key_backup(&self) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC523
        self.run(Command::Encryption(EncryptionCommand::CreateKeyBackup))
31ce2453c82fatagen2026-09-24 13:07 UTC524
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC525
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC526
31ce2453c82fatagen2026-09-24 13:07 UTC527
    pub async fn enable_key_backup(&self) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC528
        self.run(Command::Encryption(EncryptionCommand::EnableKeyBackup))
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 disable_key_backup(&self, delete_from_server: bool) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC533
        self.run(Command::Encryption(EncryptionCommand::DisableKeyBackup {
31ce2453c82fatagen2026-09-24 13:07 UTC534
            delete_from_server,
31ce2453c82fatagen2026-09-24 13:07 UTC535
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC536
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC537
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC538
31ce2453c82fatagen2026-09-24 13:07 UTC539
    pub async fn recover_key_backup(&self, recovery_key: impl Into<String>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC540
        self.run(Command::Encryption(EncryptionCommand::RecoverKeyBackup(
31ce2453c82fatagen2026-09-24 13:07 UTC541
            recovery_key.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC542
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC543
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC544
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC545
31ce2453c82fatagen2026-09-24 13:07 UTC546
    pub async fn start_verification(&self, target: VerificationTarget) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC547
        self.run(Command::Encryption(EncryptionCommand::StartVerification(
31ce2453c82fatagen2026-09-24 13:07 UTC548
            target,
31ce2453c82fatagen2026-09-24 13:07 UTC549
        )))
96fdf90aacd6atagen2026-09-08 08:24 UTC550
        .await
96fdf90aacd6atagen2026-09-08 08:24 UTC551
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC552
31ce2453c82fatagen2026-09-24 13:07 UTC553
    pub async fn verify(&self, action: VerificationAction) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC554
        self.run(Command::Encryption(EncryptionCommand::Verify(action)))
31ce2453c82fatagen2026-09-24 13:07 UTC555
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC556
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC557
5d2974de5826atagen2026-10-08 11:29 UTC558
    /// bytes for an avatar, or for media a retained timeline showed you. concurrent asks share
5d2974de5826atagen2026-10-08 11:29 UTC559
    /// one download
31ce2453c82fatagen2026-09-24 13:07 UTC560
    pub async fn media(&self, media_id: &MediaId, size: MediaSize) -> Result<Media, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC561
        self.media.timeline_media(media_id, size).await
31ce2453c82fatagen2026-09-24 13:07 UTC562
    }
31ce2453c82fatagen2026-09-24 13:07 UTC563
5b21b919d1e6atagen2026-09-27 11:47 UTC564
    /// where `media` would fetch from, for a host streaming big files itself. the byte cap
5b21b919d1e6atagen2026-09-27 11:47 UTC565
    /// doesn't apply since nothing is buffered
5b21b919d1e6atagen2026-09-27 11:47 UTC566
    pub async fn media_source(
5b21b919d1e6atagen2026-09-27 11:47 UTC567
        &self,
5b21b919d1e6atagen2026-09-27 11:47 UTC568
        media_id: &MediaId,
5b21b919d1e6atagen2026-09-27 11:47 UTC569
        size: MediaSize,
5b21b919d1e6atagen2026-09-27 11:47 UTC570
    ) -> Result<MediaLocation, Error> {
5b21b919d1e6atagen2026-09-27 11:47 UTC571
        self.media.media_location(media_id, size).await
5b21b919d1e6atagen2026-09-27 11:47 UTC572
    }
5b21b919d1e6atagen2026-09-27 11:47 UTC573
31ce2453c82fatagen2026-09-24 13:07 UTC574
    /// the space graph builds on first use and then keeps itself current
31ce2453c82fatagen2026-09-24 13:07 UTC575
    async fn spaces(&self) -> &SpaceService {
31ce2453c82fatagen2026-09-24 13:07 UTC576
        self.spaces
31ce2453c82fatagen2026-09-24 13:07 UTC577
            .get_or_init(|| SpaceService::new(self.client.clone()))
31ce2453c82fatagen2026-09-24 13:07 UTC578
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC579
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC580
96fdf90aacd6atagen2026-09-08 08:24 UTC581
    pub async fn rooms(&self) -> Vec<RoomSummary> {
31ce2453c82fatagen2026-09-24 13:07 UTC582
        room_summaries(&self.client, self.spaces().await).await
96fdf90aacd6atagen2026-09-08 08:24 UTC583
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC584
17e042fbc331atagen2026-10-08 12:39 UTC585
    pub async fn image_packs(&self) -> Result<ImagePacks, Error> {
17e042fbc331atagen2026-10-08 12:39 UTC586
        image_packs(&self.client).await
17e042fbc331atagen2026-10-08 12:39 UTC587
    }
17e042fbc331atagen2026-10-08 12:39 UTC588
31ce2453c82fatagen2026-09-24 13:07 UTC589
    /// browse a space the way the server sees it, rooms you haven't joined included
31ce2453c82fatagen2026-09-24 13:07 UTC590
    pub async fn space_hierarchy(&self, space_id: OwnedRoomId) -> SpaceHierarchy {
31ce2453c82fatagen2026-09-24 13:07 UTC591
        SpaceHierarchy(SpaceRoomList::new(self.client.clone(), space_id).await)
31ce2453c82fatagen2026-09-24 13:07 UTC592
    }
31ce2453c82fatagen2026-09-24 13:07 UTC593
31ce2453c82fatagen2026-09-24 13:07 UTC594
    pub async fn own_profile(&self) -> Result<Profile, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC595
        let user_id = self
31ce2453c82fatagen2026-09-24 13:07 UTC596
            .client
31ce2453c82fatagen2026-09-24 13:07 UTC597
            .user_id()
31ce2453c82fatagen2026-09-24 13:07 UTC598
            .ok_or_else(|| Error::new(ErrorKind::Unauthenticated, "the client is not logged in"))?
31ce2453c82fatagen2026-09-24 13:07 UTC599
            .to_owned();
31ce2453c82fatagen2026-09-24 13:07 UTC600
        let response = self
31ce2453c82fatagen2026-09-24 13:07 UTC601
            .client
31ce2453c82fatagen2026-09-24 13:07 UTC602
            .account()
31ce2453c82fatagen2026-09-24 13:07 UTC603
            .fetch_user_profile()
31ce2453c82fatagen2026-09-24 13:07 UTC604
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC605
            .map_err(|source| Error::from_sdk("fetching the profile failed", source))?;
31ce2453c82fatagen2026-09-24 13:07 UTC606
        profile(user_id, &response)
31ce2453c82fatagen2026-09-24 13:07 UTC607
    }
31ce2453c82fatagen2026-09-24 13:07 UTC608
31ce2453c82fatagen2026-09-24 13:07 UTC609
    pub async fn user_profile(&self, user_id: &UserId) -> Result<Profile, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC610
        let response = self
31ce2453c82fatagen2026-09-24 13:07 UTC611
            .client
31ce2453c82fatagen2026-09-24 13:07 UTC612
            .account()
31ce2453c82fatagen2026-09-24 13:07 UTC613
            .fetch_user_profile_of(user_id)
31ce2453c82fatagen2026-09-24 13:07 UTC614
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC615
            .map_err(|source| Error::from_sdk("fetching the profile failed", source))?;
31ce2453c82fatagen2026-09-24 13:07 UTC616
        profile(user_id.to_owned(), &response)
31ce2453c82fatagen2026-09-24 13:07 UTC617
    }
31ce2453c82fatagen2026-09-24 13:07 UTC618
31ce2453c82fatagen2026-09-24 13:07 UTC619
    pub async fn set_display_name(&self, name: Option<String>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC620
        self.run(Command::Account(AccountCommand::SetDisplayName(name)))
31ce2453c82fatagen2026-09-24 13:07 UTC621
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC622
    }
31ce2453c82fatagen2026-09-24 13:07 UTC623
31ce2453c82fatagen2026-09-24 13:07 UTC624
    pub async fn set_avatar(&self, avatar: Option<OwnedMxcUri>) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC625
        self.run(Command::Account(AccountCommand::SetAvatar(avatar)))
31ce2453c82fatagen2026-09-24 13:07 UTC626
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC627
    }
31ce2453c82fatagen2026-09-24 13:07 UTC628
31ce2453c82fatagen2026-09-24 13:07 UTC629
    pub async fn upload_avatar(
31ce2453c82fatagen2026-09-24 13:07 UTC630
        &self,
31ce2453c82fatagen2026-09-24 13:07 UTC631
        mimetype: impl Into<String>,
31ce2453c82fatagen2026-09-24 13:07 UTC632
        bytes: Vec<u8>,
31ce2453c82fatagen2026-09-24 13:07 UTC633
    ) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC634
        self.run(Command::Account(AccountCommand::UploadAvatar {
31ce2453c82fatagen2026-09-24 13:07 UTC635
            mimetype: mimetype.into(),
31ce2453c82fatagen2026-09-24 13:07 UTC636
            bytes,
31ce2453c82fatagen2026-09-24 13:07 UTC637
        }))
31ce2453c82fatagen2026-09-24 13:07 UTC638
        .await
31ce2453c82fatagen2026-09-24 13:07 UTC639
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC640
31ce2453c82fatagen2026-09-24 13:07 UTC641
    pub async fn rooms_filtered(&self, filter: &RoomListFilter) -> Vec<RoomSummary> {
31ce2453c82fatagen2026-09-24 13:07 UTC642
        let matcher = filter.matcher();
96fdf90aacd6atagen2026-09-08 08:24 UTC643
        self.rooms()
96fdf90aacd6atagen2026-09-08 08:24 UTC644
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC645
            .into_iter()
31ce2453c82fatagen2026-09-24 13:07 UTC646
            .filter(|room| matcher.matches(room))
96fdf90aacd6atagen2026-09-08 08:24 UTC647
            .collect()
96fdf90aacd6atagen2026-09-08 08:24 UTC648
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC649
31ce2453c82fatagen2026-09-24 13:07 UTC650
    pub async fn devices(&self) -> Result<Vec<OwnDevice>, Error> {
96fdf90aacd6atagen2026-09-08 08:24 UTC651
        let current_device_id = self.client.device_id();
96fdf90aacd6atagen2026-09-08 08:24 UTC652
        Ok(self
96fdf90aacd6atagen2026-09-08 08:24 UTC653
            .client
96fdf90aacd6atagen2026-09-08 08:24 UTC654
            .devices()
96fdf90aacd6atagen2026-09-08 08:24 UTC655
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC656
            .map_err(|source| Error::from_http("listing devices failed", source))?
96fdf90aacd6atagen2026-09-08 08:24 UTC657
            .devices
96fdf90aacd6atagen2026-09-08 08:24 UTC658
            .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC659
            .map(|device| OwnDevice {
96fdf90aacd6atagen2026-09-08 08:24 UTC660
                current: current_device_id == Some(device.device_id.as_ref()),
96fdf90aacd6atagen2026-09-08 08:24 UTC661
                device_id: device.device_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC662
                display_name: device.display_name,
96fdf90aacd6atagen2026-09-08 08:24 UTC663
                last_seen_ip: device.last_seen_ip,
96fdf90aacd6atagen2026-09-08 08:24 UTC664
                last_seen_timestamp_ms: device.last_seen_ts.map(|timestamp| timestamp.get().into()),
96fdf90aacd6atagen2026-09-08 08:24 UTC665
            })
96fdf90aacd6atagen2026-09-08 08:24 UTC666
            .collect())
96fdf90aacd6atagen2026-09-08 08:24 UTC667
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC668
31ce2453c82fatagen2026-09-24 13:07 UTC669
    fn room(&self, room_id: &RoomId) -> Result<matrix_sdk::Room, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC670
        self.client
31ce2453c82fatagen2026-09-24 13:07 UTC671
            .get_room(room_id)
31ce2453c82fatagen2026-09-24 13:07 UTC672
            .ok_or_else(Error::room_unknown)
31ce2453c82fatagen2026-09-24 13:07 UTC673
    }
31ce2453c82fatagen2026-09-24 13:07 UTC674
96fdf90aacd6atagen2026-09-08 08:24 UTC675
    pub async fn room_notification_settings(
96fdf90aacd6atagen2026-09-08 08:24 UTC676
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC677
        room_id: &RoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC678
    ) -> Result<Option<RoomNotificationSettings>, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC679
        let room = self.room(room_id)?;
96fdf90aacd6atagen2026-09-08 08:24 UTC680
        let custom = room.user_defined_notification_mode().await;
96fdf90aacd6atagen2026-09-08 08:24 UTC681
        let mode = match custom {
96fdf90aacd6atagen2026-09-08 08:24 UTC682
            Some(mode) => mode,
96fdf90aacd6atagen2026-09-08 08:24 UTC683
            None => match room.notification_mode().await {
96fdf90aacd6atagen2026-09-08 08:24 UTC684
                Some(mode) => mode,
96fdf90aacd6atagen2026-09-08 08:24 UTC685
                None => return Ok(None),
96fdf90aacd6atagen2026-09-08 08:24 UTC686
            },
96fdf90aacd6atagen2026-09-08 08:24 UTC687
        };
96fdf90aacd6atagen2026-09-08 08:24 UTC688
        Ok(Some(RoomNotificationSettings {
96fdf90aacd6atagen2026-09-08 08:24 UTC689
            mode: crate::normalise::notification_mode(mode),
96fdf90aacd6atagen2026-09-08 08:24 UTC690
            custom: custom.is_some(),
96fdf90aacd6atagen2026-09-08 08:24 UTC691
        }))
96fdf90aacd6atagen2026-09-08 08:24 UTC692
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC693
96fdf90aacd6atagen2026-09-08 08:24 UTC694
    pub async fn notification_keywords(&self) -> Vec<String> {
96fdf90aacd6atagen2026-09-08 08:24 UTC695
        self.client
96fdf90aacd6atagen2026-09-08 08:24 UTC696
            .notification_settings()
96fdf90aacd6atagen2026-09-08 08:24 UTC697
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC698
            .enabled_keywords()
96fdf90aacd6atagen2026-09-08 08:24 UTC699
            .await
96fdf90aacd6atagen2026-09-08 08:24 UTC700
            .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC701
            .collect()
96fdf90aacd6atagen2026-09-08 08:24 UTC702
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC703
96fdf90aacd6atagen2026-09-08 08:24 UTC704
    pub async fn resolve_push_notification(
96fdf90aacd6atagen2026-09-08 08:24 UTC705
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC706
        room_id: &RoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC707
        event_id: &EventId,
31ce2453c82fatagen2026-09-24 13:07 UTC708
    ) -> Result<PushNotificationStatus, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC709
        let notification_failed = |source| {
31ce2453c82fatagen2026-09-24 13:07 UTC710
            Error::with_source(
31ce2453c82fatagen2026-09-24 13:07 UTC711
                ErrorKind::Other,
31ce2453c82fatagen2026-09-24 13:07 UTC712
                "resolving the push notification failed",
31ce2453c82fatagen2026-09-24 13:07 UTC713
                source,
31ce2453c82fatagen2026-09-24 13:07 UTC714
            )
31ce2453c82fatagen2026-09-24 13:07 UTC715
        };
96fdf90aacd6atagen2026-09-08 08:24 UTC716
        let client = self
96fdf90aacd6atagen2026-09-08 08:24 UTC717
            .notification_client
96fdf90aacd6atagen2026-09-08 08:24 UTC718
            .get_or_try_init(|| async {
96fdf90aacd6atagen2026-09-08 08:24 UTC719
                NotificationClient::new(
96fdf90aacd6atagen2026-09-08 08:24 UTC720
                    self.client.clone(),
96fdf90aacd6atagen2026-09-08 08:24 UTC721
                    NotificationProcessSetup::SingleProcess {
96fdf90aacd6atagen2026-09-08 08:24 UTC722
                        sync_service: self.sync_service.clone(),
96fdf90aacd6atagen2026-09-08 08:24 UTC723
                    },
96fdf90aacd6atagen2026-09-08 08:24 UTC724
                )
96fdf90aacd6atagen2026-09-08 08:24 UTC725
                .await
96fdf90aacd6atagen2026-09-08 08:24 UTC726
            })
96fdf90aacd6atagen2026-09-08 08:24 UTC727
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC728
            .map_err(notification_failed)?;
96fdf90aacd6atagen2026-09-08 08:24 UTC729
        let status = client
96fdf90aacd6atagen2026-09-08 08:24 UTC730
            .get_notification(room_id, event_id)
96fdf90aacd6atagen2026-09-08 08:24 UTC731
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC732
            .map_err(notification_failed)?;
96fdf90aacd6atagen2026-09-08 08:24 UTC733
        Ok(normalise_push_notification(room_id, event_id, status))
96fdf90aacd6atagen2026-09-08 08:24 UTC734
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC735
96fdf90aacd6atagen2026-09-08 08:24 UTC736
    pub async fn members(
96fdf90aacd6atagen2026-09-08 08:24 UTC737
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC738
        room_id: &RoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC739
        filter: MemberFilter,
31ce2453c82fatagen2026-09-24 13:07 UTC740
    ) -> Result<Vec<MemberSummary>, Error> {
96fdf90aacd6atagen2026-09-08 08:24 UTC741
        let memberships = match filter {
96fdf90aacd6atagen2026-09-08 08:24 UTC742
            MemberFilter::Active => RoomMemberships::ACTIVE,
96fdf90aacd6atagen2026-09-08 08:24 UTC743
            MemberFilter::Joined => RoomMemberships::JOIN,
96fdf90aacd6atagen2026-09-08 08:24 UTC744
            MemberFilter::Invited => RoomMemberships::INVITE,
5a52012c9b1datagen2026-09-24 23:45 UTC745
            MemberFilter::Banned => RoomMemberships::BAN,
5a52012c9b1datagen2026-09-24 23:45 UTC746
            MemberFilter::Left => RoomMemberships::LEAVE,
96fdf90aacd6atagen2026-09-08 08:24 UTC747
            // An empty mask is the SDK's unfiltered wildcard: it matches every
96fdf90aacd6atagen2026-09-08 08:24 UTC748
            // membership, including custom states that `all()` would exclude.
96fdf90aacd6atagen2026-09-08 08:24 UTC749
            MemberFilter::All => RoomMemberships::empty(),
96fdf90aacd6atagen2026-09-08 08:24 UTC750
        };
31ce2453c82fatagen2026-09-24 13:07 UTC751
        Ok(self
31ce2453c82fatagen2026-09-24 13:07 UTC752
            .room(room_id)?
96fdf90aacd6atagen2026-09-08 08:24 UTC753
            .members(memberships)
96fdf90aacd6atagen2026-09-08 08:24 UTC754
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC755
            .map_err(|source| Error::from_sdk("listing members failed", source))?
96fdf90aacd6atagen2026-09-08 08:24 UTC756
            .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC757
            .map(member_summary)
96fdf90aacd6atagen2026-09-08 08:24 UTC758
            .collect())
96fdf90aacd6atagen2026-09-08 08:24 UTC759
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC760
31ce2453c82fatagen2026-09-24 13:07 UTC761
    pub async fn room_power_levels(&self, room_id: &RoomId) -> Result<RoomPowerLevels, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC762
        let levels = self
31ce2453c82fatagen2026-09-24 13:07 UTC763
            .room(room_id)?
96fdf90aacd6atagen2026-09-08 08:24 UTC764
            .power_levels()
96fdf90aacd6atagen2026-09-08 08:24 UTC765
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC766
            .map_err(|source| Error::from_sdk("reading power levels failed", source.into()))?;
96fdf90aacd6atagen2026-09-08 08:24 UTC767
        Ok(RoomPowerLevels {
96fdf90aacd6atagen2026-09-08 08:24 UTC768
            ban: levels.ban.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC769
            invite: levels.invite.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC770
            kick: levels.kick.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC771
            redact: levels.redact.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC772
            events_default: levels.events_default.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC773
            state_default: levels.state_default.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC774
            users_default: levels.users_default.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC775
            room_notification: levels.notifications.room.into(),
96fdf90aacd6atagen2026-09-08 08:24 UTC776
            users: levels
96fdf90aacd6atagen2026-09-08 08:24 UTC777
                .users
96fdf90aacd6atagen2026-09-08 08:24 UTC778
                .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC779
                .map(|(user_id, level)| (user_id, level.into()))
96fdf90aacd6atagen2026-09-08 08:24 UTC780
                .collect(),
96fdf90aacd6atagen2026-09-08 08:24 UTC781
            events: levels
96fdf90aacd6atagen2026-09-08 08:24 UTC782
                .events
96fdf90aacd6atagen2026-09-08 08:24 UTC783
                .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC784
                .map(|(event_type, level)| (event_type.to_string(), level.into()))
96fdf90aacd6atagen2026-09-08 08:24 UTC785
                .collect(),
5a52012c9b1datagen2026-09-24 23:45 UTC786
            creators: levels
5a52012c9b1datagen2026-09-24 23:45 UTC787
                .rules
5a52012c9b1datagen2026-09-24 23:45 UTC788
                .privileged_creators
5a52012c9b1datagen2026-09-24 23:45 UTC789
                .into_iter()
5a52012c9b1datagen2026-09-24 23:45 UTC790
                .flatten()
5a52012c9b1datagen2026-09-24 23:45 UTC791
                .collect(),
96fdf90aacd6atagen2026-09-08 08:24 UTC792
        })
96fdf90aacd6atagen2026-09-08 08:24 UTC793
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC794
96fdf90aacd6atagen2026-09-08 08:24 UTC795
    pub async fn pending_send_ids(
96fdf90aacd6atagen2026-09-08 08:24 UTC796
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC797
        room_id: &RoomId,
31ce2453c82fatagen2026-09-24 13:07 UTC798
    ) -> Result<Vec<OwnedTransactionId>, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC799
        let (echoes, _) = self
31ce2453c82fatagen2026-09-24 13:07 UTC800
            .room(room_id)?
96fdf90aacd6atagen2026-09-08 08:24 UTC801
            .send_queue()
96fdf90aacd6atagen2026-09-08 08:24 UTC802
            .subscribe()
96fdf90aacd6atagen2026-09-08 08:24 UTC803
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC804
            .map_err(|source| {
31ce2453c82fatagen2026-09-24 13:07 UTC805
                Error::with_source(ErrorKind::Store, "reading the send queue failed", source)
31ce2453c82fatagen2026-09-24 13:07 UTC806
            })?;
96fdf90aacd6atagen2026-09-08 08:24 UTC807
        Ok(echoes
96fdf90aacd6atagen2026-09-08 08:24 UTC808
            .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC809
            .filter(|echo| {
96fdf90aacd6atagen2026-09-08 08:24 UTC810
                matches!(
96fdf90aacd6atagen2026-09-08 08:24 UTC811
                    echo.content,
96fdf90aacd6atagen2026-09-08 08:24 UTC812
                    matrix_sdk::send_queue::LocalEchoContent::Event { .. }
96fdf90aacd6atagen2026-09-08 08:24 UTC813
                )
96fdf90aacd6atagen2026-09-08 08:24 UTC814
            })
96fdf90aacd6atagen2026-09-08 08:24 UTC815
            .map(|echo| echo.transaction_id)
96fdf90aacd6atagen2026-09-08 08:24 UTC816
            .collect())
96fdf90aacd6atagen2026-09-08 08:24 UTC817
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC818
96fdf90aacd6atagen2026-09-08 08:24 UTC819
    pub async fn global_account_data(
96fdf90aacd6atagen2026-09-08 08:24 UTC820
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC821
        event_type: GlobalAccountDataEventType,
31ce2453c82fatagen2026-09-24 13:07 UTC822
    ) -> Result<Option<Raw<AnyGlobalAccountDataEventContent>>, Error> {
96fdf90aacd6atagen2026-09-08 08:24 UTC823
        self.client
96fdf90aacd6atagen2026-09-08 08:24 UTC824
            .account()
96fdf90aacd6atagen2026-09-08 08:24 UTC825
            .account_data_raw(event_type)
96fdf90aacd6atagen2026-09-08 08:24 UTC826
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC827
            .map_err(|source| Error::from_sdk("reading account data failed", source))
96fdf90aacd6atagen2026-09-08 08:24 UTC828
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC829
96fdf90aacd6atagen2026-09-08 08:24 UTC830
    pub async fn room_account_data(
96fdf90aacd6atagen2026-09-08 08:24 UTC831
        &self,
96fdf90aacd6atagen2026-09-08 08:24 UTC832
        room_id: &RoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC833
        event_type: RoomAccountDataEventType,
31ce2453c82fatagen2026-09-24 13:07 UTC834
    ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC835
        self.room(room_id)?
31ce2453c82fatagen2026-09-24 13:07 UTC836
            .account_data(event_type)
96fdf90aacd6atagen2026-09-08 08:24 UTC837
            .await
31ce2453c82fatagen2026-09-24 13:07 UTC838
            .map_err(|source| Error::from_sdk("reading room account data failed", source))
96fdf90aacd6atagen2026-09-08 08:24 UTC839
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC840
96fdf90aacd6atagen2026-09-08 08:24 UTC841
    #[must_use]
96fdf90aacd6atagen2026-09-08 08:24 UTC842
    pub fn connection_state(&self) -> watch::Receiver<ConnectionState> {
96fdf90aacd6atagen2026-09-08 08:24 UTC843
        self.connection.clone()
96fdf90aacd6atagen2026-09-08 08:24 UTC844
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC845
96fdf90aacd6atagen2026-09-08 08:24 UTC846
    #[must_use]
96fdf90aacd6atagen2026-09-08 08:24 UTC847
    pub fn encryption_state(&self) -> Option<EncryptionState> {
96fdf90aacd6atagen2026-09-08 08:24 UTC848
        let device_id = self.client.device_id()?.to_owned();
96fdf90aacd6atagen2026-09-08 08:24 UTC849
        let encryption = self.client.encryption();
96fdf90aacd6atagen2026-09-08 08:24 UTC850
        Some(encryption_state(
96fdf90aacd6atagen2026-09-08 08:24 UTC851
            device_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC852
            encryption.recovery().state(),
96fdf90aacd6atagen2026-09-08 08:24 UTC853
            encryption.verification_state().get(),
96fdf90aacd6atagen2026-09-08 08:24 UTC854
            encryption.backups().state(),
96fdf90aacd6atagen2026-09-08 08:24 UTC855
        ))
96fdf90aacd6atagen2026-09-08 08:24 UTC856
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC857
}
96fdf90aacd6atagen2026-09-08 08:24 UTC858
31ce2453c82fatagen2026-09-24 13:07 UTC859
/// 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 UTC860
pub struct SpaceHierarchy(SpaceRoomList);
31ce2453c82fatagen2026-09-24 13:07 UTC861
31ce2453c82fatagen2026-09-24 13:07 UTC862
impl fmt::Debug for SpaceHierarchy {
31ce2453c82fatagen2026-09-24 13:07 UTC863
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
31ce2453c82fatagen2026-09-24 13:07 UTC864
        formatter
31ce2453c82fatagen2026-09-24 13:07 UTC865
            .debug_struct("SpaceHierarchy")
31ce2453c82fatagen2026-09-24 13:07 UTC866
            .finish_non_exhaustive()
31ce2453c82fatagen2026-09-24 13:07 UTC867
    }
31ce2453c82fatagen2026-09-24 13:07 UTC868
}
31ce2453c82fatagen2026-09-24 13:07 UTC869
31ce2453c82fatagen2026-09-24 13:07 UTC870
impl SpaceHierarchy {
31ce2453c82fatagen2026-09-24 13:07 UTC871
    /// fetches the next page. a no-op once the end is reached or while a page is in flight
31ce2453c82fatagen2026-09-24 13:07 UTC872
    pub async fn paginate(&self) -> Result<(), Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC873
        self.0.paginate().await.map_err(|source| {
31ce2453c82fatagen2026-09-24 13:07 UTC874
            Error::with_source(
31ce2453c82fatagen2026-09-24 13:07 UTC875
                ErrorKind::Server,
31ce2453c82fatagen2026-09-24 13:07 UTC876
                "fetching the space hierarchy failed",
31ce2453c82fatagen2026-09-24 13:07 UTC877
                source,
31ce2453c82fatagen2026-09-24 13:07 UTC878
            )
31ce2453c82fatagen2026-09-24 13:07 UTC879
        })
31ce2453c82fatagen2026-09-24 13:07 UTC880
    }
31ce2453c82fatagen2026-09-24 13:07 UTC881
31ce2453c82fatagen2026-09-24 13:07 UTC882
    /// everything fetched so far, the space itself excluded
31ce2453c82fatagen2026-09-24 13:07 UTC883
    pub async fn rooms(&self) -> Vec<SpaceChild> {
31ce2453c82fatagen2026-09-24 13:07 UTC884
        self.0.rooms().await.into_iter().map(space_child).collect()
31ce2453c82fatagen2026-09-24 13:07 UTC885
    }
31ce2453c82fatagen2026-09-24 13:07 UTC886
31ce2453c82fatagen2026-09-24 13:07 UTC887
    #[must_use]
31ce2453c82fatagen2026-09-24 13:07 UTC888
    pub fn end_reached(&self) -> bool {
31ce2453c82fatagen2026-09-24 13:07 UTC889
        matches!(
31ce2453c82fatagen2026-09-24 13:07 UTC890
            self.0.pagination_state(),
31ce2453c82fatagen2026-09-24 13:07 UTC891
            SpaceRoomListPaginationState::Idle { end_reached: true }
31ce2453c82fatagen2026-09-24 13:07 UTC892
        )
31ce2453c82fatagen2026-09-24 13:07 UTC893
    }
31ce2453c82fatagen2026-09-24 13:07 UTC894
}
31ce2453c82fatagen2026-09-24 13:07 UTC895
31ce2453c82fatagen2026-09-24 13:07 UTC896
fn profile(
31ce2453c82fatagen2026-09-24 13:07 UTC897
    user_id: OwnedUserId,
31ce2453c82fatagen2026-09-24 13:07 UTC898
    response: &ruma::api::client::profile::get_profile::v3::Response,
31ce2453c82fatagen2026-09-24 13:07 UTC899
) -> Result<Profile, Error> {
31ce2453c82fatagen2026-09-24 13:07 UTC900
    use ruma::api::client::profile::{AvatarUrl, DisplayName};
31ce2453c82fatagen2026-09-24 13:07 UTC901
    let malformed = |source| {
31ce2453c82fatagen2026-09-24 13:07 UTC902
        Error::with_source(
31ce2453c82fatagen2026-09-24 13:07 UTC903
            ErrorKind::Server,
31ce2453c82fatagen2026-09-24 13:07 UTC904
            "the server sent a malformed profile",
31ce2453c82fatagen2026-09-24 13:07 UTC905
            source,
31ce2453c82fatagen2026-09-24 13:07 UTC906
        )
31ce2453c82fatagen2026-09-24 13:07 UTC907
    };
31ce2453c82fatagen2026-09-24 13:07 UTC908
    Ok(Profile {
31ce2453c82fatagen2026-09-24 13:07 UTC909
        user_id,
31ce2453c82fatagen2026-09-24 13:07 UTC910
        display_name: response.get_static::<DisplayName>().map_err(malformed)?,
5d2974de5826atagen2026-10-08 11:29 UTC911
        avatar: response
5d2974de5826atagen2026-10-08 11:29 UTC912
            .get_static::<AvatarUrl>()
5d2974de5826atagen2026-10-08 11:29 UTC913
            .map_err(malformed)?
5d2974de5826atagen2026-10-08 11:29 UTC914
            .as_deref()
5d2974de5826atagen2026-10-08 11:29 UTC915
            .map(MediaId::plain),
31ce2453c82fatagen2026-09-24 13:07 UTC916
    })
31ce2453c82fatagen2026-09-24 13:07 UTC917
}
31ce2453c82fatagen2026-09-24 13:07 UTC918
31ce2453c82fatagen2026-09-24 13:07 UTC919
#[derive(Debug)]
31ce2453c82fatagen2026-09-24 13:07 UTC920
pub(crate) struct Request {
96fdf90aacd6atagen2026-09-08 08:24 UTC921
    pub(crate) command: Command,
31ce2453c82fatagen2026-09-24 13:07 UTC922
    pub(crate) reply: Responder,
31ce2453c82fatagen2026-09-24 13:07 UTC923
}
31ce2453c82fatagen2026-09-24 13:07 UTC924
31ce2453c82fatagen2026-09-24 13:07 UTC925
impl Request {
31ce2453c82fatagen2026-09-24 13:07 UTC926
    fn new(command: Command) -> (Self, Pending) {
31ce2453c82fatagen2026-09-24 13:07 UTC927
        let (reply, pending) = oneshot::channel();
31ce2453c82fatagen2026-09-24 13:07 UTC928
        (
31ce2453c82fatagen2026-09-24 13:07 UTC929
            Self {
31ce2453c82fatagen2026-09-24 13:07 UTC930
                command,
31ce2453c82fatagen2026-09-24 13:07 UTC931
                reply: Responder(reply),
31ce2453c82fatagen2026-09-24 13:07 UTC932
            },
31ce2453c82fatagen2026-09-24 13:07 UTC933
            Pending(pending),
31ce2453c82fatagen2026-09-24 13:07 UTC934
        )
31ce2453c82fatagen2026-09-24 13:07 UTC935
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC936
}
96fdf90aacd6atagen2026-09-08 08:24 UTC937
31ce2453c82fatagen2026-09-24 13:07 UTC938
/// whoever holds this owes the caller an answer. dropping it answers `Interrupted`
96fdf90aacd6atagen2026-09-08 08:24 UTC939
#[derive(Debug)]
31ce2453c82fatagen2026-09-24 13:07 UTC940
pub(crate) struct Responder(oneshot::Sender<Result<CommandOutput, Error>>);
31ce2453c82fatagen2026-09-24 13:07 UTC941
31ce2453c82fatagen2026-09-24 13:07 UTC942
impl Responder {
31ce2453c82fatagen2026-09-24 13:07 UTC943
    pub(crate) fn send(self, result: Result<CommandOutput, Error>) {
31ce2453c82fatagen2026-09-24 13:07 UTC944
        if let Err(error) = &result {
31ce2453c82fatagen2026-09-24 13:07 UTC945
            tracing::debug!(%error, kind = ?error.kind, "command failed");
31ce2453c82fatagen2026-09-24 13:07 UTC946
        }
31ce2453c82fatagen2026-09-24 13:07 UTC947
        let _ = self.0.send(result);
31ce2453c82fatagen2026-09-24 13:07 UTC948
    }
31ce2453c82fatagen2026-09-24 13:07 UTC949
31ce2453c82fatagen2026-09-24 13:07 UTC950
    pub(crate) fn done(self, result: Result<(), Error>) {
31ce2453c82fatagen2026-09-24 13:07 UTC951
        self.send(result.map(|()| CommandOutput::Done));
31ce2453c82fatagen2026-09-24 13:07 UTC952
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC953
}
96fdf90aacd6atagen2026-09-08 08:24 UTC954
96fdf90aacd6atagen2026-09-08 08:24 UTC955
#[derive(Debug)]
96fdf90aacd6atagen2026-09-08 08:24 UTC956
pub struct EventStream {
96fdf90aacd6atagen2026-09-08 08:24 UTC957
    events: mpsc::Receiver<Event>,
96fdf90aacd6atagen2026-09-08 08:24 UTC958
}
96fdf90aacd6atagen2026-09-08 08:24 UTC959
96fdf90aacd6atagen2026-09-08 08:24 UTC960
impl EventStream {
96fdf90aacd6atagen2026-09-08 08:24 UTC961
    pub async fn recv(&mut self) -> Option<Event> {
96fdf90aacd6atagen2026-09-08 08:24 UTC962
        self.events.recv().await
96fdf90aacd6atagen2026-09-08 08:24 UTC963
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC964
96fdf90aacd6atagen2026-09-08 08:24 UTC965
    pub fn try_recv(&mut self) -> Result<Event, mpsc::error::TryRecvError> {
96fdf90aacd6atagen2026-09-08 08:24 UTC966
        self.events.try_recv()
96fdf90aacd6atagen2026-09-08 08:24 UTC967
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC968
}
96fdf90aacd6atagen2026-09-08 08:24 UTC969
96fdf90aacd6atagen2026-09-08 08:24 UTC970
impl futures_util::Stream for EventStream {
96fdf90aacd6atagen2026-09-08 08:24 UTC971
    type Item = Event;
96fdf90aacd6atagen2026-09-08 08:24 UTC972
96fdf90aacd6atagen2026-09-08 08:24 UTC973
    fn poll_next(mut self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Option<Self::Item>> {
96fdf90aacd6atagen2026-09-08 08:24 UTC974
        self.events.poll_recv(context)
96fdf90aacd6atagen2026-09-08 08:24 UTC975
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC976
}
96fdf90aacd6atagen2026-09-08 08:24 UTC977
96fdf90aacd6atagen2026-09-08 08:24 UTC978
#[derive(Debug)]
96fdf90aacd6atagen2026-09-08 08:24 UTC979
pub(crate) struct DriverPort {
31ce2453c82fatagen2026-09-24 13:07 UTC980
    requests: mpsc::Receiver<Request>,
96fdf90aacd6atagen2026-09-08 08:24 UTC981
    events: mpsc::Sender<Event>,
96fdf90aacd6atagen2026-09-08 08:24 UTC982
    connection: watch::Sender<ConnectionState>,
96fdf90aacd6atagen2026-09-08 08:24 UTC983
}
96fdf90aacd6atagen2026-09-08 08:24 UTC984
96fdf90aacd6atagen2026-09-08 08:24 UTC985
#[derive(Clone, Debug)]
96fdf90aacd6atagen2026-09-08 08:24 UTC986
pub(crate) struct EventSender(mpsc::Sender<Event>);
96fdf90aacd6atagen2026-09-08 08:24 UTC987
96fdf90aacd6atagen2026-09-08 08:24 UTC988
impl EventSender {
96fdf90aacd6atagen2026-09-08 08:24 UTC989
    pub(crate) async fn send(&self, event: Event) -> Result<(), SendEventError> {
31ce2453c82fatagen2026-09-24 13:07 UTC990
        self.0.send(event).await.map_err(|_| SendEventError)
96fdf90aacd6atagen2026-09-08 08:24 UTC991
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC992
31ce2453c82fatagen2026-09-24 13:07 UTC993
    /// resolves once every `EventStream` is gone
96fdf90aacd6atagen2026-09-08 08:24 UTC994
    pub(crate) async fn closed(&self) {
96fdf90aacd6atagen2026-09-08 08:24 UTC995
        self.0.closed().await;
96fdf90aacd6atagen2026-09-08 08:24 UTC996
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC997
}
96fdf90aacd6atagen2026-09-08 08:24 UTC998
96fdf90aacd6atagen2026-09-08 08:24 UTC999
impl DriverPort {
96fdf90aacd6atagen2026-09-08 08:24 UTC1000
    pub(crate) fn event_sender(&self) -> EventSender {
96fdf90aacd6atagen2026-09-08 08:24 UTC1001
        EventSender(self.events.clone())
96fdf90aacd6atagen2026-09-08 08:24 UTC1002
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1003
96fdf90aacd6atagen2026-09-08 08:24 UTC1004
    pub(crate) fn connection_sender(&self) -> watch::Sender<ConnectionState> {
96fdf90aacd6atagen2026-09-08 08:24 UTC1005
        self.connection.clone()
96fdf90aacd6atagen2026-09-08 08:24 UTC1006
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1007
31ce2453c82fatagen2026-09-24 13:07 UTC1008
    pub(crate) async fn recv(&mut self) -> Option<Request> {
31ce2453c82fatagen2026-09-24 13:07 UTC1009
        self.requests.recv().await
96fdf90aacd6atagen2026-09-08 08:24 UTC1010
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1011
5a52012c9b1datagen2026-09-24 23:45 UTC1012
    pub(crate) fn try_recv(&mut self) -> Option<Request> {
5a52012c9b1datagen2026-09-24 23:45 UTC1013
        self.requests.try_recv().ok()
5a52012c9b1datagen2026-09-24 23:45 UTC1014
    }
5a52012c9b1datagen2026-09-24 23:45 UTC1015
31ce2453c82fatagen2026-09-24 13:07 UTC1016
    pub(crate) fn close(&mut self) {
31ce2453c82fatagen2026-09-24 13:07 UTC1017
        self.requests.close();
96fdf90aacd6atagen2026-09-08 08:24 UTC1018
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1019
}
96fdf90aacd6atagen2026-09-08 08:24 UTC1020
31ce2453c82fatagen2026-09-24 13:07 UTC1021
#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
31ce2453c82fatagen2026-09-24 13:07 UTC1022
#[error("the event receiver has closed")]
31ce2453c82fatagen2026-09-24 13:07 UTC1023
pub(crate) struct SendEventError;
96fdf90aacd6atagen2026-09-08 08:24 UTC1024
96fdf90aacd6atagen2026-09-08 08:24 UTC1025
#[must_use]
96fdf90aacd6atagen2026-09-08 08:24 UTC1026
pub(crate) fn transport_pair(
96fdf90aacd6atagen2026-09-08 08:24 UTC1027
    client: Client,
96fdf90aacd6atagen2026-09-08 08:24 UTC1028
    sync_service: Arc<SyncService>,
31ce2453c82fatagen2026-09-24 13:07 UTC1029
    media: Arc<MediaService>,
a250c7fa43fbatagen2026-09-26 13:35 UTC1030
    store_lock: Option<Arc<StoreLock>>,
96fdf90aacd6atagen2026-09-08 08:24 UTC1031
    command_capacity: usize,
96fdf90aacd6atagen2026-09-08 08:24 UTC1032
    event_capacity: usize,
96fdf90aacd6atagen2026-09-08 08:24 UTC1033
) -> (ClientHandle, DriverPort, EventStream) {
31ce2453c82fatagen2026-09-24 13:07 UTC1034
    let (request_tx, request_rx) = mpsc::channel(command_capacity);
96fdf90aacd6atagen2026-09-08 08:24 UTC1035
    let (event_tx, event_rx) = mpsc::channel(event_capacity);
96fdf90aacd6atagen2026-09-08 08:24 UTC1036
    let (connection_tx, connection_rx) = watch::channel(ConnectionState::Idle);
96fdf90aacd6atagen2026-09-08 08:24 UTC1037
    (
96fdf90aacd6atagen2026-09-08 08:24 UTC1038
        ClientHandle {
31ce2453c82fatagen2026-09-24 13:07 UTC1039
            requests: request_tx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1040
            client,
96fdf90aacd6atagen2026-09-08 08:24 UTC1041
            connection: connection_rx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1042
            notification_client: Arc::new(OnceCell::new()),
96fdf90aacd6atagen2026-09-08 08:24 UTC1043
            sync_service,
31ce2453c82fatagen2026-09-24 13:07 UTC1044
            media,
31ce2453c82fatagen2026-09-24 13:07 UTC1045
            spaces: Arc::new(OnceCell::new()),
a250c7fa43fbatagen2026-09-26 13:35 UTC1046
            _store_lock: store_lock,
96fdf90aacd6atagen2026-09-08 08:24 UTC1047
        },
96fdf90aacd6atagen2026-09-08 08:24 UTC1048
        DriverPort {
31ce2453c82fatagen2026-09-24 13:07 UTC1049
            requests: request_rx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1050
            events: event_tx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1051
            connection: connection_tx,
96fdf90aacd6atagen2026-09-08 08:24 UTC1052
        },
96fdf90aacd6atagen2026-09-08 08:24 UTC1053
        EventStream { events: event_rx },
96fdf90aacd6atagen2026-09-08 08:24 UTC1054
    )
96fdf90aacd6atagen2026-09-08 08:24 UTC1055
}
96fdf90aacd6atagen2026-09-08 08:24 UTC1056
96fdf90aacd6atagen2026-09-08 08:24 UTC1057
fn normalise_push_notification(
96fdf90aacd6atagen2026-09-08 08:24 UTC1058
    room_id: &RoomId,
96fdf90aacd6atagen2026-09-08 08:24 UTC1059
    event_id: &EventId,
96fdf90aacd6atagen2026-09-08 08:24 UTC1060
    status: NotificationStatus,
96fdf90aacd6atagen2026-09-08 08:24 UTC1061
) -> PushNotificationStatus {
96fdf90aacd6atagen2026-09-08 08:24 UTC1062
    match status {
96fdf90aacd6atagen2026-09-08 08:24 UTC1063
        NotificationStatus::Event(item) => {
96fdf90aacd6atagen2026-09-08 08:24 UTC1064
            let event = match &item.raw_event {
96fdf90aacd6atagen2026-09-08 08:24 UTC1065
                RawNotificationEvent::Timeline(event) => {
96fdf90aacd6atagen2026-09-08 08:24 UTC1066
                    PushNotificationEvent::Timeline(event.clone())
96fdf90aacd6atagen2026-09-08 08:24 UTC1067
                }
96fdf90aacd6atagen2026-09-08 08:24 UTC1068
                RawNotificationEvent::Invite(event) => PushNotificationEvent::Invite(event.clone()),
96fdf90aacd6atagen2026-09-08 08:24 UTC1069
            };
96fdf90aacd6atagen2026-09-08 08:24 UTC1070
            PushNotificationStatus::Event(Box::new(PushNotification {
96fdf90aacd6atagen2026-09-08 08:24 UTC1071
                event_id: event_id.to_owned(),
96fdf90aacd6atagen2026-09-08 08:24 UTC1072
                event,
96fdf90aacd6atagen2026-09-08 08:24 UTC1073
                sender: PushNotificationSender {
96fdf90aacd6atagen2026-09-08 08:24 UTC1074
                    user_id: item.event.sender().to_owned(),
96fdf90aacd6atagen2026-09-08 08:24 UTC1075
                    display_name: item.sender_display_name,
5d2974de5826atagen2026-10-08 11:29 UTC1076
                    avatar_url: item.sender_avatar_url.as_deref().map(MediaId::plain),
96fdf90aacd6atagen2026-09-08 08:24 UTC1077
                    name_ambiguous: item.is_sender_name_ambiguous,
96fdf90aacd6atagen2026-09-08 08:24 UTC1078
                },
96fdf90aacd6atagen2026-09-08 08:24 UTC1079
                room: PushNotificationRoom {
96fdf90aacd6atagen2026-09-08 08:24 UTC1080
                    room_id: room_id.to_owned(),
96fdf90aacd6atagen2026-09-08 08:24 UTC1081
                    name: item.room_computed_display_name,
5d2974de5826atagen2026-10-08 11:29 UTC1082
                    avatar_url: item.room_avatar_url.as_deref().map(MediaId::plain),
96fdf90aacd6atagen2026-09-08 08:24 UTC1083
                    canonical_alias: item
96fdf90aacd6atagen2026-09-08 08:24 UTC1084
                        .room_canonical_alias
96fdf90aacd6atagen2026-09-08 08:24 UTC1085
                        .as_deref()
96fdf90aacd6atagen2026-09-08 08:24 UTC1086
                        .and_then(|alias| alias.parse().ok()),
96fdf90aacd6atagen2026-09-08 08:24 UTC1087
                    topic: item.room_topic,
96fdf90aacd6atagen2026-09-08 08:24 UTC1088
                    encrypted: item.is_room_encrypted,
96fdf90aacd6atagen2026-09-08 08:24 UTC1089
                    direct: item.room_is_dm,
96fdf90aacd6atagen2026-09-08 08:24 UTC1090
                    joined_members_count: item.joined_members_count,
96fdf90aacd6atagen2026-09-08 08:24 UTC1091
                    service_members: item
96fdf90aacd6atagen2026-09-08 08:24 UTC1092
                        .service_members
96fdf90aacd6atagen2026-09-08 08:24 UTC1093
                        .into_iter()
96fdf90aacd6atagen2026-09-08 08:24 UTC1094
                        .filter_map(|user_id| user_id.parse().ok())
96fdf90aacd6atagen2026-09-08 08:24 UTC1095
                        .collect(),
96fdf90aacd6atagen2026-09-08 08:24 UTC1096
                    active_service_members_count: item.active_service_members_count,
96fdf90aacd6atagen2026-09-08 08:24 UTC1097
                    space: item.is_space,
96fdf90aacd6atagen2026-09-08 08:24 UTC1098
                },
96fdf90aacd6atagen2026-09-08 08:24 UTC1099
                noisy: item.is_noisy,
96fdf90aacd6atagen2026-09-08 08:24 UTC1100
                has_mention: item.has_mention,
96fdf90aacd6atagen2026-09-08 08:24 UTC1101
                thread_id: item.thread_id,
96fdf90aacd6atagen2026-09-08 08:24 UTC1102
            }))
96fdf90aacd6atagen2026-09-08 08:24 UTC1103
        }
96fdf90aacd6atagen2026-09-08 08:24 UTC1104
        NotificationStatus::EventNotFound => PushNotificationStatus::NotFound,
96fdf90aacd6atagen2026-09-08 08:24 UTC1105
        NotificationStatus::EventFilteredOut => PushNotificationStatus::FilteredOut,
96fdf90aacd6atagen2026-09-08 08:24 UTC1106
        NotificationStatus::EventRedacted => PushNotificationStatus::Redacted,
96fdf90aacd6atagen2026-09-08 08:24 UTC1107
    }
96fdf90aacd6atagen2026-09-08 08:24 UTC1108
}