From 8d3e4eba9945de178769b7158cdb3d3924788714 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 18 Dec 2025 20:33:52 +0000 Subject: [PATCH] fix: Add aggregations to the search endpoint --- src/api/client/search.rs | 7 ++++++- src/service/rooms/search/mod.rs | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/api/client/search.rs b/src/api/client/search.rs index 794a6731..d6b78b6a 100644 --- a/src/api/client/search.rs +++ b/src/api/client/search.rs @@ -110,7 +110,12 @@ async fn category_room_events( limit, }; - let (count, results) = services.rooms.search.search_pdus(&query).await.ok()?; + let (count, results) = services + .rooms + .search + .search_pdus(&query, sender_user) + .await + .ok()?; results .collect::>() diff --git a/src/service/rooms/search/mod.rs b/src/service/rooms/search/mod.rs index 259c8889..241d952f 100644 --- a/src/service/rooms/search/mod.rs +++ b/src/service/rooms/search/mod.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use conduwuit::{ PduCount, PduEvent, Result, arrayvec::ArrayVec, - implement, + debug_warn, implement, matrix::event::{Event, Matches}, utils::{ ArrayVecExt, IterStream, ReadyExt, set, @@ -35,6 +35,7 @@ struct Services { short: Dep, state_accessor: Dep, timeline: Dep, + pdu_metadata: Dep, } #[derive(Clone, Debug)] @@ -61,6 +62,7 @@ impl crate::Service for Service { state_accessor: args .depend::("rooms::state_accessor"), timeline: args.depend::("rooms::timeline"), + pdu_metadata: args.depend::("rooms::pdu_metadata"), }, })) } @@ -104,6 +106,7 @@ pub fn deindex_pdu(&self, shortroomid: ShortRoomId, pdu_id: &RawPduId, message_b pub async fn search_pdus<'a>( &'a self, query: &'a RoomQuery<'a>, + sender_user: &'a UserId, ) -> Result<(usize, impl Stream + Send + 'a)> { let pdu_ids: Vec<_> = self.search_pdu_ids(query).await?.collect().await; @@ -132,7 +135,18 @@ pub async fn search_pdus<'a>( .take(query.limit) .map(move |mut pdu| { pdu.set_unsigned(query.user_id); - // TODO: bundled aggregation + + pdu + }) + .then(async move |mut pdu| { + if let Err(e) = self + .services + .pdu_metadata + .add_bundled_aggregations_to_pdu(sender_user, &mut pdu) + .await + { + debug_warn!("Failed to add bundled aggregations: {e}"); + } pdu });