mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
add service type for short
This will be necessary in the near future.
This commit is contained in:
parent
e0cf163486
commit
a1fe0f3fff
2 changed files with 79 additions and 4 deletions
|
|
@ -93,7 +93,7 @@ impl Services {
|
|||
db,
|
||||
},
|
||||
search: db,
|
||||
short: db,
|
||||
short: rooms::short::Service::new(db),
|
||||
state: rooms::state::Service {
|
||||
db,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
mod data;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) use data::Data;
|
||||
use ruma::{events::StateEventType, EventId, RoomId};
|
||||
|
||||
use crate::utils::error::Result;
|
||||
|
||||
macro_rules! short_id_type {
|
||||
($name:ident) => {
|
||||
|
|
@ -25,4 +27,77 @@ short_id_type!(ShortEventId);
|
|||
short_id_type!(ShortStateHash);
|
||||
short_id_type!(ShortStateKey);
|
||||
|
||||
pub(crate) type Service = &'static dyn Data;
|
||||
mod data;
|
||||
|
||||
pub(crate) use data::Data;
|
||||
|
||||
pub(crate) struct Service {
|
||||
db: &'static dyn Data,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
pub(crate) fn new(db: &'static dyn Data) -> Self {
|
||||
Self {
|
||||
db,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_or_create_shorteventid(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
) -> Result<ShortEventId> {
|
||||
self.db.get_or_create_shorteventid(event_id)
|
||||
}
|
||||
|
||||
pub(crate) fn get_shortstatekey(
|
||||
&self,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<Option<ShortStateKey>> {
|
||||
self.db.get_shortstatekey(event_type, state_key)
|
||||
}
|
||||
|
||||
pub(crate) fn get_or_create_shortstatekey(
|
||||
&self,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<ShortStateKey> {
|
||||
self.db.get_or_create_shortstatekey(event_type, state_key)
|
||||
}
|
||||
|
||||
pub(crate) fn get_eventid_from_short(
|
||||
&self,
|
||||
shorteventid: ShortEventId,
|
||||
) -> Result<Arc<EventId>> {
|
||||
self.db.get_eventid_from_short(shorteventid)
|
||||
}
|
||||
|
||||
pub(crate) fn get_statekey_from_short(
|
||||
&self,
|
||||
shortstatekey: ShortStateKey,
|
||||
) -> Result<(StateEventType, String)> {
|
||||
self.db.get_statekey_from_short(shortstatekey)
|
||||
}
|
||||
|
||||
/// Returns `(shortstatehash, already_existed)`
|
||||
pub(crate) fn get_or_create_shortstatehash(
|
||||
&self,
|
||||
state_hash: &[u8],
|
||||
) -> Result<(ShortStateHash, bool)> {
|
||||
self.db.get_or_create_shortstatehash(state_hash)
|
||||
}
|
||||
|
||||
pub(crate) fn get_shortroomid(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<ShortRoomId>> {
|
||||
self.db.get_shortroomid(room_id)
|
||||
}
|
||||
|
||||
pub(crate) fn get_or_create_shortroomid(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<ShortRoomId> {
|
||||
self.db.get_or_create_shortroomid(room_id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue