add delete_shortroomid kv db function

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-01-25 23:14:56 -05:00
parent 7588790c3b
commit c98cdbb7a8
2 changed files with 20 additions and 1 deletions

View file

@ -1,7 +1,7 @@
use std::sync::Arc;
use ruma::{events::StateEventType, EventId, RoomId};
use tracing::warn;
use tracing::{error, warn};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -216,4 +216,21 @@ impl service::rooms::short::Data for KeyValueDatabase {
}
})
}
/// Attempts to delete a shortroomid from the kv database
fn delete_shortroomid(&self, room_id: &RoomId) -> Result<()> {
Ok(match self.roomid_shortroomid.get(room_id.as_bytes())? {
Some(short) => {
self.roomid_shortroomid.remove(&short).map_err(|e| {
error!("Failed to remove shortroomid in database: {e}");
Error::bad_database("Failed to remove shortroomid in database")
});
}
None => {
return Err(Error::bad_database(
"Invalid or non-existent shortroomid in db.",
))?
}
})
}
}

View file

@ -28,4 +28,6 @@ pub trait Data: Send + Sync {
fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>>;
fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result<u64>;
fn delete_shortroomid(&self, room_id: &RoomId) -> Result<()>;
}