atagen

macltok

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