Cleanup/optimize sliding sync types and arguments.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -6,7 +6,7 @@ use tuwunel_core::{
|
||||
};
|
||||
use tuwunel_service::Services;
|
||||
|
||||
use super::{KnownRooms, SyncInfo, TodoRooms, extension_rooms_todo};
|
||||
use super::{KnownRooms, SyncInfo, TodoRoom, TodoRooms, extension_rooms_todo};
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, fields(globalsince, next_batch))]
|
||||
pub(super) async fn collect(
|
||||
@@ -16,31 +16,39 @@ pub(super) async fn collect(
|
||||
known_rooms: &KnownRooms,
|
||||
todo_rooms: &TodoRooms,
|
||||
) -> Result<response::AccountData> {
|
||||
let (sender_user, _, globalsince, request) = sync_info;
|
||||
let data = &request.extensions.account_data;
|
||||
let rooms = extension_rooms_todo(
|
||||
sync_info,
|
||||
known_rooms,
|
||||
todo_rooms,
|
||||
data.lists.as_ref(),
|
||||
data.rooms.as_ref(),
|
||||
)
|
||||
.stream()
|
||||
.broad_filter_map(async |room_id| {
|
||||
let &(_, _, roomsince) = todo_rooms.get(room_id)?;
|
||||
let changes: Vec<_> = services
|
||||
.account_data
|
||||
.changes_since(Some(room_id), sender_user, roomsince, Some(next_batch))
|
||||
.ready_filter_map(|e| extract_variant!(e, AnyRawAccountDataEvent::Room))
|
||||
.collect()
|
||||
.await;
|
||||
let SyncInfo { sender_user, globalsince, request, .. } = sync_info;
|
||||
|
||||
changes
|
||||
.is_empty()
|
||||
.eq(&false)
|
||||
.then(move || (room_id.to_owned(), changes))
|
||||
})
|
||||
.collect();
|
||||
let lists = request
|
||||
.extensions
|
||||
.account_data
|
||||
.lists
|
||||
.as_deref()
|
||||
.map(<[_]>::iter);
|
||||
|
||||
let rooms = request
|
||||
.extensions
|
||||
.account_data
|
||||
.rooms
|
||||
.as_deref()
|
||||
.map(<[_]>::iter);
|
||||
|
||||
let rooms = extension_rooms_todo(sync_info, known_rooms, todo_rooms, lists, rooms)
|
||||
.stream()
|
||||
.broad_filter_map(async |room_id| {
|
||||
let &TodoRoom { roomsince, .. } = todo_rooms.get(room_id)?;
|
||||
let changes: Vec<_> = services
|
||||
.account_data
|
||||
.changes_since(Some(room_id), sender_user, roomsince, Some(next_batch))
|
||||
.ready_filter_map(|e| extract_variant!(e, AnyRawAccountDataEvent::Room))
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
changes
|
||||
.is_empty()
|
||||
.eq(&false)
|
||||
.then(move || (room_id.to_owned(), changes))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let global = services
|
||||
.account_data
|
||||
|
||||
@@ -29,10 +29,13 @@ use super::{SyncInfo, share_encrypted_room};
|
||||
#[tracing::instrument(level = "trace", skip_all, fields(globalsince, next_batch,))]
|
||||
pub(super) async fn collect(
|
||||
services: &Services,
|
||||
syncinfo: SyncInfo<'_>,
|
||||
sync_info: SyncInfo<'_>,
|
||||
next_batch: u64,
|
||||
) -> Result<response::E2EE> {
|
||||
let &(sender_user, sender_device, globalsince, _) = &syncinfo;
|
||||
let SyncInfo {
|
||||
sender_user, sender_device, globalsince, ..
|
||||
} = sync_info;
|
||||
|
||||
let keys_changed = services
|
||||
.users
|
||||
.keys_changed(sender_user, globalsince, Some(next_batch))
|
||||
@@ -46,7 +49,7 @@ pub(super) async fn collect(
|
||||
.rooms_joined(sender_user)
|
||||
.map(ToOwned::to_owned)
|
||||
.broad_filter_map(async |room_id| {
|
||||
collect_room(services, syncinfo, next_batch, &room_id)
|
||||
collect_room(services, sync_info, next_batch, &room_id)
|
||||
.await
|
||||
.ok()
|
||||
})
|
||||
@@ -101,7 +104,7 @@ pub(super) async fn collect(
|
||||
#[tracing::instrument(level = "trace", skip_all, fields(room_id))]
|
||||
async fn collect_room(
|
||||
services: &Services,
|
||||
(sender_user, _, globalsince, _): SyncInfo<'_>,
|
||||
SyncInfo { sender_user, globalsince, .. }: SyncInfo<'_>,
|
||||
next_batch: u64,
|
||||
room_id: &RoomId,
|
||||
) -> Result<pair_of!(HashSet<OwnedUserId>)> {
|
||||
|
||||
@@ -11,7 +11,7 @@ use tuwunel_core::{
|
||||
};
|
||||
use tuwunel_service::{Services, rooms::read_receipt::pack_receipts};
|
||||
|
||||
use super::{KnownRooms, SyncInfo, TodoRooms, extension_rooms_todo};
|
||||
use super::{KnownRooms, SyncInfo, TodoRoom, TodoRooms, extension_rooms_todo};
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
pub(super) async fn collect(
|
||||
@@ -21,33 +21,41 @@ pub(super) async fn collect(
|
||||
known_rooms: &KnownRooms,
|
||||
todo_rooms: &TodoRooms,
|
||||
) -> Result<response::Receipts> {
|
||||
let (_, _, _, request) = sync_info;
|
||||
let data = &request.extensions.receipts;
|
||||
let rooms = extension_rooms_todo(
|
||||
sync_info,
|
||||
known_rooms,
|
||||
todo_rooms,
|
||||
data.lists.as_ref(),
|
||||
data.rooms.as_ref(),
|
||||
)
|
||||
.stream()
|
||||
.broad_filter_map(async |room_id| {
|
||||
collect_room(services, sync_info, next_batch, todo_rooms, room_id).await
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
let SyncInfo { request, .. } = sync_info;
|
||||
|
||||
let lists = request
|
||||
.extensions
|
||||
.receipts
|
||||
.lists
|
||||
.as_deref()
|
||||
.map(<[_]>::iter);
|
||||
|
||||
let rooms = request
|
||||
.extensions
|
||||
.receipts
|
||||
.rooms
|
||||
.as_deref()
|
||||
.map(<[_]>::iter);
|
||||
|
||||
let rooms = extension_rooms_todo(sync_info, known_rooms, todo_rooms, lists, rooms)
|
||||
.stream()
|
||||
.broad_filter_map(async |room_id| {
|
||||
collect_room(services, sync_info, next_batch, todo_rooms, room_id).await
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
Ok(response::Receipts { rooms })
|
||||
}
|
||||
|
||||
async fn collect_room(
|
||||
services: &Services,
|
||||
(sender_user, ..): SyncInfo<'_>,
|
||||
SyncInfo { sender_user, .. }: SyncInfo<'_>,
|
||||
next_batch: u64,
|
||||
todo_rooms: &TodoRooms,
|
||||
room_id: &RoomId,
|
||||
) -> Option<(OwnedRoomId, Raw<SyncReceiptEvent>)> {
|
||||
let &(_, _, roomsince) = todo_rooms.get(room_id)?;
|
||||
let &TodoRoom { roomsince, .. } = todo_rooms.get(room_id)?;
|
||||
let private_receipt = services
|
||||
.read_receipt
|
||||
.last_privateread_update(sender_user, room_id)
|
||||
|
||||
@@ -7,7 +7,7 @@ use futures::{
|
||||
use ruma::{
|
||||
JsOption, MxcUri, OwnedMxcUri, RoomId, UInt, UserId,
|
||||
api::client::sync::sync_events::{UnreadNotificationsCount, v5::response},
|
||||
events::StateEventType,
|
||||
events::{StateEventType, room::member::MembershipState},
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Result, at, debug_error, is_equal_to,
|
||||
@@ -25,21 +25,25 @@ use crate::client::{DEFAULT_BUMP_TYPES, ignored_filter, sync::load_timeline};
|
||||
pub(super) async fn handle(
|
||||
services: &Services,
|
||||
next_batch: u64,
|
||||
(sender_user, _, _globalsince, _): &SyncInfo<'_>,
|
||||
SyncInfo { sender_user, .. }: SyncInfo<'_>,
|
||||
room_id: &RoomId,
|
||||
(required_state_request, timeline_limit, roomsince): &TodoRoom,
|
||||
is_invited: bool,
|
||||
&TodoRoom {
|
||||
ref membership,
|
||||
ref requested_state,
|
||||
timeline_limit,
|
||||
roomsince,
|
||||
}: &TodoRoom,
|
||||
) -> Result<Option<response::Room>> {
|
||||
let timeline: OptionFuture<_> = is_invited
|
||||
.eq(&false)
|
||||
let timeline: OptionFuture<_> = membership
|
||||
.ne(&MembershipState::Invite)
|
||||
.then(|| {
|
||||
load_timeline(
|
||||
services,
|
||||
sender_user,
|
||||
room_id,
|
||||
PduCount::Normal(*roomsince),
|
||||
PduCount::Normal(roomsince),
|
||||
Some(PduCount::from(next_batch)),
|
||||
*timeline_limit,
|
||||
timeline_limit,
|
||||
)
|
||||
})
|
||||
.into();
|
||||
@@ -52,7 +56,7 @@ pub(super) async fn handle(
|
||||
let (timeline_pdus, limited, _lastcount) =
|
||||
timeline.unwrap_or_else(|| (Vec::new(), true, PduCount::default()));
|
||||
|
||||
if *roomsince != 0 && timeline_pdus.is_empty() && !is_invited {
|
||||
if roomsince != 0 && timeline_pdus.is_empty() && membership.ne(&MembershipState::Invite) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
@@ -60,7 +64,7 @@ pub(super) async fn handle(
|
||||
.first()
|
||||
.map(at!(0))
|
||||
.map(PduCount::into_unsigned)
|
||||
.or_else(|| roomsince.ne(&0).then_some(*roomsince))
|
||||
.or_else(|| roomsince.ne(&0).then_some(roomsince))
|
||||
.as_ref()
|
||||
.map(ToString::to_string);
|
||||
|
||||
@@ -80,7 +84,7 @@ pub(super) async fn handle(
|
||||
bump_stamp
|
||||
});
|
||||
|
||||
let lazy = required_state_request
|
||||
let lazy = requested_state
|
||||
.iter()
|
||||
.any(is_equal_to!(&(StateEventType::RoomMember, "$LAZY".into())));
|
||||
|
||||
@@ -97,7 +101,7 @@ pub(super) async fn handle(
|
||||
.iter()
|
||||
.map(|sender| (StateEventType::RoomMember, StateKey::from_str(sender.as_str())));
|
||||
|
||||
let required_state = required_state_request
|
||||
let required_state = requested_state
|
||||
.iter()
|
||||
.cloned()
|
||||
.chain(timeline_senders)
|
||||
@@ -119,7 +123,8 @@ pub(super) async fn handle(
|
||||
.collect();
|
||||
|
||||
// TODO: figure out a timestamp we can use for remote invites
|
||||
let invite_state: OptionFuture<_> = is_invited
|
||||
let invite_state: OptionFuture<_> = membership
|
||||
.eq(&MembershipState::Invite)
|
||||
.then(|| {
|
||||
services
|
||||
.state_cache
|
||||
@@ -199,7 +204,7 @@ pub(super) async fn handle(
|
||||
let num_live = None; // Count events in timeline greater than global sync counter
|
||||
|
||||
Ok(Some(response::Room {
|
||||
initial: Some(*roomsince == 0),
|
||||
initial: Some(roomsince == 0),
|
||||
name: room_name.or(hero_name),
|
||||
avatar: JsOption::from_option(room_avatar.or(heroes_avatar)),
|
||||
invite_state: invite_state.flatten(),
|
||||
|
||||
@@ -8,7 +8,9 @@ use super::SyncInfo;
|
||||
#[tracing::instrument(level = "trace", skip_all, fields(globalsince, next_batch))]
|
||||
pub(super) async fn collect(
|
||||
services: &Services,
|
||||
(sender_user, sender_device, globalsince, _request): SyncInfo<'_>,
|
||||
SyncInfo {
|
||||
sender_user, sender_device, globalsince, ..
|
||||
}: SyncInfo<'_>,
|
||||
next_batch: u64,
|
||||
) -> Result<Option<response::ToDevice>> {
|
||||
services
|
||||
|
||||
@@ -2,7 +2,9 @@ use std::collections::BTreeMap;
|
||||
|
||||
use futures::{FutureExt, StreamExt, TryFutureExt};
|
||||
use ruma::{
|
||||
api::client::sync::sync_events::v5::response, events::typing::TypingEventContent, serde::Raw,
|
||||
api::client::sync::sync_events::v5::response,
|
||||
events::typing::{SyncTypingEvent, TypingEventContent},
|
||||
serde::Raw,
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Result, debug_error,
|
||||
@@ -21,37 +23,44 @@ pub(super) async fn collect(
|
||||
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);
|
||||
let SyncInfo { sender_user, request, .. } = sync_info;
|
||||
|
||||
Some((room_id.to_owned(), event.ok()?))
|
||||
})
|
||||
.collect::<BTreeMap<_, _>>()
|
||||
.map(|rooms| Typing { rooms })
|
||||
.map(Ok)
|
||||
.await
|
||||
let lists = request
|
||||
.extensions
|
||||
.typing
|
||||
.lists
|
||||
.as_deref()
|
||||
.map(<[_]>::iter);
|
||||
|
||||
let rooms = request
|
||||
.extensions
|
||||
.typing
|
||||
.rooms
|
||||
.as_deref()
|
||||
.map(<[_]>::iter);
|
||||
|
||||
extension_rooms_todo(sync_info, known_rooms, todo_rooms, lists, rooms)
|
||||
.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