diff --git a/src/api/client/sync/v3/joined.rs b/src/api/client/sync/v3/joined.rs index 7324df97..9ab26b56 100644 --- a/src/api/client/sync/v3/joined.rs +++ b/src/api/client/sync/v3/joined.rs @@ -13,7 +13,7 @@ use conduwuit::{ stream::{Tools, WidebandExt}, }, }; -use conduwuit_service::{Services, rooms::lazy_loading::MemberSet}; +use conduwuit_service::Services; use futures::{ FutureExt, StreamExt, TryFutureExt, future::{OptionFuture, join, join3, join4, try_join}, @@ -37,7 +37,7 @@ use super::{load_timeline, share_encrypted_room}; use crate::client::{ ignored_filter, sync::v3::{ - DeviceListUpdates, SyncContext, + DeviceListUpdates, SyncContext, prepare_lazily_loaded_members, state::{calculate_state_incremental, calculate_state_initial}, }, }; @@ -199,32 +199,10 @@ pub(super) async fn load_joined_room( |content: RoomMemberEventContent| content.membership != MembershipState::Join, ); - let lazy_loading_context = &sync_context.lazy_loading_context(room_id); - // the user IDs of members whose membership needs to be sent to the client, if // lazy-loading is enabled. let lazily_loaded_members = - OptionFuture::from(sync_context.lazy_loading_enabled().then(|| { - let timeline_and_receipt_members: MemberSet = timeline - .senders() - .chain(receipt_events.keys().map(Into::into)) - .collect(); - - services - .rooms - .lazy_loading - .retain_lazy_members(timeline_and_receipt_members, lazy_loading_context) - })) - .await; - - // reset lazy loading state on initial sync - if previous_sync_end_count.is_none() { - services - .rooms - .lazy_loading - .reset(lazy_loading_context) - .await; - } + prepare_lazily_loaded_members(services, sync_context, room_id, timeline.senders()).await; /* compute the state delta between the previous sync and this sync. if this is an initial sync diff --git a/src/api/client/sync/v3/mod.rs b/src/api/client/sync/v3/mod.rs index 4814c8b3..1c2ee074 100644 --- a/src/api/client/sync/v3/mod.rs +++ b/src/api/client/sync/v3/mod.rs @@ -430,8 +430,19 @@ async fn prepare_lazily_loaded_members( ) -> Option { let lazy_loading_context = &sync_context.lazy_loading_context(room_id); - // the user IDs of members whose membership needs to be sent to the client, if - // lazy-loading is enabled. + // reset lazy loading state on initial sync. + // do this even if lazy loading is disabled so future lazy loads + // will have the correct members. + if sync_context.since.is_none() { + services + .rooms + .lazy_loading + .reset(lazy_loading_context) + .await; + } + + // filter the input members through `retain_lazy_members`, which + // contains the actual lazy loading logic. let lazily_loaded_members = OptionFuture::from(sync_context.lazy_loading_enabled().then(|| { services @@ -441,14 +452,5 @@ async fn prepare_lazily_loaded_members( })) .await; - // reset lazy loading state on initial sync - if sync_context.since.is_none() { - services - .rooms - .lazy_loading - .reset(lazy_loading_context) - .await; - } - lazily_loaded_members }