diff --git a/bindings/matrix-sdk-crypto-ffi/Cargo.toml b/bindings/matrix-sdk-crypto-ffi/Cargo.toml index 31086c8b14f..1aa63edb24f 100644 --- a/bindings/matrix-sdk-crypto-ffi/Cargo.toml +++ b/bindings/matrix-sdk-crypto-ffi/Cargo.toml @@ -2,7 +2,7 @@ name = "matrix-sdk-crypto-ffi" version = "0.1.0" authors = ["Damir Jelić "] -edition = "2021" +edition = "2024" rust-version.workspace = true description = "Uniffi based bindings for the Rust SDK crypto crate" repository = "https://github.com/matrix-org/matrix-rust-sdk" diff --git a/bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs b/bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs index 239b9077204..aa086c6350a 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/backup_recovery_key.rs @@ -3,10 +3,10 @@ use std::{collections::HashMap, iter, ops::DerefMut, sync::Arc}; use hmac::Hmac; use matrix_sdk_crypto::{ backups::DecryptionError, - store::{types::BackupDecryptionKey, CryptoStoreError as InnerStoreError}, + store::{CryptoStoreError as InnerStoreError, types::BackupDecryptionKey}, }; use pbkdf2::pbkdf2; -use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use rand::{Rng, distributions::Alphanumeric, thread_rng}; use sha2::Sha512; use thiserror::Error; use zeroize::Zeroize; diff --git a/bindings/matrix-sdk-crypto-ffi/src/dehydrated_devices.rs b/bindings/matrix-sdk-crypto-ffi/src/dehydrated_devices.rs index b3477ee1739..826e3a6b7ee 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/dehydrated_devices.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/dehydrated_devices.rs @@ -8,7 +8,7 @@ use matrix_sdk_crypto::{ }, store::types::DehydratedDeviceKey as InnerDehydratedDeviceKey, }; -use ruma::{api::client::dehydrated_device, events::AnyToDeviceEvent, serde::Raw, OwnedDeviceId}; +use ruma::{OwnedDeviceId, api::client::dehydrated_device, events::AnyToDeviceEvent, serde::Raw}; use serde_json::json; use crate::{CryptoStoreError, DehydratedDeviceKey}; @@ -222,7 +222,7 @@ impl From #[cfg(test)] mod tests { - use crate::{dehydrated_devices::DehydrationError, DehydratedDeviceKey}; + use crate::{DehydratedDeviceKey, dehydrated_devices::DehydrationError}; #[test] fn test_creating_dehydrated_key() { diff --git a/bindings/matrix-sdk-crypto-ffi/src/error.rs b/bindings/matrix-sdk-crypto-ffi/src/error.rs index eff34067db1..fc230f400e5 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/error.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/error.rs @@ -1,9 +1,9 @@ #![allow(missing_docs)] use matrix_sdk_crypto::{ - store::{CryptoStoreError as InnerStoreError, DehydrationError as InnerDehydrationError}, KeyExportError, MegolmError, OlmError, SecretImportError as RustSecretImportError, SignatureError as InnerSignatureError, + store::{CryptoStoreError as InnerStoreError, DehydrationError as InnerDehydrationError}, }; use matrix_sdk_sqlite::OpenStoreError; use ruma::{IdParseError, OwnedUserId}; diff --git a/bindings/matrix-sdk-crypto-ffi/src/lib.rs b/bindings/matrix-sdk-crypto-ffi/src/lib.rs index 2ef5bb3b59a..4e3bc691854 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/lib.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/lib.rs @@ -31,22 +31,22 @@ pub use error::{ CryptoStoreError, DecryptionError, KeyImportError, SecretImportError, SignatureError, }; use js_int::UInt; -pub use logger::{set_logger, Logger}; +pub use logger::{Logger, set_logger}; pub use machine::{KeyRequestPair, OlmMachine, SignatureVerification}; use matrix_sdk_common::deserialized_responses::{ShieldState as RustShieldState, ShieldStateCode}; use matrix_sdk_crypto::{ + CollectStrategy, EncryptionSettings as RustEncryptionSettings, olm::{IdentityKeys, InboundGroupSession, SenderData, Session}, store::{ + CryptoStore, types::{ Changes, DehydratedDeviceKey as InnerDehydratedDeviceKey, PendingChanges, RoomSettings as RustRoomSettings, }, - CryptoStore, }, types::{ DeviceKey, DeviceKeys, EventEncryptionAlgorithm as RustEventEncryptionAlgorithm, SigningKey, }, - CollectStrategy, EncryptionSettings as RustEncryptionSettings, }; use matrix_sdk_sqlite::SqliteCryptoStore; pub use responses::{ @@ -54,9 +54,9 @@ pub use responses::{ Request, RequestType, SignatureUploadRequest, UploadSigningKeysRequest, }; use ruma::{ - events::room::history_visibility::HistoryVisibility as RustHistoryVisibility, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId, SecondsSinceUnixEpoch, UserId, + events::room::history_visibility::HistoryVisibility as RustHistoryVisibility, }; use serde::{Deserialize, Serialize}; use tokio::runtime::Runtime; @@ -1034,11 +1034,11 @@ uniffi::setup_scaffolding!(); #[cfg(test)] mod tests { use anyhow::Result; - use serde_json::{json, Value}; + use serde_json::{Value, json}; use tempfile::tempdir; use super::MigrationData; - use crate::{migrate, EventEncryptionAlgorithm, OlmMachine, RoomSettings}; + use crate::{EventEncryptionAlgorithm, OlmMachine, RoomSettings, migrate}; #[test] fn android_migration() -> Result<()> { diff --git a/bindings/matrix-sdk-crypto-ffi/src/logger.rs b/bindings/matrix-sdk-crypto-ffi/src/logger.rs index 6b53a352a77..97624c07177 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/logger.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/logger.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, Mutex}, }; -use tracing_subscriber::{fmt::MakeWriter, EnvFilter}; +use tracing_subscriber::{EnvFilter, fmt::MakeWriter}; /// Trait that can be used to forward Rust logs over FFI to a language specific /// logger. diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index cd5784d80e9..a859689175a 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -10,6 +10,7 @@ use std::{ use js_int::UInt; use matrix_sdk_common::deserialized_responses::AlgorithmInfo; use matrix_sdk_crypto::{ + DecryptionSettings, LocalTrust, OlmMachine as InnerMachine, UserIdentity as SdkUserIdentity, backups::{ MegolmV1BackupKey as RustBackupKey, SignatureState, SignatureVerification as RustSignatureCheckResult, @@ -18,10 +19,12 @@ use matrix_sdk_crypto::{ olm::ExportedRoomKey, store::types::{BackupDecryptionKey, Changes}, types::requests::ToDeviceRequest, - DecryptionSettings, LocalTrust, OlmMachine as InnerMachine, UserIdentity as SdkUserIdentity, }; use ruma::{ + DeviceKeyAlgorithm, EventId, OneTimeKeyAlgorithm, OwnedTransactionId, OwnedUserId, RoomId, + UserId, api::{ + IncomingResponse, client::{ backup::add_backup_keys::v3::Response as KeysBackupResponse, keys::{ @@ -31,35 +34,32 @@ use ruma::{ upload_signatures::v3::Response as SignatureUploadResponse, }, message::send_message_event::v3::Response as RoomMessageResponse, - sync::sync_events::{v3::ToDevice, DeviceLists as RumaDeviceLists}, + sync::sync_events::{DeviceLists as RumaDeviceLists, v3::ToDevice}, to_device::send_event_to_device::v3::Response as ToDeviceResponse, }, - IncomingResponse, }, events::{ - key::verification::VerificationMethod, room::message::MessageType, AnyMessageLikeEvent, - AnySyncMessageLikeEvent, MessageLikeEvent, + AnyMessageLikeEvent, AnySyncMessageLikeEvent, MessageLikeEvent, + key::verification::VerificationMethod, room::message::MessageType, }, serde::Raw, to_device::DeviceIdOrAllDevices, - DeviceKeyAlgorithm, EventId, OneTimeKeyAlgorithm, OwnedTransactionId, OwnedUserId, RoomId, - UserId, }; use serde::{Deserialize, Serialize}; -use serde_json::{value::RawValue, Value}; +use serde_json::{Value, value::RawValue}; use tokio::runtime::Runtime; use zeroize::Zeroize; use crate::{ - dehydrated_devices::DehydratedDevices, - error::{CryptoStoreError, DecryptionError, SecretImportError, SignatureError}, - parse_user_id, - responses::{response_from_string, OwnedResponse}, BackupKeys, BackupRecoveryKey, BootstrapCrossSigningResult, CrossSigningKeyExport, CrossSigningStatus, DecodeError, DecryptedEvent, Device, DeviceLists, EncryptionSettings, EventEncryptionAlgorithm, KeyImportError, KeysImportResult, MegolmV1BackupKey, ProgressListener, Request, RequestType, RequestVerificationResult, RoomKeyCounts, RoomSettings, Sas, SignatureUploadRequest, StartSasResult, UserIdentity, Verification, VerificationRequest, + dehydrated_devices::DehydratedDevices, + error::{CryptoStoreError, DecryptionError, SecretImportError, SignatureError}, + parse_user_id, + responses::{OwnedResponse, response_from_string}, }; /// The return value for the [`OlmMachine::receive_sync_changes()`] method. diff --git a/bindings/matrix-sdk-crypto-ffi/src/responses.rs b/bindings/matrix-sdk-crypto-ffi/src/responses.rs index acc1c3defd2..3f0ace1b0f5 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/responses.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/responses.rs @@ -4,14 +4,15 @@ use std::collections::HashMap; use http::Response; use matrix_sdk_crypto::{ + CrossSigningBootstrapRequests, types::requests::{ AnyIncomingResponse, KeysBackupRequest, OutgoingRequest, OutgoingVerificationRequest as SdkVerificationRequest, RoomMessageRequest, ToDeviceRequest, UploadSigningKeysRequest as RustUploadSigningKeysRequest, }, - CrossSigningBootstrapRequests, }; use ruma::{ + OwnedTransactionId, UserId, api::client::{ backup::add_backup_keys::v3::Response as KeysBackupResponse, keys::{ @@ -28,7 +29,6 @@ use ruma::{ }, assign, events::EventContent, - OwnedTransactionId, UserId, }; use serde_json::json; diff --git a/bindings/matrix-sdk-crypto-ffi/src/users.rs b/bindings/matrix-sdk-crypto-ffi/src/users.rs index 4f5f54ea85e..dadc1038c81 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/users.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/users.rs @@ -1,4 +1,4 @@ -use matrix_sdk_crypto::{types::CrossSigningKey, UserIdentity as SdkUserIdentity}; +use matrix_sdk_crypto::{UserIdentity as SdkUserIdentity, types::CrossSigningKey}; use crate::CryptoStoreError; diff --git a/bindings/matrix-sdk-crypto-ffi/src/verification.rs b/bindings/matrix-sdk-crypto-ffi/src/verification.rs index b7bcd2ae9b9..8b725afaf35 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/verification.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/verification.rs @@ -3,10 +3,11 @@ use std::sync::Arc; use futures_util::{Stream, StreamExt}; use matrix_sdk_common::executor::Handle; use matrix_sdk_crypto::{ - matrix_sdk_qrcode::QrVerificationData, CancelInfo as RustCancelInfo, QrVerification as InnerQr, - QrVerificationState, Sas as InnerSas, SasState as RustSasState, - Verification as InnerVerification, VerificationRequest as InnerVerificationRequest, + CancelInfo as RustCancelInfo, QrVerification as InnerQr, QrVerificationState, Sas as InnerSas, + SasState as RustSasState, Verification as InnerVerification, + VerificationRequest as InnerVerificationRequest, VerificationRequestState as RustVerificationRequestState, + matrix_sdk_qrcode::QrVerificationData, }; use ruma::events::key::verification::VerificationMethod; use vodozemac::{base64_decode, base64_encode}; diff --git a/bindings/matrix-sdk-ffi-macros/Cargo.toml b/bindings/matrix-sdk-ffi-macros/Cargo.toml index 9a21c5b507b..4d6d8db41fb 100644 --- a/bindings/matrix-sdk-ffi-macros/Cargo.toml +++ b/bindings/matrix-sdk-ffi-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "Helper macros to write FFI bindings" -edition = "2021" +edition = "2024" homepage = "https://github.com/matrix-org/matrix-rust-sdk" keywords = ["matrix", "chat", "messaging", "ruma"] license = "Apache-2.0" diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index c36bb2cd95c..3520dddb11f 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "matrix-sdk-ffi" version = "0.12.0" -edition = "2021" +edition = "2024" homepage = "https://github.com/matrix-org/matrix-rust-sdk" keywords = ["matrix", "chat", "messaging", "ffi"] license = "Apache-2.0" diff --git a/bindings/matrix-sdk-ffi/src/authentication.rs b/bindings/matrix-sdk-ffi/src/authentication.rs index cd04fff6558..209d995db1a 100644 --- a/bindings/matrix-sdk-ffi/src/authentication.rs +++ b/bindings/matrix-sdk-ffi/src/authentication.rs @@ -5,12 +5,12 @@ use std::{ }; use matrix_sdk::{ + Error, authentication::oauth::{ + ClientId, ClientRegistrationData, OAuthError as SdkOAuthError, error::OAuthAuthorizationCodeError, registration::{ApplicationType, ClientMetadata, Localized, OAuthGrantType}, - ClientId, ClientRegistrationData, OAuthError as SdkOAuthError, }, - Error, }; use ruma::serde::Raw; use url::Url; diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 472b3ab999f..478c5abe543 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -6,43 +6,43 @@ use std::{ time::Duration, }; -use anyhow::{anyhow, Context as _}; +use anyhow::{Context as _, anyhow}; use futures_util::pin_mut; #[cfg(not(target_family = "wasm"))] use matrix_sdk::media::MediaFileHandle as SdkMediaFileHandle; use matrix_sdk::{ + AuthApi, AuthSession, Client as MatrixClient, STATE_STORE_DATABASE_NAME, SessionChange, + SessionTokens, authentication::oauth::{ AccountManagementActionFull, ClientId, OAuthAuthorizationData, OAuthSession, }, event_cache::EventCacheError, media::{MediaFormat, MediaRequestParameters, MediaRetentionPolicy, MediaThumbnailSettings}, ruma::{ + EventEncryptionAlgorithm, RoomId, TransactionId, UInt, UserId, api::client::{ discovery::{ discover_homeserver::RtcFocusInfo, get_authorization_server_metadata::msc2965::Prompt as RumaOidcPrompt, }, push::{EmailPusherData, PusherIds, PusherInit, PusherKind as RumaPusherKind}, - room::{create_room, Visibility}, + room::{Visibility, create_room}, session::get_login_types, user_directory::search_users, }, events::{ + AnyInitialStateEvent, InitialStateEvent, room::{ avatar::RoomAvatarEventContent, encryption::RoomEncryptionEventContent, message::MessageType, }, - AnyInitialStateEvent, InitialStateEvent, }, serde::Raw, - EventEncryptionAlgorithm, RoomId, TransactionId, UInt, UserId, }, sliding_sync::Version as SdkSlidingSyncVersion, store::RoomLoadSettings as SdkRoomLoadSettings, - AuthApi, AuthSession, Client as MatrixClient, SessionChange, SessionTokens, - STATE_STORE_DATABASE_NAME, }; -use matrix_sdk_common::{stream::StreamExt, SendOutsideWasm, SyncOutsideWasm}; +use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm, stream::StreamExt}; use matrix_sdk_ui::{ notification_client::{ NotificationClient as MatrixNotificationClient, @@ -52,8 +52,12 @@ use matrix_sdk_ui::{ }; use mime::Mime; use ruma::{ + OwnedServerName, RoomAliasId, RoomOrAliasId, ServerName, api::client::{alias::get_alias, error::ErrorKind, uiaa::UserIdentifier}, events::{ + GlobalAccountDataEvent as RumaGlobalAccountDataEvent, + GlobalAccountDataEventType as RumaGlobalAccountDataEventType, + RoomAccountDataEvent as RumaRoomAccountDataEvent, direct::DirectEventContent, fully_read::FullyReadEventContent, identity_server::IdentityServerEventContent, @@ -73,24 +77,21 @@ use ruma::{ default_key::SecretStorageDefaultKeyEventContent, key::SecretStorageKeyEventContent, }, tag::TagEventContent, - GlobalAccountDataEvent as RumaGlobalAccountDataEvent, - GlobalAccountDataEventType as RumaGlobalAccountDataEventType, - RoomAccountDataEvent as RumaRoomAccountDataEvent, }, push::{HttpPusherData as RumaHttpPusherData, PushFormat as RumaPushFormat}, - OwnedServerName, RoomAliasId, RoomOrAliasId, ServerName, }; use serde::{Deserialize, Serialize}; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use tokio::sync::broadcast::error::RecvError; use tracing::{debug, error}; use url::Url; use super::{ - room::{room_info::RoomInfo, Room}, + room::{Room, room_info::RoomInfo}, session_verification::SessionVerificationController, }; use crate::{ + ClientError, authentication::{HomeserverLoginDetails, OidcConfiguration, OidcError, SsoError, SsoHandler}, client, encryption::Encryption, @@ -108,7 +109,6 @@ use crate::{ task_handle::TaskHandle, utd::{UnableToDecryptDelegate, UtdHook}, utils::AsyncRuntimeDropped, - ClientError, }; #[derive(Clone, uniffi::Record)] diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index 829ff9956a2..2c7698137c8 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -4,8 +4,10 @@ use futures_util::StreamExt; #[cfg(not(target_family = "wasm"))] use matrix_sdk::reqwest::Certificate; use matrix_sdk::{ + Client as MatrixClient, ClientBuildError as MatrixClientBuildError, HttpError, IdParseError, + RumaApiError, SqliteStoreConfig, crypto::{ - types::qr_login::QrCodeModeData, CollectStrategy, DecryptionSettings, TrustRequirement, + CollectStrategy, DecryptionSettings, TrustRequirement, types::qr_login::QrCodeModeData, }, encryption::{BackupDownloadStrategy, EncryptionSettings}, event_cache::EventCacheError, @@ -14,8 +16,6 @@ use matrix_sdk::{ Error as MatrixSlidingSyncError, VersionBuilder as MatrixSlidingSyncVersionBuilder, VersionBuilderError, }, - Client as MatrixClient, ClientBuildError as MatrixClientBuildError, HttpError, IdParseError, - RumaApiError, SqliteStoreConfig, }; use ruma::api::error::{DeserializationError, FromHttpResponseError}; use tracing::{debug, error}; diff --git a/bindings/matrix-sdk-ffi/src/error.rs b/bindings/matrix-sdk-ffi/src/error.rs index 746d9c9fb1a..a53d2033c2a 100644 --- a/bindings/matrix-sdk-ffi/src/error.rs +++ b/bindings/matrix-sdk-ffi/src/error.rs @@ -1,19 +1,19 @@ use std::{collections::HashMap, error::Error, fmt, fmt::Display}; use matrix_sdk::{ + HttpError, IdParseError, NotificationSettingsError as SdkNotificationSettingsError, + QueueWedgeError as SdkQueueWedgeError, StoreError, authentication::oauth::OAuthError, - encryption::{identities::RequestVerificationError, CryptoStoreError}, + encryption::{CryptoStoreError, identities::RequestVerificationError}, event_cache::EventCacheError, reqwest, room::edit::EditError, send_queue::RoomSendQueueError, - HttpError, IdParseError, NotificationSettingsError as SdkNotificationSettingsError, - QueueWedgeError as SdkQueueWedgeError, StoreError, }; use matrix_sdk_ui::{encryption_sync_service, notification_client, sync_service, timeline}; use ruma::{ - api::client::error::{ErrorBody, ErrorKind as RumaApiErrorKind, RetryAfter}, MilliSecondsSinceUnixEpoch, + api::client::error::{ErrorBody, ErrorKind as RumaApiErrorKind, RetryAfter}, }; use tracing::warn; use uniffi::UnexpectedUniFFICallbackError; diff --git a/bindings/matrix-sdk-ffi/src/event.rs b/bindings/matrix-sdk-ffi/src/event.rs index 98e636a9804..2a2f7575cb1 100644 --- a/bindings/matrix-sdk-ffi/src/event.rs +++ b/bindings/matrix-sdk-ffi/src/event.rs @@ -1,26 +1,26 @@ use std::ops::Deref; -use anyhow::{bail, Context}; +use anyhow::{Context, bail}; use matrix_sdk::IdParseError; use matrix_sdk_ui::timeline::TimelineEventItemId; use ruma::{ + EventId, events::{ + AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, + MessageLikeEventContent as RumaMessageLikeEventContent, RedactContent, + RedactedStateEventContent, StaticStateEventContent, SyncMessageLikeEvent, SyncStateEvent, room::{ message::{MessageType as RumaMessageType, Relation}, redaction::SyncRoomRedactionEvent, }, - AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, - MessageLikeEventContent as RumaMessageLikeEventContent, RedactContent, - RedactedStateEventContent, StaticStateEventContent, SyncMessageLikeEvent, SyncStateEvent, }, - EventId, }; use crate::{ + ClientError, room_member::MembershipState, ruma::{MessageType, NotifyType}, utils::Timestamp, - ClientError, }; #[derive(uniffi::Object)] diff --git a/bindings/matrix-sdk-ffi/src/notification.rs b/bindings/matrix-sdk-ffi/src/notification.rs index ca83703c865..d8b63403c17 100644 --- a/bindings/matrix-sdk-ffi/src/notification.rs +++ b/bindings/matrix-sdk-ffi/src/notification.rs @@ -121,14 +121,12 @@ impl NotificationClient { let room_id = RoomId::parse(room_id)?; let event_id = EventId::parse(event_id)?; - let item = - self.inner.get_notification(&room_id, &event_id).await.map_err(ClientError::from)?; - - if let Some(item) = item { - Ok(Some(NotificationItem::from_inner(item))) - } else { - Ok(None) - } + Ok(self + .inner + .get_notification(&room_id, &event_id) + .await + .map_err(ClientError::from)? + .map(NotificationItem::from_inner)) } /// Get several notification items in a single batch. diff --git a/bindings/matrix-sdk-ffi/src/notification_settings.rs b/bindings/matrix-sdk-ffi/src/notification_settings.rs index 0e0b2342426..9f8342c0908 100644 --- a/bindings/matrix-sdk-ffi/src/notification_settings.rs +++ b/bindings/matrix-sdk-ffi/src/notification_settings.rs @@ -1,22 +1,22 @@ use std::sync::{Arc, RwLock}; use matrix_sdk::{ + Client as MatrixClient, event_handler::EventHandlerHandle, notification_settings::{ NotificationSettings as SdkNotificationSettings, RoomNotificationMode as SdkRoomNotificationMode, }, ruma::events::push_rules::PushRulesEvent, - Client as MatrixClient, }; use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm}; use ruma::{ + Int, RoomId, UInt, push::{ Action as SdkAction, ComparisonOperator as SdkComparisonOperator, PredefinedOverrideRuleId, PredefinedUnderrideRuleId, PushCondition as SdkPushCondition, RoomMemberCountIs, RuleKind as SdkRuleKind, ScalarJsonValue as SdkJsonValue, Tweak as SdkTweak, }, - Int, RoomId, UInt, }; use tokio::sync::RwLock as AsyncRwLock; diff --git a/bindings/matrix-sdk-ffi/src/platform.rs b/bindings/matrix-sdk-ffi/src/platform.rs index 6ff4be1a43f..54c161bd2ce 100644 --- a/bindings/matrix-sdk-ffi/src/platform.rs +++ b/bindings/matrix-sdk-ffi/src/platform.rs @@ -1,23 +1,22 @@ use std::sync::OnceLock; #[cfg(feature = "sentry")] -use std::sync::{atomic::AtomicBool, Arc}; +use std::sync::{Arc, atomic::AtomicBool}; #[cfg(feature = "sentry")] use tracing::warn; use tracing_appender::rolling::{RollingFileAppender, Rotation}; use tracing_core::Subscriber; use tracing_subscriber::{ + Layer, field::RecordFields, fmt::{ - self, + self, FormatEvent, FormatFields, FormattedFields, format::{DefaultFields, Writer}, time::FormatTime, - FormatEvent, FormatFields, FormattedFields, }, layer::SubscriberExt as _, registry::LookupSpan, util::SubscriberInitExt as _, - Layer, }; use crate::{error::ClientError, tracing::LogLevel}; @@ -391,7 +390,10 @@ impl TracingConfiguration { #[cfg_attr(not(feature = "sentry"), allow(unused_mut))] fn build(mut self) -> LoggingCtx { // Show full backtraces, if we run into panics. - std::env::set_var("RUST_BACKTRACE", "1"); + // TODO: Audit that the environment access only happens in single-threaded code. + unsafe { + std::env::set_var("RUST_BACKTRACE", "1"); + } // Log panics. log_panics::init(); diff --git a/bindings/matrix-sdk-ffi/src/room/mod.rs b/bindings/matrix-sdk-ffi/src/room/mod.rs index ab6aa80f79a..b41419555a3 100644 --- a/bindings/matrix-sdk-ffi/src/room/mod.rs +++ b/bindings/matrix-sdk-ffi/src/room/mod.rs @@ -1,42 +1,41 @@ use std::{collections::HashMap, pin::pin, sync::Arc}; use anyhow::{Context, Result}; -use futures_util::{pin_mut, StreamExt}; +use futures_util::{StreamExt, pin_mut}; use matrix_sdk::{ - crypto::LocalTrust, - room::{ - edit::EditedContent, power_levels::RoomPowerLevelChanges, Room as SdkRoom, RoomMemberRole, - TryFromReportedContentScoreError, - }, ComposerDraft as SdkComposerDraft, ComposerDraftType as SdkComposerDraftType, EncryptionState, PredecessorRoom as SdkPredecessorRoom, RoomHero as SdkRoomHero, RoomMemberships, RoomState, SuccessorRoom as SdkSuccessorRoom, + crypto::LocalTrust, + room::{ + Room as SdkRoom, RoomMemberRole, TryFromReportedContentScoreError, edit::EditedContent, + power_levels::RoomPowerLevelChanges, + }, }; use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm}; use matrix_sdk_ui::{ - timeline::{default_event_filter, RoomExt, TimelineBuilder}, + timeline::{RoomExt, TimelineBuilder, default_event_filter}, unable_to_decrypt_hook::UtdHookManager, }; use mime::Mime; use ruma::{ - assign, + EventId, Int, OwnedDeviceId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomAliasId, + ServerName, UserId, assign, events::{ + AnyMessageLikeEventContent, AnySyncTimelineEvent, call::notify, room::{ - avatar::ImageInfo as RumaAvatarImageInfo, + MediaSource, avatar::ImageInfo as RumaAvatarImageInfo, history_visibility::HistoryVisibility as RumaHistoryVisibility, join_rules::JoinRule as RumaJoinRule, message::RoomMessageEventContentWithoutRelation, - MediaSource, }, - AnyMessageLikeEventContent, AnySyncTimelineEvent, }, - EventId, Int, OwnedDeviceId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomAliasId, - ServerName, UserId, }; use tracing::{error, warn}; use self::{power_levels::RoomPowerLevels, room_info::RoomInfo}; use crate::{ + TaskHandle, chunk_iterator::ChunkIterator, client::{JoinRule, RoomVisibility}, error::{ClientError, MediaInfoError, NotYetImplemented, RoomError}, @@ -47,11 +46,10 @@ use crate::{ ruma::{ImageInfo, LocationContent, Mentions, NotifyType}, runtime::get_runtime_handle, timeline::{ - configuration::{TimelineConfiguration, TimelineFilter}, EventTimelineItem, ReceiptType, SendHandle, Timeline, + configuration::{TimelineConfiguration, TimelineFilter}, }, - utils::{u64_to_uint, AsyncRuntimeDropped}, - TaskHandle, + utils::{AsyncRuntimeDropped, u64_to_uint}, }; mod power_levels; diff --git a/bindings/matrix-sdk-ffi/src/room/power_levels.rs b/bindings/matrix-sdk-ffi/src/room/power_levels.rs index 766391bdbfa..e0f5a1c2510 100644 --- a/bindings/matrix-sdk-ffi/src/room/power_levels.rs +++ b/bindings/matrix-sdk-ffi/src/room/power_levels.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use anyhow::Result; use ruma::{ - events::{room::power_levels::RoomPowerLevels as RumaPowerLevels, TimelineEventType}, OwnedUserId, UserId, + events::{TimelineEventType, room::power_levels::RoomPowerLevels as RumaPowerLevels}, }; use crate::{ diff --git a/bindings/matrix-sdk-ffi/src/room/room_info.rs b/bindings/matrix-sdk-ffi/src/room/room_info.rs index 189d2e0c87a..443a5d79a9d 100644 --- a/bindings/matrix-sdk-ffi/src/room/room_info.rs +++ b/bindings/matrix-sdk-ffi/src/room/room_info.rs @@ -8,7 +8,7 @@ use crate::{ error::ClientError, notification_settings::RoomNotificationMode, room::{ - power_levels::RoomPowerLevels, Membership, RoomHero, RoomHistoryVisibility, SuccessorRoom, + Membership, RoomHero, RoomHistoryVisibility, SuccessorRoom, power_levels::RoomPowerLevels, }, room_member::RoomMember, }; diff --git a/bindings/matrix-sdk-ffi/src/room_list.rs b/bindings/matrix-sdk-ffi/src/room_list.rs index 544e2a87d17..5ceb30e5fd9 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -3,29 +3,29 @@ use std::{fmt::Debug, mem::MaybeUninit, ptr::addr_of_mut, sync::Arc, time::Duration}; use eyeball_im::VectorDiff; -use futures_util::{pin_mut, StreamExt}; +use futures_util::{StreamExt, pin_mut}; use matrix_sdk::{ + Room as SdkRoom, ruma::{ - api::client::sync::sync_events::UnreadNotificationsCount as RumaUnreadNotificationsCount, RoomId, + api::client::sync::sync_events::UnreadNotificationsCount as RumaUnreadNotificationsCount, }, - Room as SdkRoom, }; use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm}; use matrix_sdk_ui::{ room_list_service::filters::{ - new_filter_all, new_filter_any, new_filter_category, new_filter_deduplicate_versions, - new_filter_favourite, new_filter_fuzzy_match_room_name, new_filter_invite, - new_filter_joined, new_filter_non_left, new_filter_none, - new_filter_normalized_match_room_name, new_filter_unread, BoxedFilterFn, RoomCategory, + BoxedFilterFn, RoomCategory, new_filter_all, new_filter_any, new_filter_category, + new_filter_deduplicate_versions, new_filter_favourite, new_filter_fuzzy_match_room_name, + new_filter_invite, new_filter_joined, new_filter_non_left, new_filter_none, + new_filter_normalized_match_room_name, new_filter_unread, }, unable_to_decrypt_hook::UtdHookManager, }; use crate::{ + TaskHandle, room::{Membership, Room}, runtime::get_runtime_handle, - TaskHandle, }; #[derive(Debug, thiserror::Error, uniffi::Error)] diff --git a/bindings/matrix-sdk-ffi/src/room_preview.rs b/bindings/matrix-sdk-ffi/src/room_preview.rs index 89c95038bbe..e750b7d3b0e 100644 --- a/bindings/matrix-sdk-ffi/src/room_preview.rs +++ b/bindings/matrix-sdk-ffi/src/room_preview.rs @@ -1,5 +1,5 @@ use anyhow::Context as _; -use matrix_sdk::{room_preview::RoomPreview as SdkRoomPreview, Client}; +use matrix_sdk::{Client, room_preview::RoomPreview as SdkRoomPreview}; use ruma::{room::RoomType as RumaRoomType, space::SpaceRoomJoinRule}; use tracing::warn; diff --git a/bindings/matrix-sdk-ffi/src/ruma.rs b/bindings/matrix-sdk-ffi/src/ruma.rs index dd9c3397dc7..8292de390e9 100644 --- a/bindings/matrix-sdk-ffi/src/ruma.rs +++ b/bindings/matrix-sdk-ffi/src/ruma.rs @@ -21,8 +21,13 @@ use std::{ use extension_trait::extension_trait; use matrix_sdk::attachment::{BaseAudioInfo, BaseFileInfo, BaseImageInfo, BaseVideoInfo}; use ruma::{ - assign, + KeyDerivationAlgorithm as RumaKeyDerivationAlgorithm, MatrixToUri, MatrixUri as RumaMatrixUri, + OwnedRoomId, OwnedUserId, UInt, UserId, assign, events::{ + GlobalAccountDataEvent as RumaGlobalAccountDataEvent, + GlobalAccountDataEventType as RumaGlobalAccountDataEventType, + RoomAccountDataEvent as RumaRoomAccountDataEvent, + RoomAccountDataEventType as RumaRoomAccountDataEventType, call::notify::NotifyType as RumaNotifyType, direct::DirectEventContent, fully_read::FullyReadEventContent, @@ -37,6 +42,8 @@ use ruma::{ poll::start::PollKind as RumaPollKind, push_rules::PushRulesEventContent, room::{ + ImageInfo as RumaImageInfo, MediaSource as RumaMediaSource, + ThumbnailInfo as RumaThumbnailInfo, message::{ AudioInfo as RumaAudioInfo, AudioMessageEventContent as RumaAudioMessageEventContent, @@ -54,8 +61,6 @@ use ruma::{ VideoInfo as RumaVideoInfo, VideoMessageEventContent as RumaVideoMessageEventContent, }, - ImageInfo as RumaImageInfo, MediaSource as RumaMediaSource, - ThumbnailInfo as RumaThumbnailInfo, }, secret_storage::{ default_key::SecretStorageDefaultKeyEventContent, @@ -70,10 +75,6 @@ use ruma::{ TagEventContent, TagInfo as RumaTagInfo, TagName as RumaTagName, UserTagName as RumaUserTagName, }, - GlobalAccountDataEvent as RumaGlobalAccountDataEvent, - GlobalAccountDataEventType as RumaGlobalAccountDataEventType, - RoomAccountDataEvent as RumaRoomAccountDataEvent, - RoomAccountDataEventType as RumaRoomAccountDataEventType, }, matrix_uri::MatrixId as RumaMatrixId, push::{ @@ -81,8 +82,6 @@ use ruma::{ Ruleset as RumaRuleset, SimplePushRule as RumaSimplePushRule, }, serde::JsonObject, - KeyDerivationAlgorithm as RumaKeyDerivationAlgorithm, MatrixToUri, MatrixUri as RumaMatrixUri, - OwnedRoomId, OwnedUserId, UInt, UserId, }; use tracing::info; @@ -389,11 +388,7 @@ pub enum MessageType { /// is its own field. /// - if a media only has a filename, then body is the filename. fn get_body_and_filename(filename: String, caption: Option) -> (String, Option) { - if let Some(caption) = caption { - (caption, Some(filename)) - } else { - (filename, None) - } + if let Some(caption) = caption { (caption, Some(filename)) } else { (filename, None) } } impl TryFrom for RumaMessageType { diff --git a/bindings/matrix-sdk-ffi/src/runtime.rs b/bindings/matrix-sdk-ffi/src/runtime.rs index 81966b22304..f947ac0e22c 100644 --- a/bindings/matrix-sdk-ffi/src/runtime.rs +++ b/bindings/matrix-sdk-ffi/src/runtime.rs @@ -39,7 +39,7 @@ mod sys { mod sys { use std::future::Future; - use matrix_sdk_common::executor::{spawn, JoinHandle}; + use matrix_sdk_common::executor::{JoinHandle, spawn}; /// A dummy guard that does nothing when dropped. /// This is used for the Wasm implementation to match diff --git a/bindings/matrix-sdk-ffi/src/session_verification.rs b/bindings/matrix-sdk-ffi/src/session_verification.rs index 1c5d79d7032..833306995cc 100644 --- a/bindings/matrix-sdk-ffi/src/session_verification.rs +++ b/bindings/matrix-sdk-ffi/src/session_verification.rs @@ -2,13 +2,13 @@ use std::sync::{Arc, RwLock}; use futures_util::StreamExt; use matrix_sdk::{ + Account, encryption::{ + Encryption, identities::UserIdentity, verification::{SasState, SasVerification, VerificationRequest, VerificationRequestState}, - Encryption, }, ruma::events::key::verification::VerificationMethod, - Account, }; use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm}; use ruma::UserId; diff --git a/bindings/matrix-sdk-ffi/src/sync_service.rs b/bindings/matrix-sdk-ffi/src/sync_service.rs index 296bf748097..3e9bfb5985b 100644 --- a/bindings/matrix-sdk-ffi/src/sync_service.rs +++ b/bindings/matrix-sdk-ffi/src/sync_service.rs @@ -26,8 +26,8 @@ use matrix_sdk_ui::{ }; use crate::{ - error::ClientError, helpers::unwrap_or_clone_arc, room_list::RoomListService, - runtime::get_runtime_handle, TaskHandle, + TaskHandle, error::ClientError, helpers::unwrap_or_clone_arc, room_list::RoomListService, + runtime::get_runtime_handle, }; #[derive(uniffi::Enum)] diff --git a/bindings/matrix-sdk-ffi/src/timeline/configuration.rs b/bindings/matrix-sdk-ffi/src/timeline/configuration.rs index 3300ba5f122..f6ec74eca53 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/configuration.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/configuration.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use matrix_sdk_ui::timeline::event_type_filter::TimelineEventTypeFilter as InnerTimelineEventTypeFilter; use ruma::{ - events::{AnySyncTimelineEvent, TimelineEventType}, EventId, + events::{AnySyncTimelineEvent, TimelineEventType}, }; use super::FocusEventError; diff --git a/bindings/matrix-sdk-ffi/src/timeline/mod.rs b/bindings/matrix-sdk-ffi/src/timeline/mod.rs index 76ae9b4e477..750ef8e5167 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/mod.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/mod.rs @@ -41,7 +41,9 @@ use matrix_sdk_ui::timeline::{ use mime::Mime; use reply::{EmbeddedEventDetails, InReplyToDetails}; use ruma::{ + EventId, UInt, events::{ + AnyMessageLikeEventContent, location::{AssetType as RumaAssetType, LocationContent, ZoomLevel}, poll::{ unstable_end::UnstablePollEndEventContent, @@ -56,9 +58,7 @@ use ruma::{ LocationMessageEventContent, MessageType, ReplyWithinThread, RoomMessageEventContentWithoutRelation, }, - AnyMessageLikeEventContent, }, - EventId, UInt, }; use tokio::sync::Mutex; use tracing::{error, warn}; @@ -1402,7 +1402,7 @@ mod galleries { error::RoomError, ruma::{AudioInfo, FileInfo, FormattedBody, ImageInfo, Mentions, VideoInfo}, runtime::get_runtime_handle, - timeline::{build_thumbnail_info, ReplyParameters, Timeline}, + timeline::{ReplyParameters, Timeline, build_thumbnail_info}, }; #[derive(uniffi::Record)] diff --git a/bindings/matrix-sdk-ffi/src/timeline/msg_like.rs b/bindings/matrix-sdk-ffi/src/timeline/msg_like.rs index 07926192870..00ac0c20347 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/msg_like.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/msg_like.rs @@ -15,7 +15,7 @@ use std::{collections::HashMap, sync::Arc}; use matrix_sdk::crypto::types::events::UtdCause; -use ruma::events::{room::MediaSource as RumaMediaSource, EventContent}; +use ruma::events::{EventContent, room::MediaSource as RumaMediaSource}; use super::{ content::Reaction, diff --git a/bindings/matrix-sdk-ffi/src/timeline/reply.rs b/bindings/matrix-sdk-ffi/src/timeline/reply.rs index 3e3dc082da8..d7300b5539f 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/reply.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/reply.rs @@ -14,7 +14,7 @@ use matrix_sdk_ui::timeline::{EmbeddedEvent, TimelineDetails}; -use super::{content::TimelineItemContent, ProfileDetails}; +use super::{ProfileDetails, content::TimelineItemContent}; #[derive(Clone, uniffi::Object)] pub struct InReplyToDetails { diff --git a/bindings/matrix-sdk-ffi/src/tracing.rs b/bindings/matrix-sdk-ffi/src/tracing.rs index ad3b0404614..7ceee41574c 100644 --- a/bindings/matrix-sdk-ffi/src/tracing.rs +++ b/bindings/matrix-sdk-ffi/src/tracing.rs @@ -4,7 +4,7 @@ use std::{ }; use once_cell::sync::OnceCell; -use tracing::{callsite::DefaultCallsite, field::FieldSet, Callsite}; +use tracing::{Callsite, callsite::DefaultCallsite, field::FieldSet}; use tracing_core::{identify_callsite, metadata::Kind as MetadataKind}; /// Log an event.