96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1 | use std::sync::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 2 | Arc, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 3 | atomic::{AtomicU64, Ordering}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 4 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 5 | use std::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 6 | fmt, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 7 | pin::Pin, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 8 | task::{Context, Poll}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 9 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 10 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 11 | use matrix_sdk::{Client, RoomMemberships}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 12 | use matrix_sdk_ui::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 13 | notification_client::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 14 | NotificationClient, NotificationProcessSetup, NotificationStatus, RawNotificationEvent, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 15 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 16 | sync_service::SyncService, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 17 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 18 | use ruma::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 19 | EventId, RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 20 | events::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 21 | AnyGlobalAccountDataEventContent, AnyRoomAccountDataEvent, GlobalAccountDataEventType, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 22 | 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 thiserror::Error; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 27 | use tokio::sync::{OnceCell, mpsc, oneshot, watch}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 28 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 29 | use crate::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 30 | AccountCommand, Command, CommandId, ConnectionState, EncryptionState, Event, InteractiveAuth, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 31 | InteractiveAuthOutcome, MemberFilter, MemberSummary, NotificationCommand, OwnDevice, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 32 | PowerLevelChanges, PushNotification, PushNotificationEvent, PushNotificationStatus, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 33 | RoomListFilter, RoomNotificationMode, RoomNotificationSettings, RoomPowerLevels, RoomSummary, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 34 | encryption::encryption_state, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 35 | model::{PushNotificationRoom, PushNotificationSender}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 36 | normalise::{member_summary, room_summaries}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 37 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 38 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 39 | #[derive(Clone)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 40 | pub struct ClientHandle { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 41 | commands: mpsc::Sender<DriverRequest>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 42 | next_id: Arc<AtomicU64>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 43 | client: Client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 44 | connection: watch::Receiver<ConnectionState>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 45 | notification_client: Arc<OnceCell<NotificationClient>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 46 | sync_service: Arc<SyncService>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 47 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 48 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 49 | impl fmt::Debug for ClientHandle { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 50 | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 51 | formatter |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 52 | .debug_struct("ClientHandle") |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 53 | .finish_non_exhaustive() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 54 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 55 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 56 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 57 | impl ClientHandle { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 58 | /// Current credentials after a refresh. Persist this snapshot atomically |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 59 | /// when `Event::SessionTokensChanged` arrives; it contains secrets. |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 60 | #[cfg(feature = "sqlite")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 61 | pub fn session_record(&self) -> Result<crate::SessionRecord, crate::AccountError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 62 | crate::account::session_record(&self.client) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 63 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 64 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 65 | /// Queue a command and return its correlation ID, not its result. Drain |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 66 | /// `EventStream` concurrently and match one terminal result event by ID. |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 67 | /// A successful timeline send only means the SDK queue accepted it. |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 68 | pub async fn send(&self, command: Command) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 69 | let id = self.next_command_id(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 70 | self.commands |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 71 | .send(DriverRequest::Command(CommandEnvelope { id, command })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 72 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 73 | .map_err(|_| SendCommandError::Closed)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 74 | Ok(id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 75 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 76 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 77 | pub async fn delete_devices( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 78 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 79 | device_ids: Vec<ruma::OwnedDeviceId>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 80 | auth: Option<InteractiveAuth>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 81 | ) -> Result<InteractiveAuthOutcome, CommandResultError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 82 | let (reply, result) = oneshot::channel(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 83 | self.commands |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 84 | .send(DriverRequest::DeleteDevices { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 85 | id: self.next_command_id(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 86 | device_ids, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 87 | auth, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 88 | reply, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 89 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 90 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 91 | .map_err(|_| SendCommandError::Closed)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 92 | result.await.map_err(|_| CommandResultError::Closed)? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 93 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 94 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 95 | pub async fn rename_device( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 96 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 97 | device_id: ruma::OwnedDeviceId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 98 | display_name: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 99 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 100 | self.send(Command::Account(AccountCommand::RenameDevice { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 101 | device_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 102 | display_name: display_name.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 103 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 104 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 105 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 106 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 107 | pub async fn set_room_notification_mode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 108 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 109 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 110 | mode: RoomNotificationMode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 111 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 112 | self.send(Command::Notification(NotificationCommand::SetRoomMode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 113 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 114 | mode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 115 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 116 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 117 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 118 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 119 | pub async fn reset_room_notification_mode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 120 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 121 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 122 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 123 | self.send(Command::Notification(NotificationCommand::ResetRoomMode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 124 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 125 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 126 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 127 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 128 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 129 | pub async fn set_default_notification_mode( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 130 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 131 | encrypted: bool, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 132 | one_to_one: bool, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 133 | mode: RoomNotificationMode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 134 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 135 | self.send(Command::Notification(NotificationCommand::SetDefaultMode { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 136 | encrypted, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 137 | one_to_one, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 138 | mode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 139 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 140 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 141 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 142 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 143 | pub async fn add_notification_keyword( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 144 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 145 | keyword: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 146 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 147 | self.send(Command::Notification(NotificationCommand::AddKeyword( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 148 | keyword.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 149 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 150 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 151 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 152 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 153 | pub async fn remove_notification_keyword( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 154 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 155 | keyword: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 156 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 157 | self.send(Command::Notification(NotificationCommand::RemoveKeyword( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 158 | keyword.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 159 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 160 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 161 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 162 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 163 | pub async fn open_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 164 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 165 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 166 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 167 | self.send(Command::Room(crate::RoomCommand::Open(room_id))) |
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 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 171 | pub async fn close_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 172 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 173 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 174 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 175 | self.send(Command::Room(crate::RoomCommand::Close(room_id))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 176 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 177 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 178 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 179 | pub async fn open_thread( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 180 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 181 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 182 | root_event_id: ruma::OwnedEventId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 183 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 184 | self.send(Command::Timeline(crate::TimelineCommand::OpenThread { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 185 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 186 | root_event_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 187 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 188 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 189 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 190 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 191 | pub async fn close_thread( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 192 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 193 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 194 | root_event_id: ruma::OwnedEventId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 195 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 196 | self.send(Command::Timeline(crate::TimelineCommand::CloseThread { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 197 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 198 | root_event_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 199 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 200 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 201 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 202 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 203 | pub async fn join_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 204 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 205 | room: ruma::OwnedRoomOrAliasId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 206 | via: Vec<ruma::OwnedServerName>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 207 | ) -> Result<ruma::OwnedRoomId, CommandResultError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 208 | self.room_result(crate::RoomCommand::Join { room, via }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 209 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 210 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 211 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 212 | pub async fn leave_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 213 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 214 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 215 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 216 | self.send(Command::Room(crate::RoomCommand::Leave(room_id))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 217 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 218 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 219 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 220 | pub async fn forget_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 221 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 222 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 223 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 224 | self.send(Command::Room(crate::RoomCommand::Forget(room_id))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 225 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 226 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 227 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 228 | pub async fn accept_invite( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 229 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 230 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 231 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 232 | self.send(Command::Room(crate::RoomCommand::AcceptInvite(room_id))) |
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 reject_invite( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 237 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 238 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 239 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 240 | self.send(Command::Room(crate::RoomCommand::RejectInvite(room_id))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 241 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 242 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 243 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 244 | pub async fn invite_user( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 245 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 246 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 247 | user_id: ruma::OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 248 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 249 | self.send(Command::Room(crate::RoomCommand::InviteUser { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 250 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 251 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 252 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 253 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 254 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 255 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 256 | pub async fn kick_user( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 257 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 258 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 259 | user_id: ruma::OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 260 | reason: Option<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 261 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 262 | self.send(Command::Room(crate::RoomCommand::KickUser { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 263 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 264 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 265 | reason, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 266 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 267 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 268 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 269 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 270 | pub async fn ban_user( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 271 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 272 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 273 | user_id: ruma::OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 274 | reason: Option<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 275 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 276 | self.send(Command::Room(crate::RoomCommand::BanUser { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 277 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 278 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 279 | reason, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 280 | })) |
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 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 284 | pub async fn unban_user( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 285 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 286 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 287 | user_id: ruma::OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 288 | reason: Option<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 289 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 290 | self.send(Command::Room(crate::RoomCommand::UnbanUser { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 291 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 292 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 293 | reason, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 294 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 295 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 296 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 297 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 298 | pub async fn set_power_levels( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 299 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 300 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 301 | changes: PowerLevelChanges, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 302 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 303 | self.send(Command::Room(crate::RoomCommand::SetPowerLevels { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 304 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 305 | changes, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 306 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 307 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 308 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 309 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 310 | pub async fn set_user_power_level( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 311 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 312 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 313 | user_id: ruma::OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 314 | level: i64, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 315 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 316 | self.send(Command::Room(crate::RoomCommand::SetUserPowerLevel { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 317 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 318 | user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 319 | level, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 320 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 321 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 322 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 323 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 324 | pub async fn create_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 325 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 326 | options: crate::CreateRoomOptions, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 327 | ) -> Result<ruma::OwnedRoomId, CommandResultError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 328 | self.room_result(crate::RoomCommand::Create(options)).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 329 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 330 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 331 | pub async fn create_direct( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 332 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 333 | user_id: ruma::OwnedUserId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 334 | ) -> Result<ruma::OwnedRoomId, CommandResultError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 335 | self.room_result(crate::RoomCommand::CreateDirect(user_id)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 336 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 337 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 338 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 339 | async fn room_result( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 340 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 341 | command: crate::RoomCommand, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 342 | ) -> Result<ruma::OwnedRoomId, CommandResultError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 343 | let (reply, result) = oneshot::channel(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 344 | self.commands |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 345 | .send(DriverRequest::RoomResult { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 346 | id: self.next_command_id(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 347 | command, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 348 | reply, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 349 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 350 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 351 | .map_err(|_| SendCommandError::Closed)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 352 | result.await.map_err(|_| CommandResultError::Closed)? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 353 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 354 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 355 | pub async fn cancel_send( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 356 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 357 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 358 | transaction_id: ruma::OwnedTransactionId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 359 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 360 | self.send(Command::Room(crate::RoomCommand::CancelSend { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 361 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 362 | transaction_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 363 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 364 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 365 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 366 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 367 | pub async fn retry_send( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 368 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 369 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 370 | transaction_id: ruma::OwnedTransactionId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 371 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 372 | self.send(Command::Room(crate::RoomCommand::RetrySend { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 373 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 374 | transaction_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 375 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 376 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 377 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 378 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 379 | pub async fn upload_media( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 380 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 381 | timeline_id: crate::TimelineId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 382 | filename: String, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 383 | mimetype: String, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 384 | bytes: Vec<u8>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 385 | caption: Option<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 386 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 387 | self.send(Command::Media(crate::MediaCommand::Upload { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 388 | timeline_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 389 | filename, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 390 | mimetype, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 391 | bytes, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 392 | caption, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 393 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 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 upload_attachment( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 398 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 399 | upload: crate::AttachmentUpload, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 400 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 401 | self.send(Command::Media(crate::MediaCommand::UploadAttachment( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 402 | upload, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 403 | ))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 404 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 405 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 406 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 407 | pub async fn create_key_backup(&self) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 408 | self.send(Command::Encryption( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 409 | crate::EncryptionCommand::CreateKeyBackup, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 410 | )) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 411 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 412 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 413 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 414 | pub async fn enable_key_backup(&self) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 415 | self.send(Command::Encryption( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 416 | crate::EncryptionCommand::EnableKeyBackup, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 417 | )) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 418 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 419 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 420 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 421 | pub async fn disable_key_backup( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 422 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 423 | delete_from_server: bool, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 424 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 425 | self.send(Command::Encryption( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 426 | crate::EncryptionCommand::DisableKeyBackup { delete_from_server }, |
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 recover_key_backup( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 432 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 433 | recovery_key: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 434 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 435 | self.send(Command::Encryption( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 436 | crate::EncryptionCommand::RecoverKeyBackup(recovery_key.into()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 437 | )) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 438 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 439 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 440 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 441 | pub async fn start_verification( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 442 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 443 | target: crate::VerificationTarget, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 444 | ) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 445 | self.send(Command::Encryption( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 446 | crate::EncryptionCommand::StartVerification(target), |
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 fn try_send(&self, command: Command) -> Result<CommandId, SendCommandError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 452 | let id = self.next_command_id(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 453 | self.commands |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 454 | .try_send(DriverRequest::Command(CommandEnvelope { id, command })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 455 | .map_err(|error| match error { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 456 | mpsc::error::TrySendError::Full(_) => SendCommandError::Full, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 457 | mpsc::error::TrySendError::Closed(_) => SendCommandError::Closed, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 458 | })?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 459 | Ok(id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 460 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 461 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 462 | fn next_command_id(&self) -> CommandId { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 463 | CommandId::new(self.next_id.fetch_add(1, Ordering::Relaxed)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 464 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 465 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 466 | pub async fn rooms(&self) -> Vec<RoomSummary> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 467 | room_summaries(&self.client).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 468 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 469 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 470 | pub async fn rooms_filtered(&self, filter: &RoomListFilter) -> Vec<RoomSummary> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 471 | let mut room_filter = filter.clone(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 472 | let search = room_filter |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 473 | .search |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 474 | .take() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 475 | .map(|search| search.to_lowercase()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 476 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 477 | self.rooms() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 478 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 479 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 480 | .filter(|room| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 481 | room_filter.matches(room) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 482 | && search.as_ref().is_none_or(|search| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 483 | room.name.to_lowercase().contains(search) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 484 | || room.room_id.as_str().to_lowercase().contains(search) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 485 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 486 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 487 | .collect() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 488 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 489 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 490 | pub async fn devices(&self) -> Result<Vec<OwnDevice>, ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 491 | let current_device_id = self.client.device_id(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 492 | Ok(self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 493 | .client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 494 | .devices() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 495 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 496 | .map_err(|source| ClientQueryError::Sdk(source.into()))? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 497 | .devices |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 498 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 499 | .map(|device| OwnDevice { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 500 | current: current_device_id == Some(device.device_id.as_ref()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 501 | device_id: device.device_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 502 | display_name: device.display_name, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 503 | last_seen_ip: device.last_seen_ip, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 504 | last_seen_timestamp_ms: device.last_seen_ts.map(|timestamp| timestamp.get().into()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 505 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 506 | .collect()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 507 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 508 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 509 | pub async fn room_notification_settings( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 510 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 511 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 512 | ) -> Result<Option<RoomNotificationSettings>, ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 513 | let room = self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 514 | .client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 515 | .get_room(room_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 516 | .ok_or_else(|| ClientQueryError::RoomUnknown(room_id.to_owned()))?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 517 | let custom = room.user_defined_notification_mode().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 518 | let mode = match custom { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 519 | Some(mode) => mode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 520 | None => match room.notification_mode().await { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 521 | Some(mode) => mode, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 522 | None => return Ok(None), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 523 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 524 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 525 | Ok(Some(RoomNotificationSettings { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 526 | mode: crate::normalise::notification_mode(mode), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 527 | custom: custom.is_some(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 528 | })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 529 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 530 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 531 | pub async fn notification_keywords(&self) -> Vec<String> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 532 | self.client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 533 | .notification_settings() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 534 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 535 | .enabled_keywords() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 536 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 537 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 538 | .collect() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 539 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 540 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 541 | pub async fn resolve_push_notification( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 542 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 543 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 544 | event_id: &EventId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 545 | ) -> Result<PushNotificationStatus, ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 546 | let client = self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 547 | .notification_client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 548 | .get_or_try_init(|| async { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 549 | NotificationClient::new( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 550 | self.client.clone(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 551 | NotificationProcessSetup::SingleProcess { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 552 | sync_service: self.sync_service.clone(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 553 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 554 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 555 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 556 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 557 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 558 | .map_err(ClientQueryError::Notification)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 559 | let status = client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 560 | .get_notification(room_id, event_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 561 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 562 | .map_err(ClientQueryError::Notification)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 563 | Ok(normalise_push_notification(room_id, event_id, status)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 564 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 565 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 566 | pub async fn members( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 567 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 568 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 569 | filter: MemberFilter, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 570 | ) -> Result<Vec<MemberSummary>, ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 571 | let room = self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 572 | .client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 573 | .get_room(room_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 574 | .ok_or_else(|| ClientQueryError::RoomUnknown(room_id.to_owned()))?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 575 | let memberships = match filter { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 576 | MemberFilter::Active => RoomMemberships::ACTIVE, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 577 | MemberFilter::Joined => RoomMemberships::JOIN, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 578 | MemberFilter::Invited => RoomMemberships::INVITE, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 579 | // An empty mask is the SDK's unfiltered wildcard: it matches every |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 580 | // membership, including custom states that `all()` would exclude. |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 581 | MemberFilter::All => RoomMemberships::empty(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 582 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 583 | Ok(room |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 584 | .members(memberships) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 585 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 586 | .map_err(ClientQueryError::Sdk)? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 587 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 588 | .map(member_summary) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 589 | .collect()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 590 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 591 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 592 | pub async fn room_power_levels( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 593 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 594 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 595 | ) -> Result<RoomPowerLevels, ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 596 | let room = self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 597 | .client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 598 | .get_room(room_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 599 | .ok_or_else(|| ClientQueryError::RoomUnknown(room_id.to_owned()))?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 600 | let levels = room |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 601 | .power_levels() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 602 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 603 | .map_err(|source| ClientQueryError::Sdk(source.into()))?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 604 | Ok(RoomPowerLevels { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 605 | ban: levels.ban.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 606 | invite: levels.invite.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 607 | kick: levels.kick.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 608 | redact: levels.redact.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 609 | events_default: levels.events_default.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 610 | state_default: levels.state_default.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 611 | users_default: levels.users_default.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 612 | room_notification: levels.notifications.room.into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 613 | users: levels |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 614 | .users |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 615 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 616 | .map(|(user_id, level)| (user_id, level.into())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 617 | .collect(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 618 | events: levels |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 619 | .events |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 620 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 621 | .map(|(event_type, level)| (event_type.to_string(), level.into())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 622 | .collect(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 623 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 624 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 625 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 626 | pub async fn pending_send_ids( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 627 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 628 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 629 | ) -> Result<Vec<ruma::OwnedTransactionId>, ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 630 | let room = self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 631 | .client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 632 | .get_room(room_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 633 | .ok_or_else(|| ClientQueryError::RoomUnknown(room_id.to_owned()))?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 634 | let (echoes, _) = room |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 635 | .send_queue() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 636 | .subscribe() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 637 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 638 | .map_err(ClientQueryError::SendQueue)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 639 | Ok(echoes |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 640 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 641 | .filter(|echo| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 642 | matches!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 643 | echo.content, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 644 | matrix_sdk::send_queue::LocalEchoContent::Event { .. } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 645 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 646 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 647 | .map(|echo| echo.transaction_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 648 | .collect()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 649 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 650 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 651 | pub async fn global_account_data( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 652 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 653 | event_type: GlobalAccountDataEventType, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 654 | ) -> Result<Option<Raw<AnyGlobalAccountDataEventContent>>, ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 655 | self.client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 656 | .account() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 657 | .account_data_raw(event_type) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 658 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 659 | .map_err(ClientQueryError::Sdk) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 660 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 661 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 662 | pub async fn set_global_account_data( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 663 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 664 | event_type: GlobalAccountDataEventType, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 665 | content: Raw<AnyGlobalAccountDataEventContent>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 666 | ) -> Result<(), ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 667 | let (reply, result) = oneshot::channel(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 668 | self.commands |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 669 | .send(DriverRequest::SetGlobalAccountData { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 670 | event_type, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 671 | content, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 672 | reply, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 673 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 674 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 675 | .map_err(|_| ClientQueryError::EngineStopped)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 676 | result.await.map_err(|_| ClientQueryError::EngineStopped)? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 677 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 678 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 679 | pub async fn room_account_data( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 680 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 681 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 682 | event_type: RoomAccountDataEventType, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 683 | ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>, ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 684 | let room = self |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 685 | .client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 686 | .get_room(room_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 687 | .ok_or_else(|| ClientQueryError::RoomUnknown(room_id.to_owned()))?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 688 | room.account_data(event_type) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 689 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 690 | .map_err(ClientQueryError::Sdk) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 691 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 692 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 693 | pub async fn set_room_account_data( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 694 | &self, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 695 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 696 | event_type: RoomAccountDataEventType, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 697 | content: Raw<ruma::events::AnyRoomAccountDataEventContent>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 698 | ) -> Result<(), ClientQueryError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 699 | let (reply, result) = oneshot::channel(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 700 | self.commands |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 701 | .send(DriverRequest::SetRoomAccountData { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 702 | room_id: room_id.to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 703 | event_type, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 704 | content, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 705 | reply, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 706 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 707 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 708 | .map_err(|_| ClientQueryError::EngineStopped)?; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 709 | result.await.map_err(|_| ClientQueryError::EngineStopped)? |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 710 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 711 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 712 | #[must_use] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 713 | pub fn connection_state(&self) -> watch::Receiver<ConnectionState> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 714 | self.connection.clone() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 715 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 716 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 717 | #[must_use] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 718 | pub fn encryption_state(&self) -> Option<EncryptionState> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 719 | let device_id = self.client.device_id()?.to_owned(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 720 | let encryption = self.client.encryption(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 721 | Some(encryption_state( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 722 | device_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 723 | encryption.recovery().state(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 724 | encryption.verification_state().get(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 725 | encryption.backups().state(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 726 | )) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 727 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 728 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 729 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 730 | #[derive(Debug, Eq, PartialEq)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 731 | pub(crate) struct CommandEnvelope { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 732 | pub(crate) id: CommandId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 733 | pub(crate) command: Command, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 734 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 735 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 736 | #[derive(Debug)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 737 | pub(crate) enum DriverRequest { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 738 | Command(CommandEnvelope), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 739 | DeleteDevices { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 740 | id: CommandId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 741 | device_ids: Vec<ruma::OwnedDeviceId>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 742 | auth: Option<InteractiveAuth>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 743 | reply: oneshot::Sender<Result<InteractiveAuthOutcome, CommandResultError>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 744 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 745 | RoomResult { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 746 | id: CommandId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 747 | command: crate::RoomCommand, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 748 | reply: oneshot::Sender<Result<ruma::OwnedRoomId, CommandResultError>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 749 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 750 | SetGlobalAccountData { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 751 | event_type: GlobalAccountDataEventType, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 752 | content: Raw<AnyGlobalAccountDataEventContent>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 753 | reply: oneshot::Sender<Result<(), ClientQueryError>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 754 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 755 | SetRoomAccountData { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 756 | room_id: ruma::OwnedRoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 757 | event_type: RoomAccountDataEventType, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 758 | content: Raw<ruma::events::AnyRoomAccountDataEventContent>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 759 | reply: oneshot::Sender<Result<(), ClientQueryError>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 760 | }, |
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 | #[derive(Debug)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 764 | pub struct EventStream { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 765 | events: mpsc::Receiver<Event>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 766 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 767 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 768 | impl EventStream { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 769 | pub async fn recv(&mut self) -> Option<Event> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 770 | self.events.recv().await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 771 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 772 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 773 | pub fn try_recv(&mut self) -> Result<Event, mpsc::error::TryRecvError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 774 | self.events.try_recv() |
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 | impl futures_util::Stream for EventStream { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 779 | type Item = Event; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 780 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 781 | fn poll_next(mut self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Option<Self::Item>> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 782 | self.events.poll_recv(context) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 783 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 784 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 785 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 786 | #[derive(Debug)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 787 | pub(crate) struct DriverPort { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 788 | commands: mpsc::Receiver<DriverRequest>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 789 | events: mpsc::Sender<Event>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 790 | connection: watch::Sender<ConnectionState>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 791 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 792 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 793 | #[derive(Clone, Debug)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 794 | pub(crate) struct EventSender(mpsc::Sender<Event>); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 795 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 796 | impl EventSender { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 797 | pub(crate) async fn send(&self, event: Event) -> Result<(), SendEventError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 798 | self.0.send(event).await.map_err(|_| SendEventError::Closed) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 799 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 800 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 801 | /// Resolves once every [`EventStream`] receiver has been dropped, so the |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 802 | /// engine can notice a lost event consumer inside a `select!`. |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 803 | pub(crate) async fn closed(&self) { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 804 | self.0.closed().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 805 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 806 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 807 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 808 | impl DriverPort { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 809 | pub(crate) fn event_sender(&self) -> EventSender { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 810 | EventSender(self.events.clone()) |
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(crate) fn connection_sender(&self) -> watch::Sender<ConnectionState> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 814 | self.connection.clone() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 815 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 816 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 817 | pub async fn recv(&mut self) -> Option<DriverRequest> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 818 | self.commands.recv().await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 819 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 820 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 821 | pub async fn send(&self, event: Event) -> Result<(), SendEventError> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 822 | self.event_sender().send(event).await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 823 | } |
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 | #[derive(Clone, Copy, Debug, Eq, Error, PartialEq)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 827 | pub enum SendCommandError { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 828 | #[error("the command channel is full")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 829 | Full, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 830 | #[error("the engine has stopped")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 831 | Closed, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 832 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 833 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 834 | #[derive(Debug, Error)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 835 | pub enum CommandResultError { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 836 | #[error(transparent)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 837 | Send(#[from] SendCommandError), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 838 | #[error("the engine stopped before the operation completed")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 839 | Closed, |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 840 | #[error("{}", .0.message)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 841 | Failed(crate::CommandFailure), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 842 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 843 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 844 | #[derive(Debug, Error)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 845 | pub enum ClientQueryError { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 846 | #[error("room {0} is not available in the local store")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 847 | RoomUnknown(ruma::OwnedRoomId), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 848 | #[error("Matrix query failed")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 849 | Sdk(#[source] matrix_sdk::Error), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 850 | #[error("reading the send queue failed")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 851 | SendQueue(#[source] matrix_sdk::send_queue::RoomSendQueueError), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 852 | #[error("resolving the push notification failed")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 853 | Notification(#[source] matrix_sdk_ui::notification_client::Error), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 854 | #[error("the engine stopped before the operation completed")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 855 | EngineStopped, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 856 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 857 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 858 | #[derive(Clone, Copy, Debug, Eq, Error, PartialEq)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 859 | pub(crate) enum SendEventError { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 860 | #[error("the event receiver has closed")] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 861 | Closed, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 862 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 863 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 864 | #[must_use] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 865 | pub(crate) fn transport_pair( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 866 | client: Client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 867 | sync_service: Arc<SyncService>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 868 | command_capacity: usize, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 869 | event_capacity: usize, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 870 | ) -> (ClientHandle, DriverPort, EventStream) { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 871 | let (command_tx, command_rx) = mpsc::channel(command_capacity); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 872 | let (event_tx, event_rx) = mpsc::channel(event_capacity); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 873 | let (connection_tx, connection_rx) = watch::channel(ConnectionState::Idle); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 874 | ( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 875 | ClientHandle { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 876 | commands: command_tx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 877 | next_id: Arc::new(AtomicU64::new(1)), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 878 | client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 879 | connection: connection_rx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 880 | notification_client: Arc::new(OnceCell::new()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 881 | sync_service, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 882 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 883 | DriverPort { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 884 | commands: command_rx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 885 | events: event_tx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 886 | connection: connection_tx, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 887 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 888 | EventStream { events: event_rx }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 889 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 890 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 891 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 892 | fn normalise_push_notification( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 893 | room_id: &RoomId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 894 | event_id: &EventId, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 895 | status: NotificationStatus, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 896 | ) -> PushNotificationStatus { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 897 | match status { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 898 | NotificationStatus::Event(item) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 899 | let event = match &item.raw_event { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 900 | RawNotificationEvent::Timeline(event) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 901 | PushNotificationEvent::Timeline(event.clone()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 902 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 903 | RawNotificationEvent::Invite(event) => PushNotificationEvent::Invite(event.clone()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 904 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 905 | PushNotificationStatus::Event(Box::new(PushNotification { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 906 | event_id: event_id.to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 907 | event, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 908 | sender: PushNotificationSender { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 909 | user_id: item.event.sender().to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 910 | display_name: item.sender_display_name, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 911 | avatar_url: item.sender_avatar_url.map(Into::into), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 912 | name_ambiguous: item.is_sender_name_ambiguous, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 913 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 914 | room: PushNotificationRoom { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 915 | room_id: room_id.to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 916 | name: item.room_computed_display_name, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 917 | avatar_url: item.room_avatar_url.map(Into::into), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 918 | canonical_alias: item |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 919 | .room_canonical_alias |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 920 | .as_deref() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 921 | .and_then(|alias| alias.parse().ok()), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 922 | topic: item.room_topic, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 923 | encrypted: item.is_room_encrypted, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 924 | direct: item.room_is_dm, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 925 | joined_members_count: item.joined_members_count, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 926 | service_members: item |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 927 | .service_members |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 928 | .into_iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 929 | .filter_map(|user_id| user_id.parse().ok()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 930 | .collect(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 931 | active_service_members_count: item.active_service_members_count, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 932 | space: item.is_space, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 933 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 934 | noisy: item.is_noisy, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 935 | has_mention: item.has_mention, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 936 | thread_id: item.thread_id, |
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 | NotificationStatus::EventNotFound => PushNotificationStatus::NotFound, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 940 | NotificationStatus::EventFilteredOut => PushNotificationStatus::FilteredOut, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 941 | NotificationStatus::EventRedacted => PushNotificationStatus::Redacted, |
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 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 945 | #[cfg(test)] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 946 | mod tests { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 947 | use matrix_sdk::{Client, SessionMeta, SessionTokens, authentication::matrix::MatrixSession}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 948 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 949 | use crate::{ConnectionState, LifecycleCommand}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 950 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 951 | use super::*; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 952 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 953 | async fn sync_service(client: Client) -> Arc<SyncService> { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 954 | Arc::new(SyncService::builder(client).build().await.unwrap()) |
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 | async fn test_client() -> Client { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 958 | let client = Client::builder() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 959 | .homeserver_url("http://localhost") |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 960 | .build() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 961 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 962 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 963 | client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 964 | .restore_session(MatrixSession { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 965 | meta: SessionMeta { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 966 | user_id: "@test:localhost".parse().unwrap(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 967 | device_id: "DEVICE".into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 968 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 969 | tokens: SessionTokens { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 970 | access_token: "access_token".to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 971 | refresh_token: None, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 972 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 973 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 974 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 975 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 976 | client |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 977 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 978 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 979 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 980 | async fn transports_are_isolated() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 981 | let first_client = test_client().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 982 | let second_client = test_client().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 983 | let (first_handle, mut first_driver, mut first_events) = |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 984 | transport_pair(first_client.clone(), sync_service(first_client).await, 2, 2); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 985 | let (_second_handle, mut second_driver, mut second_events) = transport_pair( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 986 | second_client.clone(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 987 | sync_service(second_client).await, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 988 | 2, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 989 | 2, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 990 | ); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 991 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 992 | let id = first_handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 993 | .send(Command::Lifecycle(LifecycleCommand::Shutdown)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 994 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 995 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 996 | let request = first_driver.recv().await.unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 997 | assert!(matches!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 998 | request, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 999 | DriverRequest::Command(CommandEnvelope { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1000 | id: received_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1001 | command: Command::Lifecycle(LifecycleCommand::Shutdown), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1002 | }) if received_id == id |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1003 | )); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1004 | assert!(second_driver.commands.try_recv().is_err()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1005 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1006 | first_driver |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1007 | .send(Event::ConnectionChanged(ConnectionState::Online)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1008 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1009 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1010 | assert_eq!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1011 | first_events.recv().await, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1012 | Some(Event::ConnectionChanged(ConnectionState::Online)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1013 | ); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1014 | assert!(second_events.try_recv().is_err()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1015 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1016 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1017 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1018 | async fn bounded_command_channel_reports_pressure() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1019 | let client = test_client().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1020 | let (handle, _driver, _events) = |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1021 | transport_pair(client.clone(), sync_service(client).await, 1, 1); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1022 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1023 | handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1024 | .try_send(Command::Lifecycle(LifecycleCommand::Shutdown)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1025 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1026 | assert_eq!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1027 | handle.try_send(Command::Lifecycle(LifecycleCommand::Shutdown)), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1028 | Err(SendCommandError::Full) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1029 | ); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1030 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1031 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1032 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1033 | async fn cloned_handles_share_command_id_sequence() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1034 | let client = test_client().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1035 | let (handle, mut driver, _events) = |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1036 | transport_pair(client.clone(), sync_service(client).await, 1, 1); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1037 | let cloned = handle.clone(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1038 | let first = handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1039 | .try_send(Command::Lifecycle(LifecycleCommand::Shutdown)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1040 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1041 | assert_eq!(first.get(), 1); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1042 | assert_eq!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1043 | cloned.try_send(Command::Lifecycle(LifecycleCommand::Shutdown)), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1044 | Err(SendCommandError::Full) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1045 | ); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1046 | driver.recv().await.unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1047 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1048 | let third = cloned |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1049 | .send(Command::Lifecycle(LifecycleCommand::Shutdown)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1050 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1051 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1052 | assert_eq!(third.get(), 3); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1053 | driver.recv().await.unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1054 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1055 | let fourth = handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1056 | .try_send(Command::Lifecycle(LifecycleCommand::Shutdown)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1057 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1058 | assert_eq!(fourth.get(), 4); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1059 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 1060 | } |