1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-09-12 17:20:57 +00:00
continuwuity/src/service/rooms/short/mod.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.6 KiB
Rust
Raw Normal View History

use conduit::Server;
use database::KeyValueDatabase;
mod data;
use std::sync::Arc;
use data::Data;
2022-10-05 20:34:31 +02:00
use ruma::{events::StateEventType, EventId, RoomId};
2022-10-08 13:03:07 +02:00
use crate::Result;
pub struct Service {
db: Data,
}
2022-10-05 12:45:54 +02:00
impl Service {
pub fn build(_server: &Arc<Server>, db: &Arc<KeyValueDatabase>) -> Result<Self> {
Ok(Self {
db: Data::new(db),
})
}
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)
}
pub fn multi_get_or_create_shorteventid(&self, event_ids: &[&EventId]) -> Result<Vec<u64>> {
self.db.multi_get_or_create_shorteventid(event_ids)
}
pub fn get_shortstatekey(&self, event_type: &StateEventType, 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, event_type: &StateEventType, 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
}
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)
}
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)
}
2022-06-19 22:56:14 +02:00
/// Returns (shortstatehash, already_existed)
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
}
pub fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> { self.db.get_shortroomid(room_id) }
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)
}
}