atagen

macltok

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