2022-08-07 19:42:22 +02:00
|
|
|
mod data;
|
2022-09-06 23:15:09 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-08-07 19:42:22 +02:00
|
|
|
pub use data::Data;
|
2022-10-05 20:34:31 +02:00
|
|
|
use ruma::{events::StateEventType, EventId, RoomId};
|
2021-08-11 19:15:38 +02:00
|
|
|
|
2022-10-08 13:03:07 +02:00
|
|
|
use crate::Result;
|
2022-08-07 19:42:22 +02:00
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
pub struct Service {
|
2022-10-08 13:02:52 +02:00
|
|
|
pub db: &'static dyn Data,
|
2022-08-07 19:42:22 +02:00
|
|
|
}
|
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
impl Service {
|
2022-10-05 20:34:31 +02:00
|
|
|
pub fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.get_or_create_shorteventid(event_id)
|
2021-08-11 19:15:38 +02:00
|
|
|
}
|
|
|
|
|
2021-08-12 23:04:00 +02:00
|
|
|
pub fn get_shortstatekey(
|
|
|
|
&self,
|
2022-04-06 21:31:29 +02:00
|
|
|
event_type: &StateEventType,
|
2021-08-12 23:04:00 +02:00
|
|
|
state_key: &str,
|
|
|
|
) -> Result<Option<u64>> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.get_shortstatekey(event_type, state_key)
|
2021-08-12 23:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_or_create_shortstatekey(
|
|
|
|
&self,
|
2022-04-06 21:31:29 +02:00
|
|
|
event_type: &StateEventType,
|
2021-08-12 23:04:00 +02:00
|
|
|
state_key: &str,
|
|
|
|
) -> Result<u64> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.get_or_create_shortstatekey(event_type, state_key)
|
2021-08-12 23:04:00 +02:00
|
|
|
}
|
|
|
|
|
2021-08-26 17:58:32 -04:00
|
|
|
pub fn get_eventid_from_short(&self, shorteventid: u64) -> Result<Arc<EventId>> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.get_eventid_from_short(shorteventid)
|
2021-08-11 19:15:38 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 21:31:29 +02:00
|
|
|
pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(StateEventType, String)> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.get_statekey_from_short(shortstatekey)
|
2021-08-24 19:10:31 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 22:56:14 +02:00
|
|
|
/// Returns (shortstatehash, already_existed)
|
2022-10-05 20:34:31 +02:00
|
|
|
pub fn get_or_create_shortstatehash(&self, state_hash: &[u8]) -> Result<(u64, bool)> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.get_or_create_shortstatehash(state_hash)
|
2021-03-26 11:10:45 +01:00
|
|
|
}
|
|
|
|
|
2022-06-25 16:12:23 +02:00
|
|
|
pub fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.get_shortroomid(room_id)
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|
|
|
|
|
2022-10-05 20:34:31 +02:00
|
|
|
pub fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result<u64> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.get_or_create_shortroomid(room_id)
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|
2022-08-07 19:42:22 +02:00
|
|
|
}
|