2022-08-07 19:42:22 +02:00
|
|
|
mod data;
|
2024-06-28 22:51:39 +00:00
|
|
|
|
2022-09-06 23:15:09 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2024-06-28 22:51:39 +00:00
|
|
|
use conduit::{Result, Server};
|
2024-05-26 21:29:19 +00:00
|
|
|
use data::Data;
|
2024-06-28 22:51:39 +00:00
|
|
|
use database::Database;
|
2022-10-05 20:34:31 +02:00
|
|
|
use ruma::{events::StateEventType, EventId, RoomId};
|
2021-08-11 19:15:38 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
2024-05-27 03:17:20 +00:00
|
|
|
db: Data,
|
2022-08-07 19:42:22 +02:00
|
|
|
}
|
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
impl Service {
|
2024-06-28 22:51:39 +00:00
|
|
|
pub fn build(_server: &Arc<Server>, db: &Arc<Database>) -> Result<Self> {
|
2024-05-27 03:17:20 +00:00
|
|
|
Ok(Self {
|
|
|
|
db: Data::new(db),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64> {
|
2024-03-05 19:48:54 -05:00
|
|
|
self.db.get_or_create_shorteventid(event_id)
|
|
|
|
}
|
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn multi_get_or_create_shorteventid(&self, event_ids: &[&EventId]) -> Result<Vec<u64>> {
|
2024-04-10 12:21:23 -07:00
|
|
|
self.db.multi_get_or_create_shorteventid(event_ids)
|
|
|
|
}
|
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_shortstatekey(&self, event_type: &StateEventType, state_key: &str) -> Result<Option<u64>> {
|
2024-03-05 19:48:54 -05:00
|
|
|
self.db.get_shortstatekey(event_type, state_key)
|
|
|
|
}
|
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_or_create_shortstatekey(&self, event_type: &StateEventType, state_key: &str) -> Result<u64> {
|
2024-03-05 19:48:54 -05:00
|
|
|
self.db.get_or_create_shortstatekey(event_type, state_key)
|
|
|
|
}
|
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_eventid_from_short(&self, shorteventid: u64) -> Result<Arc<EventId>> {
|
2024-03-05 19:48:54 -05:00
|
|
|
self.db.get_eventid_from_short(shorteventid)
|
|
|
|
}
|
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(StateEventType, String)> {
|
2024-03-05 19:48:54 -05:00
|
|
|
self.db.get_statekey_from_short(shortstatekey)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns (shortstatehash, already_existed)
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_or_create_shortstatehash(&self, state_hash: &[u8]) -> Result<(u64, bool)> {
|
2024-03-05 19:48:54 -05:00
|
|
|
self.db.get_or_create_shortstatehash(state_hash)
|
|
|
|
}
|
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> { self.db.get_shortroomid(room_id) }
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result<u64> {
|
2024-03-05 19:48:54 -05:00
|
|
|
self.db.get_or_create_shortroomid(room_id)
|
|
|
|
}
|
2022-08-07 19:42:22 +02:00
|
|
|
}
|