diff --git a/src/database/key_value/rooms/alias.rs b/src/database/key_value/rooms/alias.rs index a4666834..5058cb87 100644 --- a/src/database/key_value/rooms/alias.rs +++ b/src/database/key_value/rooms/alias.rs @@ -3,6 +3,7 @@ use ruma::{api::client::error::ErrorKind, OwnedRoomAliasId, OwnedRoomId, RoomAli use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; impl service::rooms::alias::Data for KeyValueDatabase { + #[tracing::instrument(skip(self))] fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> { self.alias_roomid .insert(alias.alias().as_bytes(), room_id.as_bytes())?; @@ -13,6 +14,7 @@ impl service::rooms::alias::Data for KeyValueDatabase { Ok(()) } + #[tracing::instrument(skip(self))] fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> { if let Some(room_id) = self.alias_roomid.get(alias.alias().as_bytes())? { let mut prefix = room_id.clone(); @@ -31,6 +33,7 @@ impl service::rooms::alias::Data for KeyValueDatabase { Ok(()) } + #[tracing::instrument(skip(self))] fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result> { self.alias_roomid .get(alias.alias().as_bytes())? @@ -43,6 +46,7 @@ impl service::rooms::alias::Data for KeyValueDatabase { .transpose() } + #[tracing::instrument(skip(self))] fn local_aliases_for_room<'a>( &'a self, room_id: &RoomId, diff --git a/src/database/key_value/rooms/directory.rs b/src/database/key_value/rooms/directory.rs index e05dee82..9ed62582 100644 --- a/src/database/key_value/rooms/directory.rs +++ b/src/database/key_value/rooms/directory.rs @@ -3,18 +3,22 @@ use ruma::{OwnedRoomId, RoomId}; use crate::{database::KeyValueDatabase, service, utils, Error, Result}; impl service::rooms::directory::Data for KeyValueDatabase { + #[tracing::instrument(skip(self))] fn set_public(&self, room_id: &RoomId) -> Result<()> { self.publicroomids.insert(room_id.as_bytes(), &[]) } + #[tracing::instrument(skip(self))] fn set_not_public(&self, room_id: &RoomId) -> Result<()> { self.publicroomids.remove(room_id.as_bytes()) } + #[tracing::instrument(skip(self))] fn is_public_room(&self, room_id: &RoomId) -> Result { Ok(self.publicroomids.get(room_id.as_bytes())?.is_some()) } + #[tracing::instrument(skip(self))] fn public_rooms<'a>(&'a self) -> Box> + 'a> { Box::new(self.publicroomids.iter().map(|(bytes, _)| { RoomId::parse( diff --git a/src/database/key_value/rooms/edus/read_receipt.rs b/src/database/key_value/rooms/edus/read_receipt.rs index fa97ea34..87c4e6f0 100644 --- a/src/database/key_value/rooms/edus/read_receipt.rs +++ b/src/database/key_value/rooms/edus/read_receipt.rs @@ -48,6 +48,8 @@ impl service::rooms::edus::read_receipt::Data for KeyValueDatabase { Ok(()) } + #[tracing::instrument(skip(self))] + #[allow(clippy::type_complexity)] fn readreceipts_since<'a>( &'a self, room_id: &RoomId, @@ -105,6 +107,7 @@ impl service::rooms::edus::read_receipt::Data for KeyValueDatabase { ) } + #[tracing::instrument(skip(self))] fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> { let mut key = room_id.as_bytes().to_vec(); key.push(0xff); @@ -117,6 +120,7 @@ impl service::rooms::edus::read_receipt::Data for KeyValueDatabase { .insert(&key, &services().globals.next_count()?.to_be_bytes()) } + #[tracing::instrument(skip(self))] fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result> { let mut key = room_id.as_bytes().to_vec(); key.push(0xff); diff --git a/src/database/key_value/rooms/metadata.rs b/src/database/key_value/rooms/metadata.rs index 57540c40..6a38f08b 100644 --- a/src/database/key_value/rooms/metadata.rs +++ b/src/database/key_value/rooms/metadata.rs @@ -3,6 +3,7 @@ use ruma::{OwnedRoomId, RoomId}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; impl service::rooms::metadata::Data for KeyValueDatabase { + #[tracing::instrument(skip(self))] fn exists(&self, room_id: &RoomId) -> Result { let prefix = match services().rooms.short.get_shortroomid(room_id)? { Some(b) => b.to_be_bytes().to_vec(), diff --git a/src/database/key_value/rooms/outlier.rs b/src/database/key_value/rooms/outlier.rs index 7985ba81..f4269770 100644 --- a/src/database/key_value/rooms/outlier.rs +++ b/src/database/key_value/rooms/outlier.rs @@ -19,6 +19,7 @@ impl service::rooms::outlier::Data for KeyValueDatabase { }) } + #[tracing::instrument(skip(self, pdu))] fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> { self.eventid_outlierpdu.insert( event_id.as_bytes(), diff --git a/src/database/key_value/rooms/search.rs b/src/database/key_value/rooms/search.rs index 6a52b348..0154d1a1 100644 --- a/src/database/key_value/rooms/search.rs +++ b/src/database/key_value/rooms/search.rs @@ -3,6 +3,7 @@ use ruma::RoomId; use crate::{database::KeyValueDatabase, service, services, utils, Result}; impl service::rooms::search::Data for KeyValueDatabase { + #[tracing::instrument(skip(self))] fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> { let mut batch = message_body .split_terminator(|c: char| !c.is_alphanumeric()) @@ -20,6 +21,8 @@ impl service::rooms::search::Data for KeyValueDatabase { self.tokenids.insert_batch(&mut batch) } + #[tracing::instrument(skip(self))] + #[allow(clippy::type_complexity)] fn search_pdus<'a>( &'a self, room_id: &RoomId, diff --git a/src/service.rs b/src/service.rs index fe06c40d..710edaca 100644 --- a/src/service.rs +++ b/src/service.rs @@ -60,11 +60,11 @@ impl Services { appservice: appservice::Service::build(db)?, pusher: pusher::Service { db }, rooms: rooms::Service { - alias: rooms::alias::Service { db }, + alias: db, auth_chain: rooms::auth_chain::Service { db }, - directory: rooms::directory::Service { db }, + directory: db, edus: rooms::edus::Service { - read_receipt: rooms::edus::read_receipt::Service { db }, + read_receipt: db, typing: rooms::edus::typing::Service { typing: RwLock::new(BTreeMap::new()), last_typing_update: RwLock::new(BTreeMap::new()), @@ -76,11 +76,11 @@ impl Services { db, lazy_load_waiting: Mutex::new(HashMap::new()), }, - metadata: rooms::metadata::Service { db }, - outlier: rooms::outlier::Service { db }, + metadata: db, + outlier: db, pdu_metadata: rooms::pdu_metadata::Service { db }, - search: rooms::search::Service { db }, - short: rooms::short::Service { db }, + search: db, + short: db, state: rooms::state::Service { db }, state_accessor: rooms::state_accessor::Service { db, @@ -121,17 +121,17 @@ impl Services { spaces: rooms::spaces::Service { roomid_spacechunk_cache: Mutex::new(LruCache::new(200)), }, - user: rooms::user::Service { db }, + user: db, }, - transaction_ids: transaction_ids::Service { db }, + transaction_ids: db, uiaa: uiaa::Service { db }, users: users::Service { db, connections: StdMutex::new(BTreeMap::new()), }, - account_data: account_data::Service { db }, + account_data: db, admin: admin::Service::build(), - key_backups: key_backups::Service { db }, + key_backups: db, media: media::Service { db }, sending: sending::Service::build(db, &config), diff --git a/src/service/account_data.rs b/src/service/account_data.rs index 515b970e..411199f4 100644 --- a/src/service/account_data.rs +++ b/src/service/account_data.rs @@ -1,53 +1,4 @@ mod data; pub(crate) use data::Data; - -use ruma::{ - events::{AnyEphemeralRoomEvent, RoomAccountDataEventType}, - serde::Raw, - RoomId, UserId, -}; - -use std::collections::HashMap; - -use crate::Result; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - /// Places one event in the account data of the user and removes the previous entry. - #[tracing::instrument(skip(self, room_id, user_id, event_type, data))] - pub(crate) fn update( - &self, - room_id: Option<&RoomId>, - user_id: &UserId, - event_type: RoomAccountDataEventType, - data: &serde_json::Value, - ) -> Result<()> { - self.db.update(room_id, user_id, event_type, data) - } - - /// Searches the account data for a specific kind. - #[tracing::instrument(skip(self, room_id, user_id, event_type))] - pub(crate) fn get( - &self, - room_id: Option<&RoomId>, - user_id: &UserId, - event_type: RoomAccountDataEventType, - ) -> Result>> { - self.db.get(room_id, user_id, event_type) - } - - /// Returns all changes to the account data that happened after `since`. - #[tracing::instrument(skip(self, room_id, user_id, since))] - pub(crate) fn changes_since( - &self, - room_id: Option<&RoomId>, - user_id: &UserId, - since: u64, - ) -> Result>> { - self.db.changes_since(room_id, user_id, since) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/key_backups.rs b/src/service/key_backups.rs index 542db640..411199f4 100644 --- a/src/service/key_backups.rs +++ b/src/service/key_backups.rs @@ -1,127 +1,4 @@ mod data; + pub(crate) use data::Data; - -use crate::Result; -use ruma::{ - api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, - serde::Raw, - OwnedRoomId, RoomId, UserId, -}; -use std::collections::BTreeMap; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - pub(crate) fn create_backup( - &self, - user_id: &UserId, - backup_metadata: &Raw, - ) -> Result { - self.db.create_backup(user_id, backup_metadata) - } - - pub(crate) fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> { - self.db.delete_backup(user_id, version) - } - - pub(crate) fn update_backup( - &self, - user_id: &UserId, - version: &str, - backup_metadata: &Raw, - ) -> Result { - self.db.update_backup(user_id, version, backup_metadata) - } - - pub(crate) fn get_latest_backup_version(&self, user_id: &UserId) -> Result> { - self.db.get_latest_backup_version(user_id) - } - - pub(crate) fn get_latest_backup( - &self, - user_id: &UserId, - ) -> Result)>> { - self.db.get_latest_backup(user_id) - } - - pub(crate) fn get_backup( - &self, - user_id: &UserId, - version: &str, - ) -> Result>> { - self.db.get_backup(user_id, version) - } - - pub(crate) fn add_key( - &self, - user_id: &UserId, - version: &str, - room_id: &RoomId, - session_id: &str, - key_data: &Raw, - ) -> Result<()> { - self.db - .add_key(user_id, version, room_id, session_id, key_data) - } - - pub(crate) fn count_keys(&self, user_id: &UserId, version: &str) -> Result { - self.db.count_keys(user_id, version) - } - - pub(crate) fn get_etag(&self, user_id: &UserId, version: &str) -> Result { - self.db.get_etag(user_id, version) - } - - pub(crate) fn get_all( - &self, - user_id: &UserId, - version: &str, - ) -> Result> { - self.db.get_all(user_id, version) - } - - pub(crate) fn get_room( - &self, - user_id: &UserId, - version: &str, - room_id: &RoomId, - ) -> Result>> { - self.db.get_room(user_id, version, room_id) - } - - pub(crate) fn get_session( - &self, - user_id: &UserId, - version: &str, - room_id: &RoomId, - session_id: &str, - ) -> Result>> { - self.db.get_session(user_id, version, room_id, session_id) - } - - pub(crate) fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> { - self.db.delete_all_keys(user_id, version) - } - - pub(crate) fn delete_room_keys( - &self, - user_id: &UserId, - version: &str, - room_id: &RoomId, - ) -> Result<()> { - self.db.delete_room_keys(user_id, version, room_id) - } - - pub(crate) fn delete_room_key( - &self, - user_id: &UserId, - version: &str, - room_id: &RoomId, - session_id: &str, - ) -> Result<()> { - self.db - .delete_room_key(user_id, version, room_id, session_id) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/rooms/alias.rs b/src/service/rooms/alias.rs index d078611a..411199f4 100644 --- a/src/service/rooms/alias.rs +++ b/src/service/rooms/alias.rs @@ -1,35 +1,4 @@ mod data; pub(crate) use data::Data; - -use crate::Result; -use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - #[tracing::instrument(skip(self))] - pub(crate) fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> { - self.db.set_alias(alias, room_id) - } - - #[tracing::instrument(skip(self))] - pub(crate) fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> { - self.db.remove_alias(alias) - } - - #[tracing::instrument(skip(self))] - pub(crate) fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result> { - self.db.resolve_local_alias(alias) - } - - #[tracing::instrument(skip(self))] - pub(crate) fn local_aliases_for_room<'a>( - &'a self, - room_id: &RoomId, - ) -> Box> + 'a> { - self.db.local_aliases_for_room(room_id) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/rooms/directory.rs b/src/service/rooms/directory.rs index 9e43ac45..411199f4 100644 --- a/src/service/rooms/directory.rs +++ b/src/service/rooms/directory.rs @@ -1,32 +1,4 @@ mod data; pub(crate) use data::Data; -use ruma::{OwnedRoomId, RoomId}; - -use crate::Result; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - #[tracing::instrument(skip(self))] - pub(crate) fn set_public(&self, room_id: &RoomId) -> Result<()> { - self.db.set_public(room_id) - } - - #[tracing::instrument(skip(self))] - pub(crate) fn set_not_public(&self, room_id: &RoomId) -> Result<()> { - self.db.set_not_public(room_id) - } - - #[tracing::instrument(skip(self))] - pub(crate) fn is_public_room(&self, room_id: &RoomId) -> Result { - self.db.is_public_room(room_id) - } - - #[tracing::instrument(skip(self))] - pub(crate) fn public_rooms(&self) -> impl Iterator> + '_ { - self.db.public_rooms() - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/rooms/edus/read_receipt.rs b/src/service/rooms/edus/read_receipt.rs index 54628203..411199f4 100644 --- a/src/service/rooms/edus/read_receipt.rs +++ b/src/service/rooms/edus/read_receipt.rs @@ -1,68 +1,4 @@ mod data; pub(crate) use data::Data; - -use crate::Result; -use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - /// Replaces the previous read receipt. - pub(crate) fn readreceipt_update( - &self, - user_id: &UserId, - room_id: &RoomId, - event: ReceiptEvent, - ) -> Result<()> { - self.db.readreceipt_update(user_id, room_id, event) - } - - /// Returns an iterator over the most recent read_receipts in a room that happened after the event with id `since`. - #[tracing::instrument(skip(self))] - pub(crate) fn readreceipts_since<'a>( - &'a self, - room_id: &RoomId, - since: u64, - ) -> impl Iterator< - Item = Result<( - OwnedUserId, - u64, - Raw, - )>, - > + 'a { - self.db.readreceipts_since(room_id, since) - } - - /// Sets a private read marker at `count`. - #[tracing::instrument(skip(self))] - pub(crate) fn private_read_set( - &self, - room_id: &RoomId, - user_id: &UserId, - count: u64, - ) -> Result<()> { - self.db.private_read_set(room_id, user_id, count) - } - - /// Returns the private read marker. - #[tracing::instrument(skip(self))] - pub(crate) fn private_read_get( - &self, - room_id: &RoomId, - user_id: &UserId, - ) -> Result> { - self.db.private_read_get(room_id, user_id) - } - - /// Returns the count of the last typing update in this room. - pub(crate) fn last_privateread_update( - &self, - user_id: &UserId, - room_id: &RoomId, - ) -> Result { - self.db.last_privateread_update(user_id, room_id) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/rooms/metadata.rs b/src/service/rooms/metadata.rs index 5205a94a..411199f4 100644 --- a/src/service/rooms/metadata.rs +++ b/src/service/rooms/metadata.rs @@ -1,30 +1,4 @@ mod data; pub(crate) use data::Data; -use ruma::{OwnedRoomId, RoomId}; - -use crate::Result; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - /// Checks if a room exists. - #[tracing::instrument(skip(self))] - pub(crate) fn exists(&self, room_id: &RoomId) -> Result { - self.db.exists(room_id) - } - - pub(crate) fn iter_ids<'a>(&'a self) -> Box> + 'a> { - self.db.iter_ids() - } - - pub(crate) fn is_disabled(&self, room_id: &RoomId) -> Result { - self.db.is_disabled(room_id) - } - - pub(crate) fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()> { - self.db.disable_room(room_id, disabled) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/rooms/metadata/data.rs b/src/service/rooms/metadata/data.rs index 9b49fdeb..48317458 100644 --- a/src/service/rooms/metadata/data.rs +++ b/src/service/rooms/metadata/data.rs @@ -2,6 +2,7 @@ use crate::Result; use ruma::{OwnedRoomId, RoomId}; pub(crate) trait Data: Send + Sync { + /// Checks if a room exists. fn exists(&self, room_id: &RoomId) -> Result; fn iter_ids<'a>(&'a self) -> Box> + 'a>; fn is_disabled(&self, room_id: &RoomId) -> Result; diff --git a/src/service/rooms/outlier.rs b/src/service/rooms/outlier.rs index c0e9dc28..411199f4 100644 --- a/src/service/rooms/outlier.rs +++ b/src/service/rooms/outlier.rs @@ -1,30 +1,4 @@ mod data; pub(crate) use data::Data; -use ruma::{CanonicalJsonObject, EventId}; - -use crate::Result; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - /// Returns the pdu from the outlier tree. - pub(crate) fn get_outlier_pdu_json( - &self, - event_id: &EventId, - ) -> Result> { - self.db.get_outlier_pdu_json(event_id) - } - - /// Append the PDU as an outlier. - #[tracing::instrument(skip(self, pdu))] - pub(crate) fn add_pdu_outlier( - &self, - event_id: &EventId, - pdu: &CanonicalJsonObject, - ) -> Result<()> { - self.db.add_pdu_outlier(event_id, pdu) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/rooms/outlier/data.rs b/src/service/rooms/outlier/data.rs index 34505640..8956b491 100644 --- a/src/service/rooms/outlier/data.rs +++ b/src/service/rooms/outlier/data.rs @@ -3,7 +3,9 @@ use ruma::{CanonicalJsonObject, EventId}; use crate::{PduEvent, Result}; pub(crate) trait Data: Send + Sync { + /// Returns the pdu from the outlier tree. fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result>; fn get_outlier_pdu(&self, event_id: &EventId) -> Result>; + /// Append the PDU as an outlier. fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()>; } diff --git a/src/service/rooms/search.rs b/src/service/rooms/search.rs index 8f2ae8aa..411199f4 100644 --- a/src/service/rooms/search.rs +++ b/src/service/rooms/search.rs @@ -1,31 +1,4 @@ mod data; pub(crate) use data::Data; - -use crate::Result; -use ruma::RoomId; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - #[tracing::instrument(skip(self))] - pub(crate) fn index_pdu( - &self, - shortroomid: u64, - pdu_id: &[u8], - message_body: &str, - ) -> Result<()> { - self.db.index_pdu(shortroomid, pdu_id, message_body) - } - - #[tracing::instrument(skip(self))] - pub(crate) fn search_pdus<'a>( - &'a self, - room_id: &RoomId, - search_string: &str, - ) -> Result> + 'a, Vec)>> { - self.db.search_pdus(room_id, search_string) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/rooms/short.rs b/src/service/rooms/short.rs index f8d5be16..411199f4 100644 --- a/src/service/rooms/short.rs +++ b/src/service/rooms/short.rs @@ -1,57 +1,4 @@ mod data; -use std::sync::Arc; pub(crate) use data::Data; -use ruma::{events::StateEventType, EventId, RoomId}; - -use crate::Result; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - pub(crate) fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result { - self.db.get_or_create_shorteventid(event_id) - } - - pub(crate) fn get_shortstatekey( - &self, - event_type: &StateEventType, - state_key: &str, - ) -> Result> { - self.db.get_shortstatekey(event_type, state_key) - } - - pub(crate) fn get_or_create_shortstatekey( - &self, - event_type: &StateEventType, - state_key: &str, - ) -> Result { - self.db.get_or_create_shortstatekey(event_type, state_key) - } - - pub(crate) fn get_eventid_from_short(&self, shorteventid: u64) -> Result> { - self.db.get_eventid_from_short(shorteventid) - } - - pub(crate) fn get_statekey_from_short( - &self, - shortstatekey: u64, - ) -> 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<(u64, bool)> { - self.db.get_or_create_shortstatehash(state_hash) - } - - pub(crate) fn get_shortroomid(&self, room_id: &RoomId) -> Result> { - self.db.get_shortroomid(room_id) - } - - pub(crate) fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result { - self.db.get_or_create_shortroomid(room_id) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/rooms/user.rs b/src/service/rooms/user.rs index f50754f8..411199f4 100644 --- a/src/service/rooms/user.rs +++ b/src/service/rooms/user.rs @@ -1,57 +1,4 @@ mod data; pub(crate) use data::Data; -use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; - -use crate::Result; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - pub(crate) fn reset_notification_counts( - &self, - user_id: &UserId, - room_id: &RoomId, - ) -> Result<()> { - self.db.reset_notification_counts(user_id, room_id) - } - - pub(crate) fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { - self.db.notification_count(user_id, room_id) - } - - pub(crate) fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { - self.db.highlight_count(user_id, room_id) - } - - pub(crate) fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result { - self.db.last_notification_read(user_id, room_id) - } - - pub(crate) fn associate_token_shortstatehash( - &self, - room_id: &RoomId, - token: u64, - shortstatehash: u64, - ) -> Result<()> { - self.db - .associate_token_shortstatehash(room_id, token, shortstatehash) - } - - pub(crate) fn get_token_shortstatehash( - &self, - room_id: &RoomId, - token: u64, - ) -> Result> { - self.db.get_token_shortstatehash(room_id, token) - } - - pub(crate) fn get_shared_rooms( - &self, - users: Vec, - ) -> Result>> { - self.db.get_shared_rooms(users) - } -} +pub(crate) type Service = &'static dyn Data; diff --git a/src/service/transaction_ids.rs b/src/service/transaction_ids.rs index b28919c5..411199f4 100644 --- a/src/service/transaction_ids.rs +++ b/src/service/transaction_ids.rs @@ -1,31 +1,4 @@ mod data; pub(crate) use data::Data; - -use crate::Result; -use ruma::{DeviceId, TransactionId, UserId}; - -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, -} - -impl Service { - pub(crate) fn add_txnid( - &self, - user_id: &UserId, - device_id: Option<&DeviceId>, - txn_id: &TransactionId, - data: &[u8], - ) -> Result<()> { - self.db.add_txnid(user_id, device_id, txn_id, data) - } - - pub(crate) fn existing_txnid( - &self, - user_id: &UserId, - device_id: Option<&DeviceId>, - txn_id: &TransactionId, - ) -> Result>> { - self.db.existing_txnid(user_id, device_id, txn_id) - } -} +pub(crate) type Service = &'static dyn Data;