Split sliding-sync extensions into units.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
57
src/api/client/sync/v5/typing.rs
Normal file
57
src/api/client/sync/v5/typing.rs
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user