From 75509d50caf1145f561a2eae88f24364a4385af3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 3 Oct 2025 05:01:00 +0000 Subject: [PATCH] Add shorteventid to pdu_id query; reorg related id query interface. Signed-off-by: Jason Volk --- src/api/client/sync/v3.rs | 7 +--- src/service/rooms/timeline/mod.rs | 68 +++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/api/client/sync/v3.rs b/src/api/client/sync/v3.rs index 7063b94d..b524c672 100644 --- a/src/api/client/sync/v3.rs +++ b/src/api/client/sync/v3.rs @@ -1126,11 +1126,8 @@ async fn calculate_state_changes<'a>( .chain(lazy_state_ids.stream()) .broad_filter_map(|shorteventid| { services - .short - .get_eventid_from_short(shorteventid) - .and_then(async |event_id: OwnedEventId| { - services.timeline.get_pdu(&event_id).await - }) + .timeline + .get_pdu_from_shorteventid(shorteventid) .ok() }) .collect::>() diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 8be8f766..b7644296 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -258,27 +258,6 @@ pub async fn get_shortstatehash( .await } -/// Returns the `shorteventid` from the `pdu_id` -#[implement(Service)] -pub async fn get_shorteventid_from_pdu_id(&self, pdu_id: &PduId) -> Result { - let event_id = self.get_event_id_from_pdu_id(pdu_id).await?; - - self.services - .short - .get_shorteventid(&event_id) - .await -} - -/// Returns the `event_id` from the `pdu_id` -#[implement(Service)] -pub async fn get_event_id_from_pdu_id(&self, pdu_id: &PduId) -> Result { - let pdu_id: RawPduId = (*pdu_id).into(); - - self.get_pdu_from_id(&pdu_id) - .map_ok(|pdu| pdu.event_id) - .await -} - /// Returns the shorteventid in the room preceding the exclusive `before` param. /// `before` does not have to be a valid shorteventid or in the room. #[implement(Service)] @@ -447,6 +426,20 @@ fn pdu_count_to_id(shortroomid: ShortRoomId, count: PduCount, dir: Direction) -> pdu_id.into() } +/// Returns the pdu from shorteventid +/// +/// Checks the `eventid_outlierpdu` Tree if not found in the timeline. +#[implement(Service)] +pub async fn get_pdu_from_shorteventid(&self, shorteventid: ShortEventId) -> Result { + let event_id: OwnedEventId = self + .services + .short + .get_eventid_from_short(shorteventid) + .await?; + + self.get_pdu(&event_id).await +} + /// Returns the pdu. /// /// Checks the `eventid_outlierpdu` Tree if not found in the timeline. @@ -567,6 +560,39 @@ pub async fn get_pdu_count(&self, event_id: &EventId) -> Result { .map(RawPduId::pdu_count) } +/// Returns the `shorteventid` from the `pdu_id` +#[implement(Service)] +pub async fn get_shorteventid_from_pdu_id(&self, pdu_id: &PduId) -> Result { + let event_id = self.get_event_id_from_pdu_id(pdu_id).await?; + + self.services + .short + .get_shorteventid(&event_id) + .await +} + +/// Returns the `event_id` from the `pdu_id` +#[implement(Service)] +pub async fn get_event_id_from_pdu_id(&self, pdu_id: &PduId) -> Result { + let pdu_id: RawPduId = (*pdu_id).into(); + + self.get_pdu_from_id(&pdu_id) + .map_ok(|pdu| pdu.event_id) + .await +} + +/// Returns the `pdu_id` from the `shorteventid` +#[implement(Service)] +pub async fn get_pdu_id_from_shorteventid(&self, shorteventid: ShortEventId) -> Result { + let event_id: OwnedEventId = self + .services + .short + .get_eventid_from_short(shorteventid) + .await?; + + self.get_pdu_id(&event_id).await +} + /// Returns the pdu's id. #[implement(Service)] pub async fn get_pdu_id(&self, event_id: &EventId) -> Result {