atagen

macltok

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