7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | // Copyright 2025 The Matrix.org Foundation C.I.C. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | // you may not use this file except in compliance with the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | // You may obtain a copy of the License at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | // Unless required by applicable law or agreed to in writing, software |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | // See the License for that specific language governing permissions and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | // limitations under the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | use std::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | collections::HashMap, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | fmt::Debug, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | path::PathBuf, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | sync::{Arc, OnceLock}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | time::Duration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | use anyhow::{Context as _, anyhow}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | use futures_util::pin_mut; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | #[cfg(feature = "sqlite")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | use matrix_sdk::STATE_STORE_DATABASE_NAME; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | use matrix_sdk::media::MediaFileHandle as SdkMediaFileHandle; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | use matrix_sdk::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | Account, AuthApi, AuthSession, Client as MatrixClient, Error, SessionChange, SessionTokens, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | authentication::oauth::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | ClientId, OAuthAuthorizationData, OAuthError as SdkOAuthError, OAuthSession, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | deserialized_responses::RawAnySyncOrStrippedTimelineEvent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | executor::AbortOnDrop, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | media::{MediaFormat, MediaRequestParameters, MediaRetentionPolicy, MediaThumbnailSettings}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | ruma::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | EventEncryptionAlgorithm, RoomId, TransactionId, UInt, UserId, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | api::client::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | account::request_openid_token, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | discovery::get_authorization_server_metadata::v1::Prompt as RumaOAuthPrompt, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | push::{EmailPusherData, PusherIds, PusherInit, PusherKind as RumaPusherKind}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | room::{Visibility, create_room}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | rtc::RtcTransport, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | session::get_login_types, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | user_directory::search_users, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | events::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | AnyInitialStateEvent, InitialStateEvent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | room::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | avatar::RoomAvatarEventContent, encryption::RoomEncryptionEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | message::MessageType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | serde::Raw, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | sliding_sync::Version as SdkSlidingSyncVersion, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 58 | store::RoomLoadSettings as SdkRoomLoadSettings, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 59 | sync::Notification, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 60 | task_monitor::BackgroundTaskFailureReason, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 61 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 62 | use matrix_sdk_common::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 63 | SendOutsideWasm, SyncOutsideWasm, cross_process_lock::CrossProcessLockConfig, stream::StreamExt, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 64 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 65 | use matrix_sdk_ui::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 66 | notification_client::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 67 | NotificationClient as MatrixNotificationClient, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 68 | NotificationProcessSetup as MatrixNotificationProcessSetup, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 69 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 70 | spaces::SpaceService as UISpaceService, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 71 | unable_to_decrypt_hook::UtdHookManager, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 72 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 73 | use mime::Mime; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 74 | use oauth2::Scope; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 75 | use ruma::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 76 | OwnedDeviceId, OwnedMxcUri, OwnedServerName, RoomAliasId, RoomOrAliasId, ServerName, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 77 | api::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 78 | client::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 79 | alias::get_alias, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 80 | discovery::get_authorization_server_metadata::v1::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 81 | AccountManagementActionData, DeviceDeleteData, DeviceViewData, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 82 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 83 | profile::{AvatarUrl, DisplayName}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 84 | room::create_room::{RoomPowerLevelsContentOverride, v3::CreationContent}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 85 | uiaa::{EmailUserIdentifier, UserIdentifier}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 86 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 87 | error::ErrorKind, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 88 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 89 | events::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 90 | AnyMessageLikeEventContent, AnySyncTimelineEvent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 91 | GlobalAccountDataEvent as RumaGlobalAccountDataEvent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 92 | RoomAccountDataEvent as RumaRoomAccountDataEvent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 93 | direct::DirectEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 94 | fully_read::FullyReadEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 95 | identity_server::IdentityServerEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 96 | ignored_user_list::IgnoredUserListEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 97 | key::verification::request::ToDeviceKeyVerificationRequestEvent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 98 | marked_unread::{MarkedUnreadEventContent, UnstableMarkedUnreadEventContent}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 99 | push_rules::PushRulesEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 100 | room::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 101 | history_visibility::RoomHistoryVisibilityEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 102 | join_rules::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 103 | AllowRule as RumaAllowRule, JoinRule as RumaJoinRule, RoomJoinRulesEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 104 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 105 | message::{OriginalSyncRoomMessageEvent, Relation}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 106 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 107 | secret_storage::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 108 | default_key::SecretStorageDefaultKeyEventContent, key::SecretStorageKeyEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 109 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 110 | tag::TagEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 111 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 112 | push::{HttpPusherData as RumaHttpPusherData, PushFormat as RumaPushFormat}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 113 | room::RoomType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 114 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 115 | use serde::{Deserialize, Serialize}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 116 | use serde_json::{Value, json}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 117 | use tokio::sync::broadcast::error::RecvError; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 118 | use tracing::{debug, error, warn}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 119 | use url::Url; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 120 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 121 | use super::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 122 | room::{Room, room_info::RoomInfo}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 123 | session_verification::SessionVerificationController, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 124 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 125 | use crate::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 126 | ClientError, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 127 | authentication::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 128 | HomeserverLoginDetails, OAuthConfiguration, OAuthError, SsoError, SsoHandler, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 129 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 130 | client, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 131 | encryption::Encryption, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 132 | live_locations_observer::BeaconInfoUpdate, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 133 | notification::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 134 | NotificationClient, NotificationEvent, NotificationItem, NotificationRoomInfo, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 135 | NotificationSenderInfo, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 136 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 137 | notification_settings::NotificationSettings, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 138 | qr_code::{GrantLoginWithQrCodeHandler, LoginWithQrCodeHandler}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 139 | room::{RoomHistoryVisibility, RoomInfoListener, RoomSendQueueUpdate}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 140 | room_directory_search::RoomDirectorySearch, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 141 | room_preview::RoomPreview, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 142 | ruma::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 143 | AccountDataEvent, AccountDataEventType, AuthData, InviteAvatars, MediaPreviewConfig, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 144 | MediaPreviews, MediaSource, RoomAccountDataEvent, RoomAccountDataEventType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 145 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 146 | runtime::get_runtime_handle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 147 | spaces::SpaceService, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 148 | sync_service::{SyncService, SyncServiceBuilder}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 149 | sync_v2::{SyncListenerV2, SyncResponseV2, SyncSettingsV2}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 150 | task_handle::TaskHandle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 151 | utd::{UnableToDecryptDelegate, UtdHook}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 152 | utils::AsyncRuntimeDropped, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 153 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 154 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 155 | #[derive(Clone, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 156 | pub struct PusherIdentifiers { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 157 | pub pushkey: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 158 | pub app_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 159 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 160 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 161 | impl From<PusherIdentifiers> for PusherIds { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 162 | fn from(value: PusherIdentifiers) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 163 | Self::new(value.pushkey, value.app_id) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 164 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 165 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 166 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 167 | #[derive(Clone, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 168 | pub struct HttpPusherData { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 169 | pub url: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 170 | pub format: Option<PushFormat>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 171 | pub default_payload: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 172 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 173 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 174 | #[derive(Clone, uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 175 | pub enum PusherKind { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 176 | Http { data: HttpPusherData }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 177 | Email, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 178 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 179 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 180 | impl TryFrom<PusherKind> for RumaPusherKind { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 181 | type Error = anyhow::Error; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 182 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 183 | fn try_from(value: PusherKind) -> anyhow::Result<Self> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 184 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 185 | PusherKind::Http { data } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 186 | let mut ruma_data = RumaHttpPusherData::new(data.url); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 187 | if let Some(payload) = data.default_payload { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 188 | let json: Value = serde_json::from_str(&payload)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 189 | ruma_data.data.insert("default_payload".to_owned(), json); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 190 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 191 | ruma_data.format = data.format.map(Into::into); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 192 | Ok(Self::Http(ruma_data)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 193 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 194 | PusherKind::Email => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 195 | let ruma_data = EmailPusherData::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 196 | Ok(Self::Email(ruma_data)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 197 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 198 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 199 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 200 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 201 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 202 | #[derive(Clone, uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 203 | pub enum PushFormat { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 204 | EventIdOnly, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 205 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 206 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 207 | impl From<PushFormat> for RumaPushFormat { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 208 | fn from(value: PushFormat) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 209 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 210 | client::PushFormat::EventIdOnly => Self::EventIdOnly, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 211 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 212 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 213 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 214 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 215 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 216 | pub trait ClientDelegate: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 217 | /// A callback invoked whenever the SDK runs into an unknown token error. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 218 | fn did_receive_auth_error(&self, is_soft_logout: bool); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 219 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 220 | /// A callback invoked when a background task registered with the client's |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 221 | /// task monitor encounters an error. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 222 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 223 | /// Can default to an empty implementation, if the embedder doesn't care |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 224 | /// about handling background jobs errors. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 225 | fn on_background_task_error_report( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 226 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 227 | task_name: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 228 | error: BackgroundTaskFailureReason, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 229 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 230 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 231 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 232 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 233 | pub trait ClientSessionDelegate: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 234 | fn retrieve_session_from_keychain(&self, user_id: String) -> Result<Session, ClientError>; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 235 | fn save_session_in_keychain(&self, session: Session); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 236 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 237 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 238 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 239 | pub trait ProgressWatcher: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 240 | fn transmission_progress(&self, progress: TransmissionProgress); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 241 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 242 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 243 | /// A listener to the global (client-wide) update reporter of the send queue. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 244 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 245 | pub trait SendQueueRoomUpdateListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 246 | /// Called every time the send queue emits an update for a given room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 247 | fn on_update(&self, room_id: String, update: RoomSendQueueUpdate); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 248 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 249 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 250 | /// A listener to the global (client-wide) error reporter of the send queue. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 251 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 252 | pub trait SendQueueRoomErrorListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 253 | /// Called every time the send queue has ran into an error for a given room, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 254 | /// which will disable the send queue for that particular room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 255 | fn on_error(&self, room_id: String, error: ClientError); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 256 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 257 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 258 | /// A listener for changes of global account data events. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 259 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 260 | pub trait AccountDataListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 261 | /// Called when a global account data event has changed. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 262 | fn on_change(&self, event: AccountDataEvent); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 263 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 264 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 265 | /// A listener for duplicate key upload errors triggered by requests to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 266 | /// /keys/upload. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 267 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 268 | pub trait DuplicateKeyUploadErrorListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 269 | /// Called once when uploading keys fails. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 270 | fn on_duplicate_key_upload_error(&self, message: Option<DuplicateOneTimeKeyErrorMessage>); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 271 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 272 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 273 | /// A listener for the current user's client-wide beacon_info updates. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 274 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 275 | pub trait BeaconInfoListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 276 | /// Called whenever the current user's beacon_info changes in any room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 277 | fn on_update(&self, update: BeaconInfoUpdate); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 278 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 279 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 280 | /// Information about the old and new key that caused a duplicate key upload |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 281 | /// error in /keys/upload. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 282 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 283 | pub struct DuplicateOneTimeKeyErrorMessage { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 284 | /// The previously uploaded one-time key, encoded as unpadded base64. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 285 | pub old_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 286 | /// The one-time key we attempted to upload, encoded as unpadded base64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 287 | pub new_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 288 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 289 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 290 | impl From<matrix_sdk::encryption::DuplicateOneTimeKeyErrorMessage> |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 291 | for DuplicateOneTimeKeyErrorMessage |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 292 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 293 | fn from(value: matrix_sdk::encryption::DuplicateOneTimeKeyErrorMessage) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 294 | Self { old_key: value.old_key.to_base64(), new_key: value.new_key.to_base64() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 295 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 296 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 297 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 298 | /// A listener for changes of room account data events. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 299 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 300 | pub trait RoomAccountDataListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 301 | /// Called when a room account data event was changed. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 302 | fn on_change(&self, event: RoomAccountDataEvent, room_id: String); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 303 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 304 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 305 | /// A listener for notifications generated from sync responses. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 306 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 307 | /// This is called during sync for each event that triggers a notification |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 308 | /// based on the user's push rules. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 309 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 310 | pub trait SyncNotificationListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 311 | /// Called when a notifying event is received during sync. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 312 | fn on_notification(&self, notification: NotificationItem, room_id: String); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 313 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 314 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 315 | #[derive(Clone, Copy, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 316 | pub struct TransmissionProgress { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 317 | pub current: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 318 | pub total: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 319 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 320 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 321 | impl From<matrix_sdk::TransmissionProgress> for TransmissionProgress { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 322 | fn from(value: matrix_sdk::TransmissionProgress) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 323 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 324 | current: value.current.try_into().unwrap_or(u64::MAX), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 325 | total: value.total.try_into().unwrap_or(u64::MAX), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 326 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 327 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 328 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 329 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 330 | #[derive(Clone, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 331 | pub struct OpenIdToken { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 332 | pub access_token: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 333 | pub token_type: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 334 | pub matrix_server_name: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 335 | pub expires_in_seconds: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 336 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 337 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 338 | impl From<request_openid_token::v3::Response> for OpenIdToken { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 339 | fn from(value: request_openid_token::v3::Response) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 340 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 341 | access_token: value.access_token, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 342 | token_type: serde_json::to_value(&value.token_type) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 343 | .ok() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 344 | .and_then(|value| value.as_str().map(ToOwned::to_owned)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 345 | .unwrap_or_else(|| format!("{:?}", value.token_type)), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 346 | matrix_server_name: value.matrix_server_name.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 347 | expires_in_seconds: value.expires_in.as_secs(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 348 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 349 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 350 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 351 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 352 | struct ClientDelegateData { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 353 | /// The delegate itself, that will receive the callbacks. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 354 | delegate: Arc<dyn ClientDelegate>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 355 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 356 | // The background task error listener task, that will forward errors occurring in background |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 357 | // jobs to the delegate. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 358 | _background_error_listener_task: Arc<AbortOnDrop<()>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 359 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 360 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 361 | #[derive(uniffi::Object)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 362 | pub struct Client { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 363 | pub(crate) inner: AsyncRuntimeDropped<MatrixClient>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 364 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 365 | delegate_data: OnceLock<ClientDelegateData>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 366 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 367 | pub(crate) utd_hook_manager: OnceLock<Arc<UtdHookManager>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 368 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 369 | session_verification_controller: |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 370 | Arc<tokio::sync::RwLock<Option<SessionVerificationController>>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 371 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 372 | /// The path to the directory where the state store and the crypto store are |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 373 | /// located, if the `Client` instance has been built with a store (either |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 374 | /// SQLite or IndexedDB). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 375 | #[cfg_attr(not(feature = "sqlite"), allow(unused))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 376 | store_path: Option<PathBuf>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 377 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 378 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 379 | impl Client { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 380 | pub async fn new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 381 | sdk_client: MatrixClient, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 382 | session_delegate: Option<Arc<dyn ClientSessionDelegate>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 383 | store_path: Option<PathBuf>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 384 | ) -> Result<Self, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 385 | let session_verification_controller: Arc< |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 386 | tokio::sync::RwLock<Option<SessionVerificationController>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 387 | > = Default::default(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 388 | let controller = session_verification_controller.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 389 | sdk_client.add_event_handler( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 390 | move |event: ToDeviceKeyVerificationRequestEvent| async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 391 | if let Some(session_verification_controller) = &*controller.clone().read().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 392 | session_verification_controller |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 393 | .process_incoming_verification_request( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 394 | &event.sender, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 395 | event.content.transaction_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 396 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 397 | .await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 398 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 399 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 400 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 401 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 402 | let controller = session_verification_controller.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 403 | sdk_client.add_event_handler(move |event: OriginalSyncRoomMessageEvent| async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 404 | if let MessageType::VerificationRequest(_) = &event.content.msgtype |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 405 | && let Some(session_verification_controller) = &*controller.clone().read().await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 406 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 407 | session_verification_controller |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 408 | .process_incoming_verification_request(&event.sender, event.event_id) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 409 | .await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 410 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 411 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 412 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 413 | let store_mode = sdk_client.cross_process_lock_config(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 414 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 415 | let client = Client { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 416 | inner: AsyncRuntimeDropped::new(sdk_client.clone()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 417 | delegate_data: OnceLock::new(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 418 | utd_hook_manager: OnceLock::new(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 419 | session_verification_controller, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 420 | store_path, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 421 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 422 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 423 | match store_mode { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 424 | CrossProcessLockConfig::MultiProcess { holder_name } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 425 | if session_delegate.is_none() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 426 | return Err(anyhow::anyhow!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 427 | "missing session delegates with multi-process lock configuration" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 428 | ))?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 429 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 430 | client.inner.oauth().enable_cross_process_refresh_lock(holder_name.clone()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 431 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 432 | CrossProcessLockConfig::SingleProcess => {} |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 433 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 434 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 435 | if let Some(session_delegate) = session_delegate { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 436 | client.inner.set_session_callbacks( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 437 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 438 | let session_delegate = session_delegate.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 439 | Box::new(move |client| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 440 | let session_delegate = session_delegate.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 441 | let user_id = client.user_id().context("user isn't logged in")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 442 | Ok(Self::retrieve_session(session_delegate, user_id)?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 443 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 444 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 445 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 446 | let session_delegate = session_delegate.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 447 | Box::new(move |client| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 448 | let session_delegate = session_delegate.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 449 | Ok(Self::save_session(session_delegate, client)?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 450 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 451 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 452 | )?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 453 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 454 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 455 | Ok(client) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 456 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 457 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 458 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 459 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 460 | impl Client { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 461 | /// Perform database optimizations if any are available, i.e. vacuuming in |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 462 | /// SQLite. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 463 | pub async fn optimize_stores(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 464 | Ok(self.inner.optimize_stores().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 465 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 466 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 467 | /// Pause the client for background suspension. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 468 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 469 | /// This method: |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 470 | /// 1. Disables all send queues (prevents new message sends). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 471 | /// 2. Pauses all database stores, waiting for in-flight operations and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 472 | /// releasing all connections and file locks. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 473 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 474 | /// Call [`Client::resume()`] when the app returns to the foreground. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 475 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 476 | /// # iOS |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 477 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 478 | /// Call this before the app is suspended to avoid `0xdead10cc` kills. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 479 | /// Typically called from |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 480 | /// [`applicationDidEnterBackground`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/applicationdidenterbackground(_:)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 481 | /// or an equivalent SwiftUI lifecycle event, *after* stopping the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 482 | /// `matrix_sdk_ui::sync_service::SyncService`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 483 | pub async fn pause(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 484 | Ok(self.inner.pause().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 485 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 486 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 487 | /// Resume the client after a [`Client::pause()`]. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 488 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 489 | /// Re-acquires store resources and re-enables send queues. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 490 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 491 | /// If your app stopped the `matrix_sdk_ui::sync_service::SyncService` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 492 | /// before pausing, restart it separately as appropriate for your app |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 493 | /// lifecycle. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 494 | pub async fn resume(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 495 | Ok(self.inner.resume().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 496 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 497 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 498 | /// Returns the sizes of the existing stores, if known. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 499 | pub async fn get_store_sizes(&self) -> Result<StoreSizes, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 500 | Ok(self.inner.get_store_sizes().await?.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 501 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 502 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 503 | /// Information about login options for the client's homeserver. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 504 | pub async fn homeserver_login_details(&self) -> Arc<HomeserverLoginDetails> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 505 | let oauth = self.inner.oauth(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 506 | let (supports_oauth_login, supported_oauth_prompts) = match oauth.server_metadata().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 507 | Ok(metadata) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 508 | let prompts = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 509 | metadata.prompt_values_supported.into_iter().map(Into::into).collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 510 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 511 | (true, prompts) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 512 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 513 | Err(error) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 514 | error!("Failed to fetch OAuth provider metadata: {error}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 515 | (false, Default::default()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 516 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 517 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 518 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 519 | let login_types = self.inner.matrix_auth().get_login_types().await.ok(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 520 | let supports_password_login = login_types |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 521 | .as_ref() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 522 | .map(|login_types| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 523 | login_types.flows.iter().any(|login_type| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 524 | matches!(login_type, get_login_types::v3::LoginType::Password(_)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 525 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 526 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 527 | .unwrap_or(false); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 528 | let supports_sso_login = login_types |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 529 | .as_ref() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 530 | .map(|login_types| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 531 | login_types |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 532 | .flows |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 533 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 534 | .any(|login_type| matches!(login_type, get_login_types::v3::LoginType::Sso(_))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 535 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 536 | .unwrap_or(false); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 537 | let sliding_sync_version = self.sliding_sync_version(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 538 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 539 | Arc::new(HomeserverLoginDetails { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 540 | url: self.homeserver(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 541 | sliding_sync_version, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 542 | supports_oauth_login, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 543 | supported_oauth_prompts, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 544 | supports_sso_login, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 545 | supports_password_login, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 546 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 547 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 548 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 549 | /// Login using a username and password. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 550 | pub async fn login( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 551 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 552 | username: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 553 | password: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 554 | initial_device_name: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 555 | device_id: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 556 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 557 | let mut builder = self.inner.matrix_auth().login_username(&username, &password); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 558 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 559 | if let Some(initial_device_name) = initial_device_name.as_ref() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 560 | builder = builder.initial_device_display_name(initial_device_name); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 561 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 562 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 563 | if let Some(device_id) = device_id.as_ref() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 564 | builder = builder.device_id(device_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 565 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 566 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 567 | builder.send().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 568 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 569 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 570 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 571 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 572 | /// Login using JWT |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 573 | /// This is an implementation of the custom_login https://docs.rs/matrix-sdk/latest/matrix_sdk/matrix_auth/struct.MatrixAuth.html#method.login_custom |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 574 | /// For more information on logging in with JWT: https://element-hq.github.io/synapse/latest/jwt.html |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 575 | pub async fn custom_login_with_jwt( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 576 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 577 | jwt: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 578 | initial_device_name: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 579 | device_id: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 580 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 581 | let data = json!({ "token": jwt }).as_object().unwrap().clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 582 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 583 | let mut builder = self.inner.matrix_auth().login_custom("org.matrix.login.jwt", data)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 584 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 585 | if let Some(initial_device_name) = initial_device_name.as_ref() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 586 | builder = builder.initial_device_display_name(initial_device_name); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 587 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 588 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 589 | if let Some(device_id) = device_id.as_ref() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 590 | builder = builder.device_id(device_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 591 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 592 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 593 | builder.send().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 594 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 595 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 596 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 597 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 598 | /// Login using an email and password. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 599 | pub async fn login_with_email( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 600 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 601 | email: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 602 | password: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 603 | initial_device_name: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 604 | device_id: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 605 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 606 | let mut builder = self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 607 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 608 | .matrix_auth() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 609 | .login_identifier(UserIdentifier::Email(EmailUserIdentifier::new(email)), &password); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 610 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 611 | if let Some(initial_device_name) = initial_device_name.as_ref() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 612 | builder = builder.initial_device_display_name(initial_device_name); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 613 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 614 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 615 | if let Some(device_id) = device_id.as_ref() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 616 | builder = builder.device_id(device_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 617 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 618 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 619 | builder.send().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 620 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 621 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 622 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 623 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 624 | /// Returns a handler to start the SSO login process. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 625 | pub(crate) async fn start_sso_login( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 626 | self: &Arc<Self>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 627 | redirect_url: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 628 | idp_id: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 629 | ) -> Result<Arc<SsoHandler>, SsoError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 630 | let auth = self.inner.matrix_auth(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 631 | let url = auth |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 632 | .get_sso_login_url(redirect_url.as_str(), idp_id.as_deref()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 633 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 634 | .map_err(|e| SsoError::Generic { message: e.to_string() })?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 635 | Ok(Arc::new(SsoHandler { client: Arc::clone(self), url })) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 636 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 637 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 638 | /// Requests the URL needed for opening a web view using OAuth. Once the web |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 639 | /// view has succeeded, call `login_with_oauth_callback` with the callback |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 640 | /// it returns. If a failure occurs and a callback isn't available, make |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 641 | /// sure to call `abort_oauth_auth` to inform the client of this. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 642 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 643 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 644 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 645 | /// * `oauth_configuration` - The configuration used to load the credentials |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 646 | /// of the client if it is already registered with the authorization |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 647 | /// server, or register the client and store its credentials if it isn't. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 648 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 649 | /// * `prompt` - The desired user experience in the web UI. No value means |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 650 | /// that the user wishes to login into an existing account, and a value of |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 651 | /// `Create` means that the user wishes to register a new account. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 652 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 653 | /// * `login_hint` - A generic login hint that an identity provider can use |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 654 | /// to pre-fill the login form. The format of this hint is not restricted |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 655 | /// by the spec as external providers all have their own way to handle the hint. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 656 | /// However, it should be noted that when providing a user ID as a hint |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 657 | /// for MAS (with no upstream provider), then the format to use is defined |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 658 | /// by [MSC4198]: https://github.com/matrix-org/matrix-spec-proposals/pull/4198 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 659 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 660 | /// * `device_id` - The unique ID that will be associated with the session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 661 | /// If not set, a random one will be generated. It can be an existing |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 662 | /// device ID from a previous login call. Note that this should be done |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 663 | /// only if the client also holds the corresponding encryption keys. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 664 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 665 | /// * `additional_scopes` - Additional scopes to request from the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 666 | /// authorization server, e.g. "urn:matrix:client:com.example.msc9999.foo". |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 667 | /// The scopes for API access and the device ID according to the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 668 | /// [specification](https://spec.matrix.org/v1.15/client-server-api/#allocated-scope-tokens) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 669 | /// are always requested. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 670 | pub async fn url_for_oauth( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 671 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 672 | oauth_configuration: &OAuthConfiguration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 673 | prompt: Option<OAuthPrompt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 674 | login_hint: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 675 | device_id: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 676 | additional_scopes: Option<Vec<String>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 677 | ) -> Result<Arc<OAuthAuthorizationData>, OAuthError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 678 | let registration_data = oauth_configuration.registration_data()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 679 | let redirect_uri = oauth_configuration.redirect_uri()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 680 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 681 | let device_id = device_id.map(OwnedDeviceId::from); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 682 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 683 | let additional_scopes = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 684 | additional_scopes.map(|scopes| scopes.into_iter().map(Scope::new).collect::<Vec<_>>()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 685 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 686 | let mut url_builder = self.inner.oauth().login( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 687 | redirect_uri, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 688 | device_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 689 | Some(registration_data), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 690 | additional_scopes, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 691 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 692 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 693 | if let Some(prompt) = prompt { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 694 | url_builder = url_builder.prompt(vec![prompt.into()]); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 695 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 696 | if let Some(login_hint) = login_hint { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 697 | url_builder = url_builder.login_hint(login_hint); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 698 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 699 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 700 | let data = url_builder.build().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 701 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 702 | Ok(Arc::new(data)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 703 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 704 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 705 | /// Aborts an existing OAuth login operation that might have been cancelled, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 706 | /// failed etc. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 707 | pub async fn abort_oauth_auth(&self, authorization_data: Arc<OAuthAuthorizationData>) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 708 | self.inner.oauth().abort_login(&authorization_data.state).await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 709 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 710 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 711 | /// Completes the OAuth login process. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 712 | pub async fn login_with_oauth_callback(&self, callback_url: String) -> Result<(), OAuthError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 713 | let url = Url::parse(&callback_url).or(Err(OAuthError::CallbackUrlInvalid))?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 714 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 715 | self.inner.oauth().finish_login(url.into()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 716 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 717 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 718 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 719 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 720 | /// Create a handler for requesting an existing device to grant login to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 721 | /// this device by way of a QR code. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 722 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 723 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 724 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 725 | /// * `oauth_configuration` - The data to restore or register the client |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 726 | /// with the server. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 727 | pub fn new_login_with_qr_code_handler( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 728 | self: Arc<Self>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 729 | oauth_configuration: OAuthConfiguration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 730 | ) -> LoginWithQrCodeHandler { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 731 | LoginWithQrCodeHandler::new(self.inner.oauth(), oauth_configuration) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 732 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 733 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 734 | /// Create a handler for granting login from this device to a new device by |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 735 | /// way of a QR code. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 736 | pub fn new_grant_login_with_qr_code_handler(self: Arc<Self>) -> GrantLoginWithQrCodeHandler { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 737 | GrantLoginWithQrCodeHandler::new(self.inner.oauth()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 738 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 739 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 740 | /// Restores the client from a `Session`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 741 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 742 | /// It reloads the entire set of rooms from the previous session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 743 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 744 | /// If you want to control the amount of rooms to reloads, check |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 745 | /// [`Client::restore_session_with`]. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 746 | pub async fn restore_session(&self, session: Session) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 747 | self.restore_session_with(session, RoomLoadSettings::All).await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 748 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 749 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 750 | /// Restores the client from a `Session`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 751 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 752 | /// It reloads a set of rooms controlled by [`RoomLoadSettings`]. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 753 | pub async fn restore_session_with( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 754 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 755 | session: Session, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 756 | room_load_settings: RoomLoadSettings, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 757 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 758 | let sliding_sync_version = session.sliding_sync_version.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 759 | let auth_session: AuthSession = session.try_into()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 760 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 761 | self.inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 762 | .restore_session_with( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 763 | auth_session, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 764 | room_load_settings |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 765 | .try_into() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 766 | .map_err(|error| ClientError::from_str(error, None))?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 767 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 768 | .await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 769 | self.inner.set_sliding_sync_version(sliding_sync_version.try_into()?); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 770 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 771 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 772 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 773 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 774 | /// Enables or disables all the room send queues at once. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 775 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 776 | /// When connectivity is lost on a device, it is recommended to disable the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 777 | /// room sending queues. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 778 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 779 | /// This can be controlled for individual rooms, using |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 780 | /// [`Room::enable_send_queue`]. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 781 | pub async fn enable_all_send_queues(&self, enable: bool) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 782 | self.inner.send_queue().set_enabled(enable).await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 783 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 784 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 785 | /// Enables or disables progress reporting for media uploads in the send |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 786 | /// queue. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 787 | pub fn enable_send_queue_upload_progress(&self, enable: bool) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 788 | self.inner.send_queue().enable_upload_progress(enable); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 789 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 790 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 791 | /// Subscribe to the global send queue update reporter, at the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 792 | /// client-wide level. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 793 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 794 | /// The given listener will be immediately called with |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 795 | /// `RoomSendQueueUpdate::NewLocalEvent` for each local echo existing in |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 796 | /// the queue. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 797 | pub async fn subscribe_to_send_queue_updates( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 798 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 799 | listener: Box<dyn SendQueueRoomUpdateListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 800 | ) -> Result<Arc<TaskHandle>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 801 | let q = self.inner.send_queue(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 802 | let local_echoes = q.local_echoes().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 803 | let mut subscriber = q.subscribe(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 804 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 805 | for (room_id, local_echoes) in local_echoes { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 806 | for local_echo in local_echoes { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 807 | listener.on_update( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 808 | room_id.clone().into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 809 | RoomSendQueueUpdate::NewLocalEvent { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 810 | transaction_id: local_echo.transaction_id.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 811 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 812 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 813 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 814 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 815 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 816 | Ok(Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 817 | loop { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 818 | match subscriber.recv().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 819 | Ok(update) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 820 | let room_id = update.room_id.to_string(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 821 | match update.update.try_into() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 822 | Ok(update) => listener.on_update(room_id, update), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 823 | Err(err) => error!("error when converting send queue update: {err}"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 824 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 825 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 826 | Err(err) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 827 | error!("error when listening to the send queue update reporter: {err}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 828 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 829 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 830 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 831 | })))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 832 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 833 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 834 | /// Subscribe to the global enablement status of the send queue, at the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 835 | /// client-wide level. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 836 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 837 | /// The given listener will be immediately called with the initial value of |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 838 | /// the enablement status. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 839 | pub fn subscribe_to_send_queue_status( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 840 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 841 | listener: Box<dyn SendQueueRoomErrorListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 842 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 843 | let q = self.inner.send_queue(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 844 | let mut subscriber = q.subscribe_errors(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 845 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 846 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 847 | // Respawn tasks for rooms that had unsent events. At this point we've just |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 848 | // created the subscriber, so it'll be notified about errors. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 849 | q.respawn_tasks_for_rooms_with_unsent_requests().await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 850 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 851 | loop { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 852 | match subscriber.recv().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 853 | Ok(report) => listener |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 854 | .on_error(report.room_id.to_string(), ClientError::from_err(report.error)), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 855 | Err(err) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 856 | error!("error when listening to the send queue error reporter: {err}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 857 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 858 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 859 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 860 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 861 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 862 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 863 | /// Subscribe to duplicate key upload errors triggered by requests to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 864 | /// /keys/upload. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 865 | pub fn subscribe_to_duplicate_key_upload_errors( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 866 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 867 | listener: Box<dyn DuplicateKeyUploadErrorListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 868 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 869 | let mut subscriber = self.inner.subscribe_to_duplicate_key_upload_errors(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 870 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 871 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 872 | loop { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 873 | match subscriber.recv().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 874 | Ok(message) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 875 | listener.on_duplicate_key_upload_error(message.map(|m| m.into())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 876 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 877 | Err(err) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 878 | error!("error when listening to key upload errors: {err}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 879 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 880 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 881 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 882 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 883 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 884 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 885 | /// Subscribe to beacon_info updates for the current user across all rooms. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 886 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 887 | /// The listener is only called for new matching updates; there is no |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 888 | /// initial replay. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 889 | pub fn subscribe_to_own_beacon_info_updates( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 890 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 891 | listener: Box<dyn BeaconInfoListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 892 | ) -> Result<Arc<TaskHandle>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 893 | let stream = self.inner.observe_own_beacon_info_updates()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 894 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 895 | Ok(Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 896 | pin_mut!(stream); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 897 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 898 | while let Some(update) = stream.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 899 | listener.on_update(update.into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 900 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 901 | })))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 902 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 903 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 904 | /// Subscribe to updates of global account data events. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 905 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 906 | /// Be careful that only the most recent value can be observed. Subscribers |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 907 | /// are notified when a new value is sent, but there is no guarantee that |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 908 | /// they will see all values. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 909 | pub fn observe_account_data_event( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 910 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 911 | event_type: AccountDataEventType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 912 | listener: Box<dyn AccountDataListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 913 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 914 | macro_rules! observe { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 915 | ($t:ty, $cb: expr) => {{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 916 | // Using an Arc here is mandatory or else the subscriber will never trigger |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 917 | let observer = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 918 | Arc::new(self.inner.observe_events::<RumaGlobalAccountDataEvent<$t>, ()>()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 919 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 920 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 921 | let mut subscriber = observer.subscribe(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 922 | loop { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 923 | if let Some(next) = subscriber.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 924 | $cb(next.0); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 925 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 926 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 927 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 928 | }}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 929 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 930 | ($t:ty) => {{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 931 | observe!($t, |event: RumaGlobalAccountDataEvent<$t>| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 932 | listener.on_change(event.into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 933 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 934 | }}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 935 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 936 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 937 | match event_type { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 938 | AccountDataEventType::Direct => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 939 | observe!(DirectEventContent) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 940 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 941 | AccountDataEventType::IdentityServer => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 942 | observe!(IdentityServerEventContent) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 943 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 944 | AccountDataEventType::IgnoredUserList => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 945 | observe!(IgnoredUserListEventContent) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 946 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 947 | AccountDataEventType::PushRules => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 948 | observe!(PushRulesEventContent, |event: RumaGlobalAccountDataEvent< |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 949 | PushRulesEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 950 | >| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 951 | if let Ok(event) = event.try_into() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 952 | listener.on_change(event); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 953 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 954 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 955 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 956 | AccountDataEventType::SecretStorageDefaultKey => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 957 | observe!(SecretStorageDefaultKeyEventContent) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 958 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 959 | AccountDataEventType::SecretStorageKey { key_id } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 960 | observe!(SecretStorageKeyEventContent, |event: RumaGlobalAccountDataEvent< |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 961 | SecretStorageKeyEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 962 | >| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 963 | if event.content.key_id != key_id { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 964 | return; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 965 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 966 | if let Ok(event) = event.try_into() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 967 | listener.on_change(event); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 968 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 969 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 970 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 971 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 972 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 973 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 974 | /// Subscribe to updates of room account data events. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 975 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 976 | /// Be careful that only the most recent value can be observed. Subscribers |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 977 | /// are notified when a new value is sent, but there is no guarantee that |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 978 | /// they will see all values. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 979 | pub fn observe_room_account_data_event( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 980 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 981 | room_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 982 | event_type: RoomAccountDataEventType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 983 | listener: Box<dyn RoomAccountDataListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 984 | ) -> Result<Arc<TaskHandle>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 985 | macro_rules! observe { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 986 | ($t:ty, $cb: expr) => {{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 987 | // Using an Arc here is mandatory or else the subscriber will never trigger |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 988 | let observer = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 989 | Arc::new(self.inner.observe_room_events::<RumaRoomAccountDataEvent<$t>, ()>( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 990 | &RoomId::parse(&room_id)?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 991 | )); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 992 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 993 | Ok(Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 994 | let mut subscriber = observer.subscribe(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 995 | loop { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 996 | if let Some(next) = subscriber.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 997 | $cb(next.0); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 998 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 999 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1000 | })))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1001 | }}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1002 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1003 | ($t:ty) => {{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1004 | observe!($t, |event: RumaRoomAccountDataEvent<$t>| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1005 | listener.on_change(event.into(), room_id.clone()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1006 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1007 | }}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1008 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1009 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1010 | match event_type { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1011 | RoomAccountDataEventType::FullyRead => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1012 | observe!(FullyReadEventContent) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1013 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1014 | RoomAccountDataEventType::MarkedUnread => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1015 | observe!(MarkedUnreadEventContent) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1016 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1017 | RoomAccountDataEventType::Tag => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1018 | observe!(TagEventContent, |event: RumaRoomAccountDataEvent<TagEventContent>| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1019 | if let Ok(event) = event.try_into() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1020 | listener.on_change(event, room_id.clone()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1021 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1022 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1023 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1024 | RoomAccountDataEventType::UnstableMarkedUnread => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1025 | observe!(UnstableMarkedUnreadEventContent) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1026 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1027 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1028 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1029 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1030 | /// Register a handler for notifications generated from sync responses. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1031 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1032 | /// The handler will be called during sync for each event that triggers |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1033 | /// a notification based on the user's push rules. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1034 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1035 | /// The handler receives: |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1036 | /// - The notification with push actions and event data |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1037 | /// - The room ID where the notification occurred |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1038 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1039 | /// This is useful for implementing custom notification logic, such as |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1040 | /// displaying local notifications or updating notification badges. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1041 | pub async fn register_notification_handler(&self, listener: Box<dyn SyncNotificationListener>) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1042 | let listener = Arc::new(listener); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1043 | self.inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1044 | .register_notification_handler(move |notification, room, _client| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1045 | notification_handler(notification, room, listener.clone()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1046 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1047 | .await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1048 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1049 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1050 | /// Allows generic GET requests to be made through the SDK's internal HTTP |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1051 | /// client. This is useful when the caller's native HTTP client wouldn't |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1052 | /// have the same configuration (such as certificates, proxies, etc.) This |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1053 | /// method returns the raw bytes of the response, so that any kind of |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1054 | /// resource can be fetched including images, files, etc. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1055 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1056 | /// Note: When an HTTP error occurs, the error response can be found in the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1057 | /// `ClientError::Generic`'s `details` field. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1058 | pub async fn get_url(&self, url: String) -> Result<Vec<u8>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1059 | let response = self.inner.http_client().get(url).send().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1060 | if response.status().is_success() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1061 | Ok(response.bytes().await?.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1062 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1063 | Err(ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1064 | msg: response.status().to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1065 | details: response.text().await.ok(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1066 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1067 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1068 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1069 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1070 | /// Empty the server version and unstable features cache. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1071 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1072 | /// Since the SDK caches the supported versions, it's possible to have a |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1073 | /// stale entry in the cache. This functions makes it possible to force |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1074 | /// reset it. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1075 | pub async fn reset_supported_versions(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1076 | Ok(self.inner.reset_supported_versions().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1077 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1078 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1079 | /// Empty the well-known cache. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1080 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1081 | /// Since the SDK caches the well-known, it's possible to have a stale |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1082 | /// entry in the cache. This functions makes it possible to force reset |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1083 | /// it. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1084 | pub async fn reset_well_known(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1085 | Ok(self.inner.reset_well_known().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1086 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1087 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1088 | /// Retrieves a media file from the media source |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1089 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1090 | /// Not available on Wasm platforms, due to lack of accessible file system. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1091 | pub async fn get_media_file( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1092 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1093 | media_source: Arc<MediaSource>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1094 | filename: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1095 | mime_type: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1096 | use_cache: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1097 | temp_dir: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1098 | ) -> Result<Arc<MediaFileHandle>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1099 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1100 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1101 | let source = (*media_source).clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1102 | let mime_type: mime::Mime = mime_type.parse()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1103 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1104 | let handle = self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1105 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1106 | .media() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1107 | .get_media_file( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1108 | &MediaRequestParameters { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1109 | source: source.media_source, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1110 | format: MediaFormat::File, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1111 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1112 | filename, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1113 | &mime_type, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1114 | use_cache, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1115 | temp_dir, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1116 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1117 | .await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1118 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1119 | Ok(Arc::new(MediaFileHandle::new(handle))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1120 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1121 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1122 | /// MediaFileHandle uses SdkMediaFileHandle which requires an |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1123 | /// intermediate TempFile which is not available on wasm |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1124 | /// platforms due to lack of an accessible file system. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1125 | #[cfg(target_family = "wasm")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1126 | Err(ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1127 | msg: "get_media_file is not supported on wasm platforms".to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1128 | details: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1129 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1130 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1131 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1132 | pub async fn set_display_name(&self, name: String) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1133 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1134 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1135 | self.inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1136 | .account() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1137 | .set_display_name(Some(name.as_str())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1138 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1139 | .context("Unable to set display name")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1140 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1141 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1142 | #[cfg(target_family = "wasm")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1143 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1144 | self.inner.account().set_display_name(Some(name.as_str())).await.map_err(|e| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1145 | ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1146 | msg: "Unable to set display name".to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1147 | details: Some(e.to_string()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1148 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1149 | })?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1150 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1151 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1152 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1153 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1154 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1155 | /// The sliding sync version. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1156 | pub fn sliding_sync_version(&self) -> SlidingSyncVersion { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1157 | self.inner.sliding_sync_version().into() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1158 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1159 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1160 | /// Find all sliding sync versions that are available. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1161 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1162 | /// Be careful: This method may hit the store and will send new requests for |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1163 | /// each call. It can be costly to call it repeatedly. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1164 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1165 | /// If `.well-known` or `/versions` is unreachable, it will simply move |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1166 | /// potential sliding sync versions aside. No error will be reported. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1167 | pub async fn available_sliding_sync_versions(&self) -> Vec<SlidingSyncVersion> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1168 | self.inner.available_sliding_sync_versions().await.into_iter().map(Into::into).collect() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1169 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1170 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1171 | /// Sets the [ClientDelegate] which will inform about authentication errors. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1172 | /// Returns an error if the delegate was already set. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1173 | pub fn set_delegate( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1174 | self: Arc<Self>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1175 | delegate: Option<Box<dyn ClientDelegate>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1176 | ) -> Result<Option<Arc<TaskHandle>>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1177 | if self.delegate_data.get().is_some() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1178 | return Err(ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1179 | msg: "Delegate already initialized".to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1180 | details: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1181 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1182 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1183 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1184 | let handle = delegate.map(|delegate| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1185 | let mut session_change_receiver = self.inner.subscribe_to_session_changes(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1186 | let client_clone = self.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1187 | let session_change_task = get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1188 | loop { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1189 | match session_change_receiver.recv().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1190 | Ok(session_change) => client_clone.process_session_change(session_change), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1191 | Err(receive_error) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1192 | if let RecvError::Closed = receive_error { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1193 | break; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1194 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1195 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1196 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1197 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1198 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1199 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1200 | let delegate: Arc<dyn ClientDelegate> = delegate.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1201 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1202 | let client = self.inner.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1203 | let delegate_clone = delegate.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1204 | let task = Arc::new(AbortOnDrop::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1205 | let mut receiver = client.task_monitor().subscribe(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1206 | while let Ok(error) = receiver.recv().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1207 | delegate_clone.on_background_task_error_report(error.task.name, error.reason); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1208 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1209 | }))); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1210 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1211 | let delegate_data = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1212 | ClientDelegateData { delegate, _background_error_listener_task: task }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1213 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1214 | self.delegate_data.get_or_init(|| delegate_data); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1215 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1216 | Arc::new(TaskHandle::new(session_change_task)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1217 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1218 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1219 | Ok(handle) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1220 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1221 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1222 | /// Sets the [`UnableToDecryptDelegate`] which will inform about UTDs. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1223 | /// Returns an error if the delegate was already set. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1224 | pub async fn set_utd_delegate( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1225 | self: Arc<Self>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1226 | utd_delegate: Box<dyn UnableToDecryptDelegate>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1227 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1228 | if self.utd_hook_manager.get().is_some() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1229 | return Err(ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1230 | msg: "UTD delegate already initialized".to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1231 | details: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1232 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1233 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1234 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1235 | // UTDs detected before this duration may be reclassified as "late decryption" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1236 | // events (or discarded, if they get decrypted fast enough). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1237 | const UTD_HOOK_GRACE_PERIOD: Duration = Duration::from_secs(60); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1238 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1239 | let mut utd_hook_manager = UtdHookManager::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1240 | Arc::new(UtdHook { delegate: utd_delegate.into() }), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1241 | (*self.inner).clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1242 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1243 | .with_max_delay(UTD_HOOK_GRACE_PERIOD); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1244 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1245 | if let Err(e) = utd_hook_manager.reload_from_store().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1246 | error!("Unable to reload UTD hook data from data store: {e}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1247 | // Carry on with the setup anyway; we shouldn't fail setup just |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1248 | // because the UTD hook failed to load its data. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1249 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1250 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1251 | self.utd_hook_manager.get_or_init(|| Arc::new(utd_hook_manager)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1252 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1253 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1254 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1255 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1256 | pub fn session(&self) -> Result<Session, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1257 | Self::session_inner((*self.inner).clone()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1258 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1259 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1260 | pub async fn account_url( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1261 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1262 | action: Option<AccountManagementAction>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1263 | ) -> Result<Option<String>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1264 | if !matches!(self.inner.auth_api(), Some(AuthApi::OAuth(..))) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1265 | return Ok(None); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1266 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1267 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1268 | let server_metadata = match self.inner.oauth().cached_server_metadata().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1269 | Ok(server_metadata) => server_metadata, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1270 | Err(e) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1271 | error!("Failed retrieving cached server metadata: {e}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1272 | return Err(SdkOAuthError::from(e).into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1273 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1274 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1275 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1276 | Ok(if let Some(action) = &action { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1277 | server_metadata.account_management_url_with_action(action.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1278 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1279 | server_metadata.account_management_uri |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1280 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1281 | .map(Into::into)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1282 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1283 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1284 | pub fn user_id(&self) -> Result<String, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1285 | let user_id = self.inner.user_id().context("No User ID found")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1286 | Ok(user_id.to_string()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1287 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1288 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1289 | /// The server name part of the current user ID |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1290 | pub fn user_id_server_name(&self) -> Result<String, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1291 | let user_id = self.inner.user_id().context("No User ID found")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1292 | Ok(user_id.server_name().to_string()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1293 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1294 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1295 | pub async fn display_name(&self) -> Result<String, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1296 | let display_name = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1297 | self.inner.account().get_display_name().await?.context("No User ID found")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1298 | Ok(display_name) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1299 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1300 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1301 | pub async fn request_openid_token(&self) -> Result<OpenIdToken, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1302 | Ok(self.inner.account().request_openid_token().await?.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1303 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1304 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1305 | pub async fn upload_avatar(&self, mime_type: String, data: Vec<u8>) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1306 | let mime: Mime = mime_type.parse()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1307 | self.inner.account().upload_avatar(&mime, data).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1308 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1309 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1310 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1311 | /// Updates the user's avatar using the provided MXC url. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1312 | pub async fn set_avatar_url(&self, url: String) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1313 | // MxcUri can't just be instantiated, serde deserialization seems to be the only |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1314 | // way |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1315 | let mxc = serde_json::from_str::<OwnedMxcUri>(&url)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1316 | // Validate the newly generated MxcUri |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1317 | mxc.validate().map_err(ClientError::from_err)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1318 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1319 | self.inner.account().set_avatar_url(Some(&mxc)).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1320 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1321 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1322 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1323 | pub async fn remove_avatar(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1324 | self.inner.account().set_avatar_url(None).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1325 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1326 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1327 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1328 | /// Sends a request to retrieve the avatar URL. Will fill the cache used by |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1329 | /// [`Self::cached_avatar_url`] on success. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1330 | pub async fn avatar_url(&self) -> Result<Option<String>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1331 | let avatar_url = self.inner.account().get_avatar_url().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1332 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1333 | Ok(avatar_url.map(|u| u.to_string())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1334 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1335 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1336 | /// Retrieves an avatar cached from a previous call to [`Self::avatar_url`]. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1337 | pub async fn cached_avatar_url(&self) -> Result<Option<String>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1338 | Ok(self.inner.account().get_cached_avatar_url().await?.map(Into::into)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1339 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1340 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1341 | pub fn device_id(&self) -> Result<String, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1342 | let device_id = self.inner.device_id().context("No Device ID found")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1343 | Ok(device_id.to_string()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1344 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1345 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1346 | pub async fn create_room(&self, request: CreateRoomParameters) -> Result<String, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1347 | let response = self.inner.create_room(request.try_into()?).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1348 | Ok(String::from(response.room_id())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1349 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1350 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1351 | /// Get the content of the event of the given type out of the account data |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1352 | /// store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1353 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1354 | /// It will be returned as a JSON string. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1355 | pub async fn account_data(&self, event_type: String) -> Result<Option<String>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1356 | let event = self.inner.account().account_data_raw(event_type.into()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1357 | Ok(event.map(|e| e.json().get().to_owned())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1358 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1359 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1360 | /// Set the given account data content for the given event type. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1361 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1362 | /// It should be supplied as a JSON string. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1363 | pub async fn set_account_data( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1364 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1365 | event_type: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1366 | content: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1367 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1368 | let raw_content = Raw::from_json_string(content)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1369 | self.inner.account().set_account_data_raw(event_type.into(), raw_content).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1370 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1371 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1372 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1373 | pub async fn upload_media( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1374 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1375 | mime_type: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1376 | data: Vec<u8>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1377 | progress_watcher: Option<Box<dyn ProgressWatcher>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1378 | ) -> Result<String, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1379 | let mime_type: mime::Mime = mime_type.parse().context("Parsing mime type")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1380 | let request = self.inner.media().upload(&mime_type, data, None); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1381 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1382 | if let Some(progress_watcher) = progress_watcher { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1383 | let mut subscriber = request.subscribe_to_send_progress(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1384 | get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1385 | while let Some(progress) = subscriber.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1386 | progress_watcher.transmission_progress(progress.into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1387 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1388 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1389 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1390 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1391 | let response = request.await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1392 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1393 | Ok(String::from(response.content_uri)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1394 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1395 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1396 | pub async fn get_media_content( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1397 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1398 | media_source: Arc<MediaSource>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1399 | ) -> Result<Vec<u8>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1400 | let source = (*media_source).clone().media_source; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1401 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1402 | debug!(?source, "requesting media file"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1403 | Ok(self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1404 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1405 | .media() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1406 | .get_media_content(&MediaRequestParameters { source, format: MediaFormat::File }, true) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1407 | .await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1408 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1409 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1410 | pub async fn get_media_thumbnail( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1411 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1412 | media_source: Arc<MediaSource>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1413 | width: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1414 | height: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1415 | ) -> Result<Vec<u8>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1416 | let source = (*media_source).clone().media_source; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1417 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1418 | debug!(?source, width, height, "requesting media thumbnail"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1419 | Ok(self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1420 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1421 | .media() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1422 | .get_media_content( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1423 | &MediaRequestParameters { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1424 | source, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1425 | format: MediaFormat::Thumbnail(MediaThumbnailSettings::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1426 | UInt::new(width).unwrap(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1427 | UInt::new(height).unwrap(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1428 | )), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1429 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1430 | true, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1431 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1432 | .await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1433 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1434 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1435 | pub async fn get_session_verification_controller( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1436 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1437 | ) -> Result<Arc<SessionVerificationController>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1438 | if let Some(session_verification_controller) = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1439 | &*self.session_verification_controller.read().await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1440 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1441 | return Ok(Arc::new(session_verification_controller.clone())); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1442 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1443 | let user_id = self.inner.user_id().context("Failed retrieving current user_id")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1444 | let user_identity = self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1445 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1446 | .encryption() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1447 | .get_user_identity(user_id) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1448 | .await? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1449 | .context("Failed retrieving user identity")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1450 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1451 | let session_verification_controller = SessionVerificationController::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1452 | self.inner.encryption(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1453 | user_identity, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1454 | self.inner.account(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1455 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1456 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1457 | *self.session_verification_controller.write().await = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1458 | Some(session_verification_controller.clone()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1459 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1460 | Ok(Arc::new(session_verification_controller)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1461 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1462 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1463 | /// Log the current user out. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1464 | pub async fn logout(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1465 | Ok(self.inner.logout().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1466 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1467 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1468 | /// Registers a pusher with given parameters |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1469 | #[allow(clippy::too_many_arguments)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1470 | pub async fn set_pusher( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1471 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1472 | identifiers: PusherIdentifiers, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1473 | kind: PusherKind, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1474 | app_display_name: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1475 | device_display_name: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1476 | profile_tag: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1477 | lang: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1478 | append: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1479 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1480 | let ids = identifiers.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1481 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1482 | let pusher_init = PusherInit { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1483 | ids, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1484 | kind: kind.try_into()?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1485 | app_display_name, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1486 | device_display_name, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1487 | profile_tag, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1488 | lang, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1489 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1490 | self.inner.pusher().set(pusher_init.into(), append).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1491 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1492 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1493 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1494 | /// Deletes a pusher of given pusher ids |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1495 | pub async fn delete_pusher(&self, identifiers: PusherIdentifiers) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1496 | self.inner.pusher().delete(identifiers.into()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1497 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1498 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1499 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1500 | /// The homeserver this client is configured to use. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1501 | pub fn homeserver(&self) -> String { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1502 | self.inner.homeserver().to_string() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1503 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1504 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1505 | /// The URL of the server. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1506 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1507 | /// Not to be confused with the `Self::homeserver`. `server` is usually |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1508 | /// the server part in a user ID, e.g. with `@mnt_io:matrix.org`, here |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1509 | /// `matrix.org` is the server, whilst `matrix-client.matrix.org` is the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1510 | /// homeserver (at the time of writing — 2024-08-28). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1511 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1512 | /// This value is optional depending on how the `Client` has been built. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1513 | /// If it's been built from a homeserver URL directly, we don't know the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1514 | /// server. However, if the `Client` has been built from a server URL or |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1515 | /// name, then the homeserver has been discovered, and we know both. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1516 | pub fn server(&self) -> Option<String> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1517 | self.inner.server().map(ToString::to_string) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1518 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1519 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1520 | pub fn rooms(&self) -> Vec<Arc<Room>> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1521 | self.inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1522 | .rooms() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1523 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1524 | .map(|room| Arc::new(Room::new(room, self.utd_hook_manager.get().cloned()))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1525 | .collect() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1526 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1527 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1528 | /// Mark all joined rooms as read by sending public, private and fully-read |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1529 | /// receipts on each room's latest event. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1530 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1531 | /// This is a best-effort operation — per-room errors are logged and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1532 | /// skipped. Receipts are sent unthreaded, which per the Matrix spec |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1533 | /// covers all events in a room including those inside threads. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1534 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1535 | /// This is useful to mitigate backend led wrong iOS app badges and work |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1536 | /// around https://github.com/element-hq/element-x-ios/issues/3151 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1537 | pub async fn mark_all_rooms_as_read(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1538 | use matrix_sdk::room::Receipts; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1539 | use matrix_sdk_base::RoomStateFilter; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1540 | use matrix_sdk_ui::timeline::{TimelineBuilder, TimelineFocus}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1541 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1542 | for sdk_room in self.inner.rooms_filtered(RoomStateFilter::JOINED) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1543 | let timeline = match TimelineBuilder::new(&sdk_room) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1544 | .with_focus(TimelineFocus::Live { hide_threaded_events: false }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1545 | .build() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1546 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1547 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1548 | Ok(tl) => tl, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1549 | Err(err) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1550 | warn!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1551 | "mark_all_rooms_as_read: failed to build timeline for {}: {err}", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1552 | sdk_room.room_id() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1553 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1554 | continue; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1555 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1556 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1557 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1558 | if let Some(event_id) = timeline.latest_event_id().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1559 | let receipts = Receipts::new() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1560 | .fully_read_marker(event_id.clone()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1561 | .private_read_receipt(event_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1562 | if let Err(err) = sdk_room.send_multiple_receipts(receipts).await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1563 | warn!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1564 | "mark_all_rooms_as_read: failed to send receipts for {}: {err}", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1565 | sdk_room.room_id() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1566 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1567 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1568 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1569 | // Room has no events; just clear any stale explicit unread flag. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1570 | if let Err(err) = sdk_room.set_unread_flag(false).await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1571 | warn!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1572 | "mark_all_rooms_as_read: failed to clear unread flag for {}: {err}", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1573 | sdk_room.room_id() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1574 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1575 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1576 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1577 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1578 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1579 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1580 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1581 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1582 | /// Get a room by its ID. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1583 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1584 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1585 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1586 | /// * `room_id` - The ID of the room to get. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1587 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1588 | /// # Returns |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1589 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1590 | /// A `Result` containing an optional room, or a `ClientError`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1591 | /// This method will not initialize the room's timeline or populate it with |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1592 | /// events. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1593 | pub fn get_room(&self, room_id: String) -> Result<Option<Arc<Room>>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1594 | let room_id = RoomId::parse(room_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1595 | let sdk_room = self.inner.get_room(&room_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1596 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1597 | let room = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1598 | sdk_room.map(|room| Arc::new(Room::new(room, self.utd_hook_manager.get().cloned()))); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1599 | Ok(room) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1600 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1601 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1602 | /// Get the first existing DM room with the given user, if any. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1603 | pub fn get_dm_room(&self, user_id: String) -> Result<Option<Arc<Room>>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1604 | let user_id = UserId::parse(user_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1605 | let sdk_room = self.inner.get_dm_room(&user_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1606 | let dm = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1607 | sdk_room.map(|room| Arc::new(Room::new(room, self.utd_hook_manager.get().cloned()))); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1608 | Ok(dm) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1609 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1610 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1611 | /// Get an iterator with the existing DM rooms for the given user. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1612 | pub fn get_dm_rooms(&self, user_id: String) -> Result<Vec<Arc<Room>>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1613 | let user_id = UserId::parse(user_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1614 | let sdk_rooms = self.inner.get_dm_rooms(&user_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1615 | let dms = sdk_rooms |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1616 | .map(|room| Arc::new(Room::new(room, self.utd_hook_manager.get().cloned()))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1617 | .collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1618 | Ok(dms) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1619 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1620 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1621 | pub async fn search_users( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1622 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1623 | search_term: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1624 | limit: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1625 | ) -> Result<SearchUsersResults, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1626 | let response = self.inner.search_users(&search_term, limit).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1627 | Ok(SearchUsersResults::from(response)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1628 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1629 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1630 | pub async fn get_profile(&self, user_id: String) -> Result<UserProfile, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1631 | let user_id = <&UserId>::try_from(user_id.as_str())?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1632 | UserProfile::fetch(&self.inner.account(), user_id).await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1633 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1634 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1635 | pub async fn notification_client( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1636 | self: Arc<Self>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1637 | process_setup: NotificationProcessSetup, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1638 | ) -> Result<Arc<NotificationClient>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1639 | Ok(Arc::new(NotificationClient { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1640 | inner: MatrixNotificationClient::new((*self.inner).clone(), process_setup.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1641 | .await?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1642 | client: self.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1643 | })) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1644 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1645 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1646 | pub fn sync_service(&self) -> Arc<SyncServiceBuilder> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1647 | SyncServiceBuilder::new((*self.inner).clone(), self.utd_hook_manager.get().cloned()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1648 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1649 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1650 | /// Start a sync v2 loop. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1651 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1652 | /// This is an alternative to [`Client::sync_service`] (which uses Sliding |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1653 | /// Sync / MSC4186). It works with any homeserver, including older |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1654 | /// Synapse versions that do not support Sliding Sync. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1655 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1656 | /// Returns a `TaskHandle` that can be used to cancel the sync loop. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1657 | /// The listener is called after each successful sync response. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1658 | pub fn sync_v2( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1659 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1660 | settings: SyncSettingsV2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1661 | listener: Box<dyn SyncListenerV2>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1662 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1663 | let client = (*self.inner).clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1664 | let sdk_settings: matrix_sdk::config::SyncSettings = settings.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1665 | let listener: Arc<dyn SyncListenerV2> = Arc::from(listener); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1666 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1667 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1668 | let result = client |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1669 | .sync_with_result_callback(sdk_settings, |result| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1670 | let listener = listener.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1671 | async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1672 | let response = result?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1673 | let ffi_response: SyncResponseV2 = response.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1674 | listener.on_update(ffi_response); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1675 | Ok(matrix_sdk::LoopCtrl::Continue) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1676 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1677 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1678 | .await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1679 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1680 | if let Err(e) = result { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1681 | tracing::error!("Sync loop ended with error: {e}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1682 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1683 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1684 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1685 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1686 | /// Perform a single sync v2 call. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1687 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1688 | /// This is useful for performing an initial sync or a one-shot sync |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1689 | /// without entering a continuous loop. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1690 | pub async fn sync_once_v2( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1691 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1692 | settings: SyncSettingsV2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1693 | ) -> Result<SyncResponseV2, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1694 | let sdk_settings: matrix_sdk::config::SyncSettings = settings.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1695 | let response = self.inner.sync_once(sdk_settings).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1696 | Ok(response.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1697 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1698 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1699 | pub async fn space_service(&self) -> Arc<SpaceService> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1700 | let inner = UISpaceService::new((*self.inner).clone()).await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1701 | Arc::new(SpaceService::new(inner)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1702 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1703 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1704 | pub async fn get_notification_settings(&self) -> Arc<NotificationSettings> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1705 | let inner = self.inner.notification_settings().await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1706 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1707 | Arc::new(NotificationSettings::new((*self.inner).clone(), inner)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1708 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1709 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1710 | pub fn encryption(self: Arc<Self>) -> Arc<Encryption> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1711 | Arc::new(Encryption { inner: self.inner.encryption(), _client: self.clone() }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1712 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1713 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1714 | // Ignored users |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1715 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1716 | pub async fn ignored_users(&self) -> Result<Vec<String>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1717 | if let Some(raw_content) = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1718 | self.inner.account().fetch_account_data_static::<IgnoredUserListEventContent>().await? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1719 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1720 | let content = raw_content.deserialize()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1721 | let user_ids: Vec<String> = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1722 | content.ignored_users.keys().map(|id| id.to_string()).collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1723 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1724 | return Ok(user_ids); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1725 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1726 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1727 | Ok(vec![]) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1728 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1729 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1730 | pub async fn ignore_user(&self, user_id: String) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1731 | let user_id = UserId::parse(user_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1732 | self.inner.account().ignore_user(&user_id).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1733 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1734 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1735 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1736 | pub async fn unignore_user(&self, user_id: String) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1737 | let user_id = UserId::parse(user_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1738 | self.inner.account().unignore_user(&user_id).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1739 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1740 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1741 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1742 | pub fn subscribe_to_ignored_users( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1743 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1744 | listener: Box<dyn IgnoredUsersListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1745 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1746 | let mut subscriber = self.inner.subscribe_to_ignore_user_list_changes(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1747 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1748 | while let Some(user_ids) = subscriber.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1749 | listener.call(user_ids); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1750 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1751 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1752 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1753 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1754 | pub fn room_directory_search(&self) -> Arc<RoomDirectorySearch> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1755 | Arc::new(RoomDirectorySearch::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1756 | matrix_sdk::room_directory_search::RoomDirectorySearch::new((*self.inner).clone()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1757 | )) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1758 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1759 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1760 | /// Join a room by its ID. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1761 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1762 | /// Use this method when the homeserver already knows of the given room ID. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1763 | /// Otherwise use `join_room_by_id_or_alias` so you can pass a list of |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1764 | /// server names for the homeserver to find the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1765 | pub async fn join_room_by_id(&self, room_id: String) -> Result<Arc<Room>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1766 | let room_id = RoomId::parse(room_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1767 | let room = self.inner.join_room_by_id(room_id.as_ref()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1768 | Ok(Arc::new(Room::new(room, self.utd_hook_manager.get().cloned()))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1769 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1770 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1771 | /// Join a room by its ID or alias. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1772 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1773 | /// When supplying the room's ID, you can also supply a list of server names |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1774 | /// for the homeserver to find the room. Typically these server names |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1775 | /// come from a permalink's `via` parameters, or from resolving a room's |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1776 | /// alias into an ID. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1777 | pub async fn join_room_by_id_or_alias( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1778 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1779 | room_id_or_alias: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1780 | server_names: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1781 | ) -> Result<Arc<Room>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1782 | let room_id = RoomOrAliasId::parse(&room_id_or_alias)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1783 | let server_names = server_names |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1784 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1785 | .map(|name| OwnedServerName::try_from(name.as_str())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1786 | .collect::<Result<Vec<_>, _>>()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1787 | let room = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1788 | self.inner.join_room_by_id_or_alias(room_id.as_ref(), server_names.as_ref()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1789 | Ok(Arc::new(Room::new(room, self.utd_hook_manager.get().cloned()))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1790 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1791 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1792 | /// Knock on a room to join it using its ID or alias. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1793 | pub async fn knock( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1794 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1795 | room_id_or_alias: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1796 | reason: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1797 | server_names: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1798 | ) -> Result<Arc<Room>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1799 | let room_id = RoomOrAliasId::parse(&room_id_or_alias)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1800 | let server_names = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1801 | server_names.iter().map(ServerName::parse).collect::<Result<Vec<_>, _>>()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1802 | let room = self.inner.knock(room_id, reason, server_names).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1803 | Ok(Arc::new(Room::new(room, self.utd_hook_manager.get().cloned()))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1804 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1805 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1806 | pub async fn get_recently_visited_rooms(&self) -> Result<Vec<String>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1807 | Ok(self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1808 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1809 | .account() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1810 | .get_recently_visited_rooms() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1811 | .await? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1812 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1813 | .map(Into::into) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1814 | .collect()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1815 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1816 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1817 | pub async fn track_recently_visited_room(&self, room: String) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1818 | let room_id = RoomId::parse(room)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1819 | self.inner.account().track_recently_visited_room(room_id).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1820 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1821 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1822 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1823 | /// Resolves the given room alias to a room ID (and a list of servers), if |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1824 | /// possible. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1825 | pub async fn resolve_room_alias( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1826 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1827 | room_alias: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1828 | ) -> Result<Option<ResolvedRoomAlias>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1829 | let room_alias = RoomAliasId::parse(&room_alias)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1830 | match self.inner.resolve_room_alias(&room_alias).await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1831 | Ok(response) => Ok(Some(response.into())), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1832 | Err(error) => match error.client_api_error_kind() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1833 | // The room alias wasn't found, so we return None. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1834 | Some(ErrorKind::NotFound) => Ok(None), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1835 | // In any other case we just return the error, mapped. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1836 | _ => Err(error.into()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1837 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1838 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1839 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1840 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1841 | /// Checks if a room alias exists in the current homeserver. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1842 | pub async fn room_alias_exists(&self, room_alias: String) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1843 | self.resolve_room_alias(room_alias).await.map(|ret| ret.is_some()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1844 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1845 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1846 | /// Given a room id, get the preview of a room, to interact with it. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1847 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1848 | /// The list of `via_servers` must be a list of servers that know |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1849 | /// about the room and can resolve it, and that may appear as a `via` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1850 | /// parameter in e.g. a permalink URL. This list can be empty. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1851 | pub async fn get_room_preview_from_room_id( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1852 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1853 | room_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1854 | via_servers: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1855 | ) -> Result<Arc<RoomPreview>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1856 | let room_id = RoomId::parse(&room_id).context("room_id is not a valid room id")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1857 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1858 | let via_servers = via_servers |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1859 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1860 | .map(ServerName::parse) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1861 | .collect::<Result<Vec<_>, _>>() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1862 | .context("at least one `via` server name is invalid")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1863 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1864 | // The `into()` call below doesn't work if I do `(&room_id).into()`, so I let |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1865 | // rustc win that one fight. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1866 | let room_id: &RoomId = &room_id; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1867 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1868 | let room_preview = self.inner.get_room_preview(room_id.into(), via_servers).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1869 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1870 | Ok(Arc::new(RoomPreview::new(self.inner.clone(), room_preview))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1871 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1872 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1873 | /// Given a room alias, get the preview of a room, to interact with it. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1874 | pub async fn get_room_preview_from_room_alias( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1875 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1876 | room_alias: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1877 | ) -> Result<Arc<RoomPreview>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1878 | let room_alias = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1879 | RoomAliasId::parse(&room_alias).context("room_alias is not a valid room alias")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1880 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1881 | // The `into()` call below doesn't work if I do `(&room_id).into()`, so I let |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1882 | // rustc win that one fight. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1883 | let room_alias: &RoomAliasId = &room_alias; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1884 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1885 | let room_preview = self.inner.get_room_preview(room_alias.into(), Vec::new()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1886 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1887 | Ok(Arc::new(RoomPreview::new(self.inner.clone(), room_preview))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1888 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1889 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1890 | /// Waits until an at least partially synced room is received, and returns |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1891 | /// it. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1892 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1893 | /// **Note: this function will loop endlessly until either it finds the room |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1894 | /// or an externally set timeout happens.** |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1895 | pub async fn await_room_remote_echo(&self, room_id: String) -> Result<Arc<Room>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1896 | let room_id = RoomId::parse(room_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1897 | Ok(Arc::new(Room::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1898 | self.inner.await_room_remote_echo(&room_id).await, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1899 | self.utd_hook_manager.get().cloned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1900 | ))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1901 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1902 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1903 | /// Lets the user know whether this is an `m.login.password` based |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1904 | /// auth and if the account can actually be deactivated |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1905 | pub fn can_deactivate_account(&self) -> bool { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1906 | matches!(self.inner.auth_api(), Some(AuthApi::Matrix(_))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1907 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1908 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1909 | /// Deactivate this account definitively. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1910 | /// Similarly to `encryption::reset_identity` this |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1911 | /// will only work with password-based authentication (`m.login.password`) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1912 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1913 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1914 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1915 | /// * `auth_data` - This request uses the [User-Interactive Authentication |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1916 | /// API][uiaa]. The first request needs to set this to `None` and will |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1917 | /// always fail and the same request needs to be made but this time with |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1918 | /// some `auth_data` provided. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1919 | pub async fn deactivate_account( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1920 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1921 | auth_data: Option<AuthData>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1922 | erase_data: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1923 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1924 | if let Some(auth_data) = auth_data { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1925 | _ = self.inner.account().deactivate(None, Some(auth_data.into()), erase_data).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1926 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1927 | _ = self.inner.account().deactivate(None, None, erase_data).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1928 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1929 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1930 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1931 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1932 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1933 | /// Checks if a room alias is not in use yet. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1934 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1935 | /// Returns: |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1936 | /// - `Ok(true)` if the room alias is available. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1937 | /// - `Ok(false)` if it's not (the resolve alias request returned a `404` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1938 | /// status code). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1939 | /// - An `Err` otherwise. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1940 | pub async fn is_room_alias_available(&self, alias: String) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1941 | let alias = RoomAliasId::parse(alias)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1942 | self.inner.is_room_alias_available(&alias).await.map_err(Into::into) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1943 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1944 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1945 | /// Set the media retention policy. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1946 | pub async fn set_media_retention_policy( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1947 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1948 | policy: MediaRetentionPolicy, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1949 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1950 | let closure = async || -> Result<_, Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1951 | let store = self.inner.media_store().lock().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1952 | Ok(store.set_media_retention_policy(policy).await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1953 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1954 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1955 | Ok(closure().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1956 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1957 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1958 | /// Clear all the non-critical caches for this Client instance. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1959 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1960 | /// WARNING: This will clear all the caches, including the base store (state |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1961 | /// store), so callers must make sure that the Client is at rest before |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1962 | /// calling it. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1963 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1964 | /// In particular, if a [`SyncService`] is running, it must be passed here |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1965 | /// as a parameter, or stopped before calling this method. Ideally, the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1966 | /// send queues should have been disabled and must all be inactive (i.e. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1967 | /// not sending events); this method will disable them, but it might not |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1968 | /// be enough if the queues are still processing events. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1969 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1970 | /// After the method returns, the Client will be in an unstable |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1971 | /// state, and it is required that the caller reinstantiates a new |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1972 | /// Client instance, be it via dropping the previous and re-creating it, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1973 | /// restarting their application, or any other similar means. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1974 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1975 | /// - This will get rid of the backing state store file, if provided. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1976 | /// - This will empty all the room's persisted event caches, so all rooms |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1977 | /// will start as if they were empty. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1978 | /// - This will empty the media cache according to the current media |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1979 | /// retention policy. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1980 | pub async fn clear_caches( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1981 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1982 | sync_service: Option<Arc<SyncService>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1983 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1984 | let closure = async || -> Result<_, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1985 | // First, make sure to expire sessions in the sync service. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1986 | if let Some(sync_service) = sync_service { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1987 | sync_service.inner.expire_sessions().await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1988 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1989 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1990 | // Disable the send queues, as they might read and write to the state store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1991 | // Events being send might still be active, and cause errors if |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1992 | // processing finishes, so this will only minimize damage. Since |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1993 | // this method should only be called in exceptional cases, this has |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1994 | // been deemed acceptable. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1995 | self.inner.send_queue().set_enabled(false).await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1996 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1997 | // Clean up the media cache according to the current media retention policy. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1998 | self.inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1999 | .media_store() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2000 | .lock() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2001 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2002 | .map_err(Error::from)? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2003 | .clean() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2004 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2005 | .map_err(Error::from)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2006 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2007 | // Clear all the room chunks. It's important to *not* call |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2008 | // `EventCacheStore::clear_all_linked_chunks` here, because there might be live |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2009 | // observers of the linked chunks, and that would cause some very bad state |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2010 | // mismatch. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2011 | self.inner.event_cache().clear_all_rooms().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2012 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2013 | // Delete the state store file, if it exists. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2014 | #[cfg(feature = "sqlite")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2015 | if let Some(store_path) = &self.store_path { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2016 | debug!("Removing the state store: {}", store_path.display()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2017 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2018 | // The state store and the crypto store both live in the same store path, so we |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2019 | // can't blindly delete the directory. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2020 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2021 | // Delete the state store SQLite file, as well as the write-ahead log (WAL) and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2022 | // shared-memory (SHM) files, if they exist. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2023 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2024 | for file_name in [ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2025 | PathBuf::from(STATE_STORE_DATABASE_NAME), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2026 | PathBuf::from(format!("{STATE_STORE_DATABASE_NAME}.wal")), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2027 | PathBuf::from(format!("{STATE_STORE_DATABASE_NAME}.shm")), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2028 | ] { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2029 | let file_path = store_path.join(file_name); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2030 | if file_path.exists() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2031 | debug!("Removing file: {}", file_path.display()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2032 | std::fs::remove_file(&file_path).map_err(|err| ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2033 | msg: format!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2034 | "couldn't delete the state store file {}: {err}", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2035 | file_path.display() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2036 | ), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2037 | details: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2038 | })?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2039 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2040 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2041 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2042 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2043 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2044 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2045 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2046 | closure().await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2047 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2048 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2049 | /// Checks if the server supports the report room API. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2050 | pub async fn is_report_room_api_supported(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2051 | Ok(self.inner.server_versions().await?.contains(&ruma::api::MatrixVersion::V1_13)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2052 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2053 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2054 | /// Checks if the server supports the LiveKit RTC focus for placing calls. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2055 | pub async fn is_livekit_rtc_supported(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2056 | Ok(self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2057 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2058 | .rtc_foci() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2059 | .await? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2060 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2061 | .any(|focus| matches!(focus, RtcTransport::LiveKit(_)))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2062 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2063 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2064 | /// Get information about the homeserver's advertised map tile server, if |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2065 | /// any. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2066 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2067 | /// Reads the `tile_server` field of the matrix client well-known (MSC3488). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2068 | /// Uses the cached well-known when available, otherwise fetches it from the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2069 | /// homeserver. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2070 | pub async fn tile_server(&self) -> Option<matrix_sdk::TileServerInfo> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2071 | self.inner.tile_server().await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2072 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2073 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2074 | /// Checks if the server supports login using a QR code. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2075 | pub async fn is_login_with_qr_code_supported(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2076 | Ok(matches!(self.inner.auth_api(), Some(AuthApi::OAuth(_))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2077 | && self.inner.unstable_features().await?.contains(&ruma::api::FeatureFlag::Msc4108)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2078 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2079 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2080 | /// Get server vendor information from the federation API. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2081 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2082 | /// This method retrieves information about the server's name and version |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2083 | /// by calling the `/_matrix/federation/v1/version` endpoint. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2084 | pub async fn server_vendor_info(&self) -> Result<matrix_sdk::ServerVendorInfo, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2085 | Ok(self.inner.server_vendor_info(None).await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2086 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2087 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2088 | /// Subscribe to changes in the media preview configuration. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2089 | pub async fn subscribe_to_media_preview_config( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2090 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2091 | listener: Box<dyn MediaPreviewConfigListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2092 | ) -> Result<Arc<TaskHandle>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2093 | let (initial_value, stream) = self.inner.account().observe_media_preview_config().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2094 | Ok(Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2095 | // Send the initial value to the listener. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2096 | listener.on_change(initial_value.map(|config| config.into())); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2097 | // Listen for changes and notify the listener. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2098 | pin_mut!(stream); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2099 | while let Some(media_preview_config) = stream.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2100 | listener.on_change(Some(media_preview_config.into())); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2101 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2102 | })))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2103 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2104 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2105 | /// Set the media previews timeline display policy |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2106 | pub async fn set_media_preview_display_policy( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2107 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2108 | policy: MediaPreviews, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2109 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2110 | self.inner.account().set_media_previews_display_policy(policy.into()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2111 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2112 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2113 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2114 | /// Get the media previews timeline display policy |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2115 | /// currently stored in the cache. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2116 | pub async fn get_media_preview_display_policy( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2117 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2118 | ) -> Result<Option<MediaPreviews>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2119 | let configuration = self.inner.account().get_media_preview_config_event_content().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2120 | match configuration { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2121 | Some(configuration) => Ok(configuration.media_previews.map(Into::into)), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2122 | None => Ok(None), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2123 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2124 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2125 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2126 | /// Set the invite request avatars display policy |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2127 | pub async fn set_invite_avatars_display_policy( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2128 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2129 | policy: InviteAvatars, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2130 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2131 | self.inner.account().set_invite_avatars_display_policy(policy.into()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2132 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2133 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2134 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2135 | /// Get the invite request avatars display policy |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2136 | /// currently stored in the cache. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2137 | pub async fn get_invite_avatars_display_policy( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2138 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2139 | ) -> Result<Option<InviteAvatars>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2140 | let configuration = self.inner.account().get_media_preview_config_event_content().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2141 | match configuration { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2142 | Some(configuration) => Ok(configuration.invite_avatars.map(Into::into)), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2143 | None => Ok(None), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2144 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2145 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2146 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2147 | /// Fetch the media preview configuration from the server. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2148 | pub async fn fetch_media_preview_config( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2149 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2150 | ) -> Result<Option<MediaPreviewConfig>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2151 | Ok(self.inner.account().fetch_media_preview_config_event_content().await?.map(Into::into)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2152 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2153 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2154 | /// Gets the `max_upload_size` value from the homeserver, which controls the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2155 | /// max size a media upload request can have. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2156 | pub async fn get_max_media_upload_size(&self) -> Result<u64, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2157 | let max_upload_size = self.inner.load_or_fetch_max_upload_size().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2158 | Ok(max_upload_size.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2159 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2160 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2161 | /// Subscribe to [`RoomInfo`] updates given a provided [`RoomId`]. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2162 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2163 | /// This works even for rooms we haven't received yet, so we can subscribe |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2164 | /// to this and wait until we receive updates from them when sync responses |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2165 | /// are processed. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2166 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2167 | /// Note this method should be used sparingly since using callback |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2168 | /// interfaces is expensive, as well as keeping them alive for a long |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2169 | /// time. Usages of this method should be short-lived and dropped as |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2170 | /// soon as possible. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2171 | pub async fn subscribe_to_room_info( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2172 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2173 | room_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2174 | listener: Box<dyn RoomInfoListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2175 | ) -> Result<Arc<TaskHandle>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2176 | let room_id = RoomId::parse(room_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2177 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2178 | // Emit the initial event, if present |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2179 | if let Some(room) = self.inner.get_room(&room_id) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2180 | && let Ok(room_info) = RoomInfo::new(&room).await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2181 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2182 | listener.call(room_info); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2183 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2184 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2185 | Ok(Arc::new(TaskHandle::new(get_runtime_handle().spawn({ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2186 | let client = self.inner.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2187 | let mut receiver = client.room_info_notable_update_receiver(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2188 | async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2189 | while let Ok(room_update) = receiver.recv().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2190 | if room_update.room_id != room_id { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2191 | continue; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2192 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2193 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2194 | if let Some(room) = client.get_room(&room_id) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2195 | && let Ok(room_info) = RoomInfo::new(&room).await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2196 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2197 | listener.call(room_info); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2198 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2199 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2200 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2201 | })))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2202 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2203 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2204 | /// Whether to enable automatic backpagination under certain conditions |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2205 | /// (e.g. when processing read receipts). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2206 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2207 | /// This is an experimental feature, and might cause performance issues on |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2208 | /// large accounts. Use with caution. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2209 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2210 | /// This must be called after creating a client, but before subscribing to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2211 | /// the event cache (so, before spawning a sync service or a timeline). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2212 | pub fn enable_automatic_backpagination(&self) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2213 | self.inner.event_cache().config_mut().experimental_auto_backpagination = true; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2214 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2215 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2216 | pub fn homeserver_capabilities(&self) -> HomeserverCapabilities { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2217 | HomeserverCapabilities::new(self.inner.homeserver_capabilities()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2218 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2219 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2220 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2221 | async fn notification_handler( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2222 | notification: Notification, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2223 | room: matrix_sdk::Room, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2224 | listener: Arc<Box<dyn SyncNotificationListener>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2225 | ) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2226 | let room_id = room.room_id().to_string(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2227 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2228 | // Extract information about the actions |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2229 | let is_noisy = notification.actions.iter().any(|a| a.sound().is_some()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2230 | let has_mention = notification.actions.iter().any(|a| a.is_highlight()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2231 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2232 | // Convert SDK actions to FFI type |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2233 | let actions: Vec<crate::notification_settings::Action> = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2234 | notification.actions.into_iter().filter_map(|action| action.try_into().ok()).collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2235 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2236 | // Convert SDK event to FFI type |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2237 | let (sender, event, thread_id, raw_event) = match notification.event { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2238 | RawAnySyncOrStrippedTimelineEvent::Sync(raw) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2239 | let raw_event = raw.json().get().to_owned(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2240 | match raw.deserialize() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2241 | Ok(deserialized) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2242 | let sender = deserialized.sender().to_owned(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2243 | let thread_id = if let AnySyncTimelineEvent::MessageLike(event) = &deserialized |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2244 | && let Some(AnyMessageLikeEventContent::RoomMessage(content)) = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2245 | event.original_content() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2246 | && let Some(Relation::Thread(thread)) = content.relates_to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2247 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2248 | Some(thread.event_id.to_string()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2249 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2250 | None |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2251 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2252 | let event = NotificationEvent::Timeline { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2253 | event: Arc::new(crate::event::TimelineEvent(Box::new(deserialized))), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2254 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2255 | (sender, event, thread_id, raw_event) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2256 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2257 | Err(err) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2258 | tracing::warn!("Failed to deserialize timeline event: {err}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2259 | return; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2260 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2261 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2262 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2263 | RawAnySyncOrStrippedTimelineEvent::Stripped(raw) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2264 | let raw_event = raw.json().get().to_owned(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2265 | match raw.deserialize() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2266 | Ok(deserialized) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2267 | let sender = deserialized.sender().to_owned(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2268 | let event = NotificationEvent::Invite { sender: sender.to_string() }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2269 | let thread_id = None; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2270 | (sender, event, thread_id, raw_event) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2271 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2272 | Err(err) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2273 | tracing::warn!("Failed to deserialize stripped state event: {err}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2274 | return; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2275 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2276 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2277 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2278 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2279 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2280 | // Compile sender info |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2281 | let sender = room.get_member_no_sync(&sender).await.ok().flatten(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2282 | let sender_info = if let Some(sender) = sender.as_ref() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2283 | NotificationSenderInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2284 | display_name: sender.display_name().map(|name| name.to_owned()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2285 | avatar_url: sender.avatar_url().map(|uri| uri.to_string()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2286 | is_name_ambiguous: sender.name_ambiguous(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2287 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2288 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2289 | NotificationSenderInfo { display_name: None, avatar_url: None, is_name_ambiguous: false } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2290 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2291 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2292 | // Compile room info |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2293 | let display_name = match room.display_name().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2294 | Ok(name) => name.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2295 | Err(err) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2296 | tracing::warn!("Failed to calculate the room's display name: {err}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2297 | return; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2298 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2299 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2300 | let is_direct = match room.is_direct().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2301 | Ok(is_direct) => is_direct, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2302 | Err(err) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2303 | tracing::warn!("Failed to determine if room is direct or not: {err}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2304 | return; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2305 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2306 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2307 | let room_info = NotificationRoomInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2308 | display_name, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2309 | avatar_url: room.avatar_url().map(Into::into), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2310 | canonical_alias: room.canonical_alias().map(Into::into), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2311 | topic: room.topic(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2312 | join_rule: room.join_rule().map(TryInto::try_into).transpose().ok().flatten(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2313 | joined_members_count: room.joined_members_count(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2314 | service_members: room |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2315 | .service_members() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2316 | .unwrap_or_default() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2317 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2318 | .map(ToString::to_string) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2319 | .collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2320 | active_service_members_count: room |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2321 | .update_active_service_members() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2322 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2323 | .ok() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2324 | .flatten() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2325 | .unwrap_or_default() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2326 | .len() as u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2327 | is_encrypted: Some(room.encryption_state().is_encrypted()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2328 | is_direct, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2329 | is_space: room.is_space(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2330 | is_dm: room.compute_is_dm().await.ok().unwrap_or_default(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2331 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2332 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2333 | listener.on_notification( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2334 | NotificationItem { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2335 | event, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2336 | raw_event, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2337 | sender_info, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2338 | room_info, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2339 | is_noisy: Some(is_noisy), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2340 | has_mention: Some(has_mention), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2341 | thread_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2342 | actions: Some(actions), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2343 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2344 | room_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2345 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2346 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2347 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2348 | #[cfg(feature = "experimental-element-recent-emojis")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2349 | mod recent_emoji { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2350 | use crate::{client::Client, error::ClientError}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2351 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2352 | /// Represents an emoji recently used for reactions. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2353 | #[derive(Debug, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2354 | pub struct RecentEmoji { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2355 | /// The actual emoji text representation. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2356 | pub emoji: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2357 | /// The number of times this emoji has been used for reactions. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2358 | pub count: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2359 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2360 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2361 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2362 | impl Client { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2363 | /// Adds a recently used emoji to the list and uploads the updated |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2364 | /// `io.element.recent_emoji` content to the global account data. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2365 | pub async fn add_recent_emoji(&self, emoji: String) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2366 | Ok(self.inner.account().add_recent_emoji(&emoji).await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2367 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2368 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2369 | /// Gets the list of recently used emojis from the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2370 | /// `io.element.recent_emoji` global account data. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2371 | pub async fn get_recent_emojis(&self) -> Result<Vec<RecentEmoji>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2372 | Ok(self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2373 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2374 | .account() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2375 | .get_recent_emojis(false) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2376 | .await? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2377 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2378 | .map(|(emoji, count)| RecentEmoji { emoji, count: count.into() }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2379 | .collect::<Vec<RecentEmoji>>()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2380 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2381 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2382 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2383 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2384 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2385 | pub trait MediaPreviewConfigListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2386 | fn on_change(&self, media_preview_config: Option<MediaPreviewConfig>); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2387 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2388 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2389 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2390 | pub trait IgnoredUsersListener: SyncOutsideWasm + SendOutsideWasm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2391 | fn call(&self, ignored_user_ids: Vec<String>); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2392 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2393 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2394 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2395 | pub enum NotificationProcessSetup { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2396 | MultipleProcesses, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2397 | SingleProcess { sync_service: Arc<SyncService> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2398 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2399 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2400 | impl From<NotificationProcessSetup> for MatrixNotificationProcessSetup { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2401 | fn from(value: NotificationProcessSetup) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2402 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2403 | NotificationProcessSetup::MultipleProcesses => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2404 | MatrixNotificationProcessSetup::MultipleProcesses |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2405 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2406 | NotificationProcessSetup::SingleProcess { sync_service } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2407 | MatrixNotificationProcessSetup::SingleProcess { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2408 | sync_service: sync_service.inner.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2409 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2410 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2411 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2412 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2413 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2414 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2415 | /// Information about a room, that was resolved from a room alias. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2416 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2417 | pub struct ResolvedRoomAlias { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2418 | /// The room ID that the alias resolved to. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2419 | pub room_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2420 | /// A list of servers that can be used to find the room by its room ID. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2421 | pub servers: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2422 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2423 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2424 | impl From<get_alias::v3::Response> for ResolvedRoomAlias { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2425 | fn from(value: get_alias::v3::Response) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2426 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2427 | room_id: value.room_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2428 | servers: value.servers.iter().map(ToString::to_string).collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2429 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2430 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2431 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2432 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2433 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2434 | pub struct SearchUsersResults { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2435 | pub results: Vec<UserProfile>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2436 | pub limited: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2437 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2438 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2439 | impl From<search_users::v3::Response> for SearchUsersResults { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2440 | fn from(value: search_users::v3::Response) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2441 | let results: Vec<UserProfile> = value.results.iter().map(UserProfile::from).collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2442 | SearchUsersResults { results, limited: value.limited } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2443 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2444 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2445 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2446 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2447 | pub struct UserProfile { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2448 | pub user_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2449 | pub display_name: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2450 | pub avatar_url: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2451 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2452 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2453 | impl UserProfile { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2454 | /// Fetch the profile for the given user ID, using the given [`Account`] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2455 | /// API. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2456 | pub(crate) async fn fetch(account: &Account, user_id: &UserId) -> Result<Self, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2457 | let response = account.fetch_user_profile_of(user_id).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2458 | let display_name = response.get_static::<DisplayName>()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2459 | let avatar_url = response.get_static::<AvatarUrl>()?.map(|url| url.to_string()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2460 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2461 | Ok(UserProfile { user_id: user_id.to_string(), display_name, avatar_url }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2462 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2463 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2464 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2465 | impl From<&search_users::v3::User> for UserProfile { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2466 | fn from(value: &search_users::v3::User) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2467 | UserProfile { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2468 | user_id: value.user_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2469 | display_name: value.display_name.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2470 | avatar_url: value.avatar_url.as_ref().map(|url| url.to_string()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2471 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2472 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2473 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2474 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2475 | impl Client { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2476 | fn process_session_change(&self, session_change: SessionChange) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2477 | if let Some(delegate_data) = self.delegate_data.get() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2478 | debug!("Applying session change: {session_change:?}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2479 | let delegate = delegate_data.delegate.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2480 | get_runtime_handle().spawn_blocking(move || match session_change { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2481 | SessionChange::UnknownToken(unknown_token) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2482 | delegate.did_receive_auth_error(unknown_token.soft_logout); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2483 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2484 | SessionChange::TokensRefreshed => {} |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2485 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2486 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2487 | debug!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2488 | "No client delegate found, session change couldn't be applied: {session_change:?}" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2489 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2490 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2491 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2492 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2493 | fn retrieve_session( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2494 | session_delegate: Arc<dyn ClientSessionDelegate>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2495 | user_id: &UserId, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2496 | ) -> anyhow::Result<SessionTokens> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2497 | Ok(session_delegate.retrieve_session_from_keychain(user_id.to_string())?.into_tokens()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2498 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2499 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2500 | fn session_inner(client: matrix_sdk::Client) -> Result<Session, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2501 | let auth_api = client.auth_api().context("Missing authentication API")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2502 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2503 | let homeserver_url = client.homeserver().into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2504 | let sliding_sync_version = client.sliding_sync_version(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2505 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2506 | Session::new(auth_api, homeserver_url, sliding_sync_version.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2507 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2508 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2509 | fn save_session( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2510 | session_delegate: Arc<dyn ClientSessionDelegate>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2511 | client: matrix_sdk::Client, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2512 | ) -> anyhow::Result<()> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2513 | let session = Self::session_inner(client)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2514 | session_delegate.save_session_in_keychain(session); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2515 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2516 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2517 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2518 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2519 | /// Configure how many rooms will be restored when restoring the session with |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2520 | /// [`Client::restore_session_with`]. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2521 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2522 | /// Please, see the documentation of [`matrix_sdk::store::RoomLoadSettings`] to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2523 | /// learn more. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2524 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2525 | pub enum RoomLoadSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2526 | /// Load all rooms from the `StateStore` into the in-memory state store |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2527 | /// `BaseStateStore`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2528 | All, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2529 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2530 | /// Load a single room from the `StateStore` into the in-memory state |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2531 | /// store `BaseStateStore`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2532 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2533 | /// Please, be careful with this option. Read the documentation of |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2534 | /// [`RoomLoadSettings`]. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2535 | One { room_id: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2536 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2537 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2538 | impl TryInto<SdkRoomLoadSettings> for RoomLoadSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2539 | type Error = String; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2540 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2541 | fn try_into(self) -> Result<SdkRoomLoadSettings, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2542 | Ok(match self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2543 | Self::All => SdkRoomLoadSettings::All, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2544 | Self::One { room_id } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2545 | SdkRoomLoadSettings::One(RoomId::parse(room_id).map_err(|error| error.to_string())?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2546 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2547 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2548 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2549 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2550 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2551 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2552 | pub struct NotificationPowerLevels { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2553 | pub room: i32, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2554 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2555 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2556 | impl From<NotificationPowerLevels> for ruma::power_levels::NotificationPowerLevels { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2557 | fn from(value: NotificationPowerLevels) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2558 | let mut notification_power_levels = Self::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2559 | notification_power_levels.room = value.room.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2560 | notification_power_levels |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2561 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2562 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2563 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2564 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2565 | pub struct PowerLevels { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2566 | pub users_default: Option<i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2567 | pub events_default: Option<i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2568 | pub state_default: Option<i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2569 | pub ban: Option<i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2570 | pub kick: Option<i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2571 | pub redact: Option<i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2572 | pub invite: Option<i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2573 | pub notifications: Option<NotificationPowerLevels>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2574 | pub users: HashMap<String, i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2575 | pub events: HashMap<String, i32>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2576 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2577 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2578 | impl From<PowerLevels> for RoomPowerLevelsContentOverride { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2579 | fn from(value: PowerLevels) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2580 | let mut power_levels = RoomPowerLevelsContentOverride::default(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2581 | power_levels.users_default = value.users_default.map(Into::into); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2582 | power_levels.state_default = value.state_default.map(Into::into); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2583 | power_levels.events_default = value.events_default.map(Into::into); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2584 | power_levels.ban = value.ban.map(Into::into); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2585 | power_levels.kick = value.kick.map(Into::into); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2586 | power_levels.redact = value.redact.map(Into::into); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2587 | power_levels.invite = value.invite.map(Into::into); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2588 | power_levels.notifications = value.notifications.map(Into::into).unwrap_or_default(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2589 | power_levels.users = value |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2590 | .users |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2591 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2592 | .filter_map(|(user_id, power_level)| match UserId::parse(user_id) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2593 | Ok(id) => Some((id, (*power_level).into())), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2594 | Err(e) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2595 | error!(user_id, "Skipping invalid user ID, error: {e}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2596 | None |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2597 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2598 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2599 | .collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2600 | power_levels.events = value |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2601 | .events |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2602 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2603 | .map(|(event_type, power_level)| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2604 | let event_type: ruma::events::TimelineEventType = event_type.as_str().into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2605 | (event_type, (*power_level).into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2606 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2607 | .collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2608 | power_levels |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2609 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2610 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2611 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2612 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2613 | pub struct CreateRoomParameters { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2614 | pub name: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2615 | #[uniffi(default = None)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2616 | pub topic: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2617 | pub is_encrypted: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2618 | #[uniffi(default = false)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2619 | pub is_direct: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2620 | pub visibility: RoomVisibility, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2621 | pub preset: RoomPreset, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2622 | #[uniffi(default = None)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2623 | pub invite: Option<Vec<String>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2624 | #[uniffi(default = None)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2625 | pub avatar: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2626 | #[uniffi(default = None)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2627 | pub power_level_content_override: Option<PowerLevels>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2628 | #[uniffi(default = None)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2629 | pub join_rule_override: Option<JoinRule>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2630 | #[uniffi(default = None)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2631 | pub history_visibility_override: Option<RoomHistoryVisibility>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2632 | #[uniffi(default = None)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2633 | pub canonical_alias: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2634 | #[uniffi(default = false)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2635 | pub is_space: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2636 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2637 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2638 | impl TryFrom<CreateRoomParameters> for create_room::v3::Request { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2639 | type Error = ClientError; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2640 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2641 | fn try_from(value: CreateRoomParameters) -> Result<create_room::v3::Request, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2642 | let mut request = create_room::v3::Request::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2643 | request.name = value.name; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2644 | request.topic = value.topic; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2645 | request.is_direct = value.is_direct; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2646 | request.visibility = value.visibility.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2647 | request.preset = Some(value.preset.into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2648 | request.room_alias_name = value.canonical_alias; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2649 | request.invite = match value.invite { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2650 | Some(invite) => invite |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2651 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2652 | .filter_map(|user_id| match UserId::parse(user_id) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2653 | Ok(id) => Some(id), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2654 | Err(e) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2655 | error!(user_id, "Skipping invalid user ID, error: {e}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2656 | None |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2657 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2658 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2659 | .collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2660 | None => vec![], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2661 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2662 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2663 | let mut initial_state: Vec<Raw<AnyInitialStateEvent>> = vec![]; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2664 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2665 | if value.is_encrypted { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2666 | let content = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2667 | RoomEncryptionEventContent::new(EventEncryptionAlgorithm::MegolmV1AesSha2); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2668 | initial_state.push(InitialStateEvent::with_empty_state_key(content).to_raw_any()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2669 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2670 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2671 | if let Some(url) = value.avatar { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2672 | let mut content = RoomAvatarEventContent::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2673 | content.url = Some(url.into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2674 | initial_state.push(InitialStateEvent::with_empty_state_key(content).to_raw_any()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2675 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2676 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2677 | if let Some(join_rule_override) = value.join_rule_override { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2678 | let content = RoomJoinRulesEventContent::new(join_rule_override.try_into()?); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2679 | initial_state.push(InitialStateEvent::with_empty_state_key(content).to_raw_any()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2680 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2681 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2682 | if let Some(history_visibility_override) = value.history_visibility_override { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2683 | let content = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2684 | RoomHistoryVisibilityEventContent::new(history_visibility_override.try_into()?); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2685 | initial_state.push(InitialStateEvent::with_empty_state_key(content).to_raw_any()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2686 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2687 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2688 | request.initial_state = initial_state; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2689 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2690 | if value.is_space { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2691 | let mut creation_content = CreationContent::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2692 | creation_content.room_type = Some(RoomType::Space); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2693 | request.creation_content = Some(Raw::new(&creation_content)?); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2694 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2695 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2696 | if let Some(power_levels) = value.power_level_content_override { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2697 | match Raw::<RoomPowerLevelsContentOverride>::new(&power_levels.into()) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2698 | Ok(power_levels) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2699 | request.power_level_content_override = Some(power_levels); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2700 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2701 | Err(e) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2702 | return Err(ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2703 | msg: format!("Failed to serialize power levels, error: {e}"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2704 | details: Some(format!("{e:?}")), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2705 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2706 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2707 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2708 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2709 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2710 | Ok(request) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2711 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2712 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2713 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2714 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2715 | pub enum RoomVisibility { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2716 | /// Indicates that the room will be shown in the published room list. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2717 | Public, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2718 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2719 | /// Indicates that the room will not be shown in the published room list. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2720 | Private, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2721 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2722 | /// A custom value that's not present in the spec. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2723 | Custom { value: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2724 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2725 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2726 | impl From<RoomVisibility> for Visibility { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2727 | fn from(value: RoomVisibility) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2728 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2729 | RoomVisibility::Public => Self::Public, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2730 | RoomVisibility::Private => Self::Private, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2731 | RoomVisibility::Custom { value } => value.as_str().into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2732 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2733 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2734 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2735 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2736 | impl From<Visibility> for RoomVisibility { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2737 | fn from(value: Visibility) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2738 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2739 | Visibility::Public => Self::Public, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2740 | Visibility::Private => Self::Private, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2741 | _ => Self::Custom { value: value.as_str().to_owned() }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2742 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2743 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2744 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2745 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2746 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2747 | #[allow(clippy::enum_variant_names)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2748 | pub enum RoomPreset { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2749 | /// `join_rules` is set to `invite` and `history_visibility` is set to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2750 | /// `shared`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2751 | PrivateChat, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2752 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2753 | /// `join_rules` is set to `public` and `history_visibility` is set to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2754 | /// `shared`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2755 | PublicChat, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2756 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2757 | /// Same as `PrivateChat`, but all initial invitees get the same power level |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2758 | /// as the creator. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2759 | TrustedPrivateChat, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2760 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2761 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2762 | impl From<RoomPreset> for create_room::v3::RoomPreset { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2763 | fn from(value: RoomPreset) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2764 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2765 | RoomPreset::PrivateChat => Self::PrivateChat, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2766 | RoomPreset::PublicChat => Self::PublicChat, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2767 | RoomPreset::TrustedPrivateChat => Self::TrustedPrivateChat, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2768 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2769 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2770 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2771 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2772 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2773 | pub struct Session { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2774 | // Same fields as the Session type in matrix-sdk, just simpler types |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2775 | /// The access token used for this session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2776 | pub access_token: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2777 | /// The token used for [refreshing the access token], if any. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2778 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2779 | /// [refreshing the access token]: https://spec.matrix.org/v1.3/client-server-api/#refreshing-access-tokens |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2780 | pub refresh_token: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2781 | /// The user the access token was issued for. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2782 | pub user_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2783 | /// The ID of the client device. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2784 | pub device_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2785 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2786 | // FFI-only fields (for now) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2787 | /// The URL for the homeserver used for this session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2788 | pub homeserver_url: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2789 | /// Additional data for this session if OpenID Connect was used for |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2790 | /// authentication. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2791 | pub oauth_data: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2792 | /// The sliding sync version used for this session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2793 | pub sliding_sync_version: SlidingSyncVersion, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2794 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2795 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2796 | impl Session { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2797 | fn new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2798 | auth_api: AuthApi, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2799 | homeserver_url: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2800 | sliding_sync_version: SlidingSyncVersion, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2801 | ) -> Result<Session, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2802 | match auth_api { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2803 | // Build the session from the regular Matrix Auth Session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2804 | AuthApi::Matrix(a) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2805 | let matrix_sdk::authentication::matrix::MatrixSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2806 | meta: matrix_sdk::SessionMeta { user_id, device_id }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2807 | tokens: matrix_sdk::SessionTokens { access_token, refresh_token }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2808 | } = a.session().context("Missing session")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2809 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2810 | Ok(Session { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2811 | access_token, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2812 | refresh_token, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2813 | user_id: user_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2814 | device_id: device_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2815 | homeserver_url, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2816 | oauth_data: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2817 | sliding_sync_version, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2818 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2819 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2820 | // Build the session from the OAuth UserSession. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2821 | AuthApi::OAuth(api) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2822 | let matrix_sdk::authentication::oauth::UserSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2823 | meta: matrix_sdk::SessionMeta { user_id, device_id }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2824 | tokens: matrix_sdk::SessionTokens { access_token, refresh_token }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2825 | } = api.user_session().context("Missing session")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2826 | let client_id = api.client_id().context("OAuth client ID is missing.")?.clone(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2827 | let oauth_data = OAuthSessionData { client_id }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2828 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2829 | let oauth_data_string = serde_json::to_string(&oauth_data).ok(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2830 | Ok(Session { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2831 | access_token, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2832 | refresh_token, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2833 | user_id: user_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2834 | device_id: device_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2835 | homeserver_url, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2836 | oauth_data: oauth_data_string, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2837 | sliding_sync_version, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2838 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2839 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2840 | _ => Err(anyhow!("Unknown authentication API").into()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2841 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2842 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2843 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2844 | fn into_tokens(self) -> matrix_sdk::SessionTokens { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2845 | SessionTokens { access_token: self.access_token, refresh_token: self.refresh_token } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2846 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2847 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2848 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2849 | impl TryFrom<Session> for AuthSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2850 | type Error = ClientError; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2851 | fn try_from(value: Session) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2852 | let Session { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2853 | access_token, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2854 | refresh_token, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2855 | user_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2856 | device_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2857 | homeserver_url: _, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2858 | oauth_data: oauth_data_string, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2859 | sliding_sync_version: _, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2860 | } = value; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2861 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2862 | if let Some(oauth_data_string) = oauth_data_string { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2863 | // Create an OAuth Session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2864 | let oauth_data = serde_json::from_str::<OAuthSessionData>(&oauth_data_string)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2865 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2866 | let user_session = matrix_sdk::authentication::oauth::UserSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2867 | meta: matrix_sdk::SessionMeta { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2868 | user_id: user_id.try_into()?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2869 | device_id: device_id.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2870 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2871 | tokens: matrix_sdk::SessionTokens { access_token, refresh_token }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2872 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2873 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2874 | let session = OAuthSession { client_id: oauth_data.client_id, user: user_session }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2875 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2876 | Ok(AuthSession::OAuth(session.into())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2877 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2878 | // Create a regular Matrix Session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2879 | let session = matrix_sdk::authentication::matrix::MatrixSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2880 | meta: matrix_sdk::SessionMeta { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2881 | user_id: user_id.try_into()?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2882 | device_id: device_id.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2883 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2884 | tokens: matrix_sdk::SessionTokens { access_token, refresh_token }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2885 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2886 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2887 | Ok(AuthSession::Matrix(session)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2888 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2889 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2890 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2891 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2892 | /// Represents a client registration against an OAuth authentication issuer. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2893 | #[derive(Serialize, Deserialize)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2894 | pub(crate) struct OAuthSessionData { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2895 | client_id: ClientId, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2896 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2897 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2898 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2899 | pub enum AccountManagementAction { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2900 | Profile, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2901 | DevicesList, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2902 | DeviceView { device_id: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2903 | DeviceDelete { device_id: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2904 | AccountDeactivate, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2905 | CrossSigningReset, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2906 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2907 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2908 | impl<'a> From<&'a AccountManagementAction> for AccountManagementActionData<'a> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2909 | fn from(value: &'a AccountManagementAction) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2910 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2911 | AccountManagementAction::Profile => Self::Profile, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2912 | AccountManagementAction::DevicesList => Self::DevicesList, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2913 | AccountManagementAction::DeviceView { device_id } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2914 | Self::DeviceView(DeviceViewData::new(device_id.as_str().into())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2915 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2916 | AccountManagementAction::DeviceDelete { device_id } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2917 | Self::DeviceDelete(DeviceDeleteData::new(device_id.as_str().into())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2918 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2919 | AccountManagementAction::AccountDeactivate => Self::AccountDeactivate, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2920 | AccountManagementAction::CrossSigningReset => Self::CrossSigningReset, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2921 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2922 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2923 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2924 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2925 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2926 | fn gen_transaction_id() -> String { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2927 | TransactionId::new().to_string() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2928 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2929 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2930 | /// A file handle that takes ownership of a media file on disk. When the handle |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2931 | /// is dropped, the file will be removed from the disk. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2932 | #[derive(uniffi::Object)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2933 | pub struct MediaFileHandle { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2934 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2935 | inner: std::sync::RwLock<Option<SdkMediaFileHandle>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2936 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2937 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2938 | impl MediaFileHandle { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2939 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2940 | fn new(handle: SdkMediaFileHandle) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2941 | Self { inner: std::sync::RwLock::new(Some(handle)) } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2942 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2943 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2944 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2945 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2946 | impl MediaFileHandle { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2947 | /// Get the media file's path. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2948 | pub fn path(&self) -> Result<String, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2949 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2950 | return Ok(self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2951 | .inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2952 | .read() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2953 | .unwrap() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2954 | .as_ref() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2955 | .context("MediaFileHandle must not be used after calling persist")? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2956 | .path() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2957 | .to_str() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2958 | .unwrap() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2959 | .to_owned()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2960 | #[cfg(target_family = "wasm")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2961 | Err(ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2962 | msg: "MediaFileHandle.path() is not supported on WASM targets".to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2963 | details: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2964 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2965 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2966 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2967 | pub fn persist(&self, path: String) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2968 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2969 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2970 | let mut guard = self.inner.write().unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2971 | Ok( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2972 | match guard |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2973 | .take() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2974 | .context("MediaFileHandle was already persisted")? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2975 | .persist(path.as_ref()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2976 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2977 | Ok(_) => true, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2978 | Err(e) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2979 | *guard = Some(e.file); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2980 | false |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2981 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2982 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2983 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2984 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2985 | #[cfg(target_family = "wasm")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2986 | Err(ClientError::Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2987 | msg: "MediaFileHandle.persist() is not supported on WASM targets".to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2988 | details: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2989 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2990 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2991 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2992 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2993 | #[derive(Clone, uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2994 | pub enum SlidingSyncVersion { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2995 | None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2996 | Native, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2997 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2998 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2999 | impl From<SdkSlidingSyncVersion> for SlidingSyncVersion { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3000 | fn from(value: SdkSlidingSyncVersion) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3001 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3002 | SdkSlidingSyncVersion::None => Self::None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3003 | SdkSlidingSyncVersion::Native => Self::Native, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3004 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3005 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3006 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3007 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3008 | impl TryFrom<SlidingSyncVersion> for SdkSlidingSyncVersion { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3009 | type Error = ClientError; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3010 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3011 | fn try_from(value: SlidingSyncVersion) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3012 | Ok(match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3013 | SlidingSyncVersion::None => Self::None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3014 | SlidingSyncVersion::Native => Self::Native, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3015 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3016 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3017 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3018 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3019 | #[derive(Clone, uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3020 | pub enum OAuthPrompt { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3021 | /// The Authorization Server should prompt the End-User to create a user |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3022 | /// account. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3023 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3024 | /// Defined in [Initiating User Registration via OpenID Connect](https://openid.net/specs/openid-connect-prompt-create-1_0.html). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3025 | Create, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3026 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3027 | /// The Authorization Server should prompt the End-User for |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3028 | /// reauthentication. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3029 | Login, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3030 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3031 | /// The Authorization Server should prompt the End-User for consent before |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3032 | /// returning information to the Client. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3033 | Consent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3034 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3035 | /// An unknown value. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3036 | Unknown { value: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3037 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3038 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3039 | impl From<RumaOAuthPrompt> for OAuthPrompt { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3040 | fn from(value: RumaOAuthPrompt) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3041 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3042 | RumaOAuthPrompt::Create => Self::Create, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3043 | value => match value.as_str() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3044 | "consent" => Self::Consent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3045 | "login" => Self::Login, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3046 | _ => Self::Unknown { value: value.to_string() }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3047 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3048 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3049 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3050 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3051 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3052 | impl From<OAuthPrompt> for RumaOAuthPrompt { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3053 | fn from(value: OAuthPrompt) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3054 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3055 | OAuthPrompt::Create => Self::Create, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3056 | OAuthPrompt::Consent => Self::from("consent"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3057 | OAuthPrompt::Login => Self::from("login"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3058 | OAuthPrompt::Unknown { value } => value.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3059 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3060 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3061 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3062 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3063 | /// The rule used for users wishing to join this room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3064 | #[derive(Debug, Clone, uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3065 | pub enum JoinRule { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3066 | /// Anyone can join the room without any prior action. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3067 | Public, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3068 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3069 | /// A user who wishes to join the room must first receive an invite to the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3070 | /// room from someone already inside of the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3071 | Invite, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3072 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3073 | /// Users can join the room if they are invited, or they can request an |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3074 | /// invite to the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3075 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3076 | /// They can be allowed (invited) or denied (kicked/banned) access. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3077 | Knock, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3078 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3079 | /// Reserved but not yet implemented by the Matrix specification. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3080 | Private, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3081 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3082 | /// Users can join the room if they are invited, or if they meet any of the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3083 | /// conditions described in a set of [`AllowRule`]s. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3084 | Restricted { rules: Vec<AllowRule> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3085 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3086 | /// Users can join the room if they are invited, or if they meet any of the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3087 | /// conditions described in a set of [`AllowRule`]s, or they can request |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3088 | /// an invite to the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3089 | KnockRestricted { rules: Vec<AllowRule> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3090 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3091 | /// A custom join rule, up for interpretation by the consumer. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3092 | Custom { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3093 | /// The string representation for this custom rule. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3094 | repr: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3095 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3096 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3097 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3098 | /// An allow rule which defines a condition that allows joining a room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3099 | #[derive(Debug, Clone, uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3100 | pub enum AllowRule { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3101 | /// Only a member of the `room_id` Room can join the one this rule is used |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3102 | /// in. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3103 | RoomMembership { room_id: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3104 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3105 | /// A custom allow rule implementation, containing its JSON representation |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3106 | /// as a `String`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3107 | Custom { json: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3108 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3109 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3110 | impl TryFrom<JoinRule> for RumaJoinRule { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3111 | type Error = ClientError; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3112 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3113 | fn try_from(value: JoinRule) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3114 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3115 | JoinRule::Public => Ok(Self::Public), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3116 | JoinRule::Invite => Ok(Self::Invite), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3117 | JoinRule::Knock => Ok(Self::Knock), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3118 | JoinRule::Private => Ok(Self::Private), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3119 | JoinRule::Restricted { rules } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3120 | let rules = ruma_allow_rules_from_ffi(rules)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3121 | Ok(Self::Restricted(ruma::events::room::join_rules::Restricted::new(rules))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3122 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3123 | JoinRule::KnockRestricted { rules } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3124 | let rules = ruma_allow_rules_from_ffi(rules)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3125 | Ok(Self::KnockRestricted(ruma::events::room::join_rules::Restricted::new(rules))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3126 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3127 | JoinRule::Custom { repr } => Ok(serde_json::from_str(&repr)?), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3128 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3129 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3130 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3131 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3132 | fn ruma_allow_rules_from_ffi(value: Vec<AllowRule>) -> Result<Vec<RumaAllowRule>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3133 | let mut ret = Vec::with_capacity(value.len()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3134 | for rule in value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3135 | let rule: Result<RumaAllowRule, ClientError> = rule.try_into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3136 | match rule { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3137 | Ok(rule) => ret.push(rule), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3138 | Err(error) => return Err(error), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3139 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3140 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3141 | Ok(ret) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3142 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3143 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3144 | impl TryFrom<AllowRule> for RumaAllowRule { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3145 | type Error = ClientError; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3146 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3147 | fn try_from(value: AllowRule) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3148 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3149 | AllowRule::RoomMembership { room_id } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3150 | let room_id = RoomId::parse(room_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3151 | Ok(Self::RoomMembership(ruma::room::RoomMembership::new(room_id))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3152 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3153 | AllowRule::Custom { json } => Ok(serde_json::from_str(&json)?), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3154 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3155 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3156 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3157 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3158 | impl TryFrom<RumaJoinRule> for JoinRule { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3159 | type Error = String; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3160 | fn try_from(value: RumaJoinRule) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3161 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3162 | RumaJoinRule::Knock => Ok(JoinRule::Knock), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3163 | RumaJoinRule::Public => Ok(JoinRule::Public), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3164 | RumaJoinRule::Private => Ok(JoinRule::Private), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3165 | RumaJoinRule::KnockRestricted(restricted) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3166 | let rules = restricted.allow.into_iter().map(TryInto::try_into).collect::<Result< |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3167 | Vec<_>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3168 | Self::Error, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3169 | >>( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3170 | )?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3171 | Ok(JoinRule::KnockRestricted { rules }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3172 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3173 | RumaJoinRule::Restricted(restricted) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3174 | let rules = restricted.allow.into_iter().map(TryInto::try_into).collect::<Result< |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3175 | Vec<_>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3176 | Self::Error, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3177 | >>( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3178 | )?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3179 | Ok(JoinRule::Restricted { rules }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3180 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3181 | RumaJoinRule::Invite => Ok(JoinRule::Invite), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3182 | RumaJoinRule::_Custom(_) => Ok(JoinRule::Custom { repr: value.as_str().to_owned() }), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3183 | _ => Err(format!("Unknown JoinRule: {value:?}")), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3184 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3185 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3186 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3187 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3188 | impl TryFrom<RumaAllowRule> for AllowRule { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3189 | type Error = String; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3190 | fn try_from(value: RumaAllowRule) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3191 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3192 | RumaAllowRule::RoomMembership(membership) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3193 | Ok(AllowRule::RoomMembership { room_id: membership.room_id.to_string() }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3194 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3195 | RumaAllowRule::_Custom(repr) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3196 | let json = serde_json::to_string(&repr) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3197 | .map_err(|e| format!("Couldn't serialize custom AllowRule: {e:?}"))?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3198 | Ok(Self::Custom { json }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3199 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3200 | _ => Err(format!("Invalid AllowRule: {value:?}")), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3201 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3202 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3203 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3204 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3205 | /// Contains the disk size of the different stores, if known. It won't be |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3206 | /// available for in-memory stores. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3207 | #[derive(Debug, Clone, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3208 | pub struct StoreSizes { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3209 | /// The size of the CryptoStore. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3210 | crypto_store: Option<u64>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3211 | /// The size of the StateStore. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3212 | state_store: Option<u64>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3213 | /// The size of the EventCacheStore. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3214 | event_cache_store: Option<u64>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3215 | /// The size of the MediaStore. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3216 | media_store: Option<u64>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3217 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3218 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3219 | impl From<matrix_sdk::StoreSizes> for StoreSizes { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3220 | fn from(value: matrix_sdk::StoreSizes) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3221 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3222 | crypto_store: value.crypto_store.map(|v| v as u64), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3223 | state_store: value.state_store.map(|v| v as u64), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3224 | event_cache_store: value.event_cache_store.map(|v| v as u64), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3225 | media_store: value.media_store.map(|v| v as u64), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3226 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3227 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3228 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3229 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3230 | #[derive(uniffi::Object)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3231 | pub struct HomeserverCapabilities { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3232 | inner: matrix_sdk::HomeserverCapabilities, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3233 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3234 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3235 | impl HomeserverCapabilities { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3236 | pub(crate) fn new(capabilities: matrix_sdk::HomeserverCapabilities) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3237 | Self { inner: capabilities } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3238 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3239 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3240 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3241 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3242 | impl HomeserverCapabilities { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3243 | pub async fn refresh(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3244 | Ok(self.inner.refresh().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3245 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3246 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3247 | pub async fn can_change_password(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3248 | Ok(self.inner.can_change_password().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3249 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3250 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3251 | pub async fn can_change_displayname(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3252 | Ok(self.inner.can_change_displayname().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3253 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3254 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3255 | pub async fn can_change_avatar(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3256 | Ok(self.inner.can_change_avatar().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3257 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3258 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3259 | pub async fn can_change_thirdparty_ids(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3260 | Ok(self.inner.can_change_thirdparty_ids().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3261 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3262 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3263 | pub async fn can_get_login_token(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3264 | Ok(self.inner.can_get_login_token().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3265 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3266 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3267 | pub async fn extended_profile_fields(&self) -> Result<ExtendedProfileFields, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3268 | let profile_fields = self.inner.extended_profile_fields().await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3269 | Ok(ExtendedProfileFields { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3270 | enabled: profile_fields.enabled, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3271 | allowed: profile_fields |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3272 | .allowed |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3273 | .unwrap_or_default() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3274 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3275 | .map(ToString::to_string) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3276 | .collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3277 | disallowed: profile_fields |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3278 | .disallowed |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3279 | .unwrap_or_default() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3280 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3281 | .map(ToString::to_string) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3282 | .collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3283 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3284 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3285 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3286 | pub async fn forgets_room_when_leaving(&self) -> Result<bool, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3287 | Ok(self.inner.forgets_room_when_leaving().await?) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3288 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3289 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3290 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3291 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3292 | pub struct ExtendedProfileFields { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3293 | pub enabled: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3294 | pub allowed: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3295 | pub disallowed: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3296 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3297 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3298 | #[cfg(test)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3299 | mod tests { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3300 | use std::time::Duration; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3301 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3302 | use ruma::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3303 | ServerName, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3304 | api::client::room::{Visibility, create_room}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3305 | authentication::TokenType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3306 | events::StateEventType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3307 | room::RoomType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3308 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3309 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3310 | use crate::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3311 | client::{CreateRoomParameters, JoinRule, OpenIdToken, RoomPreset, RoomVisibility}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3312 | room::RoomHistoryVisibility, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3313 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3314 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3315 | #[test] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3316 | fn test_create_room_parameters_mapping() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3317 | let params = CreateRoomParameters { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3318 | name: Some("A room".to_owned()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3319 | topic: Some("A topic".to_owned()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3320 | is_encrypted: true, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3321 | is_direct: true, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3322 | visibility: RoomVisibility::Public, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3323 | preset: RoomPreset::PublicChat, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3324 | invite: Some(vec!["@user:example.com".to_owned()]), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3325 | avatar: Some("http://example.com/avatar.jpg".to_owned()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3326 | power_level_content_override: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3327 | join_rule_override: Some(JoinRule::Knock), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3328 | history_visibility_override: Some(RoomHistoryVisibility::Shared), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3329 | canonical_alias: Some("#a-room:example.com".to_owned()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3330 | is_space: true, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3331 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3332 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3333 | let request: create_room::v3::Request = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3334 | params.try_into().expect("CreateRoomParameters couldn't be transformed into a Request"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3335 | let initial_state = request |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3336 | .initial_state |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3337 | .iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3338 | .map(|raw| raw.deserialize().expect("Initial state event failed to deserialize")) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3339 | .collect::<Vec<_>>(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3340 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3341 | assert_eq!(request.name, Some("A room".to_owned())); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3342 | assert_eq!(request.topic, Some("A topic".to_owned())); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3343 | assert!(initial_state.iter().any(|e| e.event_type() == StateEventType::RoomEncryption)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3344 | assert!(request.is_direct); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3345 | assert_eq!(request.visibility, Visibility::Public); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3346 | assert_eq!(request.preset, Some(create_room::v3::RoomPreset::PublicChat)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3347 | assert_eq!(request.invite.len(), 1); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3348 | assert!(initial_state.iter().any(|e| e.event_type() == StateEventType::RoomAvatar)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3349 | assert!(initial_state.iter().any(|e| e.event_type() == StateEventType::RoomJoinRules)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3350 | assert!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3351 | initial_state.iter().any(|e| e.event_type() == StateEventType::RoomHistoryVisibility) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3352 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3353 | assert_eq!(request.room_alias_name, Some("#a-room:example.com".to_owned())); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3354 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3355 | let room_type = request |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3356 | .creation_content |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3357 | .expect("Creation content is missing") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3358 | .deserialize() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3359 | .expect("Creation content can't be deserialized") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3360 | .room_type; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3361 | assert_eq!(room_type, Some(RoomType::Space)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3362 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3363 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3364 | #[test] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3365 | fn test_openid_token_mapping() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3366 | let response = ruma::api::client::account::request_openid_token::v3::Response::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3367 | "open-id-token".to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3368 | TokenType::Bearer, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3369 | ServerName::parse("example.com").expect("valid server name"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3370 | Duration::from_secs(3_600), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3371 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3372 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3373 | let token: OpenIdToken = response.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3374 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3375 | assert_eq!(token.access_token, "open-id-token"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3376 | assert_eq!(token.token_type, "Bearer"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3377 | assert_eq!(token.matrix_server_name, "example.com"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3378 | assert_eq!(token.expires_in_seconds, 3_600); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3379 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3380 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3381 | /// Dropping an FFI [`Client`] on a non-tokio thread must not panic. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3382 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3383 | /// Regression test: `Client.inner` is wrapped in [`AsyncRuntimeDropped`] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3384 | /// precisely because dropping a sqlite-backed [`MatrixClient`] outside a |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3385 | /// tokio runtime context causes `SyncWrapper<rusqlite::Connection>::drop` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3386 | /// to call `tokio::task::spawn_blocking`, which panics and triggers |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3387 | /// SIGABRT. This test guards against accidentally removing that wrapper. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3388 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3389 | #[tokio::test] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3390 | async fn client_drop_on_non_tokio_thread_does_not_panic() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3391 | use std::time::Duration; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3392 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3393 | use matrix_sdk::{Client, config::RequestConfig}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3394 | use matrix_sdk_common::cross_process_lock::CrossProcessLockConfig; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3395 | use tempfile::tempdir; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3396 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3397 | let dir = tempdir().unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3398 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3399 | // SingleProcess lock avoids the session-delegate requirement in |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3400 | // `Client::new`, keeping the test self-contained. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3401 | let sdk_client = Client::builder() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3402 | .homeserver_url("https://example.com") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3403 | .request_config(RequestConfig::new().disable_retry()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3404 | .sqlite_store(dir.path(), None) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3405 | .cross_process_store_config(CrossProcessLockConfig::SingleProcess) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3406 | .build() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3407 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3408 | .unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3409 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3410 | // Allow background init tasks to complete; after this the only strong |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3411 | // reference to `ClientInner` is the local `sdk_client` variable. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3412 | tokio::time::sleep(Duration::from_secs(1)).await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3413 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3414 | let ffi_client = super::Client::new(sdk_client.clone(), None, None).await.unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3415 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3416 | // Dropping `sdk_client` leaves `ffi_client` as the sole Arc holder of |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3417 | // `ClientInner` — mirroring what happens when the last JS reference to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3418 | // a Client is garbage-collected on the Hermes JS thread. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3419 | drop(sdk_client); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3420 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3421 | // Simulate Hermes GC on the JS thread (a non-tokio thread). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3422 | // Without `AsyncRuntimeDropped` wrapping `Client.inner` this SIGABRT. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3423 | std::thread::spawn(move || drop(ffi_client)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3424 | .join() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3425 | .expect("Client::drop panicked on a non-tokio thread"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3426 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3427 | } |