Skip to content

Commit

Permalink
refactor(ui): Relax some Send constraints on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Jan 10, 2025
1 parent 4043f9b commit 526b5c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 5 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use matrix_sdk::{
send_queue::{
LocalEcho, LocalEchoContent, RoomSendQueueUpdate, SendHandle, SendReactionHandle,
},
Result, Room,
Result, Room, SendOutsideWasm,
};
use ruma::{
api::client::receipt::create_receipt::v3::ReceiptType as SendReceiptType,
Expand Down Expand Up @@ -479,7 +479,10 @@ impl<P: RoomDataProvider> TimelineController<P> {

pub(super) async fn subscribe(
&self,
) -> (Vector<Arc<TimelineItem>>, impl Stream<Item = VectorDiff<Arc<TimelineItem>>> + Send) {
) -> (
Vector<Arc<TimelineItem>>,
impl Stream<Item = VectorDiff<Arc<TimelineItem>>> + SendOutsideWasm,
) {
trace!("Creating timeline items signal");
let state = self.state.read().await;
(state.items.clone_items(), state.items.subscribe().into_stream())
Expand Down
7 changes: 3 additions & 4 deletions crates/matrix-sdk-ui/src/timeline/pinned_events_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::{fmt::Formatter, sync::Arc};

use futures_util::{stream, FutureExt as _, StreamExt};
use futures_util::{stream, StreamExt};
use matrix_sdk::{
config::RequestConfig, event_cache::paginator::PaginatorError, BoxFuture, Room,
SendOutsideWasm, SyncOutsideWasm,
Expand Down Expand Up @@ -151,7 +151,7 @@ impl PinnedEventsRoom for Room {
request_config: Option<RequestConfig>,
related_event_filters: Option<Vec<RelationType>>,
) -> BoxFuture<'a, Result<(SyncTimelineEvent, Vec<SyncTimelineEvent>), PaginatorError>> {
async move {
Box::pin(async move {
if let Ok((cache, _handles)) = self.event_cache().await {
if let Some(ret) = cache.event_with_relations(event_id, related_event_filters).await
{
Expand All @@ -165,8 +165,7 @@ impl PinnedEventsRoom for Room {
.await
.map(|e| (e.into(), Vec::new()))
.map_err(|err| PaginatorError::SdkError(Box::new(err)))
}
.boxed()
})
}

fn pinned_event_ids(&self) -> Option<Vec<OwnedEventId>> {
Expand Down
10 changes: 6 additions & 4 deletions crates/matrix-sdk-ui/src/timeline/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use indexmap::IndexMap;
use matrix_sdk::crypto::{DecryptionSettings, RoomEventDecryptionResult, TrustRequirement};
use matrix_sdk::{
crypto::types::events::CryptoContextInfo, deserialized_responses::TimelineEvent,
event_cache::paginator::PaginableRoom, BoxFuture, Result, Room,
event_cache::paginator::PaginableRoom, AsyncTraitDeps, BoxFuture, Result, Room,
SendOutsideWasm,
};
use matrix_sdk_base::{latest_event::LatestEvent, RoomInfo};
use ruma::{
Expand All @@ -47,7 +48,8 @@ pub trait RoomExt {
/// independent events.
///
/// This is the same as using `room.timeline_builder().build()`.
fn timeline(&self) -> impl Future<Output = Result<Timeline, timeline::Error>> + Send;
fn timeline(&self)
-> impl Future<Output = Result<Timeline, timeline::Error>> + SendOutsideWasm;

/// Get a [`TimelineBuilder`] for this room.
///
Expand Down Expand Up @@ -289,11 +291,11 @@ 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 + Send + Sync + 'static {
pub(super) trait Decryptor: AsyncTraitDeps + Clone + 'static {
fn decrypt_event_impl(
&self,
raw: &Raw<AnySyncTimelineEvent>,
) -> impl Future<Output = Result<TimelineEvent>> + Send;
) -> impl Future<Output = Result<TimelineEvent>> + SendOutsideWasm;
}

impl Decryptor for Room {
Expand Down

0 comments on commit 526b5c4

Please sign in to comment.