mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-27 18:28:31 +00:00
implement standard traits for PduCount enable serde for arrayvec typedef various shortid's pducount simplifications split parts of pdu_metadata service to core/pdu and api/relations remove some yields; improve var names/syntax tweak types for limit timeline limit arguments Signed-off-by: Jason Volk <jason@zemos.net>
63 lines
1.6 KiB
Rust
63 lines
1.6 KiB
Rust
mod v3;
|
|
mod v4;
|
|
|
|
use conduit::{utils::ReadyExt, PduCount};
|
|
use futures::StreamExt;
|
|
use ruma::{RoomId, UserId};
|
|
|
|
pub(crate) use self::{v3::sync_events_route, v4::sync_events_v4_route};
|
|
use crate::{service::Services, Error, PduEvent, Result};
|
|
|
|
async fn load_timeline(
|
|
services: &Services, sender_user: &UserId, room_id: &RoomId, roomsincecount: PduCount, limit: usize,
|
|
) -> Result<(Vec<(PduCount, PduEvent)>, bool), Error> {
|
|
let last_timeline_count = services
|
|
.rooms
|
|
.timeline
|
|
.last_timeline_count(sender_user, room_id)
|
|
.await?;
|
|
|
|
if last_timeline_count <= roomsincecount {
|
|
return Ok((Vec::new(), false));
|
|
}
|
|
|
|
let mut non_timeline_pdus = services
|
|
.rooms
|
|
.timeline
|
|
.pdus_until(sender_user, room_id, PduCount::max())
|
|
.await?
|
|
.ready_take_while(|(pducount, _)| *pducount > roomsincecount);
|
|
|
|
// Take the last events for the timeline
|
|
let timeline_pdus: Vec<_> = non_timeline_pdus
|
|
.by_ref()
|
|
.take(limit)
|
|
.collect::<Vec<_>>()
|
|
.await
|
|
.into_iter()
|
|
.rev()
|
|
.collect();
|
|
|
|
// They /sync response doesn't always return all messages, so we say the output
|
|
// is limited unless there are events in non_timeline_pdus
|
|
let limited = non_timeline_pdus.next().await.is_some();
|
|
|
|
Ok((timeline_pdus, limited))
|
|
}
|
|
|
|
async fn share_encrypted_room(
|
|
services: &Services, sender_user: &UserId, user_id: &UserId, ignore_room: Option<&RoomId>,
|
|
) -> bool {
|
|
services
|
|
.rooms
|
|
.user
|
|
.get_shared_rooms(sender_user, user_id)
|
|
.ready_filter(|&room_id| Some(room_id) != ignore_room)
|
|
.any(|other_room_id| {
|
|
services
|
|
.rooms
|
|
.state_accessor
|
|
.is_encrypted_room(other_room_id)
|
|
})
|
|
.await
|
|
}
|