diff --git a/bindings/matrix-sdk-crypto-ffi/Cargo.toml b/bindings/matrix-sdk-crypto-ffi/Cargo.toml index 0a197ce4674..4bbdf0791dc 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 7597d0ffb21..8427717f099 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/dehydrated_devices.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/dehydrated_devices.rs @@ -2,14 +2,14 @@ use std::{mem::ManuallyDrop, sync::Arc}; use matrix_sdk_common::executor::Handle; use matrix_sdk_crypto::{ + DecryptionSettings, dehydrated_devices::{ DehydratedDevice as InnerDehydratedDevice, DehydratedDevices as InnerDehydratedDevices, RehydratedDevice as InnerRehydratedDevice, }, store::types::DehydratedDeviceKey as InnerDehydratedDeviceKey, - DecryptionSettings, }; -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}; @@ -227,7 +227,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 255f69d78e4..d2398559a23 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; @@ -1048,11 +1048,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 fb029eb7fd0..29a90f38023 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -10,6 +10,8 @@ use std::{ use js_int::UInt; use matrix_sdk_common::deserialized_responses::AlgorithmInfo; use matrix_sdk_crypto::{ + CollectStrategy, DecryptionSettings, LocalTrust, OlmMachine as InnerMachine, + UserIdentity as SdkUserIdentity, backups::{ MegolmV1BackupKey as RustBackupKey, SignatureState, SignatureVerification as RustSignatureCheckResult, @@ -18,11 +20,12 @@ use matrix_sdk_crypto::{ olm::ExportedRoomKey, store::types::{BackupDecryptionKey, Changes}, types::requests::ToDeviceRequest, - CollectStrategy, 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::{ @@ -32,35 +35,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, AnyTimelineEvent, MessageLikeEvent, + AnyMessageLikeEvent, AnySyncMessageLikeEvent, AnyTimelineEvent, 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 48e296137b4..a572eb1505f 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::MessageLikeEventContent, - 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 462938e1f9c..5502adea3f7 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.16.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 1e7186f814c..e93fe071f21 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 61f4bd4f543..22ce73cb4cc 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -6,44 +6,44 @@ 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; #[cfg(feature = "sqlite")] use matrix_sdk::STATE_STORE_DATABASE_NAME; +#[cfg(not(target_family = "wasm"))] +use matrix_sdk::media::MediaFileHandle as SdkMediaFileHandle; use matrix_sdk::{ + Account, AuthApi, AuthSession, Client as MatrixClient, Error, SessionChange, SessionTokens, authentication::oauth::{ AccountManagementActionFull, ClientId, OAuthAuthorizationData, OAuthSession, }, deserialized_responses::RawAnySyncOrStrippedTimelineEvent, media::{MediaFormat, MediaRequestParameters, MediaRetentionPolicy, MediaThumbnailSettings}, ruma::{ + EventEncryptionAlgorithm, RoomId, TransactionId, UInt, UserId, api::client::{ discovery::{ discover_homeserver::RtcFocusInfo, get_authorization_server_metadata::v1::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, - Account, AuthApi, AuthSession, Client as MatrixClient, Error, SessionChange, SessionTokens, }; -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, @@ -55,6 +55,7 @@ use matrix_sdk_ui::{ use mime::Mime; use oauth2::Scope; use ruma::{ + OwnedDeviceId, OwnedServerName, RoomAliasId, RoomOrAliasId, ServerName, api::client::{ alias::get_alias, error::ErrorKind, @@ -62,6 +63,9 @@ use ruma::{ uiaa::UserIdentifier, }, events::{ + AnyMessageLikeEventContent, AnySyncTimelineEvent, + GlobalAccountDataEvent as RumaGlobalAccountDataEvent, + RoomAccountDataEvent as RumaRoomAccountDataEvent, direct::DirectEventContent, fully_read::FullyReadEventContent, identity_server::IdentityServerEventContent, @@ -81,25 +85,22 @@ use ruma::{ default_key::SecretStorageDefaultKeyEventContent, key::SecretStorageKeyEventContent, }, tag::TagEventContent, - AnyMessageLikeEventContent, AnySyncTimelineEvent, - GlobalAccountDataEvent as RumaGlobalAccountDataEvent, - RoomAccountDataEvent as RumaRoomAccountDataEvent, }, push::{HttpPusherData as RumaHttpPusherData, PushFormat as RumaPushFormat}, room_version_rules::AuthorizationRules, - OwnedDeviceId, 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, @@ -122,7 +123,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 c9c06cf4860..df6ca61fc1a 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -6,6 +6,8 @@ use std::{num::NonZeroUsize, sync::Arc, time::Duration}; #[cfg(not(target_family = "wasm"))] use matrix_sdk::reqwest::Certificate; use matrix_sdk::{ + Client as MatrixClient, ClientBuildError as MatrixClientBuildError, HttpError, IdParseError, + RumaApiError, ThreadingSupport, encryption::{BackupDownloadStrategy, EncryptionSettings}, event_cache::EventCacheError, ruma::{ServerName, UserId}, @@ -13,8 +15,6 @@ use matrix_sdk::{ Error as MatrixSlidingSyncError, VersionBuilder as MatrixSlidingSyncVersionBuilder, VersionBuilderError, }, - Client as MatrixClient, ClientBuildError as MatrixClientBuildError, HttpError, IdParseError, - RumaApiError, ThreadingSupport, }; use matrix_sdk_base::crypto::{CollectStrategy, DecryptionSettings, TrustRequirement}; use ruma::api::error::{DeserializationError, FromHttpResponseError}; diff --git a/bindings/matrix-sdk-ffi/src/error.rs b/bindings/matrix-sdk-ffi/src/error.rs index e2283863f18..c3c37ecf93b 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::{calls::CallError, edit::EditError}, send_queue::RoomSendQueueError, - HttpError, IdParseError, NotificationSettingsError as SdkNotificationSettingsError, - QueueWedgeError as SdkQueueWedgeError, StoreError, }; use matrix_sdk_ui::{encryption_sync_service, notification_client, spaces, sync_service, timeline}; use ruma::{ - api::client::error::{ErrorBody, ErrorKind as RumaApiErrorKind, RetryAfter, StandardErrorBody}, MilliSecondsSinceUnixEpoch, + api::client::error::{ErrorBody, ErrorKind as RumaApiErrorKind, RetryAfter, StandardErrorBody}, }; 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 6f5f6d40e8a..8965169d14c 100644 --- a/bindings/matrix-sdk-ffi/src/event.rs +++ b/bindings/matrix-sdk-ffi/src/event.rs @@ -1,25 +1,25 @@ -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::{ encrypted, 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, RtcNotificationType}, utils::Timestamp, - ClientError, }; #[derive(uniffi::Object)] diff --git a/bindings/matrix-sdk-ffi/src/platform.rs b/bindings/matrix-sdk-ffi/src/platform.rs index efc80443b13..c5387e127b1 100644 --- a/bindings/matrix-sdk-ffi/src/platform.rs +++ b/bindings/matrix-sdk-ffi/src/platform.rs @@ -1,6 +1,6 @@ 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; @@ -9,18 +9,17 @@ use tracing_appender::rolling::{RollingFileAppender, Rotation}; use tracing_core::Level; use tracing_core::Subscriber; use tracing_subscriber::{ + EnvFilter, Layer, Registry, field::RecordFields, fmt::{ - self, + self, FormatEvent, FormatFields, FormattedFields, format::{DefaultFields, Writer}, time::FormatTime, - FormatEvent, FormatFields, FormattedFields, }, layer::{Layered, SubscriberExt as _}, registry::LookupSpan, reload::{self, Handle}, util::SubscriberInitExt as _, - EnvFilter, Layer, Registry, }; #[cfg(feature = "sentry")] @@ -452,7 +451,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(); @@ -471,11 +473,7 @@ impl TracingConfiguration { sentry::ClientOptions { traces_sampler: Some(Arc::new(|ctx| { // Make sure bridge spans are always uploaded - if ctx.name() == BRIDGE_SPAN_NAME { - 1.0 - } else { - 0.0 - } + if ctx.name() == BRIDGE_SPAN_NAME { 1.0 } else { 0.0 } })), attach_stacktrace: true, release: Some(env!("VERGEN_GIT_SHA").into()), diff --git a/bindings/matrix-sdk-ffi/src/qr_code.rs b/bindings/matrix-sdk-ffi/src/qr_code.rs index 898cfb98870..06f06c5b4ea 100644 --- a/bindings/matrix-sdk-ffi/src/qr_code.rs +++ b/bindings/matrix-sdk-ffi/src/qr_code.rs @@ -1,13 +1,13 @@ use std::sync::Arc; use matrix_sdk::authentication::oauth::{ + OAuth, qrcode::{ self, CheckCodeSender as SdkCheckCodeSender, CheckCodeSenderError, DeviceCodeErrorResponseType, GeneratedQrProgress, LoginFailureReason, QrProgress, }, - OAuth, }; -use matrix_sdk_common::{stream::StreamExt, SendOutsideWasm, SyncOutsideWasm}; +use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm, stream::StreamExt}; use crate::{ authentication::OidcConfiguration, runtime::get_runtime_handle, task_handle::TaskHandle, diff --git a/bindings/matrix-sdk-ffi/src/room/mod.rs b/bindings/matrix-sdk-ffi/src/room/mod.rs index 6487ee086cd..4f3cfd58a04 100644 --- a/bindings/matrix-sdk-ffi/src/room/mod.rs +++ b/bindings/matrix-sdk-ffi/src/room/mod.rs @@ -1,44 +1,43 @@ use std::{collections::HashMap, fs, path::PathBuf, pin::pin, sync::Arc}; use anyhow::{Context, Result}; -use futures_util::{pin_mut, StreamExt}; +use futures_util::{StreamExt, pin_mut}; use matrix_sdk::{ - encryption::LocalTrust, - room::{ - edit::EditedContent, power_levels::RoomPowerLevelChanges, Room as SdkRoom, RoomMemberRole, - TryFromReportedContentScoreError, - }, - send_queue::RoomSendQueueUpdate as SdkRoomSendQueueUpdate, ComposerDraft as SdkComposerDraft, ComposerDraftType as SdkComposerDraftType, DraftAttachment as SdkDraftAttachment, DraftAttachmentContent, DraftThumbnail, EncryptionState, PredecessorRoom as SdkPredecessorRoom, RoomHero as SdkRoomHero, RoomMemberships, RoomState, SuccessorRoom as SdkSuccessorRoom, + encryption::LocalTrust, + room::{ + Room as SdkRoom, RoomMemberRole, TryFromReportedContentScoreError, edit::EditedContent, + power_levels::RoomPowerLevelChanges, + }, + send_queue::RoomSendQueueUpdate as SdkRoomSendQueueUpdate, }; 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, receipt::ReceiptThread, room::{ - avatar::ImageInfo as RumaAvatarImageInfo, + MediaSource as RumaMediaSource, avatar::ImageInfo as RumaAvatarImageInfo, history_visibility::HistoryVisibility as RumaHistoryVisibility, join_rules::JoinRule as RumaJoinRule, message::RoomMessageEventContentWithoutRelation, - MediaSource as RumaMediaSource, }, - 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, QueueWedgeError, RoomError}, @@ -52,11 +51,10 @@ use crate::{ }, runtime::get_runtime_handle, timeline::{ - configuration::{TimelineConfiguration, TimelineFilter}, AbstractProgress, LatestEventValue, ReceiptType, SendHandle, Timeline, UploadSource, + 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 d257aaf2dc4..4443ee62f60 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 8f15348341e..6220961fc36 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 64ce938823e..fe82b1f6c6f 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -3,30 +3,30 @@ 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_low_priority, new_filter_non_left, new_filter_none, - new_filter_normalized_match_room_name, new_filter_not, new_filter_space, 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_low_priority, new_filter_non_left, + new_filter_none, new_filter_normalized_match_room_name, new_filter_not, new_filter_space, + 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_member.rs b/bindings/matrix-sdk-ffi/src/room_member.rs index 98f7193d33c..dfd36a47ca9 100644 --- a/bindings/matrix-sdk-ffi/src/room_member.rs +++ b/bindings/matrix-sdk-ffi/src/room_member.rs @@ -1,5 +1,5 @@ use matrix_sdk::room::{RoomMember as SdkRoomMember, RoomMemberRole}; -use ruma::{events::room::power_levels::UserPowerLevel, UserId}; +use ruma::{UserId, events::room::power_levels::UserPowerLevel}; use crate::error::{ClientError, NotYetImplemented}; diff --git a/bindings/matrix-sdk-ffi/src/room_preview.rs b/bindings/matrix-sdk-ffi/src/room_preview.rs index 8b04d708ec1..0773431df47 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::{JoinRuleSummary, RoomType as RumaRoomType}; use crate::{ diff --git a/bindings/matrix-sdk-ffi/src/ruma.rs b/bindings/matrix-sdk-ffi/src/ruma.rs index bd167f90669..691c07b0bfd 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, direct::DirectEventContent, fully_read::FullyReadEventContent, identity_server::IdentityServerEventContent, @@ -36,6 +41,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, @@ -53,8 +60,6 @@ use ruma::{ VideoInfo as RumaVideoInfo, VideoMessageEventContent as RumaVideoMessageEventContent, }, - ImageInfo as RumaImageInfo, MediaSource as RumaMediaSource, - ThumbnailInfo as RumaThumbnailInfo, }, rtc::notification::NotificationType as RumaNotificationType, secret_storage::{ @@ -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 6e0144acd5b..1ce3cb425d0 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/spaces.rs b/bindings/matrix-sdk-ffi/src/spaces.rs index 5d0b9a9be98..a02b339b0e4 100644 --- a/bindings/matrix-sdk-ffi/src/spaces.rs +++ b/bindings/matrix-sdk-ffi/src/spaces.rs @@ -15,22 +15,22 @@ use std::{fmt::Debug, sync::Arc}; use eyeball_im::VectorDiff; -use futures_util::{pin_mut, StreamExt}; +use futures_util::{StreamExt, pin_mut}; use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm}; use matrix_sdk_ui::spaces::{ + SpaceRoom as UISpaceRoom, SpaceRoomList as UISpaceRoomList, SpaceService as UISpaceService, leave::{LeaveSpaceHandle as UILeaveSpaceHandle, LeaveSpaceRoom as UILeaveSpaceRoom}, room_list::SpaceRoomListPaginationState, - SpaceRoom as UISpaceRoom, SpaceRoomList as UISpaceRoomList, SpaceService as UISpaceService, }; use ruma::RoomId; use crate::{ + TaskHandle, client::JoinRule, error::ClientError, room::{Membership, RoomHero}, room_preview::RoomType, runtime::get_runtime_handle, - TaskHandle, }; /// The main entry point into the Spaces facilities. diff --git a/bindings/matrix-sdk-ffi/src/sync_service.rs b/bindings/matrix-sdk-ffi/src/sync_service.rs index 301cd0a8c7c..fdd104b7c7f 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 795b1b01916..a9ca88024f2 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/configuration.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/configuration.rs @@ -1,12 +1,12 @@ use std::sync::Arc; use matrix_sdk_ui::timeline::{ - event_type_filter::TimelineEventTypeFilter as InnerTimelineEventTypeFilter, TimelineReadReceiptTracking, + 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/content.rs b/bindings/matrix-sdk-ffi/src/timeline/content.rs index 4b1b686881b..3f4667940d8 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/content.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/content.rs @@ -17,7 +17,7 @@ use std::collections::HashMap; use matrix_sdk::room::power_levels::power_level_user_changes; use matrix_sdk_ui::timeline::RoomPinnedEventsChange; use ruma::events::{ - room::history_visibility::HistoryVisibility as RumaHistoryVisibility, FullStateEventContent, + FullStateEventContent, room::history_visibility::HistoryVisibility as RumaHistoryVisibility, }; use crate::{client::JoinRule, timeline::msg_like::MsgLikeContent, utils::Timestamp}; diff --git a/bindings/matrix-sdk-ffi/src/timeline/mod.rs b/bindings/matrix-sdk-ffi/src/timeline/mod.rs index 5f28a68bf2a..236588f0481 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/mod.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/mod.rs @@ -37,8 +37,9 @@ use matrix_sdk_ui::timeline::{ use mime::Mime; use reply::{EmbeddedEventDetails, InReplyToDetails}; use ruma::{ - assign, + EventId, UInt, assign, events::{ + AnyMessageLikeEventContent, location::{AssetType as RumaAssetType, LocationContent, ZoomLevel}, poll::{ unstable_end::UnstablePollEndEventContent, @@ -52,9 +53,7 @@ use ruma::{ LocationMessageEventContent, MessageType, RoomMessageEventContentWithoutRelation, TextMessageEventContent, }, - AnyMessageLikeEventContent, }, - EventId, UInt, }; use tokio::sync::Mutex; use tracing::{error, warn}; @@ -1359,7 +1358,7 @@ mod galleries { use matrix_sdk_common::executor::{AbortHandle, JoinHandle}; use matrix_sdk_ui::timeline::GalleryConfig; use mime::Mime; - use ruma::{assign, events::room::message::TextMessageEventContent, EventId}; + use ruma::{EventId, assign, events::room::message::TextMessageEventContent}; use tokio::sync::Mutex; use tracing::error; @@ -1367,7 +1366,7 @@ mod galleries { error::RoomError, ruma::{AudioInfo, FileInfo, FormattedBody, ImageInfo, Mentions, VideoInfo}, runtime::get_runtime_handle, - timeline::{build_thumbnail_info, Timeline, UploadSource}, + timeline::{Timeline, UploadSource, 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 d72691d2931..c8138f3a617 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_base::crypto::types::events::UtdCause; -use ruma::events::{room::MediaSource as RumaMediaSource, MessageLikeEventContent}; +use ruma::events::{MessageLikeEventContent, 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 f548724fc4f..e2d20489f7c 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}; use crate::{event::EventOrTransactionId, utils::Timestamp}; #[derive(Clone, uniffi::Object)] diff --git a/bindings/matrix-sdk-ffi/src/tracing.rs b/bindings/matrix-sdk-ffi/src/tracing.rs index 26c039751ff..7669b1a20b2 100644 --- a/bindings/matrix-sdk-ffi/src/tracing.rs +++ b/bindings/matrix-sdk-ffi/src/tracing.rs @@ -6,7 +6,7 @@ use std::{ }; use once_cell::sync::OnceCell; -use tracing::{callsite::DefaultCallsite, debug, error, field::FieldSet, Callsite}; +use tracing::{Callsite, callsite::DefaultCallsite, debug, error, field::FieldSet}; use tracing_core::{identify_callsite, metadata::Kind as MetadataKind}; /// Log an event.