Split sliding-sync extensions into units.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-10-05 19:48:07 +00:00
parent 4baa25f66f
commit b1ea7b101d
7 changed files with 786 additions and 703 deletions

View File

@@ -0,0 +1,57 @@
use std::collections::BTreeMap;
use futures::{FutureExt, StreamExt, TryFutureExt};
use ruma::{
api::client::sync::sync_events::v5::response, events::typing::TypingEventContent, serde::Raw,
};
use tuwunel_core::{
Result, debug_error,
utils::{IterStream, ReadyExt},
};
use tuwunel_service::Services;
use super::{KnownRooms, SyncInfo, TodoRooms, extension_rooms_todo};
#[tracing::instrument(level = "trace", skip_all, fields(globalsince))]
pub(super) async fn collect(
services: &Services,
sync_info: SyncInfo<'_>,
_next_batch: u64,
known_rooms: &KnownRooms,
todo_rooms: &TodoRooms,
) -> Result<response::Typing> {
use response::Typing;
use ruma::events::typing::SyncTypingEvent;
let (sender_user, _, _, request) = sync_info;
let data = &request.extensions.typing;
extension_rooms_todo(
sync_info,
known_rooms,
todo_rooms,
data.lists.as_ref(),
data.rooms.as_ref(),
)
.stream()
.filter_map(async |room_id| {
services
.typing
.typing_users_for_user(room_id, sender_user)
.inspect_err(|e| debug_error!(%room_id, "Failed to get typing events: {e}"))
.await
.ok()
.filter(|users| !users.is_empty())
.map(|users| (room_id, users))
})
.ready_filter_map(|(room_id, users)| {
let content = TypingEventContent::new(users);
let event = SyncTypingEvent { content };
let event = Raw::new(&event);
Some((room_id.to_owned(), event.ok()?))
})
.collect::<BTreeMap<_, _>>()
.map(|rooms| Typing { rooms })
.map(Ok)
.await
}