diff --git a/src/api/client_server/sync/msc4186.rs b/src/api/client_server/sync/msc4186.rs index a0667eb5..b7f423a5 100644 --- a/src/api/client_server/sync/msc4186.rs +++ b/src/api/client_server/sync/msc4186.rs @@ -571,7 +571,9 @@ pub(crate) async fn sync_events_v5_route( let mut rooms = BTreeMap::new(); for (room_id, todo_room) in todo_rooms { - if let Some(room) = process_room(&sender_user, &room_id, &todo_room)? { + if let Some(room) = + process_room(&sender_user, &room_id, &todo_room, globalsince)? + { rooms.insert(room_id.clone(), room); } } @@ -902,6 +904,7 @@ fn process_room( sender_user: &UserId, room_id: &RoomId, todo_room: &TodoRoom, + globalsince: u64, ) -> Result> { let roomsincecount = PduCount::Normal(todo_room.roomsince); @@ -940,6 +943,25 @@ fn process_room( } }; + let num_live = Some( + timeline_pdus + .iter() + .filter(|(pdu_count, _)| match pdu_count { + // TODO check logic + PduCount::Backfilled(_) => false, + PduCount::Normal(pdu_count) => { + if globalsince == 0 { + false + } else { + *pdu_count > globalsince + } + } + }) + .count() + .try_into() + .unwrap_or(UInt::MAX), + ); + let room_events: Vec<_> = timeline_pdus.iter().map(|(_, pdu)| pdu.to_sync_room_event()).collect(); @@ -1115,8 +1137,7 @@ fn process_room( .map(UInt::new_saturating) .unwrap_or(uint!(0)), ), - // Count events in timeline greater than global sync counter - num_live: None, + num_live, bump_stamp, heroes, };