From a803b84b275b94834bcda453da665d3c975d62ad Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 29 Sep 2025 04:19:00 +0000 Subject: [PATCH] Add missing reverse query for shortroomid => room_id. Signed-off-by: Jason Volk --- src/service/rooms/short/mod.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/service/rooms/short/mod.rs b/src/service/rooms/short/mod.rs index ba8908fd..d9da2e6b 100644 --- a/src/service/rooms/short/mod.rs +++ b/src/service/rooms/short/mod.rs @@ -1,10 +1,15 @@ use std::{borrow::Borrow, fmt::Debug, mem::size_of_val, sync::Arc}; -use futures::{Stream, StreamExt}; -use ruma::{EventId, RoomId, events::StateEventType}; +use futures::{FutureExt, Stream, StreamExt}; +use ruma::{EventId, OwnedRoomId, RoomId, events::StateEventType}; use serde::Deserialize; pub use tuwunel_core::matrix::pdu::{ShortEventId, ShortId, ShortRoomId, ShortStateKey}; -use tuwunel_core::{Err, Result, err, implement, matrix::StateKey, utils, utils::IterStream}; +use tuwunel_core::{ + Err, Result, err, implement, + matrix::StateKey, + utils, + utils::{IterStream, stream::ReadyExt}, +}; use tuwunel_database::{Deserialized, Get, Map, Qry}; pub struct Service { @@ -238,6 +243,18 @@ pub async fn get_shortroomid(&self, room_id: &RoomId) -> Result { .deserialized() } +#[implement(Service)] +pub async fn get_roomid_from_short(&self, shortroomid_: ShortRoomId) -> Result { + self.db + .roomid_shortroomid + .stream() + .ready_filter_map(Result::ok) + .ready_find(|&(_, shortroomid)| shortroomid == shortroomid_) + .map(|found| found.map(|(room_id, _): (&RoomId, ShortRoomId)| room_id.to_owned())) + .await + .ok_or_else(|| err!(Database("Failed to find RoomId from {shortroomid_:?}"))) +} + #[implement(Service)] pub async fn get_or_create_shortroomid(&self, room_id: &RoomId) -> ShortRoomId { self.db