mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-08-28 16:30:54 +00:00
refactor: Promote handling unsigned data out of timeline
Also fixes: - Transaction IDs leaking in event route - Age not being set for event relations or threads - Both of the above for search results Notes down concern with relations table
This commit is contained in:
parent
5d44653e3a
commit
6c11e59c4a
17 changed files with 104 additions and 72 deletions
|
@ -84,11 +84,18 @@ pub(crate) async fn get_context_route(
|
|||
|
||||
let base_event = ignored_filter(&services, (base_count, base_pdu), sender_user);
|
||||
|
||||
// PDUs are used to get seen user IDs and then returned in response.
|
||||
|
||||
let events_before = services
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus_rev(Some(sender_user), room_id, Some(base_count))
|
||||
.pdus_rev(room_id, Some(base_count))
|
||||
.ignore_err()
|
||||
.then(async |mut pdu| {
|
||||
pdu.1.set_unsigned(Some(sender_user));
|
||||
// TODO: bundled aggregations
|
||||
pdu
|
||||
})
|
||||
.ready_filter_map(|item| event_filter(item, filter))
|
||||
.wide_filter_map(|item| ignored_filter(&services, item, sender_user))
|
||||
.wide_filter_map(|item| visibility_filter(&services, item, sender_user))
|
||||
|
@ -98,8 +105,13 @@ pub(crate) async fn get_context_route(
|
|||
let events_after = services
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus(Some(sender_user), room_id, Some(base_count))
|
||||
.pdus(room_id, Some(base_count))
|
||||
.ignore_err()
|
||||
.then(async |mut pdu| {
|
||||
pdu.1.set_unsigned(Some(sender_user));
|
||||
// TODO: bundled aggregations
|
||||
pdu
|
||||
})
|
||||
.ready_filter_map(|item| event_filter(item, filter))
|
||||
.wide_filter_map(|item| ignored_filter(&services, item, sender_user))
|
||||
.wide_filter_map(|item| visibility_filter(&services, item, sender_user))
|
||||
|
|
|
@ -114,14 +114,14 @@ pub(crate) async fn get_message_events_route(
|
|||
| Direction::Forward => services
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus(Some(sender_user), room_id, Some(from))
|
||||
.pdus(room_id, Some(from))
|
||||
.ignore_err()
|
||||
.boxed(),
|
||||
|
||||
| Direction::Backward => services
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus_rev(Some(sender_user), room_id, Some(from))
|
||||
.pdus_rev(room_id, Some(from))
|
||||
.ignore_err()
|
||||
.boxed(),
|
||||
};
|
||||
|
@ -132,6 +132,11 @@ pub(crate) async fn get_message_events_route(
|
|||
.wide_filter_map(|item| ignored_filter(&services, item, sender_user))
|
||||
.wide_filter_map(|item| visibility_filter(&services, item, sender_user))
|
||||
.take(limit)
|
||||
.then(async |mut pdu| {
|
||||
pdu.1.set_unsigned(Some(sender_user));
|
||||
// TODO: bundled aggregations
|
||||
pdu
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
|
|
|
@ -172,6 +172,10 @@ async fn paginate_relations_with_filter(
|
|||
})
|
||||
}
|
||||
|
||||
// TODO: Can we move the visibility filter lower down, to avoid checking events
|
||||
// that won't be sent? At the moment this also results in getting events that
|
||||
// appear to have no relation because intermediaries are not visible to the
|
||||
// user.
|
||||
async fn visibility_filter(
|
||||
services: &Services,
|
||||
sender_user: &UserId,
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) async fn get_room_event_route(
|
|||
"Fetched PDU must match requested"
|
||||
);
|
||||
|
||||
event.add_age().ok();
|
||||
event.set_unsigned(body.sender_user.as_deref());
|
||||
|
||||
Ok(get_room_event::v3::Response { event: event.into_room_event() })
|
||||
}
|
||||
|
|
|
@ -25,12 +25,19 @@ pub(crate) async fn room_initial_sync_route(
|
|||
return Err!(Request(Forbidden("No room preview available.")));
|
||||
}
|
||||
|
||||
// Events are returned in body
|
||||
|
||||
let limit = LIMIT_MAX;
|
||||
let events: Vec<_> = services
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus_rev(None, room_id, None)
|
||||
.pdus_rev(room_id, None)
|
||||
.try_take(limit)
|
||||
.and_then(async |mut pdu| {
|
||||
pdu.1.set_unsigned(body.sender_user.as_deref());
|
||||
// TODO: bundled aggregations
|
||||
Ok(pdu)
|
||||
})
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
|
|
|
@ -31,11 +31,7 @@ async fn load_timeline(
|
|||
next_batch: Option<PduCount>,
|
||||
limit: usize,
|
||||
) -> Result<(Vec<(PduCount, PduEvent)>, bool), Error> {
|
||||
let last_timeline_count = services
|
||||
.rooms
|
||||
.timeline
|
||||
.last_timeline_count(Some(sender_user), room_id)
|
||||
.await?;
|
||||
let last_timeline_count = services.rooms.timeline.last_timeline_count(room_id).await?;
|
||||
|
||||
if last_timeline_count <= roomsincecount {
|
||||
return Ok((Vec::new(), false));
|
||||
|
@ -44,8 +40,13 @@ async fn load_timeline(
|
|||
let non_timeline_pdus = services
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus_rev(Some(sender_user), room_id, None)
|
||||
.pdus_rev(room_id, None)
|
||||
.ignore_err()
|
||||
.map(move |mut pdu| {
|
||||
pdu.1.set_unsigned(Some(sender_user));
|
||||
// TODO: bundled aggregations
|
||||
pdu
|
||||
})
|
||||
.ready_skip_while(|&(pducount, _)| pducount > next_batch.unwrap_or_else(PduCount::max))
|
||||
.ready_take_while(|&(pducount, _)| pducount > roomsincecount);
|
||||
|
||||
|
|
|
@ -1191,7 +1191,7 @@ async fn calculate_heroes(
|
|||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.all_pdus(sender_user, room_id)
|
||||
.all_pdus(room_id)
|
||||
.ready_filter(|(_, pdu)| pdu.kind == RoomMember)
|
||||
.fold_default(|heroes: Vec<_>, (_, pdu)| {
|
||||
fold_hero(heroes, services, room_id, sender_user, pdu)
|
||||
|
|
|
@ -28,6 +28,9 @@ pub(crate) async fn get_threads_route(
|
|||
.transpose()?
|
||||
.unwrap_or_else(PduCount::max);
|
||||
|
||||
// TODO: bundled aggregation
|
||||
// TODO: user_can_see_event and set_unsigned should be at the same level /
|
||||
// function, so unsigned is only set for seen events.
|
||||
let threads: Vec<(PduCount, PduEvent)> = services
|
||||
.rooms
|
||||
.threads
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue