Skip to content

Commit

Permalink
Restore some marker traits that were needed still
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Salinas authored and Daniel Salinas committed Oct 13, 2024
1 parent 246d70e commit ac6b065
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 54 deletions.
3 changes: 2 additions & 1 deletion crates/matrix-sdk-base/src/event_cache_store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<EventCacheStoreError>;

Expand Down
16 changes: 5 additions & 11 deletions crates/matrix-sdk-base/src/read_receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<SyncTimelineEvent>;
}

/// 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<SyncTimelineEvent>;
Expand Down
3 changes: 2 additions & 1 deletion crates/matrix-sdk-base/src/store/memory_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-base/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions crates/matrix-sdk-base/src/store/observable_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -191,7 +191,8 @@ mod impl_wasm32 {
/// Get a [`Stream`] of the values.
pub(crate) fn stream(&self) -> (Vector<V>, impl Stream<Item = Vec<VectorDiff<V>>>) {
let values: Vector<V> = 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)
}
}
Expand Down
9 changes: 6 additions & 3 deletions crates/matrix-sdk-base/src/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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<StoreError> + From<serde_json::Error>;

Expand Down Expand Up @@ -450,7 +452,8 @@ impl<T: fmt::Debug> fmt::Debug for EraseStateStoreError<T> {
}
}

#[async_trait]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl<T: StateStore> StateStore for EraseStateStoreError<T> {
type Error = StoreError;

Expand Down
4 changes: 1 addition & 3 deletions crates/matrix-sdk-common/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Future<Output = T> + 'a>>;
#[cfg(not(target_arch = "wasm32"))]
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;


#[cfg(target_arch = "wasm32")]
pub fn spawn<F, T>(future: F) -> JoinHandle<T>
where
Expand Down
3 changes: 2 additions & 1 deletion crates/matrix-sdk-crypto/src/store/memorystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ impl MemoryStore {

type Result<T> = std::result::Result<T, Infallible>;

#[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;

Expand Down
9 changes: 6 additions & 3 deletions crates/matrix-sdk-crypto/src/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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<CryptoStoreError>;

Expand Down Expand Up @@ -367,7 +369,8 @@ impl<T: fmt::Debug> fmt::Debug for EraseCryptoStoreError<T> {
}
}

#[async_trait]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl<T: CryptoStore> CryptoStore for EraseCryptoStoreError<T> {
type Error = CryptoStoreError;

Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-ui/src/sync_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion crates/matrix-sdk-ui/src/timeline/futures.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{fs, future::IntoFuture, path::PathBuf};

use eyeball::{SharedObservable, Subscriber};
use eyeball::SharedObservable;
#[cfg(not(target_arch = "wasm32"))]
use eyeball::Subscriber;
use matrix_sdk::{attachment::AttachmentConfig, TransmissionProgress};
use matrix_sdk_base::boxed_into_future;
use mime::Mime;
Expand Down
5 changes: 4 additions & 1 deletion crates/matrix-sdk-ui/src/timeline/pinned_events_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
11 changes: 5 additions & 6 deletions crates/matrix-sdk-ui/src/timeline/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ use std::{
use eyeball::{SharedObservable, Subscriber};
use eyeball_im::VectorDiff;
use futures_core::Stream;
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};
Expand Down
20 changes: 10 additions & 10 deletions crates/matrix-sdk-ui/src/timeline/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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<Output = Result<Timeline, timeline::Error>> + Send;
fn timeline(&self) -> impl Future<Output = Result<Timeline, timeline::Error>> + Send;

/// Get a [`Timeline`] for this room.
///
/// This offers a higher-level API than event handlers, in treating things
Expand All @@ -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<Output = Result<Timeline, timeline::Error>>;
fn timeline(&self) -> impl Future<Output = Result<Timeline, timeline::Error>>;

/// Get a [`TimelineBuilder`] for this room.
///
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions crates/matrix-sdk-ui/src/unable_to_decrypt_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
3 changes: 2 additions & 1 deletion crates/matrix-sdk/src/event_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ use std::{
future::Future,
pin::Pin,
sync::{
atomic::{AtomicU64, Ordering::SeqCst}, RwLock
atomic::{AtomicU64, Ordering::SeqCst},
RwLock,
},
};

Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/sliding_sync/error.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
3 changes: 1 addition & 2 deletions crates/matrix-sdk/src/sliding_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ac6b065

Please sign in to comment.