From 26943b14b88bcbf789de0a82f13bd2091947a8fc Mon Sep 17 00:00:00 2001 From: Daniel Salinas Date: Sun, 13 Oct 2024 10:20:47 -0400 Subject: [PATCH] Restore some marker traits that were needed still --- .../src/event_cache_store/traits.rs | 3 ++- crates/matrix-sdk-base/src/read_receipts.rs | 16 +++++---------- .../matrix-sdk-base/src/store/memory_store.rs | 3 ++- crates/matrix-sdk-base/src/store/mod.rs | 6 +++--- .../src/store/observable_map.rs | 7 ++++--- crates/matrix-sdk-base/src/store/traits.rs | 9 ++++++--- crates/matrix-sdk-common/src/executor.rs | 4 +--- .../src/store/memorystore.rs | 3 ++- crates/matrix-sdk-crypto/src/store/traits.rs | 9 ++++++--- crates/matrix-sdk-ui/src/sync_service.rs | 2 +- .../src/timeline/pinned_events_loader.rs | 5 ++++- .../matrix-sdk-ui/src/timeline/tests/mod.rs | 10 +++++----- crates/matrix-sdk-ui/src/timeline/traits.rs | 20 +++++++++---------- .../src/unable_to_decrypt_hook.rs | 7 +++++-- crates/matrix-sdk/src/event_handler/mod.rs | 3 ++- crates/matrix-sdk/src/sliding_sync/error.rs | 2 +- crates/matrix-sdk/src/sliding_sync/mod.rs | 3 +-- 17 files changed, 60 insertions(+), 52 deletions(-) diff --git a/crates/matrix-sdk-base/src/event_cache_store/traits.rs b/crates/matrix-sdk-base/src/event_cache_store/traits.rs index f7cb15ec492..6c56166177b 100644 --- a/crates/matrix-sdk-base/src/event_cache_store/traits.rs +++ b/crates/matrix-sdk-base/src/event_cache_store/traits.rs @@ -15,6 +15,7 @@ use std::{fmt, sync::Arc}; use async_trait::async_trait; +use matrix_sdk_common::AsyncTraitDeps; use ruma::MxcUri; use super::EventCacheStoreError; @@ -24,7 +25,7 @@ use crate::media::MediaRequest; /// for the event cache of the SDK. #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] -pub trait EventCacheStore: Send + Sync { +pub trait EventCacheStore: AsyncTraitDeps { /// The error type used by this event cache store. type Error: fmt::Debug + Into; diff --git a/crates/matrix-sdk-base/src/read_receipts.rs b/crates/matrix-sdk-base/src/read_receipts.rs index 7fd14721b63..5faa3712613 100644 --- a/crates/matrix-sdk-base/src/read_receipts.rs +++ b/crates/matrix-sdk-base/src/read_receipts.rs @@ -123,7 +123,10 @@ use std::{ }; use eyeball_im::Vector; -use matrix_sdk_common::{deserialized_responses::SyncTimelineEvent, ring_buffer::RingBuffer}; +use matrix_sdk_common::{ + deserialized_responses::SyncTimelineEvent, ring_buffer::RingBuffer, SendOutsideWasm, + SyncOutsideWasm, +}; use ruma::{ events::{ poll::{start::PollStartEventContent, unstable_start::UnstablePollStartEventContent}, @@ -266,16 +269,7 @@ impl RoomReadReceipts { } /// Provider for timeline events prior to the current sync. -#[cfg(not(target_arch = "wasm32"))] -pub trait PreviousEventsProvider: Send + Sync { - /// Returns the list of known timeline events, in sync order, for the given - /// room. - fn for_room(&self, room_id: &RoomId) -> Vector; -} - -/// Provider for timeline events prior to the current sync. -#[cfg(target_arch = "wasm32")] -pub trait PreviousEventsProvider { +pub trait PreviousEventsProvider: SendOutsideWasm + SyncOutsideWasm { /// Returns the list of known timeline events, in sync order, for the given /// room. fn for_room(&self, room_id: &RoomId) -> Vector; diff --git a/crates/matrix-sdk-base/src/store/memory_store.rs b/crates/matrix-sdk-base/src/store/memory_store.rs index babfc885473..995c7113870 100644 --- a/crates/matrix-sdk-base/src/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/store/memory_store.rs @@ -137,7 +137,8 @@ impl MemoryStore { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl StateStore for MemoryStore { type Error = StoreError; diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index dacfe87c989..7df3a3ea020 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -58,9 +58,9 @@ use tokio::sync::{broadcast, Mutex, RwLock}; use tracing::warn; use crate::{ - event_cache_store::{DynEventCacheStore, IntoEventCacheStore}, - rooms::{normal::RoomInfoNotableUpdate, RoomInfo, RoomState}, - MinimalRoomMemberEvent, Room, RoomStateFilter, SessionMeta + event_cache_store::{DynEventCacheStore, IntoEventCacheStore}, + rooms::{normal::RoomInfoNotableUpdate, RoomInfo, RoomState}, + MinimalRoomMemberEvent, Room, RoomStateFilter, SessionMeta, }; pub(crate) mod ambiguity_map; diff --git a/crates/matrix-sdk-base/src/store/observable_map.rs b/crates/matrix-sdk-base/src/store/observable_map.rs index 00d85c52580..f9c8049f9b6 100644 --- a/crates/matrix-sdk-base/src/store/observable_map.rs +++ b/crates/matrix-sdk-base/src/store/observable_map.rs @@ -136,9 +136,9 @@ mod impl_non_wasm32 { #[cfg(target_arch = "wasm32")] mod impl_wasm32 { use std::{borrow::Borrow, collections::BTreeMap, hash::Hash}; - use futures_util::stream; - use futures_util::{Stream, StreamExt}; + use eyeball_im::{Vector, VectorDiff}; + use futures_util::{stream, Stream, StreamExt}; /// An observable map for Wasm. It's a simple wrapper around `BTreeMap`. #[derive(Debug)] @@ -191,7 +191,8 @@ mod impl_wasm32 { /// Get a [`Stream`] of the values. pub(crate) fn stream(&self) -> (Vector, impl Stream>>) { let values: Vector = self.0.values().cloned().collect(); - let stream = stream::iter(vec![values.clone()]).map(|v| vec![VectorDiff::Reset{ values: v }]); + let stream = + stream::iter(vec![values.clone()]).map(|v| vec![VectorDiff::Reset { values: v }]); (values, stream) } } diff --git a/crates/matrix-sdk-base/src/store/traits.rs b/crates/matrix-sdk-base/src/store/traits.rs index cd7cceb2413..d96e3f24cb0 100644 --- a/crates/matrix-sdk-base/src/store/traits.rs +++ b/crates/matrix-sdk-base/src/store/traits.rs @@ -23,6 +23,7 @@ use std::{ use as_variant::as_variant; use async_trait::async_trait; use growable_bloom_filter::GrowableBloom; +use matrix_sdk_common::AsyncTraitDeps; use ruma::{ api::MatrixVersion, events::{ @@ -49,8 +50,9 @@ use crate::{ /// An abstract state store trait that can be used to implement different stores /// for the SDK. -#[async_trait] -pub trait StateStore: fmt::Debug + Send + Sync { +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] +pub trait StateStore: AsyncTraitDeps { /// The error type used by this state store. type Error: fmt::Debug + Into + From; @@ -450,7 +452,8 @@ impl fmt::Debug for EraseStateStoreError { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl StateStore for EraseStateStoreError { type Error = StoreError; diff --git a/crates/matrix-sdk-common/src/executor.rs b/crates/matrix-sdk-common/src/executor.rs index 7f065fc72f5..0083b857f18 100644 --- a/crates/matrix-sdk-common/src/executor.rs +++ b/crates/matrix-sdk-common/src/executor.rs @@ -20,22 +20,20 @@ use std::{ task::{Context, Poll}, }; -use futures_util::FutureExt; #[cfg(target_arch = "wasm32")] pub use futures_util::future::Aborted as JoinError; #[cfg(target_arch = "wasm32")] use futures_util::future::{AbortHandle, Abortable, RemoteHandle}; +use futures_util::FutureExt; #[cfg(not(target_arch = "wasm32"))] pub use tokio::task::{spawn, JoinError, JoinHandle}; - /// A `Box::pin` future that is `Send` on non-wasm, and without `Send` on wasm. #[cfg(target_arch = "wasm32")] pub type BoxFuture<'a, T> = Pin + 'a>>; #[cfg(not(target_arch = "wasm32"))] pub type BoxFuture<'a, T> = Pin + Send + 'a>>; - #[cfg(target_arch = "wasm32")] pub fn spawn(future: F) -> JoinHandle where diff --git a/crates/matrix-sdk-crypto/src/store/memorystore.rs b/crates/matrix-sdk-crypto/src/store/memorystore.rs index c0c60456671..b773d819d94 100644 --- a/crates/matrix-sdk-crypto/src/store/memorystore.rs +++ b/crates/matrix-sdk-crypto/src/store/memorystore.rs @@ -194,7 +194,8 @@ impl MemoryStore { type Result = std::result::Result; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl CryptoStore for MemoryStore { type Error = Infallible; diff --git a/crates/matrix-sdk-crypto/src/store/traits.rs b/crates/matrix-sdk-crypto/src/store/traits.rs index bc2b33e48fd..3031e33ef8d 100644 --- a/crates/matrix-sdk-crypto/src/store/traits.rs +++ b/crates/matrix-sdk-crypto/src/store/traits.rs @@ -15,6 +15,7 @@ use std::{collections::HashMap, fmt, sync::Arc}; use async_trait::async_trait; +use matrix_sdk_common::AsyncTraitDeps; use ruma::{ events::secret::request::SecretName, DeviceId, OwnedDeviceId, RoomId, TransactionId, UserId, }; @@ -36,8 +37,9 @@ use crate::{ /// Represents a store that the `OlmMachine` uses to store E2EE data (such as /// cryptographic keys). -#[async_trait] -pub trait CryptoStore: fmt::Debug + Send + Sync { +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] +pub trait CryptoStore: AsyncTraitDeps { /// The error type used by this crypto store. type Error: fmt::Debug + Into; @@ -367,7 +369,8 @@ impl fmt::Debug for EraseCryptoStoreError { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl CryptoStore for EraseCryptoStoreError { type Error = CryptoStoreError; diff --git a/crates/matrix-sdk-ui/src/sync_service.rs b/crates/matrix-sdk-ui/src/sync_service.rs index f914df253cb..25186263bdc 100644 --- a/crates/matrix-sdk-ui/src/sync_service.rs +++ b/crates/matrix-sdk-ui/src/sync_service.rs @@ -29,8 +29,8 @@ use eyeball::{SharedObservable, Subscriber}; use futures_core::Future; use futures_util::{pin_mut, StreamExt as _}; use matrix_sdk::Client; -use thiserror::Error; use matrix_sdk_base::executor::{spawn, JoinHandle}; +use thiserror::Error; use tokio::sync::{ mpsc::{Receiver, Sender}, Mutex as AsyncMutex, OwnedMutexGuard, diff --git a/crates/matrix-sdk-ui/src/timeline/pinned_events_loader.rs b/crates/matrix-sdk-ui/src/timeline/pinned_events_loader.rs index 7c7f4f90297..340e10727d5 100644 --- a/crates/matrix-sdk-ui/src/timeline/pinned_events_loader.rs +++ b/crates/matrix-sdk-ui/src/timeline/pinned_events_loader.rs @@ -16,7 +16,10 @@ use std::{fmt::Formatter, sync::Arc}; use futures_util::{stream, StreamExt}; use matrix_sdk::{ - config::RequestConfig, event_cache::paginator::PaginatorError, executor::{BoxFuture, BoxFutureExt}, Room, + config::RequestConfig, + event_cache::paginator::PaginatorError, + executor::{BoxFuture, BoxFutureExt}, + Room, }; use matrix_sdk_base::deserialized_responses::SyncTimelineEvent; use ruma::{events::relation::RelationType, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId}; diff --git a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs index fba8e68c6ee..35e42b1f446 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs @@ -27,11 +27,11 @@ use futures_util::FutureExt as _; use indexmap::IndexMap; use matrix_sdk::{ config::RequestConfig, - deserialized_responses::{SyncTimelineEvent, TimelineEvent}, - event_cache::paginator::{PaginableRoom, PaginatorError}, - executor::{BoxFuture, BoxFutureExt}, - room::{EventWithContextResponse, Messages, MessagesOptions}, - send_queue::RoomSendQueueUpdate, + deserialized_responses::{SyncTimelineEvent, TimelineEvent}, + event_cache::paginator::{PaginableRoom, PaginatorError}, + executor::{BoxFuture, BoxFutureExt}, + room::{EventWithContextResponse, Messages, MessagesOptions}, + send_queue::RoomSendQueueUpdate, test_utils::events::EventFactory, }; use matrix_sdk_base::{latest_event::LatestEvent, RoomInfo, RoomState}; diff --git a/crates/matrix-sdk-ui/src/timeline/traits.rs b/crates/matrix-sdk-ui/src/timeline/traits.rs index 47a2f676a7c..3a1edcab2f1 100644 --- a/crates/matrix-sdk-ui/src/timeline/traits.rs +++ b/crates/matrix-sdk-ui/src/timeline/traits.rs @@ -19,10 +19,10 @@ use indexmap::IndexMap; #[cfg(test)] use matrix_sdk::crypto::{DecryptionSettings, TrustRequirement}; use matrix_sdk::{ - deserialized_responses::TimelineEvent, - event_cache::paginator::PaginableRoom, - executor::{BoxFuture, BoxFutureExt as _}, - AsyncTraitDeps, Result, Room + deserialized_responses::TimelineEvent, + event_cache::paginator::PaginableRoom, + executor::{BoxFuture, BoxFutureExt as _}, + Result, Room, SendOutsideWasm, SyncOutsideWasm, }; use matrix_sdk_base::{latest_event::LatestEvent, RoomInfo}; use ruma::{ @@ -49,8 +49,8 @@ pub trait RoomExt { /// /// This is the same as using `room.timeline_builder().build()`. #[cfg(not(target_arch = "wasm32"))] - fn timeline(&self) -> impl Future> + Send; - + fn timeline(&self) -> impl Future> + Send; + /// Get a [`Timeline`] for this room. /// /// This offers a higher-level API than event handlers, in treating things @@ -59,7 +59,7 @@ pub trait RoomExt { /// /// This is the same as using `room.timeline_builder().build()`. #[cfg(target_arch = "wasm32")] - fn timeline(&self) -> impl Future>; + fn timeline(&self) -> impl Future>; /// Get a [`TimelineBuilder`] for this room. /// @@ -82,7 +82,8 @@ impl RoomExt for Room { } } -pub(super) trait RoomDataProvider: AsyncTraitDeps + Clone + 'static + PaginableRoom + PinnedEventsRoom +pub(super) trait RoomDataProvider: + Clone + SendOutsideWasm + SyncOutsideWasm + 'static + PaginableRoom + PinnedEventsRoom { fn own_user_id(&self) -> &UserId; fn room_version(&self) -> RoomVersionId; @@ -294,8 +295,7 @@ impl RoomDataProvider for Room { // Internal helper to make most of retry_event_decryption independent of a room // object, which is annoying to create for testing and not really needed -pub(super) trait Decryptor: Clone + AsyncTraitDeps + 'static { - +pub(super) trait Decryptor: Clone + SendOutsideWasm + SyncOutsideWasm + 'static { #[cfg(not(target_arch = "wasm32"))] fn decrypt_event_impl( &self, diff --git a/crates/matrix-sdk-ui/src/unable_to_decrypt_hook.rs b/crates/matrix-sdk-ui/src/unable_to_decrypt_hook.rs index a0755c690e1..7fe284b7f0d 100644 --- a/crates/matrix-sdk-ui/src/unable_to_decrypt_hook.rs +++ b/crates/matrix-sdk-ui/src/unable_to_decrypt_hook.rs @@ -25,8 +25,11 @@ use std::{ }; use growable_bloom_filter::{GrowableBloom, GrowableBloomBuilder}; -use matrix_sdk::{crypto::types::events::UtdCause, Client}; -use matrix_sdk::executor::{spawn, JoinHandle}; +use matrix_sdk::{ + crypto::types::events::UtdCause, + executor::{spawn, JoinHandle}, + Client, +}; use matrix_sdk_base::{StateStoreDataKey, StateStoreDataValue, StoreError}; use ruma::{EventId, OwnedEventId}; use tokio::{ diff --git a/crates/matrix-sdk/src/event_handler/mod.rs b/crates/matrix-sdk/src/event_handler/mod.rs index 1a0022aa6d2..2525a781aa5 100644 --- a/crates/matrix-sdk/src/event_handler/mod.rs +++ b/crates/matrix-sdk/src/event_handler/mod.rs @@ -39,7 +39,8 @@ use std::{ future::Future, pin::Pin, sync::{ - atomic::{AtomicU64, Ordering::SeqCst}, RwLock + atomic::{AtomicU64, Ordering::SeqCst}, + RwLock, }, }; diff --git a/crates/matrix-sdk/src/sliding_sync/error.rs b/crates/matrix-sdk/src/sliding_sync/error.rs index 5b06a120672..774e31510e3 100644 --- a/crates/matrix-sdk/src/sliding_sync/error.rs +++ b/crates/matrix-sdk/src/sliding_sync/error.rs @@ -1,7 +1,7 @@ //! Sliding Sync errors. -use thiserror::Error; use matrix_sdk_common::executor::JoinError; +use thiserror::Error; /// Internal representation of errors in Sliding Sync. #[derive(Error, Debug)] diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index 3793bfe1f9d..793c7367104 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -35,10 +35,9 @@ use async_stream::stream; pub use client::{Version, VersionBuilder}; use futures_core::stream::Stream; pub use matrix_sdk_base::sliding_sync::http; -use matrix_sdk_common::{executor::spawn, timer}; #[cfg(feature = "e2e-encryption")] use matrix_sdk_common::executor::JoinHandleExt as _; - +use matrix_sdk_common::{executor::spawn, timer}; use ruma::{ api::{client::error::ErrorKind, OutgoingRequest}, assign, OwnedEventId, OwnedRoomId, RoomId,