additional sync cleanup
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
828cb96ba9
commit
1fdcab0319
1 changed files with 25 additions and 26 deletions
|
@ -14,14 +14,16 @@ use crate::{service::Services, Error, PduEvent, Result};
|
||||||
async fn load_timeline(
|
async fn load_timeline(
|
||||||
services: &Services, sender_user: &UserId, room_id: &RoomId, roomsincecount: PduCount, limit: u64,
|
services: &Services, sender_user: &UserId, room_id: &RoomId, roomsincecount: PduCount, limit: u64,
|
||||||
) -> Result<(Vec<(PduCount, PduEvent)>, bool), Error> {
|
) -> Result<(Vec<(PduCount, PduEvent)>, bool), Error> {
|
||||||
let timeline_pdus;
|
let last_timeline_count = services
|
||||||
let limited = if services
|
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.last_timeline_count(sender_user, room_id)
|
.last_timeline_count(sender_user, room_id)
|
||||||
.await?
|
.await?;
|
||||||
> roomsincecount
|
|
||||||
{
|
if last_timeline_count <= roomsincecount {
|
||||||
|
return Ok((Vec::new(), false));
|
||||||
|
}
|
||||||
|
|
||||||
let mut non_timeline_pdus = services
|
let mut non_timeline_pdus = services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
|
@ -30,22 +32,19 @@ async fn load_timeline(
|
||||||
.ready_take_while(|(pducount, _)| pducount > &roomsincecount);
|
.ready_take_while(|(pducount, _)| pducount > &roomsincecount);
|
||||||
|
|
||||||
// Take the last events for the timeline
|
// Take the last events for the timeline
|
||||||
timeline_pdus = non_timeline_pdus
|
let timeline_pdus: Vec<_> = non_timeline_pdus
|
||||||
.by_ref()
|
.by_ref()
|
||||||
.take(usize_from_u64_truncated(limit))
|
.take(usize_from_u64_truncated(limit))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await
|
.await
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.rev()
|
.rev()
|
||||||
.collect::<Vec<_>>();
|
.collect();
|
||||||
|
|
||||||
// They /sync response doesn't always return all messages, so we say the output
|
// They /sync response doesn't always return all messages, so we say the output
|
||||||
// is limited unless there are events in non_timeline_pdus
|
// is limited unless there are events in non_timeline_pdus
|
||||||
non_timeline_pdus.next().await.is_some()
|
let limited = non_timeline_pdus.next().await.is_some();
|
||||||
} else {
|
|
||||||
timeline_pdus = Vec::new();
|
|
||||||
false
|
|
||||||
};
|
|
||||||
Ok((timeline_pdus, limited))
|
Ok((timeline_pdus, limited))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue