mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
Remove useless wrapper Services
This commit is contained in:
parent
87a1012ab5
commit
ad7a5ea777
20 changed files with 43 additions and 530 deletions
|
|
@ -3,6 +3,7 @@ use ruma::{api::client::error::ErrorKind, OwnedRoomAliasId, OwnedRoomId, RoomAli
|
||||||
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
|
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
|
||||||
|
|
||||||
impl service::rooms::alias::Data for KeyValueDatabase {
|
impl service::rooms::alias::Data for KeyValueDatabase {
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> {
|
fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> {
|
||||||
self.alias_roomid
|
self.alias_roomid
|
||||||
.insert(alias.alias().as_bytes(), room_id.as_bytes())?;
|
.insert(alias.alias().as_bytes(), room_id.as_bytes())?;
|
||||||
|
|
@ -13,6 +14,7 @@ impl service::rooms::alias::Data for KeyValueDatabase {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> {
|
fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> {
|
||||||
if let Some(room_id) = self.alias_roomid.get(alias.alias().as_bytes())? {
|
if let Some(room_id) = self.alias_roomid.get(alias.alias().as_bytes())? {
|
||||||
let mut prefix = room_id.clone();
|
let mut prefix = room_id.clone();
|
||||||
|
|
@ -31,6 +33,7 @@ impl service::rooms::alias::Data for KeyValueDatabase {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<OwnedRoomId>> {
|
fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<OwnedRoomId>> {
|
||||||
self.alias_roomid
|
self.alias_roomid
|
||||||
.get(alias.alias().as_bytes())?
|
.get(alias.alias().as_bytes())?
|
||||||
|
|
@ -43,6 +46,7 @@ impl service::rooms::alias::Data for KeyValueDatabase {
|
||||||
.transpose()
|
.transpose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn local_aliases_for_room<'a>(
|
fn local_aliases_for_room<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,22 @@ use ruma::{OwnedRoomId, RoomId};
|
||||||
use crate::{database::KeyValueDatabase, service, utils, Error, Result};
|
use crate::{database::KeyValueDatabase, service, utils, Error, Result};
|
||||||
|
|
||||||
impl service::rooms::directory::Data for KeyValueDatabase {
|
impl service::rooms::directory::Data for KeyValueDatabase {
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn set_public(&self, room_id: &RoomId) -> Result<()> {
|
fn set_public(&self, room_id: &RoomId) -> Result<()> {
|
||||||
self.publicroomids.insert(room_id.as_bytes(), &[])
|
self.publicroomids.insert(room_id.as_bytes(), &[])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn set_not_public(&self, room_id: &RoomId) -> Result<()> {
|
fn set_not_public(&self, room_id: &RoomId) -> Result<()> {
|
||||||
self.publicroomids.remove(room_id.as_bytes())
|
self.publicroomids.remove(room_id.as_bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn is_public_room(&self, room_id: &RoomId) -> Result<bool> {
|
fn is_public_room(&self, room_id: &RoomId) -> Result<bool> {
|
||||||
Ok(self.publicroomids.get(room_id.as_bytes())?.is_some())
|
Ok(self.publicroomids.get(room_id.as_bytes())?.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn public_rooms<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
|
fn public_rooms<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
|
||||||
Box::new(self.publicroomids.iter().map(|(bytes, _)| {
|
Box::new(self.publicroomids.iter().map(|(bytes, _)| {
|
||||||
RoomId::parse(
|
RoomId::parse(
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ impl service::rooms::edus::read_receipt::Data for KeyValueDatabase {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
fn readreceipts_since<'a>(
|
fn readreceipts_since<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
room_id: &RoomId,
|
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<()> {
|
fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> {
|
||||||
let mut key = room_id.as_bytes().to_vec();
|
let mut key = room_id.as_bytes().to_vec();
|
||||||
key.push(0xff);
|
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())
|
.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<Option<u64>> {
|
fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
|
||||||
let mut key = room_id.as_bytes().to_vec();
|
let mut key = room_id.as_bytes().to_vec();
|
||||||
key.push(0xff);
|
key.push(0xff);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use ruma::{OwnedRoomId, RoomId};
|
||||||
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
|
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
|
||||||
|
|
||||||
impl service::rooms::metadata::Data for KeyValueDatabase {
|
impl service::rooms::metadata::Data for KeyValueDatabase {
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn exists(&self, room_id: &RoomId) -> Result<bool> {
|
fn exists(&self, room_id: &RoomId) -> Result<bool> {
|
||||||
let prefix = match services().rooms.short.get_shortroomid(room_id)? {
|
let prefix = match services().rooms.short.get_shortroomid(room_id)? {
|
||||||
Some(b) => b.to_be_bytes().to_vec(),
|
Some(b) => b.to_be_bytes().to_vec(),
|
||||||
|
|
|
||||||
|
|
@ -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<()> {
|
fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> {
|
||||||
self.eventid_outlierpdu.insert(
|
self.eventid_outlierpdu.insert(
|
||||||
event_id.as_bytes(),
|
event_id.as_bytes(),
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use ruma::RoomId;
|
||||||
use crate::{database::KeyValueDatabase, service, services, utils, Result};
|
use crate::{database::KeyValueDatabase, service, services, utils, Result};
|
||||||
|
|
||||||
impl service::rooms::search::Data for KeyValueDatabase {
|
impl service::rooms::search::Data for KeyValueDatabase {
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> {
|
fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> {
|
||||||
let mut batch = message_body
|
let mut batch = message_body
|
||||||
.split_terminator(|c: char| !c.is_alphanumeric())
|
.split_terminator(|c: char| !c.is_alphanumeric())
|
||||||
|
|
@ -20,6 +21,8 @@ impl service::rooms::search::Data for KeyValueDatabase {
|
||||||
self.tokenids.insert_batch(&mut batch)
|
self.tokenids.insert_batch(&mut batch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
fn search_pdus<'a>(
|
fn search_pdus<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
|
|
||||||
|
|
@ -60,11 +60,11 @@ impl Services {
|
||||||
appservice: appservice::Service::build(db)?,
|
appservice: appservice::Service::build(db)?,
|
||||||
pusher: pusher::Service { db },
|
pusher: pusher::Service { db },
|
||||||
rooms: rooms::Service {
|
rooms: rooms::Service {
|
||||||
alias: rooms::alias::Service { db },
|
alias: db,
|
||||||
auth_chain: rooms::auth_chain::Service { db },
|
auth_chain: rooms::auth_chain::Service { db },
|
||||||
directory: rooms::directory::Service { db },
|
directory: db,
|
||||||
edus: rooms::edus::Service {
|
edus: rooms::edus::Service {
|
||||||
read_receipt: rooms::edus::read_receipt::Service { db },
|
read_receipt: db,
|
||||||
typing: rooms::edus::typing::Service {
|
typing: rooms::edus::typing::Service {
|
||||||
typing: RwLock::new(BTreeMap::new()),
|
typing: RwLock::new(BTreeMap::new()),
|
||||||
last_typing_update: RwLock::new(BTreeMap::new()),
|
last_typing_update: RwLock::new(BTreeMap::new()),
|
||||||
|
|
@ -76,11 +76,11 @@ impl Services {
|
||||||
db,
|
db,
|
||||||
lazy_load_waiting: Mutex::new(HashMap::new()),
|
lazy_load_waiting: Mutex::new(HashMap::new()),
|
||||||
},
|
},
|
||||||
metadata: rooms::metadata::Service { db },
|
metadata: db,
|
||||||
outlier: rooms::outlier::Service { db },
|
outlier: db,
|
||||||
pdu_metadata: rooms::pdu_metadata::Service { db },
|
pdu_metadata: rooms::pdu_metadata::Service { db },
|
||||||
search: rooms::search::Service { db },
|
search: db,
|
||||||
short: rooms::short::Service { db },
|
short: db,
|
||||||
state: rooms::state::Service { db },
|
state: rooms::state::Service { db },
|
||||||
state_accessor: rooms::state_accessor::Service {
|
state_accessor: rooms::state_accessor::Service {
|
||||||
db,
|
db,
|
||||||
|
|
@ -121,17 +121,17 @@ impl Services {
|
||||||
spaces: rooms::spaces::Service {
|
spaces: rooms::spaces::Service {
|
||||||
roomid_spacechunk_cache: Mutex::new(LruCache::new(200)),
|
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 },
|
uiaa: uiaa::Service { db },
|
||||||
users: users::Service {
|
users: users::Service {
|
||||||
db,
|
db,
|
||||||
connections: StdMutex::new(BTreeMap::new()),
|
connections: StdMutex::new(BTreeMap::new()),
|
||||||
},
|
},
|
||||||
account_data: account_data::Service { db },
|
account_data: db,
|
||||||
admin: admin::Service::build(),
|
admin: admin::Service::build(),
|
||||||
key_backups: key_backups::Service { db },
|
key_backups: db,
|
||||||
media: media::Service { db },
|
media: media::Service { db },
|
||||||
sending: sending::Service::build(db, &config),
|
sending: sending::Service::build(db, &config),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,53 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
|
pub(crate) type Service = &'static dyn 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<Option<Box<serde_json::value::RawValue>>> {
|
|
||||||
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<HashMap<RoomAccountDataEventType, Raw<AnyEphemeralRoomEvent>>> {
|
|
||||||
self.db.changes_since(room_id, user_id, since)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,127 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
|
pub(crate) type Service = &'static dyn 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<BackupAlgorithm>,
|
|
||||||
) -> Result<String> {
|
|
||||||
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<BackupAlgorithm>,
|
|
||||||
) -> Result<String> {
|
|
||||||
self.db.update_backup(user_id, version, backup_metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_latest_backup_version(&self, user_id: &UserId) -> Result<Option<String>> {
|
|
||||||
self.db.get_latest_backup_version(user_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_latest_backup(
|
|
||||||
&self,
|
|
||||||
user_id: &UserId,
|
|
||||||
) -> Result<Option<(String, Raw<BackupAlgorithm>)>> {
|
|
||||||
self.db.get_latest_backup(user_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_backup(
|
|
||||||
&self,
|
|
||||||
user_id: &UserId,
|
|
||||||
version: &str,
|
|
||||||
) -> Result<Option<Raw<BackupAlgorithm>>> {
|
|
||||||
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<KeyBackupData>,
|
|
||||||
) -> 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<usize> {
|
|
||||||
self.db.count_keys(user_id, version)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> {
|
|
||||||
self.db.get_etag(user_id, version)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_all(
|
|
||||||
&self,
|
|
||||||
user_id: &UserId,
|
|
||||||
version: &str,
|
|
||||||
) -> Result<BTreeMap<OwnedRoomId, RoomKeyBackup>> {
|
|
||||||
self.db.get_all(user_id, version)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_room(
|
|
||||||
&self,
|
|
||||||
user_id: &UserId,
|
|
||||||
version: &str,
|
|
||||||
room_id: &RoomId,
|
|
||||||
) -> Result<BTreeMap<String, Raw<KeyBackupData>>> {
|
|
||||||
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<Option<Raw<KeyBackupData>>> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
|
pub(crate) type Service = &'static dyn 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<Option<OwnedRoomId>> {
|
|
||||||
self.db.resolve_local_alias(alias)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
|
||||||
pub(crate) fn local_aliases_for_room<'a>(
|
|
||||||
&'a self,
|
|
||||||
room_id: &RoomId,
|
|
||||||
) -> Box<dyn Iterator<Item = Result<OwnedRoomAliasId>> + 'a> {
|
|
||||||
self.db.local_aliases_for_room(room_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
use ruma::{OwnedRoomId, RoomId};
|
pub(crate) type Service = &'static dyn Data;
|
||||||
|
|
||||||
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<bool> {
|
|
||||||
self.db.is_public_room(room_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
|
||||||
pub(crate) fn public_rooms(&self) -> impl Iterator<Item = Result<OwnedRoomId>> + '_ {
|
|
||||||
self.db.public_rooms()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,68 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
|
pub(crate) type Service = &'static dyn 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<ruma::events::AnySyncEphemeralRoomEvent>,
|
|
||||||
)>,
|
|
||||||
> + '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<Option<u64>> {
|
|
||||||
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<u64> {
|
|
||||||
self.db.last_privateread_update(user_id, room_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
use ruma::{OwnedRoomId, RoomId};
|
pub(crate) type Service = &'static dyn Data;
|
||||||
|
|
||||||
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<bool> {
|
|
||||||
self.db.exists(room_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
|
|
||||||
self.db.iter_ids()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn is_disabled(&self, room_id: &RoomId) -> Result<bool> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use crate::Result;
|
||||||
use ruma::{OwnedRoomId, RoomId};
|
use ruma::{OwnedRoomId, RoomId};
|
||||||
|
|
||||||
pub(crate) trait Data: Send + Sync {
|
pub(crate) trait Data: Send + Sync {
|
||||||
|
/// Checks if a room exists.
|
||||||
fn exists(&self, room_id: &RoomId) -> Result<bool>;
|
fn exists(&self, room_id: &RoomId) -> Result<bool>;
|
||||||
fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a>;
|
fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a>;
|
||||||
fn is_disabled(&self, room_id: &RoomId) -> Result<bool>;
|
fn is_disabled(&self, room_id: &RoomId) -> Result<bool>;
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
use ruma::{CanonicalJsonObject, EventId};
|
pub(crate) type Service = &'static dyn Data;
|
||||||
|
|
||||||
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<Option<CanonicalJsonObject>> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ use ruma::{CanonicalJsonObject, EventId};
|
||||||
use crate::{PduEvent, Result};
|
use crate::{PduEvent, Result};
|
||||||
|
|
||||||
pub(crate) trait Data: Send + Sync {
|
pub(crate) trait Data: Send + Sync {
|
||||||
|
/// Returns the pdu from the outlier tree.
|
||||||
fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>>;
|
fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>>;
|
||||||
fn get_outlier_pdu(&self, event_id: &EventId) -> Result<Option<PduEvent>>;
|
fn get_outlier_pdu(&self, event_id: &EventId) -> Result<Option<PduEvent>>;
|
||||||
|
/// Append the PDU as an outlier.
|
||||||
fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()>;
|
fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
|
pub(crate) type Service = &'static dyn 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<Option<(impl Iterator<Item = Vec<u8>> + 'a, Vec<String>)>> {
|
|
||||||
self.db.search_pdus(room_id, search_string)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,57 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
use ruma::{events::StateEventType, EventId, RoomId};
|
pub(crate) type Service = &'static dyn Data;
|
||||||
|
|
||||||
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<u64> {
|
|
||||||
self.db.get_or_create_shorteventid(event_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_shortstatekey(
|
|
||||||
&self,
|
|
||||||
event_type: &StateEventType,
|
|
||||||
state_key: &str,
|
|
||||||
) -> Result<Option<u64>> {
|
|
||||||
self.db.get_shortstatekey(event_type, state_key)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_or_create_shortstatekey(
|
|
||||||
&self,
|
|
||||||
event_type: &StateEventType,
|
|
||||||
state_key: &str,
|
|
||||||
) -> Result<u64> {
|
|
||||||
self.db.get_or_create_shortstatekey(event_type, state_key)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_eventid_from_short(&self, shorteventid: u64) -> Result<Arc<EventId>> {
|
|
||||||
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<Option<u64>> {
|
|
||||||
self.db.get_shortroomid(room_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result<u64> {
|
|
||||||
self.db.get_or_create_shortroomid(room_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,57 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId};
|
pub(crate) type Service = &'static dyn Data;
|
||||||
|
|
||||||
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<u64> {
|
|
||||||
self.db.notification_count(user_id, room_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
|
|
||||||
self.db.highlight_count(user_id, room_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
|
|
||||||
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<Option<u64>> {
|
|
||||||
self.db.get_token_shortstatehash(room_id, token)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_shared_rooms(
|
|
||||||
&self,
|
|
||||||
users: Vec<OwnedUserId>,
|
|
||||||
) -> Result<impl Iterator<Item = Result<OwnedRoomId>>> {
|
|
||||||
self.db.get_shared_rooms(users)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,4 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
pub(crate) use data::Data;
|
pub(crate) use data::Data;
|
||||||
|
pub(crate) type Service = &'static dyn 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<Option<Vec<u8>>> {
|
|
||||||
self.db.existing_txnid(user_id, device_id, txn_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue