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