Compare commits

...
This repository has been archived on 2025-08-14. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.

1 commit

Author SHA1 Message Date
strawberry
c98cdbb7a8 add delete_shortroomid kv db function
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-01-25 23:14:56 -05:00
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<()>;
}