96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1 | use std::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 2 | fmt, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 3 | future::Future, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 4 | pin::Pin, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 5 | sync::Arc, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 6 | task::{Context, Poll}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 7 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 8 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 9 | use matrix_sdk::{Client, RoomMemberships}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 10 | use matrix_sdk_ui::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 11 | notification_client::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 12 | NotificationClient, NotificationProcessSetup, NotificationStatus, RawNotificationEvent, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 13 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 14 | spaces::{SpaceRoomList, SpaceService, room_list::SpaceRoomListPaginationState}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 15 | sync_service::SyncService, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 16 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 17 | use ruma::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 18 | EventId, MxcUri, OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedRoomOrAliasId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 19 | OwnedServerName, OwnedTransactionId, OwnedUserId, RoomId, UserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 20 | events::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 21 | AnyGlobalAccountDataEventContent, AnyRoomAccountDataEvent, AnyRoomAccountDataEventContent, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 22 | GlobalAccountDataEventType, RoomAccountDataEventType, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 23 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 24 | serde::Raw, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 25 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 26 | use tokio::sync::{OnceCell, mpsc, oneshot, watch}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 27 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 28 | use crate::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 29 | AccountCommand, AttachmentUpload, Command, CommandOutput, ConnectionState, CreateRoomOptions, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 30 | EncryptionCommand, EncryptionState, Error, ErrorKind, Event, EventRef, InteractiveAuth, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 31 | InteractiveAuthOutcome, LifecycleCommand, Media, MediaCommand, MediaId, MediaSize, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 32 | MemberFilter, MemberSummary, MessageContent, MessageEditContent, NotificationCommand, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 33 | OwnDevice, PowerLevelChanges, Profile, PushNotification, PushNotificationEvent, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 34 | PushNotificationStatus, RoomCommand, RoomListFilter, RoomNotificationMode, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 35 | RoomNotificationSettings, RoomPowerLevels, RoomSummary, SpaceChild, TimelineCommand, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 36 | TimelineId, VerificationAction, VerificationTarget, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 37 | encryption::encryption_state, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 38 | engine::MediaService, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 39 | model::{PushNotificationRoom, PushNotificationSender}, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 40 | normalise::{member_summary, room_summaries, space_child}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 41 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 42 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 43 | #[derive(Clone)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 44 | pub struct ClientHandle { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 45 | requests: mpsc::Sender<Request>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 46 | client: Client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 47 | connection: watch::Receiver<ConnectionState>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 48 | notification_client: Arc<OnceCell<NotificationClient>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 49 | sync_service: Arc<SyncService>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 50 | media: Arc<MediaService>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 51 | spaces: Arc<OnceCell<SpaceService>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 52 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 53 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 54 | impl fmt::Debug for ClientHandle { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 55 | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 56 | formatter |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 57 | .debug_struct("ClientHandle") |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 58 | .finish_non_exhaustive() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 59 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 60 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 61 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 62 | /// a command's answer. drop it if you don't care, the command still runs |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 63 | #[derive(Debug)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 64 | #[must_use = "dropping it is fine but then you'll never know"] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 65 | pub struct Pending(oneshot::Receiver<Result<CommandOutput, Error>>); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 66 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 67 | impl Future for Pending { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 68 | type Output = Result<CommandOutput, Error>; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 69 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 70 | fn poll(mut self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 71 | Pin::new(&mut self.0) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 72 | .poll(context) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 73 | .map(|result| result.unwrap_or_else(|_| Err(Error::interrupted()))) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 74 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 75 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 76 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 77 | impl ClientHandle { |
f12377bce9b9 | atagen | 2026-09-26 12:32 UTC | 78 | /// current credentials, it holds secrets. the engine saves it for you unless the |
f12377bce9b9 | atagen | 2026-09-26 12:32 UTC | 79 | /// session was built `without_persistence` |
62fe32759529 | atagen | 2026-09-26 08:50 UTC | 80 | #[cfg(any(feature = "sqlite", feature = "indexeddb"))] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 81 | pub fn session_record(&self) -> Result<crate::SessionRecord, crate::AccountError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 82 | crate::account::session_record(&self.client) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 83 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 84 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 85 | /// queue a command, waiting for room in the queue if there isn't any |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 86 | pub async fn send(&self, command: Command) -> Result<Pending, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 87 | let (request, pending) = Request::new(command); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 88 | self.requests |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 89 | .send(request) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 90 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 91 | .map_err(|_| Error::interrupted())?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 92 | Ok(pending) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 93 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 94 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 95 | /// queue a command or fail with `QueueFull` right now |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 96 | pub fn try_send(&self, command: Command) -> Result<Pending, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 97 | let (request, pending) = Request::new(command); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 98 | self.requests |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 99 | .try_send(request) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 100 | .map_err(|error| match error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 101 | mpsc::error::TrySendError::Full(_) => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 102 | Error::new(ErrorKind::QueueFull, "the command queue is full") |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 103 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 104 | mpsc::error::TrySendError::Closed(_) => Error::interrupted(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 105 | })?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 106 | Ok(pending) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 107 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 108 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 109 | /// queue a command and wait for its answer. timeline sends answer once the |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 110 | /// sdk send queue has them, delivery shows up later as the item's send state |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 111 | pub async fn execute(&self, command: Command) -> Result<CommandOutput, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 112 | self.send(command).await?.await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 113 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 114 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 115 | async fn run(&self, command: Command) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 116 | self.execute(command).await.map(drop) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 117 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 118 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 119 | async fn run_for_room(&self, command: RoomCommand) -> Result<OwnedRoomId, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 120 | match self.execute(Command::Room(command)).await? { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 121 | CommandOutput::Room(room_id) => Ok(room_id), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 122 | output => Err(Error::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 123 | ErrorKind::Other, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 124 | format!("expected a room but got {output:?}"), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 125 | )), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 126 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 127 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 128 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 129 | pub async fn shutdown(&self) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 130 | self.run(Command::Lifecycle(LifecycleCommand::Shutdown)) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 131 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 132 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 133 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 134 | pub async fn logout(&self) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 135 | self.run(Command::Account(AccountCommand::Logout)).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 136 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 137 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 138 | pub async fn delete_devices( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 139 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 140 | device_ids: Vec<OwnedDeviceId>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 141 | auth: Option<InteractiveAuth>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 142 | ) -> Result<InteractiveAuthOutcome, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 143 | match self |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 144 | .run(Command::Account(AccountCommand::DeleteDevices { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 145 | device_ids, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 146 | auth, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 147 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 148 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 149 | { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 150 | Ok(()) => Ok(InteractiveAuthOutcome::Completed), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 151 | Err(Error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 152 | challenge: Some(challenge), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 153 | .. |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 154 | }) => Ok(InteractiveAuthOutcome::Challenge(*challenge)), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 155 | Err(error) => Err(error), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 156 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 157 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 158 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 159 | pub async fn rename_device( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 160 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 161 | device_id: OwnedDeviceId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 162 | display_name: impl Into<String>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 163 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 164 | self.run(Command::Account(AccountCommand::RenameDevice { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 165 | device_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 166 | display_name: display_name.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 167 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 168 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 169 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 170 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 171 | pub async fn set_global_account_data( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 172 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 173 | event_type: GlobalAccountDataEventType, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 174 | content: Raw<AnyGlobalAccountDataEventContent>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 175 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 176 | self.run(Command::Account(AccountCommand::SetAccountData { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 177 | event_type, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 178 | content, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 179 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 180 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 181 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 182 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 183 | pub async fn set_room_account_data( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 184 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 185 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 186 | event_type: RoomAccountDataEventType, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 187 | content: Raw<AnyRoomAccountDataEventContent>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 188 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 189 | self.run(Command::Room(RoomCommand::SetAccountData { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 190 | room_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 191 | event_type, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 192 | content, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 193 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 194 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 195 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 196 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 197 | pub async fn set_room_notification_mode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 198 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 199 | room_id: OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 200 | mode: RoomNotificationMode, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 201 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 202 | self.run(Command::Notification(NotificationCommand::SetRoomMode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 203 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 204 | mode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 205 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 206 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 207 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 208 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 209 | pub async fn reset_room_notification_mode(&self, room_id: OwnedRoomId) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 210 | self.run(Command::Notification(NotificationCommand::ResetRoomMode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 211 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 212 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 213 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 214 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 215 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 216 | pub async fn set_default_notification_mode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 217 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 218 | encrypted: bool, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 219 | one_to_one: bool, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 220 | mode: RoomNotificationMode, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 221 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 222 | self.run(Command::Notification(NotificationCommand::SetDefaultMode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 223 | encrypted, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 224 | one_to_one, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 225 | mode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 226 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 227 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 228 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 229 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 230 | pub async fn add_notification_keyword(&self, keyword: impl Into<String>) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 231 | self.run(Command::Notification(NotificationCommand::AddKeyword( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 232 | keyword.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 233 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 234 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 235 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 236 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 237 | pub async fn remove_notification_keyword( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 238 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 239 | keyword: impl Into<String>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 240 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 241 | self.run(Command::Notification(NotificationCommand::RemoveKeyword( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 242 | keyword.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 243 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 244 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 245 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 246 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 247 | pub async fn open_room(&self, room_id: OwnedRoomId) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 248 | self.run(Command::Room(RoomCommand::Open(room_id))).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 249 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 250 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 251 | pub async fn close_room(&self, room_id: OwnedRoomId) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 252 | self.run(Command::Room(RoomCommand::Close(room_id))).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 253 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 254 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 255 | pub async fn open_thread( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 256 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 257 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 258 | root_event_id: OwnedEventId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 259 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 260 | self.run(Command::Timeline(TimelineCommand::OpenThread { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 261 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 262 | root_event_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 263 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 264 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 265 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 266 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 267 | pub async fn close_thread( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 268 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 269 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 270 | root_event_id: OwnedEventId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 271 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 272 | self.run(Command::Timeline(TimelineCommand::CloseThread { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 273 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 274 | root_event_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 275 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 276 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 277 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 278 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 279 | pub async fn resync(&self, timeline_id: TimelineId) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 280 | self.run(Command::Timeline(TimelineCommand::Resync { timeline_id })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 281 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 282 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 283 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 284 | pub async fn paginate(&self, timeline_id: TimelineId, limit: u16) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 285 | self.run(Command::Timeline(TimelineCommand::Paginate { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 286 | timeline_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 287 | limit, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 288 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 289 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 290 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 291 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 292 | pub async fn send_message( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 293 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 294 | timeline_id: TimelineId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 295 | content: MessageContent, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 296 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 297 | self.run(Command::Timeline(TimelineCommand::Send { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 298 | timeline_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 299 | content, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 300 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 301 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 302 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 303 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 304 | pub async fn edit_message( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 305 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 306 | timeline_id: TimelineId, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 307 | target: impl Into<EventRef>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 308 | content: MessageEditContent, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 309 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 310 | self.run(Command::Timeline(TimelineCommand::Edit { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 311 | timeline_id, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 312 | target: target.into(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 313 | content, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 314 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 315 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 316 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 317 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 318 | pub async fn redact( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 319 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 320 | timeline_id: TimelineId, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 321 | target: impl Into<EventRef>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 322 | reason: Option<String>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 323 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 324 | self.run(Command::Timeline(TimelineCommand::Redact { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 325 | timeline_id, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 326 | target: target.into(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 327 | reason, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 328 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 329 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 330 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 331 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 332 | pub async fn toggle_reaction( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 333 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 334 | timeline_id: TimelineId, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 335 | target: impl Into<EventRef>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 336 | key: impl Into<String>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 337 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 338 | self.run(Command::Timeline(TimelineCommand::ToggleReaction { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 339 | timeline_id, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 340 | target: target.into(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 341 | key: key.into(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 342 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 343 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 344 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 345 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 346 | pub async fn mark_read( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 347 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 348 | timeline_id: TimelineId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 349 | event_id: OwnedEventId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 350 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 351 | self.run(Command::Timeline(TimelineCommand::MarkRead { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 352 | timeline_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 353 | event_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 354 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 355 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 356 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 357 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 358 | pub async fn set_typing(&self, room_id: OwnedRoomId, typing: bool) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 359 | self.run(Command::Room(RoomCommand::SetTyping { room_id, typing })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 360 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 361 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 362 | |
38c4caecdb3d | atagen | 2026-09-26 13:35 UTC | 363 | pub async fn prepare_to_send(&self, room_id: OwnedRoomId) -> Result<(), Error> { |
38c4caecdb3d | atagen | 2026-09-26 13:35 UTC | 364 | self.run(Command::Room(RoomCommand::PrepareToSend(room_id))) |
38c4caecdb3d | atagen | 2026-09-26 13:35 UTC | 365 | .await |
38c4caecdb3d | atagen | 2026-09-26 13:35 UTC | 366 | } |
38c4caecdb3d | atagen | 2026-09-26 13:35 UTC | 367 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 368 | pub async fn join_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 369 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 370 | room: OwnedRoomOrAliasId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 371 | via: Vec<OwnedServerName>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 372 | ) -> Result<OwnedRoomId, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 373 | self.run_for_room(RoomCommand::Join { room, via }).await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 374 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 375 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 376 | pub async fn leave_room(&self, room_id: OwnedRoomId) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 377 | self.run(Command::Room(RoomCommand::Leave(room_id))).await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 378 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 379 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 380 | pub async fn forget_room(&self, room_id: OwnedRoomId) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 381 | self.run(Command::Room(RoomCommand::Forget(room_id))).await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 382 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 383 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 384 | pub async fn accept_invite(&self, room_id: OwnedRoomId) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 385 | self.run(Command::Room(RoomCommand::AcceptInvite(room_id))) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 386 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 387 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 388 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 389 | pub async fn reject_invite(&self, room_id: OwnedRoomId) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 390 | self.run(Command::Room(RoomCommand::RejectInvite(room_id))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 391 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 392 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 393 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 394 | pub async fn invite_user( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 395 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 396 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 397 | user_id: OwnedUserId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 398 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 399 | self.run(Command::Room(RoomCommand::InviteUser { room_id, user_id })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 400 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 401 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 402 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 403 | pub async fn kick_user( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 404 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 405 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 406 | user_id: OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 407 | reason: Option<String>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 408 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 409 | self.run(Command::Room(RoomCommand::KickUser { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 410 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 411 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 412 | reason, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 413 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 414 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 415 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 416 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 417 | pub async fn ban_user( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 418 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 419 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 420 | user_id: OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 421 | reason: Option<String>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 422 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 423 | self.run(Command::Room(RoomCommand::BanUser { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 424 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 425 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 426 | reason, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 427 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 428 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 429 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 430 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 431 | pub async fn unban_user( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 432 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 433 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 434 | user_id: OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 435 | reason: Option<String>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 436 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 437 | self.run(Command::Room(RoomCommand::UnbanUser { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 438 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 439 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 440 | reason, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 441 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 442 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 443 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 444 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 445 | pub async fn set_power_levels( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 446 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 447 | room_id: OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 448 | changes: PowerLevelChanges, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 449 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 450 | self.run(Command::Room(RoomCommand::SetPowerLevels { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 451 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 452 | changes, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 453 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 454 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 455 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 456 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 457 | pub async fn set_user_power_level( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 458 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 459 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 460 | user_id: OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 461 | level: i64, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 462 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 463 | self.run(Command::Room(RoomCommand::SetUserPowerLevel { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 464 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 465 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 466 | level, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 467 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 468 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 469 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 470 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 471 | pub async fn create_room(&self, options: CreateRoomOptions) -> Result<OwnedRoomId, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 472 | self.run_for_room(RoomCommand::Create(options)).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 473 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 474 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 475 | /// hands back the existing dm with them if there is one |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 476 | pub async fn create_direct(&self, user_id: OwnedUserId) -> Result<OwnedRoomId, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 477 | self.run_for_room(RoomCommand::CreateDirect(user_id)).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 478 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 479 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 480 | pub async fn cancel_send( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 481 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 482 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 483 | transaction_id: OwnedTransactionId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 484 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 485 | self.run(Command::Room(RoomCommand::CancelSend { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 486 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 487 | transaction_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 488 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 489 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 490 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 491 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 492 | pub async fn retry_send( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 493 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 494 | room_id: OwnedRoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 495 | transaction_id: OwnedTransactionId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 496 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 497 | self.run(Command::Room(RoomCommand::RetrySend { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 498 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 499 | transaction_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 500 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 501 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 502 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 503 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 504 | pub async fn upload(&self, upload: AttachmentUpload) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 505 | self.run(Command::Media(MediaCommand::Upload(upload))).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 506 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 507 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 508 | pub async fn recover(&self, recovery_key: impl Into<String>) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 509 | self.run(Command::Encryption(EncryptionCommand::Recover( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 510 | recovery_key.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 511 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 512 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 513 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 514 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 515 | pub async fn create_key_backup(&self) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 516 | self.run(Command::Encryption(EncryptionCommand::CreateKeyBackup)) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 517 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 518 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 519 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 520 | pub async fn enable_key_backup(&self) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 521 | self.run(Command::Encryption(EncryptionCommand::EnableKeyBackup)) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 522 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 523 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 524 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 525 | pub async fn disable_key_backup(&self, delete_from_server: bool) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 526 | self.run(Command::Encryption(EncryptionCommand::DisableKeyBackup { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 527 | delete_from_server, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 528 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 529 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 530 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 531 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 532 | pub async fn recover_key_backup(&self, recovery_key: impl Into<String>) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 533 | self.run(Command::Encryption(EncryptionCommand::RecoverKeyBackup( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 534 | recovery_key.into(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 535 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 536 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 537 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 538 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 539 | pub async fn start_verification(&self, target: VerificationTarget) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 540 | self.run(Command::Encryption(EncryptionCommand::StartVerification( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 541 | target, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 542 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 543 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 544 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 545 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 546 | pub async fn verify(&self, action: VerificationAction) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 547 | self.run(Command::Encryption(EncryptionCommand::Verify(action))) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 548 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 549 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 550 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 551 | /// bytes for media a retained timeline showed you. concurrent asks share one download |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 552 | pub async fn media(&self, media_id: &MediaId, size: MediaSize) -> Result<Media, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 553 | self.media.timeline_media(media_id, size).await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 554 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 555 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 556 | /// bytes for any plain mxc uri, avatars mostly. same byte cap as everything else |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 557 | pub async fn mxc_media(&self, uri: &MxcUri, size: MediaSize) -> Result<Media, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 558 | self.media.mxc_media(uri, size).await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 559 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 560 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 561 | /// the space graph builds on first use and then keeps itself current |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 562 | async fn spaces(&self) -> &SpaceService { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 563 | self.spaces |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 564 | .get_or_init(|| SpaceService::new(self.client.clone())) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 565 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 566 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 567 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 568 | pub async fn rooms(&self) -> Vec<RoomSummary> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 569 | room_summaries(&self.client, self.spaces().await).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 570 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 571 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 572 | /// browse a space the way the server sees it, rooms you haven't joined included |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 573 | pub async fn space_hierarchy(&self, space_id: OwnedRoomId) -> SpaceHierarchy { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 574 | SpaceHierarchy(SpaceRoomList::new(self.client.clone(), space_id).await) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 575 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 576 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 577 | pub async fn own_profile(&self) -> Result<Profile, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 578 | let user_id = self |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 579 | .client |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 580 | .user_id() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 581 | .ok_or_else(|| Error::new(ErrorKind::Unauthenticated, "the client is not logged in"))? |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 582 | .to_owned(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 583 | let response = self |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 584 | .client |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 585 | .account() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 586 | .fetch_user_profile() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 587 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 588 | .map_err(|source| Error::from_sdk("fetching the profile failed", source))?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 589 | profile(user_id, &response) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 590 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 591 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 592 | pub async fn user_profile(&self, user_id: &UserId) -> Result<Profile, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 593 | let response = self |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 594 | .client |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 595 | .account() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 596 | .fetch_user_profile_of(user_id) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 597 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 598 | .map_err(|source| Error::from_sdk("fetching the profile failed", source))?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 599 | profile(user_id.to_owned(), &response) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 600 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 601 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 602 | pub async fn set_display_name(&self, name: Option<String>) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 603 | self.run(Command::Account(AccountCommand::SetDisplayName(name))) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 604 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 605 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 606 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 607 | pub async fn set_avatar(&self, avatar: Option<OwnedMxcUri>) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 608 | self.run(Command::Account(AccountCommand::SetAvatar(avatar))) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 609 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 610 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 611 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 612 | pub async fn upload_avatar( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 613 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 614 | mimetype: impl Into<String>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 615 | bytes: Vec<u8>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 616 | ) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 617 | self.run(Command::Account(AccountCommand::UploadAvatar { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 618 | mimetype: mimetype.into(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 619 | bytes, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 620 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 621 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 622 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 623 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 624 | pub async fn rooms_filtered(&self, filter: &RoomListFilter) -> Vec<RoomSummary> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 625 | let matcher = filter.matcher(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 626 | self.rooms() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 627 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 628 | .into_iter() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 629 | .filter(|room| matcher.matches(room)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 630 | .collect() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 631 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 632 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 633 | pub async fn devices(&self) -> Result<Vec<OwnDevice>, Error> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 634 | let current_device_id = self.client.device_id(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 635 | Ok(self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 636 | .client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 637 | .devices() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 638 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 639 | .map_err(|source| Error::from_http("listing devices failed", source))? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 640 | .devices |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 641 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 642 | .map(|device| OwnDevice { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 643 | current: current_device_id == Some(device.device_id.as_ref()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 644 | device_id: device.device_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 645 | display_name: device.display_name, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 646 | last_seen_ip: device.last_seen_ip, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 647 | last_seen_timestamp_ms: device.last_seen_ts.map(|timestamp| timestamp.get().into()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 648 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 649 | .collect()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 650 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 651 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 652 | fn room(&self, room_id: &RoomId) -> Result<matrix_sdk::Room, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 653 | self.client |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 654 | .get_room(room_id) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 655 | .ok_or_else(Error::room_unknown) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 656 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 657 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 658 | pub async fn room_notification_settings( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 659 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 660 | room_id: &RoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 661 | ) -> Result<Option<RoomNotificationSettings>, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 662 | let room = self.room(room_id)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 663 | let custom = room.user_defined_notification_mode().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 664 | let mode = match custom { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 665 | Some(mode) => mode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 666 | None => match room.notification_mode().await { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 667 | Some(mode) => mode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 668 | None => return Ok(None), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 669 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 670 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 671 | Ok(Some(RoomNotificationSettings { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 672 | mode: crate::normalise::notification_mode(mode), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 673 | custom: custom.is_some(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 674 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 675 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 676 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 677 | pub async fn notification_keywords(&self) -> Vec<String> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 678 | self.client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 679 | .notification_settings() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 680 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 681 | .enabled_keywords() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 682 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 683 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 684 | .collect() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 685 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 686 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 687 | pub async fn resolve_push_notification( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 688 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 689 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 690 | event_id: &EventId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 691 | ) -> Result<PushNotificationStatus, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 692 | let notification_failed = |source| { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 693 | Error::with_source( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 694 | ErrorKind::Other, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 695 | "resolving the push notification failed", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 696 | source, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 697 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 698 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 699 | let client = self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 700 | .notification_client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 701 | .get_or_try_init(|| async { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 702 | NotificationClient::new( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 703 | self.client.clone(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 704 | NotificationProcessSetup::SingleProcess { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 705 | sync_service: self.sync_service.clone(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 706 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 707 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 708 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 709 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 710 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 711 | .map_err(notification_failed)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 712 | let status = client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 713 | .get_notification(room_id, event_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 714 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 715 | .map_err(notification_failed)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 716 | Ok(normalise_push_notification(room_id, event_id, status)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 717 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 718 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 719 | pub async fn members( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 720 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 721 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 722 | filter: MemberFilter, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 723 | ) -> Result<Vec<MemberSummary>, Error> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 724 | let memberships = match filter { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 725 | MemberFilter::Active => RoomMemberships::ACTIVE, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 726 | MemberFilter::Joined => RoomMemberships::JOIN, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 727 | MemberFilter::Invited => RoomMemberships::INVITE, |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 728 | MemberFilter::Banned => RoomMemberships::BAN, |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 729 | MemberFilter::Left => RoomMemberships::LEAVE, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 730 | // An empty mask is the SDK's unfiltered wildcard: it matches every |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 731 | // membership, including custom states that `all()` would exclude. |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 732 | MemberFilter::All => RoomMemberships::empty(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 733 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 734 | Ok(self |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 735 | .room(room_id)? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 736 | .members(memberships) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 737 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 738 | .map_err(|source| Error::from_sdk("listing members failed", source))? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 739 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 740 | .map(member_summary) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 741 | .collect()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 742 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 743 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 744 | pub async fn room_power_levels(&self, room_id: &RoomId) -> Result<RoomPowerLevels, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 745 | let levels = self |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 746 | .room(room_id)? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 747 | .power_levels() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 748 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 749 | .map_err(|source| Error::from_sdk("reading power levels failed", source.into()))?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 750 | Ok(RoomPowerLevels { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 751 | ban: levels.ban.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 752 | invite: levels.invite.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 753 | kick: levels.kick.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 754 | redact: levels.redact.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 755 | events_default: levels.events_default.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 756 | state_default: levels.state_default.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 757 | users_default: levels.users_default.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 758 | room_notification: levels.notifications.room.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 759 | users: levels |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 760 | .users |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 761 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 762 | .map(|(user_id, level)| (user_id, level.into())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 763 | .collect(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 764 | events: levels |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 765 | .events |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 766 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 767 | .map(|(event_type, level)| (event_type.to_string(), level.into())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 768 | .collect(), |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 769 | creators: levels |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 770 | .rules |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 771 | .privileged_creators |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 772 | .into_iter() |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 773 | .flatten() |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 774 | .collect(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 775 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 776 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 777 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 778 | pub async fn pending_send_ids( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 779 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 780 | room_id: &RoomId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 781 | ) -> Result<Vec<OwnedTransactionId>, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 782 | let (echoes, _) = self |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 783 | .room(room_id)? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 784 | .send_queue() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 785 | .subscribe() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 786 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 787 | .map_err(|source| { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 788 | Error::with_source(ErrorKind::Store, "reading the send queue failed", source) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 789 | })?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 790 | Ok(echoes |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 791 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 792 | .filter(|echo| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 793 | matches!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 794 | echo.content, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 795 | matrix_sdk::send_queue::LocalEchoContent::Event { .. } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 796 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 797 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 798 | .map(|echo| echo.transaction_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 799 | .collect()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 800 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 801 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 802 | pub async fn global_account_data( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 803 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 804 | event_type: GlobalAccountDataEventType, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 805 | ) -> Result<Option<Raw<AnyGlobalAccountDataEventContent>>, Error> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 806 | self.client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 807 | .account() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 808 | .account_data_raw(event_type) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 809 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 810 | .map_err(|source| Error::from_sdk("reading account data failed", source)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 811 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 812 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 813 | pub async fn room_account_data( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 814 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 815 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 816 | event_type: RoomAccountDataEventType, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 817 | ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 818 | self.room(room_id)? |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 819 | .account_data(event_type) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 820 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 821 | .map_err(|source| Error::from_sdk("reading room account data failed", source)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 822 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 823 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 824 | #[must_use] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 825 | pub fn connection_state(&self) -> watch::Receiver<ConnectionState> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 826 | self.connection.clone() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 827 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 828 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 829 | #[must_use] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 830 | pub fn encryption_state(&self) -> Option<EncryptionState> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 831 | let device_id = self.client.device_id()?.to_owned(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 832 | let encryption = self.client.encryption(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 833 | Some(encryption_state( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 834 | device_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 835 | encryption.recovery().state(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 836 | encryption.verification_state().get(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 837 | encryption.backups().state(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 838 | )) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 839 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 840 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 841 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 842 | /// one space's hierarchy, a page at a time. hold on to it while you browse, it remembers where it got to |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 843 | pub struct SpaceHierarchy(SpaceRoomList); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 844 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 845 | impl fmt::Debug for SpaceHierarchy { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 846 | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 847 | formatter |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 848 | .debug_struct("SpaceHierarchy") |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 849 | .finish_non_exhaustive() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 850 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 851 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 852 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 853 | impl SpaceHierarchy { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 854 | /// fetches the next page. a no-op once the end is reached or while a page is in flight |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 855 | pub async fn paginate(&self) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 856 | self.0.paginate().await.map_err(|source| { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 857 | Error::with_source( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 858 | ErrorKind::Server, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 859 | "fetching the space hierarchy failed", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 860 | source, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 861 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 862 | }) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 863 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 864 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 865 | /// everything fetched so far, the space itself excluded |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 866 | pub async fn rooms(&self) -> Vec<SpaceChild> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 867 | self.0.rooms().await.into_iter().map(space_child).collect() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 868 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 869 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 870 | #[must_use] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 871 | pub fn end_reached(&self) -> bool { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 872 | matches!( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 873 | self.0.pagination_state(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 874 | SpaceRoomListPaginationState::Idle { end_reached: true } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 875 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 876 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 877 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 878 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 879 | fn profile( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 880 | user_id: OwnedUserId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 881 | response: &ruma::api::client::profile::get_profile::v3::Response, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 882 | ) -> Result<Profile, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 883 | use ruma::api::client::profile::{AvatarUrl, DisplayName}; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 884 | let malformed = |source| { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 885 | Error::with_source( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 886 | ErrorKind::Server, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 887 | "the server sent a malformed profile", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 888 | source, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 889 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 890 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 891 | Ok(Profile { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 892 | user_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 893 | display_name: response.get_static::<DisplayName>().map_err(malformed)?, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 894 | avatar: response.get_static::<AvatarUrl>().map_err(malformed)?, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 895 | }) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 896 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 897 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 898 | #[derive(Debug)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 899 | pub(crate) struct Request { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 900 | pub(crate) command: Command, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 901 | pub(crate) reply: Responder, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 902 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 903 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 904 | impl Request { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 905 | fn new(command: Command) -> (Self, Pending) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 906 | let (reply, pending) = oneshot::channel(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 907 | ( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 908 | Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 909 | command, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 910 | reply: Responder(reply), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 911 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 912 | Pending(pending), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 913 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 914 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 915 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 916 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 917 | /// whoever holds this owes the caller an answer. dropping it answers `Interrupted` |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 918 | #[derive(Debug)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 919 | pub(crate) struct Responder(oneshot::Sender<Result<CommandOutput, Error>>); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 920 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 921 | impl Responder { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 922 | pub(crate) fn send(self, result: Result<CommandOutput, Error>) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 923 | if let Err(error) = &result { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 924 | tracing::debug!(%error, kind = ?error.kind, "command failed"); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 925 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 926 | let _ = self.0.send(result); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 927 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 928 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 929 | pub(crate) fn done(self, result: Result<(), Error>) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 930 | self.send(result.map(|()| CommandOutput::Done)); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 931 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 932 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 933 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 934 | #[derive(Debug)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 935 | pub struct EventStream { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 936 | events: mpsc::Receiver<Event>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 937 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 938 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 939 | impl EventStream { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 940 | pub async fn recv(&mut self) -> Option<Event> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 941 | self.events.recv().await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 942 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 943 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 944 | pub fn try_recv(&mut self) -> Result<Event, mpsc::error::TryRecvError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 945 | self.events.try_recv() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 946 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 947 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 948 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 949 | impl futures_util::Stream for EventStream { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 950 | type Item = Event; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 951 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 952 | fn poll_next(mut self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Option<Self::Item>> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 953 | self.events.poll_recv(context) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 954 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 955 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 956 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 957 | #[derive(Debug)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 958 | pub(crate) struct DriverPort { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 959 | requests: mpsc::Receiver<Request>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 960 | events: mpsc::Sender<Event>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 961 | connection: watch::Sender<ConnectionState>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 962 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 963 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 964 | #[derive(Clone, Debug)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 965 | pub(crate) struct EventSender(mpsc::Sender<Event>); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 966 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 967 | impl EventSender { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 968 | pub(crate) async fn send(&self, event: Event) -> Result<(), SendEventError> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 969 | self.0.send(event).await.map_err(|_| SendEventError) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 970 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 971 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 972 | /// resolves once every `EventStream` is gone |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 973 | pub(crate) async fn closed(&self) { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 974 | self.0.closed().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 975 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 976 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 977 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 978 | impl DriverPort { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 979 | pub(crate) fn event_sender(&self) -> EventSender { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 980 | EventSender(self.events.clone()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 981 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 982 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 983 | pub(crate) fn connection_sender(&self) -> watch::Sender<ConnectionState> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 984 | self.connection.clone() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 985 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 986 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 987 | pub(crate) async fn recv(&mut self) -> Option<Request> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 988 | self.requests.recv().await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 989 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 990 | |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 991 | pub(crate) fn try_recv(&mut self) -> Option<Request> { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 992 | self.requests.try_recv().ok() |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 993 | } |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 994 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 995 | pub(crate) fn close(&mut self) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 996 | self.requests.close(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 997 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 998 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 999 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1000 | #[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1001 | #[error("the event receiver has closed")] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1002 | pub(crate) struct SendEventError; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1003 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1004 | #[must_use] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1005 | pub(crate) fn transport_pair( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1006 | client: Client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1007 | sync_service: Arc<SyncService>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1008 | media: Arc<MediaService>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1009 | command_capacity: usize, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1010 | event_capacity: usize, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1011 | ) -> (ClientHandle, DriverPort, EventStream) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1012 | let (request_tx, request_rx) = mpsc::channel(command_capacity); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1013 | let (event_tx, event_rx) = mpsc::channel(event_capacity); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1014 | let (connection_tx, connection_rx) = watch::channel(ConnectionState::Idle); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1015 | ( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1016 | ClientHandle { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1017 | requests: request_tx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1018 | client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1019 | connection: connection_rx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1020 | notification_client: Arc::new(OnceCell::new()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1021 | sync_service, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1022 | media, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1023 | spaces: Arc::new(OnceCell::new()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1024 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1025 | DriverPort { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1026 | requests: request_rx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1027 | events: event_tx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1028 | connection: connection_tx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1029 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1030 | EventStream { events: event_rx }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1031 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1032 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1033 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1034 | fn normalise_push_notification( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1035 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1036 | event_id: &EventId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1037 | status: NotificationStatus, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1038 | ) -> PushNotificationStatus { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1039 | match status { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1040 | NotificationStatus::Event(item) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1041 | let event = match &item.raw_event { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1042 | RawNotificationEvent::Timeline(event) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1043 | PushNotificationEvent::Timeline(event.clone()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1044 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1045 | RawNotificationEvent::Invite(event) => PushNotificationEvent::Invite(event.clone()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1046 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1047 | PushNotificationStatus::Event(Box::new(PushNotification { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1048 | event_id: event_id.to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1049 | event, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1050 | sender: PushNotificationSender { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1051 | user_id: item.event.sender().to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1052 | display_name: item.sender_display_name, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1053 | avatar_url: item.sender_avatar_url.map(Into::into), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1054 | name_ambiguous: item.is_sender_name_ambiguous, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1055 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1056 | room: PushNotificationRoom { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1057 | room_id: room_id.to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1058 | name: item.room_computed_display_name, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1059 | avatar_url: item.room_avatar_url.map(Into::into), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1060 | canonical_alias: item |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1061 | .room_canonical_alias |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1062 | .as_deref() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1063 | .and_then(|alias| alias.parse().ok()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1064 | topic: item.room_topic, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1065 | encrypted: item.is_room_encrypted, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1066 | direct: item.room_is_dm, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1067 | joined_members_count: item.joined_members_count, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1068 | service_members: item |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1069 | .service_members |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1070 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1071 | .filter_map(|user_id| user_id.parse().ok()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1072 | .collect(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1073 | active_service_members_count: item.active_service_members_count, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1074 | space: item.is_space, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1075 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1076 | noisy: item.is_noisy, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1077 | has_mention: item.has_mention, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1078 | thread_id: item.thread_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1079 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1080 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1081 | NotificationStatus::EventNotFound => PushNotificationStatus::NotFound, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1082 | NotificationStatus::EventFilteredOut => PushNotificationStatus::FilteredOut, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1083 | NotificationStatus::EventRedacted => PushNotificationStatus::Redacted, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1084 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1085 | } |