From f28f435dfb4825c548a907e58f3d1f2332153203 Mon Sep 17 00:00:00 2001 From: maan2003 Date: Fri, 9 Feb 2024 18:23:47 +0530 Subject: [PATCH] fix: matrix sdk ui on wasm --- Cargo.lock | 1 + Cargo.toml | 2 +- crates/matrix-sdk-base/src/read_receipts.rs | 7 +++-- crates/matrix-sdk-common/src/timeout.rs | 4 +-- crates/matrix-sdk-common/src/tracing_timer.rs | 4 +-- crates/matrix-sdk-ui/Cargo.toml | 5 +++- .../src/encryption_sync_service.rs | 3 ++ .../matrix-sdk-ui/src/notification_client.rs | 3 ++ .../src/room_list_service/mod.rs | 6 ++-- .../src/room_list_service/state.rs | 24 ++++++++++----- crates/matrix-sdk-ui/src/sync_service.rs | 14 ++++----- crates/matrix-sdk-ui/src/timeline/futures.rs | 27 ++++++++++++----- .../matrix-sdk-ui/src/timeline/inner/mod.rs | 4 +-- .../src/timeline/sliding_sync_ext.rs | 6 ++-- .../matrix-sdk-ui/src/timeline/tests/mod.rs | 3 +- crates/matrix-sdk-ui/src/timeline/traits.rs | 29 ++++++++++++------- crates/matrix-sdk/src/event_cache/mod.rs | 6 ++-- crates/matrix-sdk/src/sliding_sync/error.rs | 2 +- crates/matrix-sdk/src/sliding_sync/mod.rs | 4 +-- crates/matrix-sdk/src/sliding_sync/utils.rs | 4 +-- 20 files changed, 101 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a802d556fa2..ccd2ae221ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3525,6 +3525,7 @@ dependencies = [ "futures-core", "futures-util", "fuzzy-matcher", + "gloo-timers", "imbl", "indexmap 2.2.2", "itertools 0.12.1", diff --git a/Cargo.toml b/Cargo.toml index 29b2a43a62f..bd157c0a8d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ serde_json = "1.0.91" sha2 = "0.10.8" stream_assert = "0.1.1" thiserror = "1.0.38" -tokio = { version = "1.30.0", default-features = false, features = ["sync"] } +tokio = { version = "1.30.0", default-features = false, features = ["sync", "macros"] } tokio-stream = "0.1.14" tracing = { version = "0.1.40", default-features = false, features = ["std"] } tracing-core = "0.1.32" diff --git a/crates/matrix-sdk-base/src/read_receipts.rs b/crates/matrix-sdk-base/src/read_receipts.rs index 43cab3355a0..818782d044d 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,7 +269,7 @@ impl RoomReadReceipts { } /// Provider for timeline events prior to the current sync. -pub trait PreviousEventsProvider: Send + Sync { +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-common/src/timeout.rs b/crates/matrix-sdk-common/src/timeout.rs index 328711609e1..7f7ce68b787 100644 --- a/crates/matrix-sdk-common/src/timeout.rs +++ b/crates/matrix-sdk-common/src/timeout.rs @@ -41,7 +41,7 @@ impl Error for ElapsedError {} /// an error. pub async fn timeout(future: F, duration: Duration) -> Result where - F: Future + Unpin, + F: Future, { #[cfg(not(target_arch = "wasm32"))] return tokio_timeout(duration, future).await.map_err(|_| ElapsedError(())); @@ -51,7 +51,7 @@ where let timeout_future = TimeoutFuture::new(u32::try_from(duration.as_millis()).expect("Overlong duration")); - match select(future, timeout_future).await { + match select(std::pin::pin!(future), timeout_future).await { Either::Left((res, _)) => Ok(res), Either::Right((_, _)) => Err(ElapsedError(())), } diff --git a/crates/matrix-sdk-common/src/tracing_timer.rs b/crates/matrix-sdk-common/src/tracing_timer.rs index 6253a905b11..c861afc3030 100644 --- a/crates/matrix-sdk-common/src/tracing_timer.rs +++ b/crates/matrix-sdk-common/src/tracing_timer.rs @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::instant::Instant; - use tracing::{callsite::DefaultCallsite, Callsite as _}; +use crate::instant::Instant; + /// A named RAII that will show on Drop how long its covered section took to /// execute. pub struct TracingTimer { diff --git a/crates/matrix-sdk-ui/Cargo.toml b/crates/matrix-sdk-ui/Cargo.toml index 6cbe12d96f8..20d4cc5233e 100644 --- a/crates/matrix-sdk-ui/Cargo.toml +++ b/crates/matrix-sdk-ui/Cargo.toml @@ -37,7 +37,7 @@ fuzzy-matcher = "0.3.7" imbl = { workspace = true, features = ["serde"] } indexmap = "2.0.0" itertools = { workspace = true } -matrix-sdk = { workspace = true, features = ["experimental-oidc", "experimental-sliding-sync"] } +matrix-sdk = { workspace = true, features = ["experimental-sliding-sync"] } matrix-sdk-base = { workspace = true } mime = "0.3.16" once_cell = { workspace = true } @@ -66,3 +66,6 @@ wiremock = { workspace = true } [lints] workspace = true + +[target.'cfg(target_arch = "wasm32")'.dependencies] +gloo-timers = { version = "0.3.0", features = ["futures"] } diff --git a/crates/matrix-sdk-ui/src/encryption_sync_service.rs b/crates/matrix-sdk-ui/src/encryption_sync_service.rs index c4ca039f04e..937383d7d2a 100644 --- a/crates/matrix-sdk-ui/src/encryption_sync_service.rs +++ b/crates/matrix-sdk-ui/src/encryption_sync_service.rs @@ -171,7 +171,10 @@ impl EncryptionSyncService { LEASE_DURATION_MS ); + #[cfg(not(target_arch = "wasm32"))] tokio::time::sleep(Duration::from_millis(LEASE_DURATION_MS.into())).await; + #[cfg(target_arch = "wasm32")] + gloo_timers::future::TimeoutFuture::new(LEASE_DURATION_MS).await; lock_guard = self .client diff --git a/crates/matrix-sdk-ui/src/notification_client.rs b/crates/matrix-sdk-ui/src/notification_client.rs index 3ece08deefe..c22e01062e4 100644 --- a/crates/matrix-sdk-ui/src/notification_client.rs +++ b/crates/matrix-sdk-ui/src/notification_client.rs @@ -209,7 +209,10 @@ impl NotificationClient { for _ in 0..3 { trace!("waiting for decryption…"); + #[cfg(not(target_arch = "wasm32"))] tokio::time::sleep(Duration::from_millis(wait)).await; + #[cfg(target_arch = "wasm32")] + gloo_timers::future::TimeoutFuture::new(wait).await; match room.decrypt_event(raw_event.cast_ref()).await { Ok(new_event) => { diff --git a/crates/matrix-sdk-ui/src/room_list_service/mod.rs b/crates/matrix-sdk-ui/src/room_list_service/mod.rs index 9038a7774db..2da4f3df5dd 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/mod.rs @@ -71,11 +71,11 @@ use std::{future::ready, num::NonZeroUsize, sync::Arc, time::Duration}; use async_stream::stream; use eyeball::{SharedObservable, Subscriber}; use futures_util::{pin_mut, Stream, StreamExt}; -use matrix_sdk::timeout::timeout; pub use matrix_sdk::RoomListEntry; use matrix_sdk::{ - event_cache::EventCacheError, sliding_sync::Ranges, Client, Error as SlidingSyncError, - SlidingSync, SlidingSyncList, SlidingSyncListBuilder, SlidingSyncMode, + event_cache::EventCacheError, sliding_sync::Ranges, timeout::timeout, Client, + Error as SlidingSyncError, SlidingSync, SlidingSyncList, SlidingSyncListBuilder, + SlidingSyncMode, }; use matrix_sdk_base::ring_buffer::RingBuffer; pub use room::*; diff --git a/crates/matrix-sdk-ui/src/room_list_service/state.rs b/crates/matrix-sdk-ui/src/room_list_service/state.rs index f2c1991d7e8..8f0cb426720 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/state.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/state.rs @@ -93,7 +93,8 @@ impl State { } /// A trait to define what an `Action` is. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] trait Action { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error>; } @@ -106,7 +107,8 @@ pub const VISIBLE_ROOMS_DEFAULT_TIMELINE_LIMIT: Bound = 20; /// Default range for the `VISIBLE_ROOMS_LIST_NAME` list. pub const VISIBLE_ROOMS_DEFAULT_RANGE: Range = 0..=19; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Action for AddVisibleRooms { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync @@ -132,7 +134,8 @@ impl Action for AddVisibleRooms { struct SetVisibleRoomsToZeroTimelineLimit; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Action for SetVisibleRoomsToZeroTimelineLimit { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync @@ -150,7 +153,8 @@ impl Action for SetVisibleRoomsToZeroTimelineLimit { struct SetVisibleRoomsToDefaultTimelineLimit; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Action for SetVisibleRoomsToDefaultTimelineLimit { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync @@ -172,7 +176,8 @@ struct SetAllRoomsToSelectiveSyncMode; /// `ALL_ROOMS_LIST_NAME` list. pub const ALL_ROOMS_DEFAULT_SELECTIVE_RANGE: Range = 0..=19; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Action for SetAllRoomsToSelectiveSyncMode { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync @@ -196,7 +201,8 @@ struct SetAllRoomsToGrowingSyncMode; /// list. pub const ALL_ROOMS_DEFAULT_GROWING_BATCH_SIZE: u32 = 100; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Action for SetAllRoomsToGrowingSyncMode { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync @@ -219,7 +225,8 @@ struct SetInvitesToSelectiveSyncMode; /// Default `range` for the selective sync-mode of the `INVITES_LIST_NAME` list. pub const INVITES_DEFAULT_SELECTIVE_RANGE: Range = 0..=0; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Action for SetInvitesToSelectiveSyncMode { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync @@ -243,7 +250,8 @@ struct SetInvitesToGrowingSyncMode; /// list. pub const INVITES_DEFAULT_GROWING_BATCH_SIZE: u32 = 20; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Action for SetInvitesToGrowingSyncMode { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync diff --git a/crates/matrix-sdk-ui/src/sync_service.rs b/crates/matrix-sdk-ui/src/sync_service.rs index 7cfa7a94307..dfd50385822 100644 --- a/crates/matrix-sdk-ui/src/sync_service.rs +++ b/crates/matrix-sdk-ui/src/sync_service.rs @@ -28,14 +28,14 @@ use std::sync::{Arc, Mutex}; use eyeball::{SharedObservable, Subscriber}; use futures_core::Future; use futures_util::{pin_mut, StreamExt as _}; -use matrix_sdk::Client; +use matrix_sdk::{ + executor::{spawn, JoinHandle}, + Client, +}; use thiserror::Error; -use tokio::{ - sync::{ - mpsc::{Receiver, Sender}, - Mutex as AsyncMutex, OwnedMutexGuard, - }, - task::{spawn, JoinHandle}, +use tokio::sync::{ + mpsc::{Receiver, Sender}, + Mutex as AsyncMutex, OwnedMutexGuard, }; use tracing::{error, info, instrument, trace, warn, Instrument, Level}; diff --git a/crates/matrix-sdk-ui/src/timeline/futures.rs b/crates/matrix-sdk-ui/src/timeline/futures.rs index 459be113de1..e61bdfa3ff2 100644 --- a/crates/matrix-sdk-ui/src/timeline/futures.rs +++ b/crates/matrix-sdk-ui/src/timeline/futures.rs @@ -1,7 +1,10 @@ use std::{fs, future::IntoFuture, path::Path}; +#[cfg(not(target_arch = "wasm32"))] use eyeball::{SharedObservable, Subscriber}; -use matrix_sdk::{attachment::AttachmentConfig, TransmissionProgress}; +use matrix_sdk::attachment::AttachmentConfig; +#[cfg(not(target_arch = "wasm32"))] +use matrix_sdk::TransmissionProgress; use matrix_sdk_base::boxed_into_future; use mime::Mime; use tracing::{Instrument as _, Span}; @@ -14,6 +17,7 @@ pub struct SendAttachment<'a> { mime_type: Mime, config: AttachmentConfig, tracing_span: Span, + #[cfg(not(target_arch = "wasm32"))] pub(crate) send_progress: SharedObservable, } @@ -30,6 +34,7 @@ impl<'a> SendAttachment<'a> { mime_type, config, tracing_span: Span::current(), + #[cfg(not(target_arch = "wasm32"))] send_progress: Default::default(), } } @@ -47,7 +52,15 @@ impl<'a> IntoFuture for SendAttachment<'a> { boxed_into_future!(extra_bounds: 'a); fn into_future(self) -> Self::IntoFuture { - let Self { timeline, filename, mime_type, config, tracing_span, send_progress } = self; + let Self { + timeline, + filename, + mime_type, + config, + tracing_span, + #[cfg(not(target_arch = "wasm32"))] + send_progress, + } = self; let fut = async move { let body = Path::new(&filename) .file_name() @@ -56,12 +69,10 @@ impl<'a> IntoFuture for SendAttachment<'a> { .expect("path was created from UTF-8 string, hence filename part is UTF-8 too"); let data = fs::read(&filename).map_err(|_| Error::InvalidAttachmentData)?; - timeline - .room() - .send_attachment(body, &mime_type, data, config) - .with_send_progress_observable(send_progress) - .await - .map_err(|_| Error::FailedSendingAttachment)?; + let value = timeline.room().send_attachment(body, &mime_type, data, config); + #[cfg(not(target_arch = "wasm32"))] + let value = value.with_send_progress_observable(send_progress); + value.await.map_err(|_| Error::FailedSendingAttachment)?; Ok(()) }; diff --git a/crates/matrix-sdk-ui/src/timeline/inner/mod.rs b/crates/matrix-sdk-ui/src/timeline/inner/mod.rs index 83a10c0407f..2991b90f1b0 100644 --- a/crates/matrix-sdk-ui/src/timeline/inner/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/inner/mod.rs @@ -12,9 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(feature = "e2e-encryption")] -use std::collections::BTreeSet; -use std::{fmt, sync::Arc}; +use std::{collections::BTreeSet, fmt, sync::Arc}; use as_variant::as_variant; use eyeball_im::{ObservableVectorEntry, VectorDiff}; diff --git a/crates/matrix-sdk-ui/src/timeline/sliding_sync_ext.rs b/crates/matrix-sdk-ui/src/timeline/sliding_sync_ext.rs index 3ac674210ea..b36a4eeafea 100644 --- a/crates/matrix-sdk-ui/src/timeline/sliding_sync_ext.rs +++ b/crates/matrix-sdk-ui/src/timeline/sliding_sync_ext.rs @@ -18,7 +18,8 @@ use tracing::instrument; use super::EventTimelineItem; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait SlidingSyncRoomExt { /// Get the latest timeline item of this room, if it is already cached. /// @@ -27,7 +28,8 @@ pub trait SlidingSyncRoomExt { async fn latest_timeline_item(&self) -> Option; } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl SlidingSyncRoomExt for SlidingSyncRoom { /// Get a timeline item representing the latest event in this room. /// This method wraps latest_event, converting the event into an diff --git a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs index 2d5714b6674..2d60e3f4e65 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs @@ -284,7 +284,8 @@ impl TestRoomDataProvider { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl RoomDataProvider for TestRoomDataProvider { fn own_user_id(&self) -> &UserId { &ALICE diff --git a/crates/matrix-sdk-ui/src/timeline/traits.rs b/crates/matrix-sdk-ui/src/timeline/traits.rs index 0ded5a50e1b..b9dc7aa3d31 100644 --- a/crates/matrix-sdk-ui/src/timeline/traits.rs +++ b/crates/matrix-sdk-ui/src/timeline/traits.rs @@ -17,7 +17,7 @@ use indexmap::IndexMap; #[cfg(feature = "e2e-encryption")] use matrix_sdk::{deserialized_responses::TimelineEvent, Result}; use matrix_sdk::{event_cache, Room}; -use matrix_sdk_base::latest_event::LatestEvent; +use matrix_sdk_base::{latest_event::LatestEvent, SendOutsideWasm, SyncOutsideWasm}; use ruma::{ events::receipt::{Receipt, ReceiptThread, ReceiptType}, push::{PushConditionRoomCtx, Ruleset}, @@ -30,7 +30,8 @@ use tracing::{debug, error}; use super::{Profile, TimelineBuilder}; use crate::timeline::Timeline; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait RoomExt { /// Get a [`Timeline`] for this room. /// @@ -52,7 +53,8 @@ pub trait RoomExt { fn timeline_builder(&self) -> TimelineBuilder; } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl RoomExt for Room { async fn timeline(&self) -> event_cache::Result { self.timeline_builder().build().await @@ -63,8 +65,11 @@ impl RoomExt for Room { } } -#[async_trait] -pub(super) trait RoomDataProvider: Clone + Send + Sync + 'static { +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] +pub(super) trait RoomDataProvider: + Clone + SendOutsideWasm + SyncOutsideWasm + 'static +{ fn own_user_id(&self) -> &UserId; fn room_version(&self) -> RoomVersionId; async fn profile_from_user_id(&self, user_id: &UserId) -> Option; @@ -84,7 +89,8 @@ pub(super) trait RoomDataProvider: Clone + Send + Sync + 'static { async fn push_rules_and_context(&self) -> Option<(Ruleset, PushConditionRoomCtx)>; } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl RoomDataProvider for Room { fn own_user_id(&self) -> &UserId { (**self).own_user_id() @@ -193,13 +199,15 @@ 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 #[cfg(feature = "e2e-encryption")] -#[async_trait] -pub(super) trait Decryptor: Clone + Send + Sync + 'static { +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] +pub(super) trait Decryptor: Clone + SendOutsideWasm + SyncOutsideWasm + 'static { async fn decrypt_event_impl(&self, raw: &Raw) -> Result; } #[cfg(feature = "e2e-encryption")] -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Decryptor for Room { async fn decrypt_event_impl(&self, raw: &Raw) -> Result { self.decrypt_event(raw.cast_ref()).await @@ -207,7 +215,8 @@ impl Decryptor for Room { } #[cfg(all(test, feature = "e2e-encryption"))] -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Decryptor for (matrix_sdk_base::crypto::OlmMachine, ruma::OwnedRoomId) { async fn decrypt_event_impl(&self, raw: &Raw) -> Result { let (olm_machine, room_id) = self; diff --git a/crates/matrix-sdk/src/event_cache/mod.rs b/crates/matrix-sdk/src/event_cache/mod.rs index d68afa98f14..1d1313297c9 100644 --- a/crates/matrix-sdk/src/event_cache/mod.rs +++ b/crates/matrix-sdk/src/event_cache/mod.rs @@ -52,8 +52,10 @@ use matrix_sdk_base::{ deserialized_responses::{AmbiguityChange, SyncTimelineEvent, TimelineEvent}, sync::{JoinedRoomUpdate, LeftRoomUpdate, RoomUpdates, Timeline}, }; -use matrix_sdk_common::executor::{spawn, JoinHandle}; -use matrix_sdk_common::timeout::timeout; +use matrix_sdk_common::{ + executor::{spawn, JoinHandle}, + timeout::timeout, +}; use ruma::{ assign, events::{AnyRoomAccountDataEvent, AnySyncEphemeralRoomEvent}, diff --git a/crates/matrix-sdk/src/sliding_sync/error.rs b/crates/matrix-sdk/src/sliding_sync/error.rs index 34431f21fdc..8eb71350608 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 matrix_sdk_common::executor::JoinError; use thiserror::Error; -use tokio::task::JoinError; /// 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 b7c1aa29e59..d7d8cdde6b9 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -44,7 +44,7 @@ use ruma::{ }; use serde::{Deserialize, Serialize}; use tokio::{ - select, spawn, + select, sync::{broadcast::Sender, Mutex as AsyncMutex, OwnedMutexGuard, RwLock as AsyncRwLock}, }; use tracing::{debug, error, info, instrument, trace, warn, Instrument, Span}; @@ -58,7 +58,7 @@ use self::{ client::SlidingSyncResponseProcessor, sticky_parameters::{LazyTransactionId, SlidingSyncStickyManager, StickyData}, }; -use crate::{config::RequestConfig, Client, Result}; +use crate::{config::RequestConfig, executor::spawn, Client, Result}; /// The Sliding Sync instance. /// diff --git a/crates/matrix-sdk/src/sliding_sync/utils.rs b/crates/matrix-sdk/src/sliding_sync/utils.rs index 0bc1e998d43..6d39f74a4f8 100644 --- a/crates/matrix-sdk/src/sliding_sync/utils.rs +++ b/crates/matrix-sdk/src/sliding_sync/utils.rs @@ -6,7 +6,7 @@ use std::{ task::{Context, Poll}, }; -use tokio::task::{JoinError, JoinHandle}; +use matrix_sdk_common::executor::{JoinError, JoinHandle}; /// Private type to ensure a task is aborted on drop. pub(crate) struct AbortOnDrop(JoinHandle); @@ -23,7 +23,7 @@ impl Drop for AbortOnDrop { } } -impl Future for AbortOnDrop { +impl Future for AbortOnDrop { type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll {