enable unreachable_pub lint

This causes some other lints to start firing too (which is good), but
I'm going to fix them in follow-up commits to keep things organized.
This commit is contained in:
Charles Hall 2024-05-01 22:26:21 -07:00
parent a626e7b0f0
commit d748544f0e
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
111 changed files with 1007 additions and 876 deletions

View file

@ -6,12 +6,16 @@ macro_use_extern_crate = "warn"
missing_abi = "warn" missing_abi = "warn"
noop_method_call = "warn" noop_method_call = "warn"
pointer_structural_match = "warn" pointer_structural_match = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn" unsafe_op_in_unsafe_fn = "warn"
unused_extern_crates = "warn" unused_extern_crates = "warn"
unused_import_braces = "warn" unused_import_braces = "warn"
unused_macro_rules = "warn" unused_macro_rules = "warn"
unused_qualifications = "warn" unused_qualifications = "warn"
# TODO: Remove these
dead_code = "allow"
# Keep alphabetically sorted # Keep alphabetically sorted
[workspace.lints.clippy] [workspace.lints.clippy]
assertions_on_result_states = "warn" assertions_on_result_states = "warn"
@ -47,6 +51,9 @@ unseparated_literal_suffix = "warn"
verbose_file_reads = "warn" verbose_file_reads = "warn"
wildcard_dependencies = "warn" wildcard_dependencies = "warn"
# TODO: Remove these
enum_variant_names = "allow"
[package] [package]
name = "grapevine" name = "grapevine"
description = "A Matrix homeserver written in Rust" description = "A Matrix homeserver written in Rust"

View file

@ -1,4 +1,4 @@
pub mod appservice_server; pub(crate) mod appservice_server;
pub mod client_server; pub(crate) mod client_server;
pub mod ruma_wrapper; pub(crate) mod ruma_wrapper;
pub mod server_server; pub(crate) mod server_server;

View file

@ -32,41 +32,41 @@ mod unversioned;
mod user_directory; mod user_directory;
mod voip; mod voip;
pub use account::*; pub(crate) use account::*;
pub use alias::*; pub(crate) use alias::*;
pub use backup::*; pub(crate) use backup::*;
pub use capabilities::*; pub(crate) use capabilities::*;
pub use config::*; pub(crate) use config::*;
pub use context::*; pub(crate) use context::*;
pub use device::*; pub(crate) use device::*;
pub use directory::*; pub(crate) use directory::*;
pub use filter::*; pub(crate) use filter::*;
pub use keys::*; pub(crate) use keys::*;
pub use media::*; pub(crate) use media::*;
pub use membership::*; pub(crate) use membership::*;
pub use message::*; pub(crate) use message::*;
pub use profile::*; pub(crate) use profile::*;
pub use push::*; pub(crate) use push::*;
pub use read_marker::*; pub(crate) use read_marker::*;
pub use redact::*; pub(crate) use redact::*;
pub use relations::*; pub(crate) use relations::*;
pub use report::*; pub(crate) use report::*;
pub use room::*; pub(crate) use room::*;
pub use search::*; pub(crate) use search::*;
pub use session::*; pub(crate) use session::*;
pub use space::*; pub(crate) use space::*;
pub use state::*; pub(crate) use state::*;
pub use sync::*; pub(crate) use sync::*;
pub use tag::*; pub(crate) use tag::*;
pub use thirdparty::*; pub(crate) use thirdparty::*;
pub use threads::*; pub(crate) use threads::*;
pub use to_device::*; pub(crate) use to_device::*;
pub use typing::*; pub(crate) use typing::*;
pub use unversioned::*; pub(crate) use unversioned::*;
pub use user_directory::*; pub(crate) use user_directory::*;
pub use voip::*; pub(crate) use voip::*;
pub const DEVICE_ID_LENGTH: usize = 10; pub(crate) const DEVICE_ID_LENGTH: usize = 10;
pub const TOKEN_LENGTH: usize = 32; pub(crate) const TOKEN_LENGTH: usize = 32;
pub const SESSION_ID_LENGTH: usize = 32; pub(crate) const SESSION_ID_LENGTH: usize = 32;
pub const AUTO_GEN_PASSWORD_LENGTH: usize = 15; pub(crate) const AUTO_GEN_PASSWORD_LENGTH: usize = 15;

View file

@ -30,7 +30,7 @@ const RANDOM_USER_ID_LENGTH: usize = 10;
/// - No user or appservice on this server already claimed this username /// - No user or appservice on this server already claimed this username
/// ///
/// Note: This will not reserve the username, so the username might become invalid when trying to register /// Note: This will not reserve the username, so the username might become invalid when trying to register
pub async fn get_register_available_route( pub(crate) async fn get_register_available_route(
body: Ruma<get_username_availability::v3::Request>, body: Ruma<get_username_availability::v3::Request>,
) -> Result<get_username_availability::v3::Response> { ) -> Result<get_username_availability::v3::Response> {
// Validate user id // Validate user id
@ -74,7 +74,9 @@ pub async fn get_register_available_route(
/// - If type is not guest and no username is given: Always fails after UIAA check /// - If type is not guest and no username is given: Always fails after UIAA check
/// - Creates a new account and populates it with default account data /// - Creates a new account and populates it with default account data
/// - If `inhibit_login` is false: Creates a device and returns device id and access_token /// - If `inhibit_login` is false: Creates a device and returns device id and access_token
pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<register::v3::Response> { pub(crate) async fn register_route(
body: Ruma<register::v3::Request>,
) -> Result<register::v3::Response> {
if !services().globals.allow_registration() && body.appservice_info.is_none() { if !services().globals.allow_registration() && body.appservice_info.is_none() {
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::Forbidden, ErrorKind::Forbidden,
@ -307,7 +309,7 @@ pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<registe
/// - Deletes device metadata (device id, device display name, last seen ip, last seen ts) /// - Deletes device metadata (device id, device display name, last seen ip, last seen ts)
/// - Forgets to-device events /// - Forgets to-device events
/// - Triggers device list updates /// - Triggers device list updates
pub async fn change_password_route( pub(crate) async fn change_password_route(
body: Ruma<change_password::v3::Request>, body: Ruma<change_password::v3::Request>,
) -> Result<change_password::v3::Response> { ) -> Result<change_password::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -373,7 +375,7 @@ pub async fn change_password_route(
/// Get user_id of the sender user. /// Get user_id of the sender user.
/// ///
/// Note: Also works for Application Services /// Note: Also works for Application Services
pub async fn whoami_route(body: Ruma<whoami::v3::Request>) -> Result<whoami::v3::Response> { pub(crate) async fn whoami_route(body: Ruma<whoami::v3::Request>) -> Result<whoami::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let device_id = body.sender_device.as_ref().cloned(); let device_id = body.sender_device.as_ref().cloned();
@ -394,7 +396,7 @@ pub async fn whoami_route(body: Ruma<whoami::v3::Request>) -> Result<whoami::v3:
/// - Forgets all to-device events /// - Forgets all to-device events
/// - Triggers device list updates /// - Triggers device list updates
/// - Removes ability to log in again /// - Removes ability to log in again
pub async fn deactivate_route( pub(crate) async fn deactivate_route(
body: Ruma<deactivate::v3::Request>, body: Ruma<deactivate::v3::Request>,
) -> Result<deactivate::v3::Response> { ) -> Result<deactivate::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -452,7 +454,7 @@ pub async fn deactivate_route(
/// Get a list of third party identifiers associated with this account. /// Get a list of third party identifiers associated with this account.
/// ///
/// - Currently always returns empty list /// - Currently always returns empty list
pub async fn third_party_route( pub(crate) async fn third_party_route(
body: Ruma<get_3pids::v3::Request>, body: Ruma<get_3pids::v3::Request>,
) -> Result<get_3pids::v3::Response> { ) -> Result<get_3pids::v3::Response> {
let _sender_user = body.sender_user.as_ref().expect("user is authenticated"); let _sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -465,7 +467,7 @@ pub async fn third_party_route(
/// "This API should be used to request validation tokens when adding an email address to an account" /// "This API should be used to request validation tokens when adding an email address to an account"
/// ///
/// - 403 signals that The homeserver does not allow the third party identifier as a contact option. /// - 403 signals that The homeserver does not allow the third party identifier as a contact option.
pub async fn request_3pid_management_token_via_email_route( pub(crate) async fn request_3pid_management_token_via_email_route(
_body: Ruma<request_3pid_management_token_via_email::v3::Request>, _body: Ruma<request_3pid_management_token_via_email::v3::Request>,
) -> Result<request_3pid_management_token_via_email::v3::Response> { ) -> Result<request_3pid_management_token_via_email::v3::Response> {
Err(Error::BadRequest( Err(Error::BadRequest(
@ -479,7 +481,7 @@ pub async fn request_3pid_management_token_via_email_route(
/// "This API should be used to request validation tokens when adding an phone number to an account" /// "This API should be used to request validation tokens when adding an phone number to an account"
/// ///
/// - 403 signals that The homeserver does not allow the third party identifier as a contact option. /// - 403 signals that The homeserver does not allow the third party identifier as a contact option.
pub async fn request_3pid_management_token_via_msisdn_route( pub(crate) async fn request_3pid_management_token_via_msisdn_route(
_body: Ruma<request_3pid_management_token_via_msisdn::v3::Request>, _body: Ruma<request_3pid_management_token_via_msisdn::v3::Request>,
) -> Result<request_3pid_management_token_via_msisdn::v3::Response> { ) -> Result<request_3pid_management_token_via_msisdn::v3::Response> {
Err(Error::BadRequest( Err(Error::BadRequest(

View file

@ -15,7 +15,7 @@ use ruma::{
/// # `PUT /_matrix/client/r0/directory/room/{roomAlias}` /// # `PUT /_matrix/client/r0/directory/room/{roomAlias}`
/// ///
/// Creates a new room alias on this server. /// Creates a new room alias on this server.
pub async fn create_alias_route( pub(crate) async fn create_alias_route(
body: Ruma<create_alias::v3::Request>, body: Ruma<create_alias::v3::Request>,
) -> Result<create_alias::v3::Response> { ) -> Result<create_alias::v3::Response> {
if body.room_alias.server_name() != services().globals.server_name() { if body.room_alias.server_name() != services().globals.server_name() {
@ -66,7 +66,7 @@ pub async fn create_alias_route(
/// ///
/// - TODO: additional access control checks /// - TODO: additional access control checks
/// - TODO: Update canonical alias event /// - TODO: Update canonical alias event
pub async fn delete_alias_route( pub(crate) async fn delete_alias_route(
body: Ruma<delete_alias::v3::Request>, body: Ruma<delete_alias::v3::Request>,
) -> Result<delete_alias::v3::Response> { ) -> Result<delete_alias::v3::Response> {
if body.room_alias.server_name() != services().globals.server_name() { if body.room_alias.server_name() != services().globals.server_name() {
@ -106,7 +106,7 @@ pub async fn delete_alias_route(
/// Resolve an alias locally or over federation. /// Resolve an alias locally or over federation.
/// ///
/// - TODO: Suggest more servers to join via /// - TODO: Suggest more servers to join via
pub async fn get_alias_route( pub(crate) async fn get_alias_route(
body: Ruma<get_alias::v3::Request>, body: Ruma<get_alias::v3::Request>,
) -> Result<get_alias::v3::Response> { ) -> Result<get_alias::v3::Response> {
get_alias_helper(body.body.room_alias).await get_alias_helper(body.body.room_alias).await

View file

@ -13,7 +13,7 @@ use ruma::api::client::{
/// # `POST /_matrix/client/r0/room_keys/version` /// # `POST /_matrix/client/r0/room_keys/version`
/// ///
/// Creates a new backup. /// Creates a new backup.
pub async fn create_backup_version_route( pub(crate) async fn create_backup_version_route(
body: Ruma<create_backup_version::v3::Request>, body: Ruma<create_backup_version::v3::Request>,
) -> Result<create_backup_version::v3::Response> { ) -> Result<create_backup_version::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -27,7 +27,7 @@ pub async fn create_backup_version_route(
/// # `PUT /_matrix/client/r0/room_keys/version/{version}` /// # `PUT /_matrix/client/r0/room_keys/version/{version}`
/// ///
/// Update information about an existing backup. Only `auth_data` can be modified. /// Update information about an existing backup. Only `auth_data` can be modified.
pub async fn update_backup_version_route( pub(crate) async fn update_backup_version_route(
body: Ruma<update_backup_version::v3::Request>, body: Ruma<update_backup_version::v3::Request>,
) -> Result<update_backup_version::v3::Response> { ) -> Result<update_backup_version::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -41,7 +41,7 @@ pub async fn update_backup_version_route(
/// # `GET /_matrix/client/r0/room_keys/version` /// # `GET /_matrix/client/r0/room_keys/version`
/// ///
/// Get information about the latest backup version. /// Get information about the latest backup version.
pub async fn get_latest_backup_info_route( pub(crate) async fn get_latest_backup_info_route(
body: Ruma<get_latest_backup_info::v3::Request>, body: Ruma<get_latest_backup_info::v3::Request>,
) -> Result<get_latest_backup_info::v3::Response> { ) -> Result<get_latest_backup_info::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -65,7 +65,7 @@ pub async fn get_latest_backup_info_route(
/// # `GET /_matrix/client/r0/room_keys/version` /// # `GET /_matrix/client/r0/room_keys/version`
/// ///
/// Get information about an existing backup. /// Get information about an existing backup.
pub async fn get_backup_info_route( pub(crate) async fn get_backup_info_route(
body: Ruma<get_backup_info::v3::Request>, body: Ruma<get_backup_info::v3::Request>,
) -> Result<get_backup_info::v3::Response> { ) -> Result<get_backup_info::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -95,7 +95,7 @@ pub async fn get_backup_info_route(
/// Delete an existing key backup. /// Delete an existing key backup.
/// ///
/// - Deletes both information about the backup, as well as all key data related to the backup /// - Deletes both information about the backup, as well as all key data related to the backup
pub async fn delete_backup_version_route( pub(crate) async fn delete_backup_version_route(
body: Ruma<delete_backup_version::v3::Request>, body: Ruma<delete_backup_version::v3::Request>,
) -> Result<delete_backup_version::v3::Response> { ) -> Result<delete_backup_version::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -114,7 +114,7 @@ pub async fn delete_backup_version_route(
/// - Only manipulating the most recently created version of the backup is allowed /// - Only manipulating the most recently created version of the backup is allowed
/// - Adds the keys to the backup /// - Adds the keys to the backup
/// - Returns the new number of keys in this backup and the etag /// - Returns the new number of keys in this backup and the etag
pub async fn add_backup_keys_route( pub(crate) async fn add_backup_keys_route(
body: Ruma<add_backup_keys::v3::Request>, body: Ruma<add_backup_keys::v3::Request>,
) -> Result<add_backup_keys::v3::Response> { ) -> Result<add_backup_keys::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -161,7 +161,7 @@ pub async fn add_backup_keys_route(
/// - Only manipulating the most recently created version of the backup is allowed /// - Only manipulating the most recently created version of the backup is allowed
/// - Adds the keys to the backup /// - Adds the keys to the backup
/// - Returns the new number of keys in this backup and the etag /// - Returns the new number of keys in this backup and the etag
pub async fn add_backup_keys_for_room_route( pub(crate) async fn add_backup_keys_for_room_route(
body: Ruma<add_backup_keys_for_room::v3::Request>, body: Ruma<add_backup_keys_for_room::v3::Request>,
) -> Result<add_backup_keys_for_room::v3::Response> { ) -> Result<add_backup_keys_for_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -206,7 +206,7 @@ pub async fn add_backup_keys_for_room_route(
/// - Only manipulating the most recently created version of the backup is allowed /// - Only manipulating the most recently created version of the backup is allowed
/// - Adds the keys to the backup /// - Adds the keys to the backup
/// - Returns the new number of keys in this backup and the etag /// - Returns the new number of keys in this backup and the etag
pub async fn add_backup_keys_for_session_route( pub(crate) async fn add_backup_keys_for_session_route(
body: Ruma<add_backup_keys_for_session::v3::Request>, body: Ruma<add_backup_keys_for_session::v3::Request>,
) -> Result<add_backup_keys_for_session::v3::Response> { ) -> Result<add_backup_keys_for_session::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -245,7 +245,7 @@ pub async fn add_backup_keys_for_session_route(
/// # `GET /_matrix/client/r0/room_keys/keys` /// # `GET /_matrix/client/r0/room_keys/keys`
/// ///
/// Retrieves all keys from the backup. /// Retrieves all keys from the backup.
pub async fn get_backup_keys_route( pub(crate) async fn get_backup_keys_route(
body: Ruma<get_backup_keys::v3::Request>, body: Ruma<get_backup_keys::v3::Request>,
) -> Result<get_backup_keys::v3::Response> { ) -> Result<get_backup_keys::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -258,7 +258,7 @@ pub async fn get_backup_keys_route(
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}` /// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
/// ///
/// Retrieves all keys from the backup for a given room. /// Retrieves all keys from the backup for a given room.
pub async fn get_backup_keys_for_room_route( pub(crate) async fn get_backup_keys_for_room_route(
body: Ruma<get_backup_keys_for_room::v3::Request>, body: Ruma<get_backup_keys_for_room::v3::Request>,
) -> Result<get_backup_keys_for_room::v3::Response> { ) -> Result<get_backup_keys_for_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -273,7 +273,7 @@ pub async fn get_backup_keys_for_room_route(
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}` /// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
/// ///
/// Retrieves a key from the backup. /// Retrieves a key from the backup.
pub async fn get_backup_keys_for_session_route( pub(crate) async fn get_backup_keys_for_session_route(
body: Ruma<get_backup_keys_for_session::v3::Request>, body: Ruma<get_backup_keys_for_session::v3::Request>,
) -> Result<get_backup_keys_for_session::v3::Response> { ) -> Result<get_backup_keys_for_session::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -292,7 +292,7 @@ pub async fn get_backup_keys_for_session_route(
/// # `DELETE /_matrix/client/r0/room_keys/keys` /// # `DELETE /_matrix/client/r0/room_keys/keys`
/// ///
/// Delete the keys from the backup. /// Delete the keys from the backup.
pub async fn delete_backup_keys_route( pub(crate) async fn delete_backup_keys_route(
body: Ruma<delete_backup_keys::v3::Request>, body: Ruma<delete_backup_keys::v3::Request>,
) -> Result<delete_backup_keys::v3::Response> { ) -> Result<delete_backup_keys::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -315,7 +315,7 @@ pub async fn delete_backup_keys_route(
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}` /// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
/// ///
/// Delete the keys from the backup for a given room. /// Delete the keys from the backup for a given room.
pub async fn delete_backup_keys_for_room_route( pub(crate) async fn delete_backup_keys_for_room_route(
body: Ruma<delete_backup_keys_for_room::v3::Request>, body: Ruma<delete_backup_keys_for_room::v3::Request>,
) -> Result<delete_backup_keys_for_room::v3::Response> { ) -> Result<delete_backup_keys_for_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -338,7 +338,7 @@ pub async fn delete_backup_keys_for_room_route(
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}` /// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
/// ///
/// Delete a key from the backup. /// Delete a key from the backup.
pub async fn delete_backup_keys_for_session_route( pub(crate) async fn delete_backup_keys_for_session_route(
body: Ruma<delete_backup_keys_for_session::v3::Request>, body: Ruma<delete_backup_keys_for_session::v3::Request>,
) -> Result<delete_backup_keys_for_session::v3::Response> { ) -> Result<delete_backup_keys_for_session::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -7,7 +7,7 @@ use std::collections::BTreeMap;
/// # `GET /_matrix/client/r0/capabilities` /// # `GET /_matrix/client/r0/capabilities`
/// ///
/// Get information on the supported feature set and other relevent capabilities of this server. /// Get information on the supported feature set and other relevent capabilities of this server.
pub async fn get_capabilities_route( pub(crate) async fn get_capabilities_route(
_body: Ruma<get_capabilities::v3::Request>, _body: Ruma<get_capabilities::v3::Request>,
) -> Result<get_capabilities::v3::Response> { ) -> Result<get_capabilities::v3::Response> {
let mut available = BTreeMap::new(); let mut available = BTreeMap::new();

View file

@ -16,7 +16,7 @@ use serde_json::{json, value::RawValue as RawJsonValue};
/// # `PUT /_matrix/client/r0/user/{userId}/account_data/{type}` /// # `PUT /_matrix/client/r0/user/{userId}/account_data/{type}`
/// ///
/// Sets some account data for the sender user. /// Sets some account data for the sender user.
pub async fn set_global_account_data_route( pub(crate) async fn set_global_account_data_route(
body: Ruma<set_global_account_data::v3::Request>, body: Ruma<set_global_account_data::v3::Request>,
) -> Result<set_global_account_data::v3::Response> { ) -> Result<set_global_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -42,7 +42,7 @@ pub async fn set_global_account_data_route(
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}` /// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
/// ///
/// Sets some room account data for the sender user. /// Sets some room account data for the sender user.
pub async fn set_room_account_data_route( pub(crate) async fn set_room_account_data_route(
body: Ruma<set_room_account_data::v3::Request>, body: Ruma<set_room_account_data::v3::Request>,
) -> Result<set_room_account_data::v3::Response> { ) -> Result<set_room_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -68,7 +68,7 @@ pub async fn set_room_account_data_route(
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}` /// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
/// ///
/// Gets some account data for the sender user. /// Gets some account data for the sender user.
pub async fn get_global_account_data_route( pub(crate) async fn get_global_account_data_route(
body: Ruma<get_global_account_data::v3::Request>, body: Ruma<get_global_account_data::v3::Request>,
) -> Result<get_global_account_data::v3::Response> { ) -> Result<get_global_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -88,7 +88,7 @@ pub async fn get_global_account_data_route(
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}` /// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
/// ///
/// Gets some room account data for the sender user. /// Gets some room account data for the sender user.
pub async fn get_room_account_data_route( pub(crate) async fn get_room_account_data_route(
body: Ruma<get_room_account_data::v3::Request>, body: Ruma<get_room_account_data::v3::Request>,
) -> Result<get_room_account_data::v3::Response> { ) -> Result<get_room_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -12,7 +12,7 @@ use tracing::error;
/// ///
/// - Only works if the user is joined (TODO: always allow, but only show events if the user was /// - Only works if the user is joined (TODO: always allow, but only show events if the user was
/// joined, depending on history_visibility) /// joined, depending on history_visibility)
pub async fn get_context_route( pub(crate) async fn get_context_route(
body: Ruma<get_context::v3::Request>, body: Ruma<get_context::v3::Request>,
) -> Result<get_context::v3::Response> { ) -> Result<get_context::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -10,7 +10,7 @@ use super::SESSION_ID_LENGTH;
/// # `GET /_matrix/client/r0/devices` /// # `GET /_matrix/client/r0/devices`
/// ///
/// Get metadata on all devices of the sender user. /// Get metadata on all devices of the sender user.
pub async fn get_devices_route( pub(crate) async fn get_devices_route(
body: Ruma<get_devices::v3::Request>, body: Ruma<get_devices::v3::Request>,
) -> Result<get_devices::v3::Response> { ) -> Result<get_devices::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -27,7 +27,7 @@ pub async fn get_devices_route(
/// # `GET /_matrix/client/r0/devices/{deviceId}` /// # `GET /_matrix/client/r0/devices/{deviceId}`
/// ///
/// Get metadata on a single device of the sender user. /// Get metadata on a single device of the sender user.
pub async fn get_device_route( pub(crate) async fn get_device_route(
body: Ruma<get_device::v3::Request>, body: Ruma<get_device::v3::Request>,
) -> Result<get_device::v3::Response> { ) -> Result<get_device::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -43,7 +43,7 @@ pub async fn get_device_route(
/// # `PUT /_matrix/client/r0/devices/{deviceId}` /// # `PUT /_matrix/client/r0/devices/{deviceId}`
/// ///
/// Updates the metadata on a given device of the sender user. /// Updates the metadata on a given device of the sender user.
pub async fn update_device_route( pub(crate) async fn update_device_route(
body: Ruma<update_device::v3::Request>, body: Ruma<update_device::v3::Request>,
) -> Result<update_device::v3::Response> { ) -> Result<update_device::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -71,7 +71,7 @@ pub async fn update_device_route(
/// - Deletes device metadata (device id, device display name, last seen ip, last seen ts) /// - Deletes device metadata (device id, device display name, last seen ip, last seen ts)
/// - Forgets to-device events /// - Forgets to-device events
/// - Triggers device list updates /// - Triggers device list updates
pub async fn delete_device_route( pub(crate) async fn delete_device_route(
body: Ruma<delete_device::v3::Request>, body: Ruma<delete_device::v3::Request>,
) -> Result<delete_device::v3::Response> { ) -> Result<delete_device::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -125,7 +125,7 @@ pub async fn delete_device_route(
/// - Deletes device metadata (device id, device display name, last seen ip, last seen ts) /// - Deletes device metadata (device id, device display name, last seen ip, last seen ts)
/// - Forgets to-device events /// - Forgets to-device events
/// - Triggers device list updates /// - Triggers device list updates
pub async fn delete_devices_route( pub(crate) async fn delete_devices_route(
body: Ruma<delete_devices::v3::Request>, body: Ruma<delete_devices::v3::Request>,
) -> Result<delete_devices::v3::Response> { ) -> Result<delete_devices::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -33,7 +33,7 @@ use tracing::{error, info, warn};
/// Lists the public rooms on this server. /// Lists the public rooms on this server.
/// ///
/// - Rooms are ordered by the number of joined members /// - Rooms are ordered by the number of joined members
pub async fn get_public_rooms_filtered_route( pub(crate) async fn get_public_rooms_filtered_route(
body: Ruma<get_public_rooms_filtered::v3::Request>, body: Ruma<get_public_rooms_filtered::v3::Request>,
) -> Result<get_public_rooms_filtered::v3::Response> { ) -> Result<get_public_rooms_filtered::v3::Response> {
get_public_rooms_filtered_helper( get_public_rooms_filtered_helper(
@ -51,7 +51,7 @@ pub async fn get_public_rooms_filtered_route(
/// Lists the public rooms on this server. /// Lists the public rooms on this server.
/// ///
/// - Rooms are ordered by the number of joined members /// - Rooms are ordered by the number of joined members
pub async fn get_public_rooms_route( pub(crate) async fn get_public_rooms_route(
body: Ruma<get_public_rooms::v3::Request>, body: Ruma<get_public_rooms::v3::Request>,
) -> Result<get_public_rooms::v3::Response> { ) -> Result<get_public_rooms::v3::Response> {
let response = get_public_rooms_filtered_helper( let response = get_public_rooms_filtered_helper(
@ -76,7 +76,7 @@ pub async fn get_public_rooms_route(
/// Sets the visibility of a given room in the room directory. /// Sets the visibility of a given room in the room directory.
/// ///
/// - TODO: Access control checks /// - TODO: Access control checks
pub async fn set_room_visibility_route( pub(crate) async fn set_room_visibility_route(
body: Ruma<set_room_visibility::v3::Request>, body: Ruma<set_room_visibility::v3::Request>,
) -> Result<set_room_visibility::v3::Response> { ) -> Result<set_room_visibility::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -106,7 +106,7 @@ pub async fn set_room_visibility_route(
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}` /// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
/// ///
/// Gets the visibility of a given room in the room directory. /// Gets the visibility of a given room in the room directory.
pub async fn get_room_visibility_route( pub(crate) async fn get_room_visibility_route(
body: Ruma<get_room_visibility::v3::Request>, body: Ruma<get_room_visibility::v3::Request>,
) -> Result<get_room_visibility::v3::Response> { ) -> Result<get_room_visibility::v3::Response> {
if !services().rooms.metadata.exists(&body.room_id)? { if !services().rooms.metadata.exists(&body.room_id)? {

View file

@ -9,7 +9,7 @@ use ruma::api::client::{
/// Loads a filter that was previously created. /// Loads a filter that was previously created.
/// ///
/// - A user can only access their own filters /// - A user can only access their own filters
pub async fn get_filter_route( pub(crate) async fn get_filter_route(
body: Ruma<get_filter::v3::Request>, body: Ruma<get_filter::v3::Request>,
) -> Result<get_filter::v3::Response> { ) -> Result<get_filter::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -24,7 +24,7 @@ pub async fn get_filter_route(
/// # `PUT /_matrix/client/r0/user/{userId}/filter` /// # `PUT /_matrix/client/r0/user/{userId}/filter`
/// ///
/// Creates a new filter to be used by other endpoints. /// Creates a new filter to be used by other endpoints.
pub async fn create_filter_route( pub(crate) async fn create_filter_route(
body: Ruma<create_filter::v3::Request>, body: Ruma<create_filter::v3::Request>,
) -> Result<create_filter::v3::Response> { ) -> Result<create_filter::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -29,7 +29,7 @@ use tracing::debug;
/// ///
/// - Adds one time keys /// - Adds one time keys
/// - If there are no device keys yet: Adds device keys (TODO: merge with existing keys?) /// - If there are no device keys yet: Adds device keys (TODO: merge with existing keys?)
pub async fn upload_keys_route( pub(crate) async fn upload_keys_route(
body: Ruma<upload_keys::v3::Request>, body: Ruma<upload_keys::v3::Request>,
) -> Result<upload_keys::v3::Response> { ) -> Result<upload_keys::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -69,7 +69,9 @@ pub async fn upload_keys_route(
/// - Always fetches users from other servers over federation /// - Always fetches users from other servers over federation
/// - Gets master keys, self-signing keys, user signing keys and device keys. /// - Gets master keys, self-signing keys, user signing keys and device keys.
/// - The master and self-signing keys contain signatures that the user is allowed to see /// - The master and self-signing keys contain signatures that the user is allowed to see
pub async fn get_keys_route(body: Ruma<get_keys::v3::Request>) -> Result<get_keys::v3::Response> { pub(crate) async fn get_keys_route(
body: Ruma<get_keys::v3::Request>,
) -> Result<get_keys::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let response = let response =
@ -81,7 +83,7 @@ pub async fn get_keys_route(body: Ruma<get_keys::v3::Request>) -> Result<get_key
/// # `POST /_matrix/client/r0/keys/claim` /// # `POST /_matrix/client/r0/keys/claim`
/// ///
/// Claims one-time keys /// Claims one-time keys
pub async fn claim_keys_route( pub(crate) async fn claim_keys_route(
body: Ruma<claim_keys::v3::Request>, body: Ruma<claim_keys::v3::Request>,
) -> Result<claim_keys::v3::Response> { ) -> Result<claim_keys::v3::Response> {
let response = claim_keys_helper(&body.one_time_keys).await?; let response = claim_keys_helper(&body.one_time_keys).await?;
@ -94,7 +96,7 @@ pub async fn claim_keys_route(
/// Uploads end-to-end key information for the sender user. /// Uploads end-to-end key information for the sender user.
/// ///
/// - Requires UIAA to verify password /// - Requires UIAA to verify password
pub async fn upload_signing_keys_route( pub(crate) async fn upload_signing_keys_route(
body: Ruma<upload_signing_keys::v3::Request>, body: Ruma<upload_signing_keys::v3::Request>,
) -> Result<upload_signing_keys::v3::Response> { ) -> Result<upload_signing_keys::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -146,7 +148,7 @@ pub async fn upload_signing_keys_route(
/// # `POST /_matrix/client/r0/keys/signatures/upload` /// # `POST /_matrix/client/r0/keys/signatures/upload`
/// ///
/// Uploads end-to-end key signatures from the sender user. /// Uploads end-to-end key signatures from the sender user.
pub async fn upload_signatures_route( pub(crate) async fn upload_signatures_route(
body: Ruma<upload_signatures::v3::Request>, body: Ruma<upload_signatures::v3::Request>,
) -> Result<upload_signatures::v3::Response> { ) -> Result<upload_signatures::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -204,7 +206,7 @@ pub async fn upload_signatures_route(
/// Gets a list of users who have updated their device identity keys since the previous sync token. /// Gets a list of users who have updated their device identity keys since the previous sync token.
/// ///
/// - TODO: left users /// - TODO: left users
pub async fn get_key_changes_route( pub(crate) async fn get_key_changes_route(
body: Ruma<get_key_changes::v3::Request>, body: Ruma<get_key_changes::v3::Request>,
) -> Result<get_key_changes::v3::Response> { ) -> Result<get_key_changes::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -14,7 +14,7 @@ const MXC_LENGTH: usize = 32;
/// # `GET /_matrix/media/r0/config` /// # `GET /_matrix/media/r0/config`
/// ///
/// Returns max upload size. /// Returns max upload size.
pub async fn get_media_config_route( pub(crate) async fn get_media_config_route(
_body: Ruma<get_media_config::v3::Request>, _body: Ruma<get_media_config::v3::Request>,
) -> Result<get_media_config::v3::Response> { ) -> Result<get_media_config::v3::Response> {
Ok(get_media_config::v3::Response { Ok(get_media_config::v3::Response {
@ -28,7 +28,7 @@ pub async fn get_media_config_route(
/// ///
/// - Some metadata will be saved in the database /// - Some metadata will be saved in the database
/// - Media will be saved in the media/ directory /// - Media will be saved in the media/ directory
pub async fn create_content_route( pub(crate) async fn create_content_route(
body: Ruma<create_content::v3::Request>, body: Ruma<create_content::v3::Request>,
) -> Result<create_content::v3::Response> { ) -> Result<create_content::v3::Response> {
let mxc = format!( let mxc = format!(
@ -56,7 +56,7 @@ pub async fn create_content_route(
}) })
} }
pub async fn get_remote_content( pub(crate) async fn get_remote_content(
mxc: &str, mxc: &str,
server_name: &ruma::ServerName, server_name: &ruma::ServerName,
media_id: String, media_id: String,
@ -93,7 +93,7 @@ pub async fn get_remote_content(
/// Load media from our server or over federation. /// Load media from our server or over federation.
/// ///
/// - Only allows federation if `allow_remote` is true /// - Only allows federation if `allow_remote` is true
pub async fn get_content_route( pub(crate) async fn get_content_route(
body: Ruma<get_content::v3::Request>, body: Ruma<get_content::v3::Request>,
) -> Result<get_content::v3::Response> { ) -> Result<get_content::v3::Response> {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
@ -124,7 +124,7 @@ pub async fn get_content_route(
/// Load media from our server or over federation, permitting desired filename. /// Load media from our server or over federation, permitting desired filename.
/// ///
/// - Only allows federation if `allow_remote` is true /// - Only allows federation if `allow_remote` is true
pub async fn get_content_as_filename_route( pub(crate) async fn get_content_as_filename_route(
body: Ruma<get_content_as_filename::v3::Request>, body: Ruma<get_content_as_filename::v3::Request>,
) -> Result<get_content_as_filename::v3::Response> { ) -> Result<get_content_as_filename::v3::Response> {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
@ -161,7 +161,7 @@ pub async fn get_content_as_filename_route(
/// Load media thumbnail from our server or over federation. /// Load media thumbnail from our server or over federation.
/// ///
/// - Only allows federation if `allow_remote` is true /// - Only allows federation if `allow_remote` is true
pub async fn get_content_thumbnail_route( pub(crate) async fn get_content_thumbnail_route(
body: Ruma<get_content_thumbnail::v3::Request>, body: Ruma<get_content_thumbnail::v3::Request>,
) -> Result<get_content_thumbnail::v3::Response> { ) -> Result<get_content_thumbnail::v3::Response> {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);

View file

@ -44,7 +44,7 @@ use super::get_alias_helper;
/// ///
/// - If the server knowns about this room: creates the join event and does auth rules locally /// - If the server knowns about this room: creates the join event and does auth rules locally
/// - If the server does not know about the room: asks other servers over federation /// - If the server does not know about the room: asks other servers over federation
pub async fn join_room_by_id_route( pub(crate) async fn join_room_by_id_route(
body: Ruma<join_room_by_id::v3::Request>, body: Ruma<join_room_by_id::v3::Request>,
) -> Result<join_room_by_id::v3::Response> { ) -> Result<join_room_by_id::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -87,7 +87,7 @@ pub async fn join_room_by_id_route(
/// ///
/// - If the server knowns about this room: creates the join event and does auth rules locally /// - If the server knowns about this room: creates the join event and does auth rules locally
/// - If the server does not know about the room: asks other servers over federation /// - If the server does not know about the room: asks other servers over federation
pub async fn join_room_by_id_or_alias_route( pub(crate) async fn join_room_by_id_or_alias_route(
body: Ruma<join_room_by_id_or_alias::v3::Request>, body: Ruma<join_room_by_id_or_alias::v3::Request>,
) -> Result<join_room_by_id_or_alias::v3::Response> { ) -> Result<join_room_by_id_or_alias::v3::Response> {
let sender_user = body.sender_user.as_deref().expect("user is authenticated"); let sender_user = body.sender_user.as_deref().expect("user is authenticated");
@ -145,7 +145,7 @@ pub async fn join_room_by_id_or_alias_route(
/// Tries to leave the sender user from a room. /// Tries to leave the sender user from a room.
/// ///
/// - This should always work if the user is currently joined. /// - This should always work if the user is currently joined.
pub async fn leave_room_route( pub(crate) async fn leave_room_route(
body: Ruma<leave_room::v3::Request>, body: Ruma<leave_room::v3::Request>,
) -> Result<leave_room::v3::Response> { ) -> Result<leave_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -158,7 +158,7 @@ pub async fn leave_room_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/invite` /// # `POST /_matrix/client/r0/rooms/{roomId}/invite`
/// ///
/// Tries to send an invite event into the room. /// Tries to send an invite event into the room.
pub async fn invite_user_route( pub(crate) async fn invite_user_route(
body: Ruma<invite_user::v3::Request>, body: Ruma<invite_user::v3::Request>,
) -> Result<invite_user::v3::Response> { ) -> Result<invite_user::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -181,7 +181,7 @@ pub async fn invite_user_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/kick` /// # `POST /_matrix/client/r0/rooms/{roomId}/kick`
/// ///
/// Tries to send a kick event into the room. /// Tries to send a kick event into the room.
pub async fn kick_user_route( pub(crate) async fn kick_user_route(
body: Ruma<kick_user::v3::Request>, body: Ruma<kick_user::v3::Request>,
) -> Result<kick_user::v3::Response> { ) -> Result<kick_user::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -251,7 +251,9 @@ pub async fn kick_user_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/ban` /// # `POST /_matrix/client/r0/rooms/{roomId}/ban`
/// ///
/// Tries to send a ban event into the room. /// Tries to send a ban event into the room.
pub async fn ban_user_route(body: Ruma<ban_user::v3::Request>) -> Result<ban_user::v3::Response> { pub(crate) async fn ban_user_route(
body: Ruma<ban_user::v3::Request>,
) -> Result<ban_user::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if let Ok(Some(membership_event)) = services() if let Ok(Some(membership_event)) = services()
@ -330,7 +332,7 @@ pub async fn ban_user_route(body: Ruma<ban_user::v3::Request>) -> Result<ban_use
/// # `POST /_matrix/client/r0/rooms/{roomId}/unban` /// # `POST /_matrix/client/r0/rooms/{roomId}/unban`
/// ///
/// Tries to send an unban event into the room. /// Tries to send an unban event into the room.
pub async fn unban_user_route( pub(crate) async fn unban_user_route(
body: Ruma<unban_user::v3::Request>, body: Ruma<unban_user::v3::Request>,
) -> Result<unban_user::v3::Response> { ) -> Result<unban_user::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -407,7 +409,7 @@ pub async fn unban_user_route(
/// ///
/// Note: Other devices of the user have no way of knowing the room was forgotten, so this has to /// Note: Other devices of the user have no way of knowing the room was forgotten, so this has to
/// be called from every device /// be called from every device
pub async fn forget_room_route( pub(crate) async fn forget_room_route(
body: Ruma<forget_room::v3::Request>, body: Ruma<forget_room::v3::Request>,
) -> Result<forget_room::v3::Response> { ) -> Result<forget_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -423,7 +425,7 @@ pub async fn forget_room_route(
/// # `POST /_matrix/client/r0/joined_rooms` /// # `POST /_matrix/client/r0/joined_rooms`
/// ///
/// Lists all rooms the user has joined. /// Lists all rooms the user has joined.
pub async fn joined_rooms_route( pub(crate) async fn joined_rooms_route(
body: Ruma<joined_rooms::v3::Request>, body: Ruma<joined_rooms::v3::Request>,
) -> Result<joined_rooms::v3::Response> { ) -> Result<joined_rooms::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -443,7 +445,7 @@ pub async fn joined_rooms_route(
/// Lists all joined users in a room (TODO: at a specific point in time, with a specific membership). /// Lists all joined users in a room (TODO: at a specific point in time, with a specific membership).
/// ///
/// - Only works if the user is currently joined /// - Only works if the user is currently joined
pub async fn get_member_events_route( pub(crate) async fn get_member_events_route(
body: Ruma<get_member_events::v3::Request>, body: Ruma<get_member_events::v3::Request>,
) -> Result<get_member_events::v3::Response> { ) -> Result<get_member_events::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -478,7 +480,7 @@ pub async fn get_member_events_route(
/// ///
/// - The sender user must be in the room /// - The sender user must be in the room
/// - TODO: An appservice just needs a puppet joined /// - TODO: An appservice just needs a puppet joined
pub async fn joined_members_route( pub(crate) async fn joined_members_route(
body: Ruma<joined_members::v3::Request>, body: Ruma<joined_members::v3::Request>,
) -> Result<joined_members::v3::Response> { ) -> Result<joined_members::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -1378,7 +1380,7 @@ pub(crate) async fn invite_helper<'a>(
} }
// Make a user leave all their joined rooms // Make a user leave all their joined rooms
pub async fn leave_all_rooms(user_id: &UserId) -> Result<()> { pub(crate) async fn leave_all_rooms(user_id: &UserId) -> Result<()> {
let all_rooms = services() let all_rooms = services()
.rooms .rooms
.state_cache .state_cache
@ -1404,7 +1406,11 @@ pub async fn leave_all_rooms(user_id: &UserId) -> Result<()> {
Ok(()) Ok(())
} }
pub async fn leave_room(user_id: &UserId, room_id: &RoomId, reason: Option<String>) -> Result<()> { pub(crate) async fn leave_room(
user_id: &UserId,
room_id: &RoomId,
reason: Option<String>,
) -> Result<()> {
// Ask a remote server if we don't have this room // Ask a remote server if we don't have this room
if !services() if !services()
.rooms .rooms

View file

@ -21,7 +21,7 @@ use std::{
/// - Is a NOOP if the txn id was already used before and returns the same event id again /// - Is a NOOP if the txn id was already used before and returns the same event id again
/// - The only requirement for the content is that it has to be valid json /// - The only requirement for the content is that it has to be valid json
/// - Tries to send the event into the room, auth rules will determine if it is allowed /// - Tries to send the event into the room, auth rules will determine if it is allowed
pub async fn send_message_event_route( pub(crate) async fn send_message_event_route(
body: Ruma<send_message_event::v3::Request>, body: Ruma<send_message_event::v3::Request>,
) -> Result<send_message_event::v3::Response> { ) -> Result<send_message_event::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -111,7 +111,7 @@ pub async fn send_message_event_route(
/// ///
/// - Only works if the user is joined (TODO: always allow, but only show events where the user was /// - Only works if the user is joined (TODO: always allow, but only show events where the user was
/// joined, depending on history_visibility) /// joined, depending on history_visibility)
pub async fn get_message_events_route( pub(crate) async fn get_message_events_route(
body: Ruma<get_message_events::v3::Request>, body: Ruma<get_message_events::v3::Request>,
) -> Result<get_message_events::v3::Response> { ) -> Result<get_message_events::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -19,7 +19,7 @@ use std::sync::Arc;
/// Updates the displayname. /// Updates the displayname.
/// ///
/// - Also makes sure other users receive the update using presence EDUs /// - Also makes sure other users receive the update using presence EDUs
pub async fn set_displayname_route( pub(crate) async fn set_displayname_route(
body: Ruma<set_display_name::v3::Request>, body: Ruma<set_display_name::v3::Request>,
) -> Result<set_display_name::v3::Response> { ) -> Result<set_display_name::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -99,7 +99,7 @@ pub async fn set_displayname_route(
/// Returns the displayname of the user. /// Returns the displayname of the user.
/// ///
/// - If user is on another server: Fetches displayname over federation /// - If user is on another server: Fetches displayname over federation
pub async fn get_displayname_route( pub(crate) async fn get_displayname_route(
body: Ruma<get_display_name::v3::Request>, body: Ruma<get_display_name::v3::Request>,
) -> Result<get_display_name::v3::Response> { ) -> Result<get_display_name::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() { if body.user_id.server_name() != services().globals.server_name() {
@ -129,7 +129,7 @@ pub async fn get_displayname_route(
/// Updates the avatar_url and blurhash. /// Updates the avatar_url and blurhash.
/// ///
/// - Also makes sure other users receive the update using presence EDUs /// - Also makes sure other users receive the update using presence EDUs
pub async fn set_avatar_url_route( pub(crate) async fn set_avatar_url_route(
body: Ruma<set_avatar_url::v3::Request>, body: Ruma<set_avatar_url::v3::Request>,
) -> Result<set_avatar_url::v3::Response> { ) -> Result<set_avatar_url::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -213,7 +213,7 @@ pub async fn set_avatar_url_route(
/// Returns the avatar_url and blurhash of the user. /// Returns the avatar_url and blurhash of the user.
/// ///
/// - If user is on another server: Fetches avatar_url and blurhash over federation /// - If user is on another server: Fetches avatar_url and blurhash over federation
pub async fn get_avatar_url_route( pub(crate) async fn get_avatar_url_route(
body: Ruma<get_avatar_url::v3::Request>, body: Ruma<get_avatar_url::v3::Request>,
) -> Result<get_avatar_url::v3::Response> { ) -> Result<get_avatar_url::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() { if body.user_id.server_name() != services().globals.server_name() {
@ -245,7 +245,7 @@ pub async fn get_avatar_url_route(
/// Returns the displayname, avatar_url and blurhash of the user. /// Returns the displayname, avatar_url and blurhash of the user.
/// ///
/// - If user is on another server: Fetches profile over federation /// - If user is on another server: Fetches profile over federation
pub async fn get_profile_route( pub(crate) async fn get_profile_route(
body: Ruma<get_profile::v3::Request>, body: Ruma<get_profile::v3::Request>,
) -> Result<get_profile::v3::Response> { ) -> Result<get_profile::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() { if body.user_id.server_name() != services().globals.server_name() {

View file

@ -15,7 +15,7 @@ use ruma::{
/// # `GET /_matrix/client/r0/pushrules` /// # `GET /_matrix/client/r0/pushrules`
/// ///
/// Retrieves the push rules event for this user. /// Retrieves the push rules event for this user.
pub async fn get_pushrules_all_route( pub(crate) async fn get_pushrules_all_route(
body: Ruma<get_pushrules_all::v3::Request>, body: Ruma<get_pushrules_all::v3::Request>,
) -> Result<get_pushrules_all::v3::Response> { ) -> Result<get_pushrules_all::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -44,7 +44,7 @@ pub async fn get_pushrules_all_route(
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}` /// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
/// ///
/// Retrieves a single specified push rule for this user. /// Retrieves a single specified push rule for this user.
pub async fn get_pushrule_route( pub(crate) async fn get_pushrule_route(
body: Ruma<get_pushrule::v3::Request>, body: Ruma<get_pushrule::v3::Request>,
) -> Result<get_pushrule::v3::Response> { ) -> Result<get_pushrule::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -83,7 +83,7 @@ pub async fn get_pushrule_route(
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}` /// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
/// ///
/// Creates a single specified push rule for this user. /// Creates a single specified push rule for this user.
pub async fn set_pushrule_route( pub(crate) async fn set_pushrule_route(
body: Ruma<set_pushrule::v3::Request>, body: Ruma<set_pushrule::v3::Request>,
) -> Result<set_pushrule::v3::Response> { ) -> Result<set_pushrule::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -156,7 +156,7 @@ pub async fn set_pushrule_route(
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions` /// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
/// ///
/// Gets the actions of a single specified push rule for this user. /// Gets the actions of a single specified push rule for this user.
pub async fn get_pushrule_actions_route( pub(crate) async fn get_pushrule_actions_route(
body: Ruma<get_pushrule_actions::v3::Request>, body: Ruma<get_pushrule_actions::v3::Request>,
) -> Result<get_pushrule_actions::v3::Response> { ) -> Result<get_pushrule_actions::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -199,7 +199,7 @@ pub async fn get_pushrule_actions_route(
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions` /// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
/// ///
/// Sets the actions of a single specified push rule for this user. /// Sets the actions of a single specified push rule for this user.
pub async fn set_pushrule_actions_route( pub(crate) async fn set_pushrule_actions_route(
body: Ruma<set_pushrule_actions::v3::Request>, body: Ruma<set_pushrule_actions::v3::Request>,
) -> Result<set_pushrule_actions::v3::Response> { ) -> Result<set_pushrule_actions::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -251,7 +251,7 @@ pub async fn set_pushrule_actions_route(
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled` /// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
/// ///
/// Gets the enabled status of a single specified push rule for this user. /// Gets the enabled status of a single specified push rule for this user.
pub async fn get_pushrule_enabled_route( pub(crate) async fn get_pushrule_enabled_route(
body: Ruma<get_pushrule_enabled::v3::Request>, body: Ruma<get_pushrule_enabled::v3::Request>,
) -> Result<get_pushrule_enabled::v3::Response> { ) -> Result<get_pushrule_enabled::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -293,7 +293,7 @@ pub async fn get_pushrule_enabled_route(
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled` /// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
/// ///
/// Sets the enabled status of a single specified push rule for this user. /// Sets the enabled status of a single specified push rule for this user.
pub async fn set_pushrule_enabled_route( pub(crate) async fn set_pushrule_enabled_route(
body: Ruma<set_pushrule_enabled::v3::Request>, body: Ruma<set_pushrule_enabled::v3::Request>,
) -> Result<set_pushrule_enabled::v3::Response> { ) -> Result<set_pushrule_enabled::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -345,7 +345,7 @@ pub async fn set_pushrule_enabled_route(
/// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}` /// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
/// ///
/// Deletes a single specified push rule for this user. /// Deletes a single specified push rule for this user.
pub async fn delete_pushrule_route( pub(crate) async fn delete_pushrule_route(
body: Ruma<delete_pushrule::v3::Request>, body: Ruma<delete_pushrule::v3::Request>,
) -> Result<delete_pushrule::v3::Response> { ) -> Result<delete_pushrule::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -404,7 +404,7 @@ pub async fn delete_pushrule_route(
/// # `GET /_matrix/client/r0/pushers` /// # `GET /_matrix/client/r0/pushers`
/// ///
/// Gets all currently active pushers for the sender user. /// Gets all currently active pushers for the sender user.
pub async fn get_pushers_route( pub(crate) async fn get_pushers_route(
body: Ruma<get_pushers::v3::Request>, body: Ruma<get_pushers::v3::Request>,
) -> Result<get_pushers::v3::Response> { ) -> Result<get_pushers::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -419,7 +419,7 @@ pub async fn get_pushers_route(
/// Adds a pusher for the sender user. /// Adds a pusher for the sender user.
/// ///
/// - TODO: Handle `append` /// - TODO: Handle `append`
pub async fn set_pushers_route( pub(crate) async fn set_pushers_route(
body: Ruma<set_pusher::v3::Request>, body: Ruma<set_pusher::v3::Request>,
) -> Result<set_pusher::v3::Response> { ) -> Result<set_pusher::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -15,7 +15,7 @@ use std::collections::BTreeMap;
/// ///
/// - Updates fully-read account data event to `fully_read` /// - Updates fully-read account data event to `fully_read`
/// - If `read_receipt` is set: Update private marker and public read receipt EDU /// - If `read_receipt` is set: Update private marker and public read receipt EDU
pub async fn set_read_marker_route( pub(crate) async fn set_read_marker_route(
body: Ruma<set_read_marker::v3::Request>, body: Ruma<set_read_marker::v3::Request>,
) -> Result<set_read_marker::v3::Response> { ) -> Result<set_read_marker::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -98,7 +98,7 @@ pub async fn set_read_marker_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}` /// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
/// ///
/// Sets private read marker and public read receipt EDU. /// Sets private read marker and public read receipt EDU.
pub async fn create_receipt_route( pub(crate) async fn create_receipt_route(
body: Ruma<create_receipt::v3::Request>, body: Ruma<create_receipt::v3::Request>,
) -> Result<create_receipt::v3::Response> { ) -> Result<create_receipt::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -13,7 +13,7 @@ use serde_json::value::to_raw_value;
/// Tries to send a redaction event into the room. /// Tries to send a redaction event into the room.
/// ///
/// - TODO: Handle txn id /// - TODO: Handle txn id
pub async fn redact_event_route( pub(crate) async fn redact_event_route(
body: Ruma<redact_event::v3::Request>, body: Ruma<redact_event::v3::Request>,
) -> Result<redact_event::v3::Response> { ) -> Result<redact_event::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -6,7 +6,7 @@ use ruma::api::client::relations::{
use crate::{service::rooms::timeline::PduCount, services, Result, Ruma}; use crate::{service::rooms::timeline::PduCount, services, Result, Ruma};
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}` /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}`
pub async fn get_relating_events_with_rel_type_and_event_type_route( pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route(
body: Ruma<get_relating_events_with_rel_type_and_event_type::v1::Request>, body: Ruma<get_relating_events_with_rel_type_and_event_type::v1::Request>,
) -> Result<get_relating_events_with_rel_type_and_event_type::v1::Response> { ) -> Result<get_relating_events_with_rel_type_and_event_type::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -56,7 +56,7 @@ pub async fn get_relating_events_with_rel_type_and_event_type_route(
} }
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}` /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}`
pub async fn get_relating_events_with_rel_type_route( pub(crate) async fn get_relating_events_with_rel_type_route(
body: Ruma<get_relating_events_with_rel_type::v1::Request>, body: Ruma<get_relating_events_with_rel_type::v1::Request>,
) -> Result<get_relating_events_with_rel_type::v1::Response> { ) -> Result<get_relating_events_with_rel_type::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -104,7 +104,7 @@ pub async fn get_relating_events_with_rel_type_route(
} }
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}` /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}`
pub async fn get_relating_events_route( pub(crate) async fn get_relating_events_route(
body: Ruma<get_relating_events::v1::Request>, body: Ruma<get_relating_events::v1::Request>,
) -> Result<get_relating_events::v1::Response> { ) -> Result<get_relating_events::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -9,7 +9,7 @@ use ruma::{
/// ///
/// Reports an inappropriate event to homeserver admins /// Reports an inappropriate event to homeserver admins
/// ///
pub async fn report_event_route( pub(crate) async fn report_event_route(
body: Ruma<report_content::v3::Request>, body: Ruma<report_content::v3::Request>,
) -> Result<report_content::v3::Response> { ) -> Result<report_content::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -45,7 +45,7 @@ use tracing::{info, warn};
/// - Send events listed in initial state /// - Send events listed in initial state
/// - Send events implied by `name` and `topic` /// - Send events implied by `name` and `topic`
/// - Send invite events /// - Send invite events
pub async fn create_room_route( pub(crate) async fn create_room_route(
body: Ruma<create_room::v3::Request>, body: Ruma<create_room::v3::Request>,
) -> Result<create_room::v3::Response> { ) -> Result<create_room::v3::Response> {
use create_room::v3::RoomPreset; use create_room::v3::RoomPreset;
@ -502,7 +502,7 @@ pub async fn create_room_route(
/// Gets a single event. /// Gets a single event.
/// ///
/// - You have to currently be joined to the room (TODO: Respect history visibility) /// - You have to currently be joined to the room (TODO: Respect history visibility)
pub async fn get_room_event_route( pub(crate) async fn get_room_event_route(
body: Ruma<get_room_event::v3::Request>, body: Ruma<get_room_event::v3::Request>,
) -> Result<get_room_event::v3::Response> { ) -> Result<get_room_event::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -540,7 +540,7 @@ pub async fn get_room_event_route(
/// Lists all aliases of the room. /// Lists all aliases of the room.
/// ///
/// - Only users joined to the room are allowed to call this TODO: Allow any user to call it if history_visibility is world readable /// - Only users joined to the room are allowed to call this TODO: Allow any user to call it if history_visibility is world readable
pub async fn get_room_aliases_route( pub(crate) async fn get_room_aliases_route(
body: Ruma<aliases::v3::Request>, body: Ruma<aliases::v3::Request>,
) -> Result<aliases::v3::Response> { ) -> Result<aliases::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -576,7 +576,7 @@ pub async fn get_room_aliases_route(
/// - Transfers some state events /// - Transfers some state events
/// - Moves local aliases /// - Moves local aliases
/// - Modifies old room power levels to prevent users from speaking /// - Modifies old room power levels to prevent users from speaking
pub async fn upgrade_room_route( pub(crate) async fn upgrade_room_route(
body: Ruma<upgrade_room::v3::Request>, body: Ruma<upgrade_room::v3::Request>,
) -> Result<upgrade_room::v3::Response> { ) -> Result<upgrade_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -14,7 +14,7 @@ use std::collections::BTreeMap;
/// Searches rooms for messages. /// Searches rooms for messages.
/// ///
/// - Only works if the user is currently joined to the room (TODO: Respect history visibility) /// - Only works if the user is currently joined to the room (TODO: Respect history visibility)
pub async fn search_events_route( pub(crate) async fn search_events_route(
body: Ruma<search_events::v3::Request>, body: Ruma<search_events::v3::Request>,
) -> Result<search_events::v3::Response> { ) -> Result<search_events::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -21,7 +21,7 @@ struct Claims {
/// ///
/// Get the supported login types of this server. One of these should be used as the `type` field /// Get the supported login types of this server. One of these should be used as the `type` field
/// when logging in. /// when logging in.
pub async fn get_login_types_route( pub(crate) async fn get_login_types_route(
_body: Ruma<get_login_types::v3::Request>, _body: Ruma<get_login_types::v3::Request>,
) -> Result<get_login_types::v3::Response> { ) -> Result<get_login_types::v3::Response> {
Ok(get_login_types::v3::Response::new(vec![ Ok(get_login_types::v3::Response::new(vec![
@ -41,7 +41,7 @@ pub async fn get_login_types_route(
/// ///
/// Note: You can use [`GET /_matrix/client/r0/login`](fn.get_supported_versions_route.html) to see /// Note: You can use [`GET /_matrix/client/r0/login`](fn.get_supported_versions_route.html) to see
/// supported login types. /// supported login types.
pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Response> { pub(crate) async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Response> {
// To allow deprecated login methods // To allow deprecated login methods
#![allow(deprecated)] #![allow(deprecated)]
// Validate login method // Validate login method
@ -223,7 +223,7 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
/// - Deletes device metadata (device id, device display name, last seen ip, last seen ts) /// - Deletes device metadata (device id, device display name, last seen ip, last seen ts)
/// - Forgets to-device events /// - Forgets to-device events
/// - Triggers device list updates /// - Triggers device list updates
pub async fn logout_route(body: Ruma<logout::v3::Request>) -> Result<logout::v3::Response> { pub(crate) async fn logout_route(body: Ruma<logout::v3::Request>) -> Result<logout::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let sender_device = body.sender_device.as_ref().expect("user is authenticated"); let sender_device = body.sender_device.as_ref().expect("user is authenticated");
@ -252,7 +252,7 @@ pub async fn logout_route(body: Ruma<logout::v3::Request>) -> Result<logout::v3:
/// ///
/// Note: This is equivalent to calling [`GET /_matrix/client/r0/logout`](fn.logout_route.html) /// Note: This is equivalent to calling [`GET /_matrix/client/r0/logout`](fn.logout_route.html)
/// from each device of this user. /// from each device of this user.
pub async fn logout_all_route( pub(crate) async fn logout_all_route(
body: Ruma<logout_all::v3::Request>, body: Ruma<logout_all::v3::Request>,
) -> Result<logout_all::v3::Response> { ) -> Result<logout_all::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -4,7 +4,7 @@ use ruma::api::client::space::get_hierarchy;
/// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy`` /// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy``
/// ///
/// Paginates over the space tree in a depth-first manner to locate child rooms of a given space. /// Paginates over the space tree in a depth-first manner to locate child rooms of a given space.
pub async fn get_hierarchy_route( pub(crate) async fn get_hierarchy_route(
body: Ruma<get_hierarchy::v1::Request>, body: Ruma<get_hierarchy::v1::Request>,
) -> Result<get_hierarchy::v1::Response> { ) -> Result<get_hierarchy::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -21,7 +21,7 @@ use tracing::log::warn;
/// - The only requirement for the content is that it has to be valid json /// - The only requirement for the content is that it has to be valid json
/// - Tries to send the event into the room, auth rules will determine if it is allowed /// - Tries to send the event into the room, auth rules will determine if it is allowed
/// - If event is new canonical_alias: Rejects if alias is incorrect /// - If event is new canonical_alias: Rejects if alias is incorrect
pub async fn send_state_event_for_key_route( pub(crate) async fn send_state_event_for_key_route(
body: Ruma<send_state_event::v3::Request>, body: Ruma<send_state_event::v3::Request>,
) -> Result<send_state_event::v3::Response> { ) -> Result<send_state_event::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -46,7 +46,7 @@ pub async fn send_state_event_for_key_route(
/// - The only requirement for the content is that it has to be valid json /// - The only requirement for the content is that it has to be valid json
/// - Tries to send the event into the room, auth rules will determine if it is allowed /// - Tries to send the event into the room, auth rules will determine if it is allowed
/// - If event is new canonical_alias: Rejects if alias is incorrect /// - If event is new canonical_alias: Rejects if alias is incorrect
pub async fn send_state_event_for_empty_key_route( pub(crate) async fn send_state_event_for_empty_key_route(
body: Ruma<send_state_event::v3::Request>, body: Ruma<send_state_event::v3::Request>,
) -> Result<RumaResponse<send_state_event::v3::Response>> { ) -> Result<RumaResponse<send_state_event::v3::Response>> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -77,7 +77,7 @@ pub async fn send_state_event_for_empty_key_route(
/// Get all state events for a room. /// Get all state events for a room.
/// ///
/// - If not joined: Only works if current room history visibility is world readable /// - If not joined: Only works if current room history visibility is world readable
pub async fn get_state_events_route( pub(crate) async fn get_state_events_route(
body: Ruma<get_state_events::v3::Request>, body: Ruma<get_state_events::v3::Request>,
) -> Result<get_state_events::v3::Response> { ) -> Result<get_state_events::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -110,7 +110,7 @@ pub async fn get_state_events_route(
/// Get single state event of a room. /// Get single state event of a room.
/// ///
/// - If not joined: Only works if current room history visibility is world readable /// - If not joined: Only works if current room history visibility is world readable
pub async fn get_state_events_for_key_route( pub(crate) async fn get_state_events_for_key_route(
body: Ruma<get_state_events_for_key::v3::Request>, body: Ruma<get_state_events_for_key::v3::Request>,
) -> Result<get_state_events_for_key::v3::Response> { ) -> Result<get_state_events_for_key::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -149,7 +149,7 @@ pub async fn get_state_events_for_key_route(
/// Get single state event of a room. /// Get single state event of a room.
/// ///
/// - If not joined: Only works if current room history visibility is world readable /// - If not joined: Only works if current room history visibility is world readable
pub async fn get_state_events_for_empty_key_route( pub(crate) async fn get_state_events_for_empty_key_route(
body: Ruma<get_state_events_for_key::v3::Request>, body: Ruma<get_state_events_for_key::v3::Request>,
) -> Result<RumaResponse<get_state_events_for_key::v3::Response>> { ) -> Result<RumaResponse<get_state_events_for_key::v3::Response>> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -65,7 +65,7 @@ use tracing::{error, info};
/// ///
/// - Sync is handled in an async task, multiple requests from the same device with the same /// - Sync is handled in an async task, multiple requests from the same device with the same
/// `since` will be cached /// `since` will be cached
pub async fn sync_events_route( pub(crate) async fn sync_events_route(
body: Ruma<sync_events::v3::Request>, body: Ruma<sync_events::v3::Request>,
) -> Result<sync_events::v3::Response, RumaResponse<UiaaResponse>> { ) -> Result<sync_events::v3::Response, RumaResponse<UiaaResponse>> {
let sender_user = body.sender_user.expect("user is authenticated"); let sender_user = body.sender_user.expect("user is authenticated");
@ -1180,7 +1180,7 @@ fn share_encrypted_room(
.any(|encrypted| encrypted)) .any(|encrypted| encrypted))
} }
pub async fn sync_events_v4_route( pub(crate) async fn sync_events_v4_route(
body: Ruma<sync_events::v4::Request>, body: Ruma<sync_events::v4::Request>,
) -> Result<sync_events::v4::Response, RumaResponse<UiaaResponse>> { ) -> Result<sync_events::v4::Response, RumaResponse<UiaaResponse>> {
let sender_user = body.sender_user.expect("user is authenticated"); let sender_user = body.sender_user.expect("user is authenticated");

View file

@ -13,7 +13,7 @@ use std::collections::BTreeMap;
/// Adds a tag to the room. /// Adds a tag to the room.
/// ///
/// - Inserts the tag into the tag event of the room account data. /// - Inserts the tag into the tag event of the room account data.
pub async fn update_tag_route( pub(crate) async fn update_tag_route(
body: Ruma<create_tag::v3::Request>, body: Ruma<create_tag::v3::Request>,
) -> Result<create_tag::v3::Response> { ) -> Result<create_tag::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -57,7 +57,7 @@ pub async fn update_tag_route(
/// Deletes a tag from the room. /// Deletes a tag from the room.
/// ///
/// - Removes the tag from the tag event of the room account data. /// - Removes the tag from the tag event of the room account data.
pub async fn delete_tag_route( pub(crate) async fn delete_tag_route(
body: Ruma<delete_tag::v3::Request>, body: Ruma<delete_tag::v3::Request>,
) -> Result<delete_tag::v3::Response> { ) -> Result<delete_tag::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@ -98,7 +98,9 @@ pub async fn delete_tag_route(
/// Returns tags on the room. /// Returns tags on the room.
/// ///
/// - Gets the tag event of the room account data. /// - Gets the tag event of the room account data.
pub async fn get_tags_route(body: Ruma<get_tags::v3::Request>) -> Result<get_tags::v3::Response> { pub(crate) async fn get_tags_route(
body: Ruma<get_tags::v3::Request>,
) -> Result<get_tags::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let event = services().account_data.get( let event = services().account_data.get(

View file

@ -6,7 +6,7 @@ use std::collections::BTreeMap;
/// # `GET /_matrix/client/r0/thirdparty/protocols` /// # `GET /_matrix/client/r0/thirdparty/protocols`
/// ///
/// TODO: Fetches all metadata about protocols supported by the homeserver. /// TODO: Fetches all metadata about protocols supported by the homeserver.
pub async fn get_protocols_route( pub(crate) async fn get_protocols_route(
_body: Ruma<get_protocols::v3::Request>, _body: Ruma<get_protocols::v3::Request>,
) -> Result<get_protocols::v3::Response> { ) -> Result<get_protocols::v3::Response> {
// TODO // TODO

View file

@ -3,7 +3,7 @@ use ruma::api::client::{error::ErrorKind, threads::get_threads};
use crate::{services, Error, Result, Ruma}; use crate::{services, Error, Result, Ruma};
/// # `GET /_matrix/client/r0/rooms/{roomId}/threads` /// # `GET /_matrix/client/r0/rooms/{roomId}/threads`
pub async fn get_threads_route( pub(crate) async fn get_threads_route(
body: Ruma<get_threads::v1::Request>, body: Ruma<get_threads::v1::Request>,
) -> Result<get_threads::v1::Response> { ) -> Result<get_threads::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -12,7 +12,7 @@ use ruma::{
/// # `PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}` /// # `PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}`
/// ///
/// Send a to-device event to a set of client devices. /// Send a to-device event to a set of client devices.
pub async fn send_event_to_device_route( pub(crate) async fn send_event_to_device_route(
body: Ruma<send_event_to_device::v3::Request>, body: Ruma<send_event_to_device::v3::Request>,
) -> Result<send_event_to_device::v3::Response> { ) -> Result<send_event_to_device::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -4,7 +4,7 @@ use ruma::api::client::{error::ErrorKind, typing::create_typing_event};
/// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}` /// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}`
/// ///
/// Sets the typing state of the sender user. /// Sets the typing state of the sender user.
pub async fn create_typing_event_route( pub(crate) async fn create_typing_event_route(
body: Ruma<create_typing_event::v3::Request>, body: Ruma<create_typing_event::v3::Request>,
) -> Result<create_typing_event::v3::Response> { ) -> Result<create_typing_event::v3::Response> {
use create_typing_event::v3::Typing; use create_typing_event::v3::Typing;

View file

@ -15,7 +15,7 @@ use crate::{services, Error, Result, Ruma};
/// ///
/// Note: Unstable features are used while developing new features. Clients should avoid using /// Note: Unstable features are used while developing new features. Clients should avoid using
/// unstable features in their stable releases /// unstable features in their stable releases
pub async fn get_supported_versions_route( pub(crate) async fn get_supported_versions_route(
_body: Ruma<get_supported_versions::Request>, _body: Ruma<get_supported_versions::Request>,
) -> Result<get_supported_versions::Response> { ) -> Result<get_supported_versions::Response> {
let resp = get_supported_versions::Response { let resp = get_supported_versions::Response {
@ -35,7 +35,7 @@ pub async fn get_supported_versions_route(
} }
/// # `GET /.well-known/matrix/client` /// # `GET /.well-known/matrix/client`
pub async fn well_known_client_route( pub(crate) async fn well_known_client_route(
_body: Ruma<get_supported_versions::Request>, _body: Ruma<get_supported_versions::Request>,
) -> Result<impl IntoResponse> { ) -> Result<impl IntoResponse> {
let client_url = match services().globals.well_known_client() { let client_url = match services().globals.well_known_client() {

View file

@ -13,7 +13,7 @@ use ruma::{
/// ///
/// - Hides any local users that aren't in any public rooms (i.e. those that have the join rule set to public) /// - Hides any local users that aren't in any public rooms (i.e. those that have the join rule set to public)
/// and don't share a room with the sender /// and don't share a room with the sender
pub async fn search_users_route( pub(crate) async fn search_users_route(
body: Ruma<search_users::v3::Request>, body: Ruma<search_users::v3::Request>,
) -> Result<search_users::v3::Response> { ) -> Result<search_users::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -10,7 +10,7 @@ type HmacSha1 = Hmac<Sha1>;
/// # `GET /_matrix/client/r0/voip/turnServer` /// # `GET /_matrix/client/r0/voip/turnServer`
/// ///
/// TODO: Returns information about the recommended turn server. /// TODO: Returns information about the recommended turn server.
pub async fn turn_server_route( pub(crate) async fn turn_server_route(
body: Ruma<get_turn_server_info::v3::Request>, body: Ruma<get_turn_server_info::v3::Request>,
) -> Result<get_turn_server_info::v3::Response> { ) -> Result<get_turn_server_info::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -8,14 +8,14 @@ use std::ops::Deref;
mod axum; mod axum;
/// Extractor for Ruma request structs /// Extractor for Ruma request structs
pub struct Ruma<T> { pub(crate) struct Ruma<T> {
pub body: T, pub(crate) body: T,
pub sender_user: Option<OwnedUserId>, pub(crate) sender_user: Option<OwnedUserId>,
pub sender_device: Option<OwnedDeviceId>, pub(crate) sender_device: Option<OwnedDeviceId>,
pub sender_servername: Option<OwnedServerName>, pub(crate) sender_servername: Option<OwnedServerName>,
// This is None when body is not a valid string // This is None when body is not a valid string
pub json_body: Option<CanonicalJsonValue>, pub(crate) json_body: Option<CanonicalJsonValue>,
pub appservice_info: Option<RegistrationInfo>, pub(crate) appservice_info: Option<RegistrationInfo>,
} }
impl<T> Deref for Ruma<T> { impl<T> Deref for Ruma<T> {
@ -27,7 +27,7 @@ impl<T> Deref for Ruma<T> {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct RumaResponse<T>(pub T); pub(crate) struct RumaResponse<T>(pub(crate) T);
impl<T> From<T> for RumaResponse<T> { impl<T> From<T> for RumaResponse<T> {
fn from(t: T) -> Self { fn from(t: T) -> Self {

View file

@ -77,7 +77,7 @@ use tracing::{debug, error, warn};
/// # } /// # }
/// ``` /// ```
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum FedDest { pub(crate) enum FedDest {
Literal(SocketAddr), Literal(SocketAddr),
Named(String, String), Named(String, String),
} }
@ -524,7 +524,7 @@ async fn request_well_known(destination: &str) -> Option<String> {
/// # `GET /_matrix/federation/v1/version` /// # `GET /_matrix/federation/v1/version`
/// ///
/// Get version information on this server. /// Get version information on this server.
pub async fn get_server_version_route( pub(crate) async fn get_server_version_route(
_body: Ruma<get_server_version::v1::Request>, _body: Ruma<get_server_version::v1::Request>,
) -> Result<get_server_version::v1::Response> { ) -> Result<get_server_version::v1::Response> {
Ok(get_server_version::v1::Response { Ok(get_server_version::v1::Response {
@ -542,7 +542,7 @@ pub async fn get_server_version_route(
/// - Matrix does not support invalidating public keys, so the key returned by this will be valid /// - Matrix does not support invalidating public keys, so the key returned by this will be valid
/// forever. /// forever.
// Response type for this endpoint is Json because we need to calculate a signature for the response // Response type for this endpoint is Json because we need to calculate a signature for the response
pub async fn get_server_keys_route() -> Result<impl IntoResponse> { pub(crate) async fn get_server_keys_route() -> Result<impl IntoResponse> {
let mut verify_keys: BTreeMap<OwnedServerSigningKeyId, VerifyKey> = BTreeMap::new(); let mut verify_keys: BTreeMap<OwnedServerSigningKeyId, VerifyKey> = BTreeMap::new();
verify_keys.insert( verify_keys.insert(
format!("ed25519:{}", services().globals.keypair().version()) format!("ed25519:{}", services().globals.keypair().version())
@ -588,14 +588,14 @@ pub async fn get_server_keys_route() -> Result<impl IntoResponse> {
/// ///
/// - Matrix does not support invalidating public keys, so the key returned by this will be valid /// - Matrix does not support invalidating public keys, so the key returned by this will be valid
/// forever. /// forever.
pub async fn get_server_keys_deprecated_route() -> impl IntoResponse { pub(crate) async fn get_server_keys_deprecated_route() -> impl IntoResponse {
get_server_keys_route().await get_server_keys_route().await
} }
/// # `POST /_matrix/federation/v1/publicRooms` /// # `POST /_matrix/federation/v1/publicRooms`
/// ///
/// Lists the public rooms on this server. /// Lists the public rooms on this server.
pub async fn get_public_rooms_filtered_route( pub(crate) async fn get_public_rooms_filtered_route(
body: Ruma<get_public_rooms_filtered::v1::Request>, body: Ruma<get_public_rooms_filtered::v1::Request>,
) -> Result<get_public_rooms_filtered::v1::Response> { ) -> Result<get_public_rooms_filtered::v1::Response> {
let response = client_server::get_public_rooms_filtered_helper( let response = client_server::get_public_rooms_filtered_helper(
@ -618,7 +618,7 @@ pub async fn get_public_rooms_filtered_route(
/// # `GET /_matrix/federation/v1/publicRooms` /// # `GET /_matrix/federation/v1/publicRooms`
/// ///
/// Lists the public rooms on this server. /// Lists the public rooms on this server.
pub async fn get_public_rooms_route( pub(crate) async fn get_public_rooms_route(
body: Ruma<get_public_rooms::v1::Request>, body: Ruma<get_public_rooms::v1::Request>,
) -> Result<get_public_rooms::v1::Response> { ) -> Result<get_public_rooms::v1::Response> {
let response = client_server::get_public_rooms_filtered_helper( let response = client_server::get_public_rooms_filtered_helper(
@ -638,7 +638,7 @@ pub async fn get_public_rooms_route(
}) })
} }
pub fn parse_incoming_pdu( pub(crate) fn parse_incoming_pdu(
pdu: &RawJsonValue, pdu: &RawJsonValue,
) -> Result<(OwnedEventId, CanonicalJsonObject, OwnedRoomId)> { ) -> Result<(OwnedEventId, CanonicalJsonObject, OwnedRoomId)> {
let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| { let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| {
@ -672,7 +672,7 @@ pub fn parse_incoming_pdu(
/// # `PUT /_matrix/federation/v1/send/{txnId}` /// # `PUT /_matrix/federation/v1/send/{txnId}`
/// ///
/// Push EDUs and PDUs to this server. /// Push EDUs and PDUs to this server.
pub async fn send_transaction_message_route( pub(crate) async fn send_transaction_message_route(
body: Ruma<send_transaction_message::v1::Request>, body: Ruma<send_transaction_message::v1::Request>,
) -> Result<send_transaction_message::v1::Response> { ) -> Result<send_transaction_message::v1::Response> {
let sender_servername = body let sender_servername = body
@ -942,7 +942,7 @@ pub async fn send_transaction_message_route(
/// Retrieves a single event from the server. /// Retrieves a single event from the server.
/// ///
/// - Only works if a user of this server is currently invited or joined the room /// - Only works if a user of this server is currently invited or joined the room
pub async fn get_event_route( pub(crate) async fn get_event_route(
body: Ruma<get_event::v1::Request>, body: Ruma<get_event::v1::Request>,
) -> Result<get_event::v1::Response> { ) -> Result<get_event::v1::Response> {
let sender_servername = body let sender_servername = body
@ -1000,7 +1000,7 @@ pub async fn get_event_route(
/// ///
/// Retrieves events from before the sender joined the room, if the room's /// Retrieves events from before the sender joined the room, if the room's
/// history visibility allows. /// history visibility allows.
pub async fn get_backfill_route( pub(crate) async fn get_backfill_route(
body: Ruma<get_backfill::v1::Request>, body: Ruma<get_backfill::v1::Request>,
) -> Result<get_backfill::v1::Response> { ) -> Result<get_backfill::v1::Response> {
let sender_servername = body let sender_servername = body
@ -1072,7 +1072,7 @@ pub async fn get_backfill_route(
/// # `POST /_matrix/federation/v1/get_missing_events/{roomId}` /// # `POST /_matrix/federation/v1/get_missing_events/{roomId}`
/// ///
/// Retrieves events that the sender is missing. /// Retrieves events that the sender is missing.
pub async fn get_missing_events_route( pub(crate) async fn get_missing_events_route(
body: Ruma<get_missing_events::v1::Request>, body: Ruma<get_missing_events::v1::Request>,
) -> Result<get_missing_events::v1::Response> { ) -> Result<get_missing_events::v1::Response> {
let sender_servername = body let sender_servername = body
@ -1157,7 +1157,7 @@ pub async fn get_missing_events_route(
/// Retrieves the auth chain for a given event. /// Retrieves the auth chain for a given event.
/// ///
/// - This does not include the event itself /// - This does not include the event itself
pub async fn get_event_authorization_route( pub(crate) async fn get_event_authorization_route(
body: Ruma<get_event_authorization::v1::Request>, body: Ruma<get_event_authorization::v1::Request>,
) -> Result<get_event_authorization::v1::Response> { ) -> Result<get_event_authorization::v1::Response> {
let sender_servername = body let sender_servername = body
@ -1215,7 +1215,7 @@ pub async fn get_event_authorization_route(
/// # `GET /_matrix/federation/v1/state/{roomId}` /// # `GET /_matrix/federation/v1/state/{roomId}`
/// ///
/// Retrieves the current state of the room. /// Retrieves the current state of the room.
pub async fn get_room_state_route( pub(crate) async fn get_room_state_route(
body: Ruma<get_room_state::v1::Request>, body: Ruma<get_room_state::v1::Request>,
) -> Result<get_room_state::v1::Response> { ) -> Result<get_room_state::v1::Response> {
let sender_servername = body let sender_servername = body
@ -1291,7 +1291,7 @@ pub async fn get_room_state_route(
/// # `GET /_matrix/federation/v1/state_ids/{roomId}` /// # `GET /_matrix/federation/v1/state_ids/{roomId}`
/// ///
/// Retrieves the current state of the room. /// Retrieves the current state of the room.
pub async fn get_room_state_ids_route( pub(crate) async fn get_room_state_ids_route(
body: Ruma<get_room_state_ids::v1::Request>, body: Ruma<get_room_state_ids::v1::Request>,
) -> Result<get_room_state_ids::v1::Response> { ) -> Result<get_room_state_ids::v1::Response> {
let sender_servername = body let sender_servername = body
@ -1348,7 +1348,7 @@ pub async fn get_room_state_ids_route(
/// # `GET /_matrix/federation/v1/make_join/{roomId}/{userId}` /// # `GET /_matrix/federation/v1/make_join/{roomId}/{userId}`
/// ///
/// Creates a join template. /// Creates a join template.
pub async fn create_join_event_template_route( pub(crate) async fn create_join_event_template_route(
body: Ruma<prepare_join_event::v1::Request>, body: Ruma<prepare_join_event::v1::Request>,
) -> Result<prepare_join_event::v1::Response> { ) -> Result<prepare_join_event::v1::Response> {
if !services().rooms.metadata.exists(&body.room_id)? { if !services().rooms.metadata.exists(&body.room_id)? {
@ -1592,7 +1592,7 @@ async fn create_join_event(
/// # `PUT /_matrix/federation/v1/send_join/{roomId}/{eventId}` /// # `PUT /_matrix/federation/v1/send_join/{roomId}/{eventId}`
/// ///
/// Submits a signed join event. /// Submits a signed join event.
pub async fn create_join_event_v1_route( pub(crate) async fn create_join_event_v1_route(
body: Ruma<create_join_event::v1::Request>, body: Ruma<create_join_event::v1::Request>,
) -> Result<create_join_event::v1::Response> { ) -> Result<create_join_event::v1::Response> {
let sender_servername = body let sender_servername = body
@ -1608,7 +1608,7 @@ pub async fn create_join_event_v1_route(
/// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}` /// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}`
/// ///
/// Submits a signed join event. /// Submits a signed join event.
pub async fn create_join_event_v2_route( pub(crate) async fn create_join_event_v2_route(
body: Ruma<create_join_event::v2::Request>, body: Ruma<create_join_event::v2::Request>,
) -> Result<create_join_event::v2::Response> { ) -> Result<create_join_event::v2::Response> {
let sender_servername = body let sender_servername = body
@ -1635,7 +1635,7 @@ pub async fn create_join_event_v2_route(
/// # `PUT /_matrix/federation/v2/invite/{roomId}/{eventId}` /// # `PUT /_matrix/federation/v2/invite/{roomId}/{eventId}`
/// ///
/// Invites a remote user to a room. /// Invites a remote user to a room.
pub async fn create_invite_route( pub(crate) async fn create_invite_route(
body: Ruma<create_invite::v2::Request>, body: Ruma<create_invite::v2::Request>,
) -> Result<create_invite::v2::Response> { ) -> Result<create_invite::v2::Response> {
let sender_servername = body let sender_servername = body
@ -1748,7 +1748,7 @@ pub async fn create_invite_route(
/// # `GET /_matrix/federation/v1/user/devices/{userId}` /// # `GET /_matrix/federation/v1/user/devices/{userId}`
/// ///
/// Gets information on all devices of the user. /// Gets information on all devices of the user.
pub async fn get_devices_route( pub(crate) async fn get_devices_route(
body: Ruma<get_devices::v1::Request>, body: Ruma<get_devices::v1::Request>,
) -> Result<get_devices::v1::Response> { ) -> Result<get_devices::v1::Response> {
if body.user_id.server_name() != services().globals.server_name() { if body.user_id.server_name() != services().globals.server_name() {
@ -1800,7 +1800,7 @@ pub async fn get_devices_route(
/// # `GET /_matrix/federation/v1/query/directory` /// # `GET /_matrix/federation/v1/query/directory`
/// ///
/// Resolve a room alias to a room id. /// Resolve a room alias to a room id.
pub async fn get_room_information_route( pub(crate) async fn get_room_information_route(
body: Ruma<get_room_information::v1::Request>, body: Ruma<get_room_information::v1::Request>,
) -> Result<get_room_information::v1::Response> { ) -> Result<get_room_information::v1::Response> {
let room_id = services() let room_id = services()
@ -1821,7 +1821,7 @@ pub async fn get_room_information_route(
/// # `GET /_matrix/federation/v1/query/profile` /// # `GET /_matrix/federation/v1/query/profile`
/// ///
/// Gets information on a profile. /// Gets information on a profile.
pub async fn get_profile_information_route( pub(crate) async fn get_profile_information_route(
body: Ruma<get_profile_information::v1::Request>, body: Ruma<get_profile_information::v1::Request>,
) -> Result<get_profile_information::v1::Response> { ) -> Result<get_profile_information::v1::Response> {
if body.user_id.server_name() != services().globals.server_name() { if body.user_id.server_name() != services().globals.server_name() {
@ -1862,7 +1862,9 @@ pub async fn get_profile_information_route(
/// # `POST /_matrix/federation/v1/user/keys/query` /// # `POST /_matrix/federation/v1/user/keys/query`
/// ///
/// Gets devices and identity keys for the given users. /// Gets devices and identity keys for the given users.
pub async fn get_keys_route(body: Ruma<get_keys::v1::Request>) -> Result<get_keys::v1::Response> { pub(crate) async fn get_keys_route(
body: Ruma<get_keys::v1::Request>,
) -> Result<get_keys::v1::Response> {
if body if body
.device_keys .device_keys
.iter() .iter()
@ -1889,7 +1891,7 @@ pub async fn get_keys_route(body: Ruma<get_keys::v1::Request>) -> Result<get_key
/// # `POST /_matrix/federation/v1/user/keys/claim` /// # `POST /_matrix/federation/v1/user/keys/claim`
/// ///
/// Claims one-time keys. /// Claims one-time keys.
pub async fn claim_keys_route( pub(crate) async fn claim_keys_route(
body: Ruma<claim_keys::v1::Request>, body: Ruma<claim_keys::v1::Request>,
) -> Result<claim_keys::v1::Response> { ) -> Result<claim_keys::v1::Response> {
if body if body

View file

@ -19,9 +19,9 @@ fn version() -> String {
/// Command line arguments /// Command line arguments
#[derive(Parser)] #[derive(Parser)]
#[clap(about, version = version())] #[clap(about, version = version())]
pub struct Args {} pub(crate) struct Args {}
/// Parse command line arguments into structured data /// Parse command line arguments into structured data
pub fn parse() -> Args { pub(crate) fn parse() -> Args {
Args::parse() Args::parse()
} }

View file

@ -13,84 +13,84 @@ mod proxy;
use self::proxy::ProxyConfig; use self::proxy::ProxyConfig;
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub struct Config { pub(crate) struct Config {
#[serde(default = "default_address")] #[serde(default = "default_address")]
pub address: IpAddr, pub(crate) address: IpAddr,
#[serde(default = "default_port")] #[serde(default = "default_port")]
pub port: u16, pub(crate) port: u16,
pub tls: Option<TlsConfig>, pub(crate) tls: Option<TlsConfig>,
pub server_name: OwnedServerName, pub(crate) server_name: OwnedServerName,
pub database_backend: String, pub(crate) database_backend: String,
pub database_path: String, pub(crate) database_path: String,
#[serde(default = "default_db_cache_capacity_mb")] #[serde(default = "default_db_cache_capacity_mb")]
pub db_cache_capacity_mb: f64, pub(crate) db_cache_capacity_mb: f64,
#[serde(default = "default_cache_capacity_modifier")] #[serde(default = "default_cache_capacity_modifier")]
pub cache_capacity_modifier: f64, pub(crate) cache_capacity_modifier: f64,
#[serde(default = "default_rocksdb_max_open_files")] #[serde(default = "default_rocksdb_max_open_files")]
pub rocksdb_max_open_files: i32, pub(crate) rocksdb_max_open_files: i32,
#[serde(default = "default_pdu_cache_capacity")] #[serde(default = "default_pdu_cache_capacity")]
pub pdu_cache_capacity: u32, pub(crate) pdu_cache_capacity: u32,
#[serde(default = "default_cleanup_second_interval")] #[serde(default = "default_cleanup_second_interval")]
pub cleanup_second_interval: u32, pub(crate) cleanup_second_interval: u32,
#[serde(default = "default_max_request_size")] #[serde(default = "default_max_request_size")]
pub max_request_size: u32, pub(crate) max_request_size: u32,
#[serde(default = "default_max_concurrent_requests")] #[serde(default = "default_max_concurrent_requests")]
pub max_concurrent_requests: u16, pub(crate) max_concurrent_requests: u16,
#[serde(default = "default_max_fetch_prev_events")] #[serde(default = "default_max_fetch_prev_events")]
pub max_fetch_prev_events: u16, pub(crate) max_fetch_prev_events: u16,
#[serde(default = "false_fn")] #[serde(default = "false_fn")]
pub allow_registration: bool, pub(crate) allow_registration: bool,
pub registration_token: Option<String>, pub(crate) registration_token: Option<String>,
#[serde(default = "true_fn")] #[serde(default = "true_fn")]
pub allow_encryption: bool, pub(crate) allow_encryption: bool,
#[serde(default = "false_fn")] #[serde(default = "false_fn")]
pub allow_federation: bool, pub(crate) allow_federation: bool,
#[serde(default = "true_fn")] #[serde(default = "true_fn")]
pub allow_room_creation: bool, pub(crate) allow_room_creation: bool,
#[serde(default = "true_fn")] #[serde(default = "true_fn")]
pub allow_unstable_room_versions: bool, pub(crate) allow_unstable_room_versions: bool,
#[serde(default = "default_default_room_version")] #[serde(default = "default_default_room_version")]
pub default_room_version: RoomVersionId, pub(crate) default_room_version: RoomVersionId,
pub well_known_client: Option<String>, pub(crate) well_known_client: Option<String>,
#[serde(default = "false_fn")] #[serde(default = "false_fn")]
pub allow_jaeger: bool, pub(crate) allow_jaeger: bool,
#[serde(default = "false_fn")] #[serde(default = "false_fn")]
pub tracing_flame: bool, pub(crate) tracing_flame: bool,
#[serde(default)] #[serde(default)]
pub proxy: ProxyConfig, pub(crate) proxy: ProxyConfig,
pub jwt_secret: Option<String>, pub(crate) jwt_secret: Option<String>,
#[serde(default = "default_trusted_servers")] #[serde(default = "default_trusted_servers")]
pub trusted_servers: Vec<OwnedServerName>, pub(crate) trusted_servers: Vec<OwnedServerName>,
#[serde(default = "default_log")] #[serde(default = "default_log")]
pub log: String, pub(crate) log: String,
#[serde(default)] #[serde(default)]
pub turn_username: String, pub(crate) turn_username: String,
#[serde(default)] #[serde(default)]
pub turn_password: String, pub(crate) turn_password: String,
#[serde(default = "Vec::new")] #[serde(default = "Vec::new")]
pub turn_uris: Vec<String>, pub(crate) turn_uris: Vec<String>,
#[serde(default)] #[serde(default)]
pub turn_secret: String, pub(crate) turn_secret: String,
#[serde(default = "default_turn_ttl")] #[serde(default = "default_turn_ttl")]
pub turn_ttl: u64, pub(crate) turn_ttl: u64,
pub emergency_password: Option<String>, pub(crate) emergency_password: Option<String>,
#[serde(flatten)] #[serde(flatten)]
pub catchall: BTreeMap<String, IgnoredAny>, pub(crate) catchall: BTreeMap<String, IgnoredAny>,
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub struct TlsConfig { pub(crate) struct TlsConfig {
pub certs: String, pub(crate) certs: String,
pub key: String, pub(crate) key: String,
} }
const DEPRECATED_KEYS: &[&str] = &["cache_capacity"]; const DEPRECATED_KEYS: &[&str] = &["cache_capacity"];
impl Config { impl Config {
pub fn warn_deprecated(&self) { pub(crate) fn warn_deprecated(&self) {
let mut was_deprecated = false; let mut was_deprecated = false;
for key in self for key in self
.catchall .catchall
@ -259,6 +259,6 @@ fn default_turn_ttl() -> u64 {
} }
// I know, it's a great name // I know, it's a great name
pub fn default_default_room_version() -> RoomVersionId { pub(crate) fn default_default_room_version() -> RoomVersionId {
RoomVersionId::V10 RoomVersionId::V10
} }

View file

@ -30,7 +30,7 @@ use crate::Result;
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
#[derive(Default)] #[derive(Default)]
pub enum ProxyConfig { pub(crate) enum ProxyConfig {
#[default] #[default]
None, None,
Global { Global {
@ -40,7 +40,7 @@ pub enum ProxyConfig {
ByDomain(Vec<PartialProxyConfig>), ByDomain(Vec<PartialProxyConfig>),
} }
impl ProxyConfig { impl ProxyConfig {
pub fn to_proxy(&self) -> Result<Option<Proxy>> { pub(crate) fn to_proxy(&self) -> Result<Option<Proxy>> {
Ok(match self.clone() { Ok(match self.clone() {
ProxyConfig::None => None, ProxyConfig::None => None,
ProxyConfig::Global { url } => Some(Proxy::all(url)?), ProxyConfig::Global { url } => Some(Proxy::all(url)?),
@ -52,7 +52,7 @@ impl ProxyConfig {
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub struct PartialProxyConfig { pub(crate) struct PartialProxyConfig {
#[serde(deserialize_with = "crate::utils::deserialize_from_str")] #[serde(deserialize_with = "crate::utils::deserialize_from_str")]
url: Url, url: Url,
#[serde(default)] #[serde(default)]
@ -61,7 +61,7 @@ pub struct PartialProxyConfig {
exclude: Vec<WildCardedDomain>, exclude: Vec<WildCardedDomain>,
} }
impl PartialProxyConfig { impl PartialProxyConfig {
pub fn for_url(&self, url: &Url) -> Option<&Url> { pub(crate) fn for_url(&self, url: &Url) -> Option<&Url> {
let domain = url.domain()?; let domain = url.domain()?;
let mut included_because = None; // most specific reason it was included let mut included_because = None; // most specific reason it was included
let mut excluded_because = None; // most specific reason it was excluded let mut excluded_because = None; // most specific reason it was excluded
@ -95,20 +95,20 @@ impl PartialProxyConfig {
/// A domain name, that optionally allows a * as its first subdomain. /// A domain name, that optionally allows a * as its first subdomain.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum WildCardedDomain { pub(crate) enum WildCardedDomain {
WildCard, WildCard,
WildCarded(String), WildCarded(String),
Exact(String), Exact(String),
} }
impl WildCardedDomain { impl WildCardedDomain {
pub fn matches(&self, domain: &str) -> bool { pub(crate) fn matches(&self, domain: &str) -> bool {
match self { match self {
WildCardedDomain::WildCard => true, WildCardedDomain::WildCard => true,
WildCardedDomain::WildCarded(d) => domain.ends_with(d), WildCardedDomain::WildCarded(d) => domain.ends_with(d),
WildCardedDomain::Exact(d) => domain == d, WildCardedDomain::Exact(d) => domain == d,
} }
} }
pub fn more_specific_than(&self, other: &Self) -> bool { pub(crate) fn more_specific_than(&self, other: &Self) -> bool {
match (self, other) { match (self, other) {
(WildCardedDomain::WildCard, WildCardedDomain::WildCard) => false, (WildCardedDomain::WildCard, WildCardedDomain::WildCard) => false,
(_, WildCardedDomain::WildCard) => true, (_, WildCardedDomain::WildCard) => true,

View file

@ -1,5 +1,5 @@
pub mod abstraction; pub(crate) mod abstraction;
pub mod key_value; pub(crate) mod key_value;
use crate::{ use crate::{
service::rooms::timeline::PduCount, services, utils, Config, Error, PduEvent, Result, Services, service::rooms::timeline::PduCount, services, utils, Config, Error, PduEvent, Result, Services,
@ -29,14 +29,14 @@ use std::{
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info, warn};
pub struct KeyValueDatabase { pub(crate) struct KeyValueDatabase {
_db: Arc<dyn KeyValueDatabaseEngine>, _db: Arc<dyn KeyValueDatabaseEngine>,
//pub globals: globals::Globals, //pub(crate) globals: globals::Globals,
pub(super) global: Arc<dyn KvTree>, pub(super) global: Arc<dyn KvTree>,
pub(super) server_signingkeys: Arc<dyn KvTree>, pub(super) server_signingkeys: Arc<dyn KvTree>,
//pub users: users::Users, //pub(crate) users: users::Users,
pub(super) userid_password: Arc<dyn KvTree>, pub(super) userid_password: Arc<dyn KvTree>,
pub(super) userid_displayname: Arc<dyn KvTree>, pub(super) userid_displayname: Arc<dyn KvTree>,
pub(super) userid_avatarurl: Arc<dyn KvTree>, pub(super) userid_avatarurl: Arc<dyn KvTree>,
@ -58,12 +58,12 @@ pub struct KeyValueDatabase {
pub(super) todeviceid_events: Arc<dyn KvTree>, // ToDeviceId = UserId + DeviceId + Count pub(super) todeviceid_events: Arc<dyn KvTree>, // ToDeviceId = UserId + DeviceId + Count
//pub uiaa: uiaa::Uiaa, //pub(crate) uiaa: uiaa::Uiaa,
pub(super) userdevicesessionid_uiaainfo: Arc<dyn KvTree>, // User-interactive authentication pub(super) userdevicesessionid_uiaainfo: Arc<dyn KvTree>, // User-interactive authentication
pub(super) userdevicesessionid_uiaarequest: pub(super) userdevicesessionid_uiaarequest:
RwLock<BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>>, RwLock<BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>>,
//pub edus: RoomEdus, //pub(crate) edus: RoomEdus,
pub(super) readreceiptid_readreceipt: Arc<dyn KvTree>, // ReadReceiptId = RoomId + Count + UserId pub(super) readreceiptid_readreceipt: Arc<dyn KvTree>, // ReadReceiptId = RoomId + Count + UserId
pub(super) roomuserid_privateread: Arc<dyn KvTree>, // RoomUserId = Room + User, PrivateRead = Count pub(super) roomuserid_privateread: Arc<dyn KvTree>, // RoomUserId = Room + User, PrivateRead = Count
pub(super) roomuserid_lastprivatereadupdate: Arc<dyn KvTree>, // LastPrivateReadUpdate = Count pub(super) roomuserid_lastprivatereadupdate: Arc<dyn KvTree>, // LastPrivateReadUpdate = Count
@ -74,7 +74,7 @@ pub struct KeyValueDatabase {
#[allow(dead_code)] #[allow(dead_code)]
pub(super) userid_lastpresenceupdate: Arc<dyn KvTree>, // LastPresenceUpdate = Count pub(super) userid_lastpresenceupdate: Arc<dyn KvTree>, // LastPresenceUpdate = Count
//pub rooms: rooms::Rooms, //pub(crate) rooms: rooms::Rooms,
pub(super) pduid_pdu: Arc<dyn KvTree>, // PduId = ShortRoomId + Count pub(super) pduid_pdu: Arc<dyn KvTree>, // PduId = ShortRoomId + Count
pub(super) eventid_pduid: Arc<dyn KvTree>, pub(super) eventid_pduid: Arc<dyn KvTree>,
pub(super) roomid_pduleaves: Arc<dyn KvTree>, pub(super) roomid_pduleaves: Arc<dyn KvTree>,
@ -137,28 +137,28 @@ pub struct KeyValueDatabase {
/// RoomId + EventId -> Parent PDU EventId. /// RoomId + EventId -> Parent PDU EventId.
pub(super) referencedevents: Arc<dyn KvTree>, pub(super) referencedevents: Arc<dyn KvTree>,
//pub account_data: account_data::AccountData, //pub(crate) account_data: account_data::AccountData,
pub(super) roomuserdataid_accountdata: Arc<dyn KvTree>, // RoomUserDataId = Room + User + Count + Type pub(super) roomuserdataid_accountdata: Arc<dyn KvTree>, // RoomUserDataId = Room + User + Count + Type
pub(super) roomusertype_roomuserdataid: Arc<dyn KvTree>, // RoomUserType = Room + User + Type pub(super) roomusertype_roomuserdataid: Arc<dyn KvTree>, // RoomUserType = Room + User + Type
//pub media: media::Media, //pub(crate) media: media::Media,
pub(super) mediaid_file: Arc<dyn KvTree>, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType pub(super) mediaid_file: Arc<dyn KvTree>, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType
//pub key_backups: key_backups::KeyBackups, //pub(crate) key_backups: key_backups::KeyBackups,
pub(super) backupid_algorithm: Arc<dyn KvTree>, // BackupId = UserId + Version(Count) pub(super) backupid_algorithm: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
pub(super) backupid_etag: Arc<dyn KvTree>, // BackupId = UserId + Version(Count) pub(super) backupid_etag: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
pub(super) backupkeyid_backup: Arc<dyn KvTree>, // BackupKeyId = UserId + Version + RoomId + SessionId pub(super) backupkeyid_backup: Arc<dyn KvTree>, // BackupKeyId = UserId + Version + RoomId + SessionId
//pub transaction_ids: transaction_ids::TransactionIds, //pub(crate) transaction_ids: transaction_ids::TransactionIds,
pub(super) userdevicetxnid_response: Arc<dyn KvTree>, // Response can be empty (/sendToDevice) or the event id (/send) pub(super) userdevicetxnid_response: Arc<dyn KvTree>, // Response can be empty (/sendToDevice) or the event id (/send)
//pub sending: sending::Sending, //pub(crate) sending: sending::Sending,
pub(super) servername_educount: Arc<dyn KvTree>, // EduCount: Count of last EDU sync pub(super) servername_educount: Arc<dyn KvTree>, // EduCount: Count of last EDU sync
pub(super) servernameevent_data: Arc<dyn KvTree>, // ServernameEvent = (+ / $)SenderKey / ServerName / UserId + PduId / Id (for edus), Data = EDU content pub(super) servernameevent_data: Arc<dyn KvTree>, // ServernameEvent = (+ / $)SenderKey / ServerName / UserId + PduId / Id (for edus), Data = EDU content
pub(super) servercurrentevent_data: Arc<dyn KvTree>, // ServerCurrentEvents = (+ / $)ServerName / UserId + PduId / Id (for edus), Data = EDU content pub(super) servercurrentevent_data: Arc<dyn KvTree>, // ServerCurrentEvents = (+ / $)ServerName / UserId + PduId / Id (for edus), Data = EDU content
//pub appservice: appservice::Appservice, //pub(crate) appservice: appservice::Appservice,
pub(super) id_appserviceregistrations: Arc<dyn KvTree>, pub(super) id_appserviceregistrations: Arc<dyn KvTree>,
//pub pusher: pusher::PushData, //pub(crate) pusher: pusher::PushData,
pub(super) senderkey_pusher: Arc<dyn KvTree>, pub(super) senderkey_pusher: Arc<dyn KvTree>,
pub(super) pdu_cache: Mutex<LruCache<OwnedEventId, Arc<PduEvent>>>, pub(super) pdu_cache: Mutex<LruCache<OwnedEventId, Arc<PduEvent>>>,
@ -214,7 +214,7 @@ impl KeyValueDatabase {
not(any(feature = "rocksdb", feature = "sqlite")), not(any(feature = "rocksdb", feature = "sqlite")),
allow(unreachable_code) allow(unreachable_code)
)] )]
pub async fn load_or_create(config: Config) -> Result<()> { pub(crate) async fn load_or_create(config: Config) -> Result<()> {
Self::check_db_setup(&config)?; Self::check_db_setup(&config)?;
if !Path::new(&config.database_path).exists() { if !Path::new(&config.database_path).exists() {
@ -959,7 +959,7 @@ impl KeyValueDatabase {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn flush(&self) -> Result<()> { pub(crate) fn flush(&self) -> Result<()> {
let start = std::time::Instant::now(); let start = std::time::Instant::now();
let res = self._db.flush(); let res = self._db.flush();
@ -970,7 +970,7 @@ impl KeyValueDatabase {
} }
#[tracing::instrument] #[tracing::instrument]
pub async fn start_cleanup_task() { pub(crate) async fn start_cleanup_task() {
use tokio::time::interval; use tokio::time::interval;
#[cfg(unix)] #[cfg(unix)]

View file

@ -4,15 +4,15 @@ use crate::Result;
use std::{future::Future, pin::Pin, sync::Arc}; use std::{future::Future, pin::Pin, sync::Arc};
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
pub mod sqlite; pub(crate) mod sqlite;
#[cfg(feature = "rocksdb")] #[cfg(feature = "rocksdb")]
pub mod rocksdb; pub(crate) mod rocksdb;
#[cfg(any(feature = "sqlite", feature = "rocksdb",))] #[cfg(any(feature = "sqlite", feature = "rocksdb",))]
pub mod watchers; pub(crate) mod watchers;
pub trait KeyValueDatabaseEngine: Send + Sync { pub(crate) trait KeyValueDatabaseEngine: Send + Sync {
fn open(config: &Config) -> Result<Self> fn open(config: &Config) -> Result<Self>
where where
Self: Sized; Self: Sized;
@ -27,7 +27,7 @@ pub trait KeyValueDatabaseEngine: Send + Sync {
fn clear_caches(&self) {} fn clear_caches(&self) {}
} }
pub trait KvTree: Send + Sync { pub(crate) trait KvTree: Send + Sync {
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>; fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>; fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;

View file

@ -6,14 +6,14 @@ use std::{
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
pub struct Engine { pub(crate) struct Engine {
rocks: rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>, rocks: rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>,
max_open_files: i32, max_open_files: i32,
cache: rocksdb::Cache, cache: rocksdb::Cache,
old_cfs: Vec<String>, old_cfs: Vec<String>,
} }
pub struct RocksDbEngineTree<'a> { pub(crate) struct RocksDbEngineTree<'a> {
db: Arc<Engine>, db: Arc<Engine>,
name: &'a str, name: &'a str,
watchers: Watchers, watchers: Watchers,

View file

@ -18,8 +18,8 @@ thread_local! {
} }
struct PreparedStatementIterator<'a> { struct PreparedStatementIterator<'a> {
pub iterator: Box<dyn Iterator<Item = TupleOfBytes> + 'a>, pub(crate) iterator: Box<dyn Iterator<Item = TupleOfBytes> + 'a>,
pub _statement_ref: NonAliasingBox<rusqlite::Statement<'a>>, pub(crate) _statement_ref: NonAliasingBox<rusqlite::Statement<'a>>,
} }
impl Iterator for PreparedStatementIterator<'_> { impl Iterator for PreparedStatementIterator<'_> {
@ -37,7 +37,7 @@ impl<T> Drop for NonAliasingBox<T> {
} }
} }
pub struct Engine { pub(crate) struct Engine {
writer: Mutex<Connection>, writer: Mutex<Connection>,
read_conn_tls: ThreadLocal<Connection>, read_conn_tls: ThreadLocal<Connection>,
read_iterator_conn_tls: ThreadLocal<Connection>, read_iterator_conn_tls: ThreadLocal<Connection>,
@ -73,7 +73,7 @@ impl Engine {
.get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap()) .get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap())
} }
pub fn flush_wal(self: &Arc<Self>) -> Result<()> { pub(crate) fn flush_wal(self: &Arc<Self>) -> Result<()> {
self.write_lock() self.write_lock()
.pragma_update(Some(Main), "wal_checkpoint", "RESTART")?; .pragma_update(Some(Main), "wal_checkpoint", "RESTART")?;
Ok(()) Ok(())
@ -125,7 +125,7 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
} }
} }
pub struct SqliteTable { pub(crate) struct SqliteTable {
engine: Arc<Engine>, engine: Arc<Engine>,
name: String, name: String,
watchers: Watchers, watchers: Watchers,
@ -153,7 +153,7 @@ impl SqliteTable {
Ok(()) Ok(())
} }
pub fn iter_with_guard<'a>( pub(crate) fn iter_with_guard<'a>(
&'a self, &'a self,
guard: &'a Connection, guard: &'a Connection,
) -> Box<dyn Iterator<Item = TupleOfBytes> + 'a> { ) -> Box<dyn Iterator<Item = TupleOfBytes> + 'a> {

View file

@ -11,7 +11,7 @@ use ruma::{
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
pub const COUNTER: &[u8] = b"c"; pub(crate) const COUNTER: &[u8] = b"c";
#[async_trait] #[async_trait]
impl service::globals::Data for KeyValueDatabase { impl service::globals::Data for KeyValueDatabase {

View file

@ -38,19 +38,19 @@ use tower_http::{
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info, warn};
use tracing_subscriber::{prelude::*, EnvFilter}; use tracing_subscriber::{prelude::*, EnvFilter};
pub mod api; pub(crate) mod api;
pub mod clap; pub(crate) mod clap;
mod config; mod config;
mod database; mod database;
mod service; mod service;
mod utils; mod utils;
pub use api::ruma_wrapper::{Ruma, RumaResponse}; pub(crate) use api::ruma_wrapper::{Ruma, RumaResponse};
use api::{client_server, server_server}; use api::{client_server, server_server};
pub use config::Config; pub(crate) use config::Config;
pub use database::KeyValueDatabase; pub(crate) use database::KeyValueDatabase;
pub use service::{pdu::PduEvent, Services}; pub(crate) use service::{pdu::PduEvent, Services};
pub use utils::error::{Error, Result}; pub(crate) use utils::error::{Error, Result};
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
use tikv_jemallocator::Jemalloc; use tikv_jemallocator::Jemalloc;
@ -59,12 +59,12 @@ use tikv_jemallocator::Jemalloc;
#[global_allocator] #[global_allocator]
static GLOBAL: Jemalloc = Jemalloc; static GLOBAL: Jemalloc = Jemalloc;
pub static SERVICES: RwLock<Option<&'static Services>> = RwLock::new(None); pub(crate) static SERVICES: RwLock<Option<&'static Services>> = RwLock::new(None);
// Not async due to services() being used in many closures, and async closures are not stable as of writing // Not async due to services() being used in many closures, and async closures are not stable as of writing
// This is the case for every other occurence of sync Mutex/RwLock, except for database related ones, where // This is the case for every other occurence of sync Mutex/RwLock, except for database related ones, where
// the previous maintainer has asked to not modify those // the previous maintainer has asked to not modify those
pub fn services() -> &'static Services { pub(crate) fn services() -> &'static Services {
SERVICES SERVICES
.read() .read()
.unwrap() .unwrap()
@ -534,7 +534,7 @@ impl RouterExt for Router {
} }
} }
pub trait RumaHandler<T> { pub(crate) trait RumaHandler<T> {
// Can't transform to a handler without boxing or relying on the nightly-only // Can't transform to a handler without boxing or relying on the nightly-only
// impl-trait-in-traits feature. Moving a small amount of extra logic into the trait // impl-trait-in-traits feature. Moving a small amount of extra logic into the trait
// allows bypassing both. // allows bypassing both.

View file

@ -9,37 +9,37 @@ use tokio::sync::{broadcast, Mutex};
use crate::{Config, Result}; use crate::{Config, Result};
use tokio::sync::RwLock; use tokio::sync::RwLock;
pub mod account_data; pub(crate) mod account_data;
pub mod admin; pub(crate) mod admin;
pub mod appservice; pub(crate) mod appservice;
pub mod globals; pub(crate) mod globals;
pub mod key_backups; pub(crate) mod key_backups;
pub mod media; pub(crate) mod media;
pub mod pdu; pub(crate) mod pdu;
pub mod pusher; pub(crate) mod pusher;
pub mod rooms; pub(crate) mod rooms;
pub mod sending; pub(crate) mod sending;
pub mod transaction_ids; pub(crate) mod transaction_ids;
pub mod uiaa; pub(crate) mod uiaa;
pub mod users; pub(crate) mod users;
pub struct Services { pub(crate) struct Services {
pub appservice: appservice::Service, pub(crate) appservice: appservice::Service,
pub pusher: pusher::Service, pub(crate) pusher: pusher::Service,
pub rooms: rooms::Service, pub(crate) rooms: rooms::Service,
pub transaction_ids: transaction_ids::Service, pub(crate) transaction_ids: transaction_ids::Service,
pub uiaa: uiaa::Service, pub(crate) uiaa: uiaa::Service,
pub users: users::Service, pub(crate) users: users::Service,
pub account_data: account_data::Service, pub(crate) account_data: account_data::Service,
pub admin: Arc<admin::Service>, pub(crate) admin: Arc<admin::Service>,
pub globals: globals::Service, pub(crate) globals: globals::Service,
pub key_backups: key_backups::Service, pub(crate) key_backups: key_backups::Service,
pub media: media::Service, pub(crate) media: media::Service,
pub sending: Arc<sending::Service>, pub(crate) sending: Arc<sending::Service>,
} }
impl Services { impl Services {
pub fn build< pub(crate) fn build<
D: appservice::Data D: appservice::Data
+ pusher::Data + pusher::Data
+ rooms::Data + rooms::Data

View file

@ -1,6 +1,6 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use ruma::{ use ruma::{
events::{AnyEphemeralRoomEvent, RoomAccountDataEventType}, events::{AnyEphemeralRoomEvent, RoomAccountDataEventType},
@ -12,14 +12,14 @@ use std::collections::HashMap;
use crate::Result; use crate::Result;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
/// Places one event in the account data of the user and removes the previous entry. /// 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))] #[tracing::instrument(skip(self, room_id, user_id, event_type, data))]
pub fn update( pub(crate) fn update(
&self, &self,
room_id: Option<&RoomId>, room_id: Option<&RoomId>,
user_id: &UserId, user_id: &UserId,
@ -31,7 +31,7 @@ impl Service {
/// Searches the account data for a specific kind. /// Searches the account data for a specific kind.
#[tracing::instrument(skip(self, room_id, user_id, event_type))] #[tracing::instrument(skip(self, room_id, user_id, event_type))]
pub fn get( pub(crate) fn get(
&self, &self,
room_id: Option<&RoomId>, room_id: Option<&RoomId>,
user_id: &UserId, user_id: &UserId,
@ -42,7 +42,7 @@ impl Service {
/// Returns all changes to the account data that happened after `since`. /// Returns all changes to the account data that happened after `since`.
#[tracing::instrument(skip(self, room_id, user_id, since))] #[tracing::instrument(skip(self, room_id, user_id, since))]
pub fn changes_since( pub(crate) fn changes_since(
&self, &self,
room_id: Option<&RoomId>, room_id: Option<&RoomId>,
user_id: &UserId, user_id: &UserId,

View file

@ -7,7 +7,7 @@ use ruma::{
RoomId, UserId, RoomId, UserId,
}; };
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
/// Places one event in the account data of the user and removes the previous entry. /// Places one event in the account data of the user and removes the previous entry.
fn update( fn update(
&self, &self,

View file

@ -181,18 +181,18 @@ enum AdminCommand {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AdminRoomEvent { pub(crate) enum AdminRoomEvent {
ProcessMessage(String), ProcessMessage(String),
SendMessage(RoomMessageEventContent), SendMessage(RoomMessageEventContent),
} }
pub struct Service { pub(crate) struct Service {
pub sender: mpsc::UnboundedSender<AdminRoomEvent>, pub(crate) sender: mpsc::UnboundedSender<AdminRoomEvent>,
receiver: Mutex<mpsc::UnboundedReceiver<AdminRoomEvent>>, receiver: Mutex<mpsc::UnboundedReceiver<AdminRoomEvent>>,
} }
impl Service { impl Service {
pub fn build() -> Arc<Self> { pub(crate) fn build() -> Arc<Self> {
let (sender, receiver) = mpsc::unbounded_channel(); let (sender, receiver) = mpsc::unbounded_channel();
Arc::new(Self { Arc::new(Self {
sender, sender,
@ -200,7 +200,7 @@ impl Service {
}) })
} }
pub fn start_handler(self: &Arc<Self>) { pub(crate) fn start_handler(self: &Arc<Self>) {
let self2 = Arc::clone(self); let self2 = Arc::clone(self);
tokio::spawn(async move { tokio::spawn(async move {
self2.handler().await; self2.handler().await;
@ -259,13 +259,13 @@ impl Service {
} }
} }
pub fn process_message(&self, room_message: String) { pub(crate) fn process_message(&self, room_message: String) {
self.sender self.sender
.send(AdminRoomEvent::ProcessMessage(room_message)) .send(AdminRoomEvent::ProcessMessage(room_message))
.unwrap(); .unwrap();
} }
pub fn send_message(&self, message_content: RoomMessageEventContent) { pub(crate) fn send_message(&self, message_content: RoomMessageEventContent) {
self.sender self.sender
.send(AdminRoomEvent::SendMessage(message_content)) .send(AdminRoomEvent::SendMessage(message_content))
.unwrap(); .unwrap();

View file

@ -2,7 +2,7 @@ mod data;
use std::collections::BTreeMap; use std::collections::BTreeMap;
pub use data::Data; pub(crate) use data::Data;
use futures_util::Future; use futures_util::Future;
use regex::RegexSet; use regex::RegexSet;
@ -16,14 +16,14 @@ use crate::{services, Result};
/// Compiled regular expressions for a namespace. /// Compiled regular expressions for a namespace.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct NamespaceRegex { pub(crate) struct NamespaceRegex {
pub exclusive: Option<RegexSet>, pub(crate) exclusive: Option<RegexSet>,
pub non_exclusive: Option<RegexSet>, pub(crate) non_exclusive: Option<RegexSet>,
} }
impl NamespaceRegex { impl NamespaceRegex {
/// Checks if this namespace has rights to a namespace /// Checks if this namespace has rights to a namespace
pub fn is_match(&self, heystack: &str) -> bool { pub(crate) fn is_match(&self, heystack: &str) -> bool {
if self.is_exclusive_match(heystack) { if self.is_exclusive_match(heystack) {
return true; return true;
} }
@ -37,7 +37,7 @@ impl NamespaceRegex {
} }
/// Checks if this namespace has exlusive rights to a namespace /// Checks if this namespace has exlusive rights to a namespace
pub fn is_exclusive_match(&self, heystack: &str) -> bool { pub(crate) fn is_exclusive_match(&self, heystack: &str) -> bool {
if let Some(exclusive) = &self.exclusive { if let Some(exclusive) = &self.exclusive {
if exclusive.is_match(heystack) { if exclusive.is_match(heystack) {
return true; return true;
@ -79,20 +79,20 @@ impl TryFrom<Vec<Namespace>> for NamespaceRegex {
/// Appservice registration combined with its compiled regular expressions. /// Appservice registration combined with its compiled regular expressions.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct RegistrationInfo { pub(crate) struct RegistrationInfo {
pub registration: Registration, pub(crate) registration: Registration,
pub users: NamespaceRegex, pub(crate) users: NamespaceRegex,
pub aliases: NamespaceRegex, pub(crate) aliases: NamespaceRegex,
pub rooms: NamespaceRegex, pub(crate) rooms: NamespaceRegex,
} }
impl RegistrationInfo { impl RegistrationInfo {
pub fn is_user_match(&self, user_id: &UserId) -> bool { pub(crate) fn is_user_match(&self, user_id: &UserId) -> bool {
self.users.is_match(user_id.as_str()) self.users.is_match(user_id.as_str())
|| self.registration.sender_localpart == user_id.localpart() || self.registration.sender_localpart == user_id.localpart()
} }
pub fn is_exclusive_user_match(&self, user_id: &UserId) -> bool { pub(crate) fn is_exclusive_user_match(&self, user_id: &UserId) -> bool {
self.users.is_exclusive_match(user_id.as_str()) self.users.is_exclusive_match(user_id.as_str())
|| self.registration.sender_localpart == user_id.localpart() || self.registration.sender_localpart == user_id.localpart()
} }
@ -111,13 +111,13 @@ impl TryFrom<Registration> for RegistrationInfo {
type Error = regex::Error; type Error = regex::Error;
} }
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
registration_info: RwLock<BTreeMap<String, RegistrationInfo>>, registration_info: RwLock<BTreeMap<String, RegistrationInfo>>,
} }
impl Service { impl Service {
pub fn build(db: &'static dyn Data) -> Result<Self> { pub(crate) fn build(db: &'static dyn Data) -> Result<Self> {
let mut registration_info = BTreeMap::new(); let mut registration_info = BTreeMap::new();
// Inserting registrations into cache // Inserting registrations into cache
for appservice in db.all()? { for appservice in db.all()? {
@ -136,7 +136,7 @@ impl Service {
}) })
} }
/// Registers an appservice and returns the ID to the caller. /// Registers an appservice and returns the ID to the caller.
pub async fn register_appservice(&self, yaml: Registration) -> Result<String> { pub(crate) async fn register_appservice(&self, yaml: Registration) -> Result<String> {
//TODO: Check for collisions between exclusive appservice namespaces //TODO: Check for collisions between exclusive appservice namespaces
services() services()
.appservice .appservice
@ -153,7 +153,7 @@ impl Service {
/// # Arguments /// # Arguments
/// ///
/// * `service_name` - the name you send to register the service previously /// * `service_name` - the name you send to register the service previously
pub async fn unregister_appservice(&self, service_name: &str) -> Result<()> { pub(crate) async fn unregister_appservice(&self, service_name: &str) -> Result<()> {
services() services()
.appservice .appservice
.registration_info .registration_info
@ -165,7 +165,7 @@ impl Service {
self.db.unregister_appservice(service_name) self.db.unregister_appservice(service_name)
} }
pub async fn get_registration(&self, id: &str) -> Option<Registration> { pub(crate) async fn get_registration(&self, id: &str) -> Option<Registration> {
self.registration_info self.registration_info
.read() .read()
.await .await
@ -174,7 +174,7 @@ impl Service {
.map(|info| info.registration) .map(|info| info.registration)
} }
pub async fn iter_ids(&self) -> Vec<String> { pub(crate) async fn iter_ids(&self) -> Vec<String> {
self.registration_info self.registration_info
.read() .read()
.await .await
@ -183,7 +183,7 @@ impl Service {
.collect() .collect()
} }
pub async fn find_from_token(&self, token: &str) -> Option<RegistrationInfo> { pub(crate) async fn find_from_token(&self, token: &str) -> Option<RegistrationInfo> {
self.read() self.read()
.await .await
.values() .values()
@ -192,7 +192,7 @@ impl Service {
} }
// Checks if a given user id matches any exclusive appservice regex // Checks if a given user id matches any exclusive appservice regex
pub async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool { pub(crate) async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool {
self.read() self.read()
.await .await
.values() .values()
@ -200,7 +200,7 @@ impl Service {
} }
// Checks if a given room alias matches any exclusive appservice regex // Checks if a given room alias matches any exclusive appservice regex
pub async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool { pub(crate) async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool {
self.read() self.read()
.await .await
.values() .values()
@ -208,14 +208,14 @@ impl Service {
} }
// Checks if a given room id matches any exclusive appservice regex // Checks if a given room id matches any exclusive appservice regex
pub async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool { pub(crate) async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool {
self.read() self.read()
.await .await
.values() .values()
.any(|info| info.rooms.is_exclusive_match(room_id.as_str())) .any(|info| info.rooms.is_exclusive_match(room_id.as_str()))
} }
pub fn read( pub(crate) fn read(
&self, &self,
) -> impl Future<Output = tokio::sync::RwLockReadGuard<'_, BTreeMap<String, RegistrationInfo>>> ) -> impl Future<Output = tokio::sync::RwLockReadGuard<'_, BTreeMap<String, RegistrationInfo>>>
{ {

View file

@ -2,7 +2,7 @@ use ruma::api::appservice::Registration;
use crate::Result; use crate::Result;
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
/// Registers an appservice and returns the ID to the caller /// Registers an appservice and returns the ID to the caller
fn register_appservice(&self, yaml: Registration) -> Result<String>; fn register_appservice(&self, yaml: Registration) -> Result<String>;

View file

@ -1,5 +1,5 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use ruma::{ use ruma::{
serde::Base64, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedServerName, serde::Base64, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedServerName,
OwnedServerSigningKeyId, OwnedUserId, OwnedServerSigningKeyId, OwnedUserId,
@ -49,46 +49,46 @@ type SyncHandle = (
Receiver<Option<Result<sync_events::v3::Response>>>, // rx Receiver<Option<Result<sync_events::v3::Response>>>, // rx
); );
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host pub(crate) actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
pub tls_name_override: Arc<StdRwLock<TlsNameMap>>, pub(crate) tls_name_override: Arc<StdRwLock<TlsNameMap>>,
pub config: Config, pub(crate) config: Config,
keypair: Arc<ruma::signatures::Ed25519KeyPair>, keypair: Arc<ruma::signatures::Ed25519KeyPair>,
dns_resolver: TokioAsyncResolver, dns_resolver: TokioAsyncResolver,
jwt_decoding_key: Option<jsonwebtoken::DecodingKey>, jwt_decoding_key: Option<jsonwebtoken::DecodingKey>,
federation_client: reqwest::Client, federation_client: reqwest::Client,
default_client: reqwest::Client, default_client: reqwest::Client,
pub stable_room_versions: Vec<RoomVersionId>, pub(crate) stable_room_versions: Vec<RoomVersionId>,
pub unstable_room_versions: Vec<RoomVersionId>, pub(crate) unstable_room_versions: Vec<RoomVersionId>,
pub bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>, pub(crate) bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>,
pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>, pub(crate) bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>,
pub bad_query_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, RateLimitState>>>, pub(crate) bad_query_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, RateLimitState>>>,
pub servername_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, Arc<Semaphore>>>>, pub(crate) servername_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, Arc<Semaphore>>>>,
pub sync_receivers: RwLock<HashMap<(OwnedUserId, OwnedDeviceId), SyncHandle>>, pub(crate) sync_receivers: RwLock<HashMap<(OwnedUserId, OwnedDeviceId), SyncHandle>>,
pub roomid_mutex_insert: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>, pub(crate) roomid_mutex_insert: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>, pub(crate) roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub roomid_mutex_federation: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>, // this lock will be held longer pub(crate) roomid_mutex_federation: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>, // this lock will be held longer
pub roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>, pub(crate) roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>,
pub stateres_mutex: Arc<Mutex<()>>, pub(crate) stateres_mutex: Arc<Mutex<()>>,
pub rotate: RotationHandler, pub(crate) rotate: RotationHandler,
pub shutdown: AtomicBool, pub(crate) shutdown: AtomicBool,
} }
/// Handles "rotation" of long-polling requests. "Rotation" in this context is similar to "rotation" of log files and the like. /// Handles "rotation" of long-polling requests. "Rotation" in this context is similar to "rotation" of log files and the like.
/// ///
/// This is utilized to have sync workers return early and release read locks on the database. /// This is utilized to have sync workers return early and release read locks on the database.
pub struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>); pub(crate) struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>);
impl RotationHandler { impl RotationHandler {
pub fn new() -> Self { pub(crate) fn new() -> Self {
let (s, r) = broadcast::channel(1); let (s, r) = broadcast::channel(1);
Self(s, r) Self(s, r)
} }
pub fn watch(&self) -> impl Future<Output = ()> { pub(crate) fn watch(&self) -> impl Future<Output = ()> {
let mut r = self.0.subscribe(); let mut r = self.0.subscribe();
async move { async move {
@ -96,7 +96,7 @@ impl RotationHandler {
} }
} }
pub fn fire(&self) { pub(crate) fn fire(&self) {
let _ = self.0.send(()); let _ = self.0.send(());
} }
} }
@ -107,13 +107,13 @@ impl Default for RotationHandler {
} }
} }
pub struct Resolver { pub(crate) struct Resolver {
inner: GaiResolver, inner: GaiResolver,
overrides: Arc<StdRwLock<TlsNameMap>>, overrides: Arc<StdRwLock<TlsNameMap>>,
} }
impl Resolver { impl Resolver {
pub fn new(overrides: Arc<StdRwLock<TlsNameMap>>) -> Self { pub(crate) fn new(overrides: Arc<StdRwLock<TlsNameMap>>) -> Self {
Resolver { Resolver {
inner: GaiResolver::new(), inner: GaiResolver::new(),
overrides, overrides,
@ -147,7 +147,7 @@ impl Resolve for Resolver {
} }
impl Service { impl Service {
pub fn load(db: &'static dyn Data, config: Config) -> Result<Self> { pub(crate) fn load(db: &'static dyn Data, config: Config) -> Result<Self> {
let keypair = db.load_keypair(); let keypair = db.load_keypair();
let keypair = match keypair { let keypair = match keypair {
@ -229,113 +229,113 @@ impl Service {
} }
/// Returns this server's keypair. /// Returns this server's keypair.
pub fn keypair(&self) -> &ruma::signatures::Ed25519KeyPair { pub(crate) fn keypair(&self) -> &ruma::signatures::Ed25519KeyPair {
&self.keypair &self.keypair
} }
/// Returns a reqwest client which can be used to send requests /// Returns a reqwest client which can be used to send requests
pub fn default_client(&self) -> reqwest::Client { pub(crate) fn default_client(&self) -> reqwest::Client {
// Client is cheap to clone (Arc wrapper) and avoids lifetime issues // Client is cheap to clone (Arc wrapper) and avoids lifetime issues
self.default_client.clone() self.default_client.clone()
} }
/// Returns a client used for resolving .well-knowns /// Returns a client used for resolving .well-knowns
pub fn federation_client(&self) -> reqwest::Client { pub(crate) fn federation_client(&self) -> reqwest::Client {
// Client is cheap to clone (Arc wrapper) and avoids lifetime issues // Client is cheap to clone (Arc wrapper) and avoids lifetime issues
self.federation_client.clone() self.federation_client.clone()
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn next_count(&self) -> Result<u64> { pub(crate) fn next_count(&self) -> Result<u64> {
self.db.next_count() self.db.next_count()
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn current_count(&self) -> Result<u64> { pub(crate) fn current_count(&self) -> Result<u64> {
self.db.current_count() self.db.current_count()
} }
pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { pub(crate) async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
self.db.watch(user_id, device_id).await self.db.watch(user_id, device_id).await
} }
pub fn cleanup(&self) -> Result<()> { pub(crate) fn cleanup(&self) -> Result<()> {
self.db.cleanup() self.db.cleanup()
} }
pub fn server_name(&self) -> &ServerName { pub(crate) fn server_name(&self) -> &ServerName {
self.config.server_name.as_ref() self.config.server_name.as_ref()
} }
pub fn max_request_size(&self) -> u32 { pub(crate) fn max_request_size(&self) -> u32 {
self.config.max_request_size self.config.max_request_size
} }
pub fn max_fetch_prev_events(&self) -> u16 { pub(crate) fn max_fetch_prev_events(&self) -> u16 {
self.config.max_fetch_prev_events self.config.max_fetch_prev_events
} }
pub fn allow_registration(&self) -> bool { pub(crate) fn allow_registration(&self) -> bool {
self.config.allow_registration self.config.allow_registration
} }
pub fn allow_encryption(&self) -> bool { pub(crate) fn allow_encryption(&self) -> bool {
self.config.allow_encryption self.config.allow_encryption
} }
pub fn allow_federation(&self) -> bool { pub(crate) fn allow_federation(&self) -> bool {
self.config.allow_federation self.config.allow_federation
} }
pub fn allow_room_creation(&self) -> bool { pub(crate) fn allow_room_creation(&self) -> bool {
self.config.allow_room_creation self.config.allow_room_creation
} }
pub fn allow_unstable_room_versions(&self) -> bool { pub(crate) fn allow_unstable_room_versions(&self) -> bool {
self.config.allow_unstable_room_versions self.config.allow_unstable_room_versions
} }
pub fn default_room_version(&self) -> RoomVersionId { pub(crate) fn default_room_version(&self) -> RoomVersionId {
self.config.default_room_version.clone() self.config.default_room_version.clone()
} }
pub fn trusted_servers(&self) -> &[OwnedServerName] { pub(crate) fn trusted_servers(&self) -> &[OwnedServerName] {
&self.config.trusted_servers &self.config.trusted_servers
} }
pub fn dns_resolver(&self) -> &TokioAsyncResolver { pub(crate) fn dns_resolver(&self) -> &TokioAsyncResolver {
&self.dns_resolver &self.dns_resolver
} }
pub fn jwt_decoding_key(&self) -> Option<&jsonwebtoken::DecodingKey> { pub(crate) fn jwt_decoding_key(&self) -> Option<&jsonwebtoken::DecodingKey> {
self.jwt_decoding_key.as_ref() self.jwt_decoding_key.as_ref()
} }
pub fn turn_password(&self) -> &String { pub(crate) fn turn_password(&self) -> &String {
&self.config.turn_password &self.config.turn_password
} }
pub fn turn_ttl(&self) -> u64 { pub(crate) fn turn_ttl(&self) -> u64 {
self.config.turn_ttl self.config.turn_ttl
} }
pub fn turn_uris(&self) -> &[String] { pub(crate) fn turn_uris(&self) -> &[String] {
&self.config.turn_uris &self.config.turn_uris
} }
pub fn turn_username(&self) -> &String { pub(crate) fn turn_username(&self) -> &String {
&self.config.turn_username &self.config.turn_username
} }
pub fn turn_secret(&self) -> &String { pub(crate) fn turn_secret(&self) -> &String {
&self.config.turn_secret &self.config.turn_secret
} }
pub fn emergency_password(&self) -> &Option<String> { pub(crate) fn emergency_password(&self) -> &Option<String> {
&self.config.emergency_password &self.config.emergency_password
} }
pub fn supported_room_versions(&self) -> Vec<RoomVersionId> { pub(crate) fn supported_room_versions(&self) -> Vec<RoomVersionId> {
let mut room_versions: Vec<RoomVersionId> = vec![]; let mut room_versions: Vec<RoomVersionId> = vec![];
room_versions.extend(self.stable_room_versions.clone()); room_versions.extend(self.stable_room_versions.clone());
if self.allow_unstable_room_versions() { if self.allow_unstable_room_versions() {
@ -348,7 +348,7 @@ impl Service {
/// Remove the outdated keys and insert the new ones. /// Remove the outdated keys and insert the new ones.
/// ///
/// This doesn't actually check that the keys provided are newer than the old set. /// This doesn't actually check that the keys provided are newer than the old set.
pub fn add_signing_key( pub(crate) fn add_signing_key(
&self, &self,
origin: &ServerName, origin: &ServerName,
new_keys: ServerSigningKeys, new_keys: ServerSigningKeys,
@ -357,7 +357,7 @@ impl Service {
} }
/// This returns an empty `Ok(BTreeMap<..>)` when there are no keys found for the server. /// This returns an empty `Ok(BTreeMap<..>)` when there are no keys found for the server.
pub fn signing_keys_for( pub(crate) fn signing_keys_for(
&self, &self,
origin: &ServerName, origin: &ServerName,
) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>> { ) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>> {
@ -376,22 +376,22 @@ impl Service {
Ok(keys) Ok(keys)
} }
pub fn database_version(&self) -> Result<u64> { pub(crate) fn database_version(&self) -> Result<u64> {
self.db.database_version() self.db.database_version()
} }
pub fn bump_database_version(&self, new_version: u64) -> Result<()> { pub(crate) fn bump_database_version(&self, new_version: u64) -> Result<()> {
self.db.bump_database_version(new_version) self.db.bump_database_version(new_version)
} }
pub fn get_media_folder(&self) -> PathBuf { pub(crate) fn get_media_folder(&self) -> PathBuf {
let mut r = PathBuf::new(); let mut r = PathBuf::new();
r.push(self.config.database_path.clone()); r.push(self.config.database_path.clone());
r.push("media"); r.push("media");
r r
} }
pub fn get_media_file(&self, key: &[u8]) -> PathBuf { pub(crate) fn get_media_file(&self, key: &[u8]) -> PathBuf {
let mut r = PathBuf::new(); let mut r = PathBuf::new();
r.push(self.config.database_path.clone()); r.push(self.config.database_path.clone());
r.push("media"); r.push("media");
@ -399,11 +399,11 @@ impl Service {
r r
} }
pub fn well_known_client(&self) -> &Option<String> { pub(crate) fn well_known_client(&self) -> &Option<String> {
&self.config.well_known_client &self.config.well_known_client
} }
pub fn shutdown(&self) { pub(crate) fn shutdown(&self) {
self.shutdown.store(true, atomic::Ordering::Relaxed); self.shutdown.store(true, atomic::Ordering::Relaxed);
// On shutdown // On shutdown
info!(target: "shutdown-sync", "Received shutdown notification, notifying sync helpers..."); info!(target: "shutdown-sync", "Received shutdown notification, notifying sync helpers...");

View file

@ -10,7 +10,7 @@ use ruma::{
use crate::Result; use crate::Result;
#[async_trait] #[async_trait]
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn next_count(&self) -> Result<u64>; fn next_count(&self) -> Result<u64>;
fn current_count(&self) -> Result<u64>; fn current_count(&self) -> Result<u64>;
async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>; async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>;

View file

@ -1,5 +1,5 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use crate::Result; use crate::Result;
use ruma::{ use ruma::{
@ -9,12 +9,12 @@ use ruma::{
}; };
use std::collections::BTreeMap; use std::collections::BTreeMap;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
pub fn create_backup( pub(crate) fn create_backup(
&self, &self,
user_id: &UserId, user_id: &UserId,
backup_metadata: &Raw<BackupAlgorithm>, backup_metadata: &Raw<BackupAlgorithm>,
@ -22,11 +22,11 @@ impl Service {
self.db.create_backup(user_id, backup_metadata) self.db.create_backup(user_id, backup_metadata)
} }
pub fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> { pub(crate) fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> {
self.db.delete_backup(user_id, version) self.db.delete_backup(user_id, version)
} }
pub fn update_backup( pub(crate) fn update_backup(
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
@ -35,18 +35,18 @@ impl Service {
self.db.update_backup(user_id, version, backup_metadata) self.db.update_backup(user_id, version, backup_metadata)
} }
pub fn get_latest_backup_version(&self, user_id: &UserId) -> Result<Option<String>> { pub(crate) fn get_latest_backup_version(&self, user_id: &UserId) -> Result<Option<String>> {
self.db.get_latest_backup_version(user_id) self.db.get_latest_backup_version(user_id)
} }
pub fn get_latest_backup( pub(crate) fn get_latest_backup(
&self, &self,
user_id: &UserId, user_id: &UserId,
) -> Result<Option<(String, Raw<BackupAlgorithm>)>> { ) -> Result<Option<(String, Raw<BackupAlgorithm>)>> {
self.db.get_latest_backup(user_id) self.db.get_latest_backup(user_id)
} }
pub fn get_backup( pub(crate) fn get_backup(
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
@ -54,7 +54,7 @@ impl Service {
self.db.get_backup(user_id, version) self.db.get_backup(user_id, version)
} }
pub fn add_key( pub(crate) fn add_key(
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
@ -66,15 +66,15 @@ impl Service {
.add_key(user_id, version, room_id, session_id, key_data) .add_key(user_id, version, room_id, session_id, key_data)
} }
pub fn count_keys(&self, user_id: &UserId, version: &str) -> Result<usize> { pub(crate) fn count_keys(&self, user_id: &UserId, version: &str) -> Result<usize> {
self.db.count_keys(user_id, version) self.db.count_keys(user_id, version)
} }
pub fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> { pub(crate) fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> {
self.db.get_etag(user_id, version) self.db.get_etag(user_id, version)
} }
pub fn get_all( pub(crate) fn get_all(
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
@ -82,7 +82,7 @@ impl Service {
self.db.get_all(user_id, version) self.db.get_all(user_id, version)
} }
pub fn get_room( pub(crate) fn get_room(
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
@ -91,7 +91,7 @@ impl Service {
self.db.get_room(user_id, version, room_id) self.db.get_room(user_id, version, room_id)
} }
pub fn get_session( pub(crate) fn get_session(
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
@ -101,11 +101,11 @@ impl Service {
self.db.get_session(user_id, version, room_id, session_id) self.db.get_session(user_id, version, room_id, session_id)
} }
pub fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> { pub(crate) fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> {
self.db.delete_all_keys(user_id, version) self.db.delete_all_keys(user_id, version)
} }
pub fn delete_room_keys( pub(crate) fn delete_room_keys(
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
@ -114,7 +114,7 @@ impl Service {
self.db.delete_room_keys(user_id, version, room_id) self.db.delete_room_keys(user_id, version, room_id)
} }
pub fn delete_room_key( pub(crate) fn delete_room_key(
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,

View file

@ -7,7 +7,7 @@ use ruma::{
OwnedRoomId, RoomId, UserId, OwnedRoomId, RoomId, UserId,
}; };
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn create_backup( fn create_backup(
&self, &self,
user_id: &UserId, user_id: &UserId,

View file

@ -1,7 +1,7 @@
mod data; mod data;
use std::io::Cursor; use std::io::Cursor;
pub use data::Data; pub(crate) use data::Data;
use crate::{services, Result}; use crate::{services, Result};
use image::imageops::FilterType; use image::imageops::FilterType;
@ -11,19 +11,19 @@ use tokio::{
io::{AsyncReadExt, AsyncWriteExt, BufReader}, io::{AsyncReadExt, AsyncWriteExt, BufReader},
}; };
pub struct FileMeta { pub(crate) struct FileMeta {
pub content_disposition: Option<String>, pub(crate) content_disposition: Option<String>,
pub content_type: Option<String>, pub(crate) content_type: Option<String>,
pub file: Vec<u8>, pub(crate) file: Vec<u8>,
} }
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
/// Uploads a file. /// Uploads a file.
pub async fn create( pub(crate) async fn create(
&self, &self,
mxc: String, mxc: String,
content_disposition: Option<&str>, content_disposition: Option<&str>,
@ -43,7 +43,7 @@ impl Service {
/// Uploads or replaces a file thumbnail. /// Uploads or replaces a file thumbnail.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn upload_thumbnail( pub(crate) async fn upload_thumbnail(
&self, &self,
mxc: String, mxc: String,
content_disposition: Option<&str>, content_disposition: Option<&str>,
@ -64,7 +64,7 @@ impl Service {
} }
/// Downloads a file. /// Downloads a file.
pub async fn get(&self, mxc: String) -> Result<Option<FileMeta>> { pub(crate) async fn get(&self, mxc: String) -> Result<Option<FileMeta>> {
if let Ok((content_disposition, content_type, key)) = if let Ok((content_disposition, content_type, key)) =
self.db.search_file_metadata(mxc, 0, 0) self.db.search_file_metadata(mxc, 0, 0)
{ {
@ -86,7 +86,7 @@ impl Service {
/// Returns width, height of the thumbnail and whether it should be cropped. Returns None when /// Returns width, height of the thumbnail and whether it should be cropped. Returns None when
/// the server should send the original file. /// the server should send the original file.
pub fn thumbnail_properties(&self, width: u32, height: u32) -> Option<(u32, u32, bool)> { pub(crate) fn thumbnail_properties(&self, width: u32, height: u32) -> Option<(u32, u32, bool)> {
match (width, height) { match (width, height) {
(0..=32, 0..=32) => Some((32, 32, true)), (0..=32, 0..=32) => Some((32, 32, true)),
(0..=96, 0..=96) => Some((96, 96, true)), (0..=96, 0..=96) => Some((96, 96, true)),
@ -107,7 +107,7 @@ impl Service {
/// - Server creates the thumbnail and sends it to the user /// - Server creates the thumbnail and sends it to the user
/// ///
/// For width,height <= 96 the server uses another thumbnailing algorithm which crops the image afterwards. /// For width,height <= 96 the server uses another thumbnailing algorithm which crops the image afterwards.
pub async fn get_thumbnail( pub(crate) async fn get_thumbnail(
&self, &self,
mxc: String, mxc: String,
width: u32, width: u32,

View file

@ -1,6 +1,6 @@
use crate::Result; use crate::Result;
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn create_file_metadata( fn create_file_metadata(
&self, &self,
mxc: String, mxc: String,

View file

@ -21,37 +21,37 @@ use tracing::warn;
/// Content hashes of a PDU. /// Content hashes of a PDU.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EventHash { pub(crate) struct EventHash {
/// The SHA-256 hash. /// The SHA-256 hash.
pub sha256: String, pub(crate) sha256: String,
} }
#[derive(Clone, Deserialize, Debug, Serialize)] #[derive(Clone, Deserialize, Debug, Serialize)]
pub struct PduEvent { pub(crate) struct PduEvent {
pub event_id: Arc<EventId>, pub(crate) event_id: Arc<EventId>,
pub room_id: OwnedRoomId, pub(crate) room_id: OwnedRoomId,
pub sender: OwnedUserId, pub(crate) sender: OwnedUserId,
pub origin_server_ts: UInt, pub(crate) origin_server_ts: UInt,
#[serde(rename = "type")] #[serde(rename = "type")]
pub kind: TimelineEventType, pub(crate) kind: TimelineEventType,
pub content: Box<RawJsonValue>, pub(crate) content: Box<RawJsonValue>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub state_key: Option<String>, pub(crate) state_key: Option<String>,
pub prev_events: Vec<Arc<EventId>>, pub(crate) prev_events: Vec<Arc<EventId>>,
pub depth: UInt, pub(crate) depth: UInt,
pub auth_events: Vec<Arc<EventId>>, pub(crate) auth_events: Vec<Arc<EventId>>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub redacts: Option<Arc<EventId>>, pub(crate) redacts: Option<Arc<EventId>>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub unsigned: Option<Box<RawJsonValue>>, pub(crate) unsigned: Option<Box<RawJsonValue>>,
pub hashes: EventHash, pub(crate) hashes: EventHash,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub signatures: Option<Box<RawJsonValue>>, // BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>> pub(crate) signatures: Option<Box<RawJsonValue>>, // BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>
} }
impl PduEvent { impl PduEvent {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn redact( pub(crate) fn redact(
&mut self, &mut self,
room_version_id: RoomVersionId, room_version_id: RoomVersionId,
reason: &PduEvent, reason: &PduEvent,
@ -72,7 +72,7 @@ impl PduEvent {
Ok(()) Ok(())
} }
pub fn remove_transaction_id(&mut self) -> crate::Result<()> { pub(crate) fn remove_transaction_id(&mut self) -> crate::Result<()> {
if let Some(unsigned) = &self.unsigned { if let Some(unsigned) = &self.unsigned {
let mut unsigned: BTreeMap<String, Box<RawJsonValue>> = let mut unsigned: BTreeMap<String, Box<RawJsonValue>> =
serde_json::from_str(unsigned.get()) serde_json::from_str(unsigned.get())
@ -84,7 +84,7 @@ impl PduEvent {
Ok(()) Ok(())
} }
pub fn add_age(&mut self) -> crate::Result<()> { pub(crate) fn add_age(&mut self) -> crate::Result<()> {
let mut unsigned: BTreeMap<String, Box<RawJsonValue>> = self let mut unsigned: BTreeMap<String, Box<RawJsonValue>> = self
.unsigned .unsigned
.as_ref() .as_ref()
@ -109,7 +109,7 @@ impl PduEvent {
/// > For improved compatibility with newer clients, servers should add a redacts property /// > For improved compatibility with newer clients, servers should add a redacts property
/// > to the content of m.room.redaction events in older room versions when serving /// > to the content of m.room.redaction events in older room versions when serving
/// > such events over the Client-Server API. /// > such events over the Client-Server API.
pub fn copy_redacts(&self) -> (Option<Arc<EventId>>, Box<RawJsonValue>) { pub(crate) fn copy_redacts(&self) -> (Option<Arc<EventId>>, Box<RawJsonValue>) {
if self.kind == TimelineEventType::RoomRedaction { if self.kind == TimelineEventType::RoomRedaction {
if let Ok(mut content) = if let Ok(mut content) =
serde_json::from_str::<RoomRedactionEventContent>(self.content.get()) serde_json::from_str::<RoomRedactionEventContent>(self.content.get())
@ -130,7 +130,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_sync_room_event(&self) -> Raw<AnySyncTimelineEvent> { pub(crate) fn to_sync_room_event(&self) -> Raw<AnySyncTimelineEvent> {
let (redacts, content) = self.copy_redacts(); let (redacts, content) = self.copy_redacts();
let mut json = json!({ let mut json = json!({
"content": content, "content": content,
@ -155,7 +155,7 @@ impl PduEvent {
/// This only works for events that are also AnyRoomEvents. /// This only works for events that are also AnyRoomEvents.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_any_event(&self) -> Raw<AnyEphemeralRoomEvent> { pub(crate) fn to_any_event(&self) -> Raw<AnyEphemeralRoomEvent> {
let mut json = json!({ let mut json = json!({
"content": self.content, "content": self.content,
"type": self.kind, "type": self.kind,
@ -179,7 +179,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_room_event(&self) -> Raw<AnyTimelineEvent> { pub(crate) fn to_room_event(&self) -> Raw<AnyTimelineEvent> {
let (redacts, content) = self.copy_redacts(); let (redacts, content) = self.copy_redacts();
let mut json = json!({ let mut json = json!({
"content": content, "content": content,
@ -204,7 +204,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_message_like_event(&self) -> Raw<AnyMessageLikeEvent> { pub(crate) fn to_message_like_event(&self) -> Raw<AnyMessageLikeEvent> {
let (redacts, content) = self.copy_redacts(); let (redacts, content) = self.copy_redacts();
let mut json = json!({ let mut json = json!({
"content": content, "content": content,
@ -229,7 +229,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_state_event(&self) -> Raw<AnyStateEvent> { pub(crate) fn to_state_event(&self) -> Raw<AnyStateEvent> {
let mut json = json!({ let mut json = json!({
"content": self.content, "content": self.content,
"type": self.kind, "type": self.kind,
@ -248,7 +248,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_sync_state_event(&self) -> Raw<AnySyncStateEvent> { pub(crate) fn to_sync_state_event(&self) -> Raw<AnySyncStateEvent> {
let mut json = json!({ let mut json = json!({
"content": self.content, "content": self.content,
"type": self.kind, "type": self.kind,
@ -266,7 +266,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_stripped_state_event(&self) -> Raw<AnyStrippedStateEvent> { pub(crate) fn to_stripped_state_event(&self) -> Raw<AnyStrippedStateEvent> {
let json = json!({ let json = json!({
"content": self.content, "content": self.content,
"type": self.kind, "type": self.kind,
@ -278,7 +278,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_stripped_spacechild_state_event(&self) -> Raw<HierarchySpaceChildEvent> { pub(crate) fn to_stripped_spacechild_state_event(&self) -> Raw<HierarchySpaceChildEvent> {
let json = json!({ let json = json!({
"content": self.content, "content": self.content,
"type": self.kind, "type": self.kind,
@ -291,7 +291,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_member_event(&self) -> Raw<StateEvent<RoomMemberEventContent>> { pub(crate) fn to_member_event(&self) -> Raw<StateEvent<RoomMemberEventContent>> {
let mut json = json!({ let mut json = json!({
"content": self.content, "content": self.content,
"type": self.kind, "type": self.kind,
@ -312,7 +312,7 @@ impl PduEvent {
/// This does not return a full `Pdu` it is only to satisfy ruma's types. /// This does not return a full `Pdu` it is only to satisfy ruma's types.
#[tracing::instrument] #[tracing::instrument]
pub fn convert_to_outgoing_federation_event( pub(crate) fn convert_to_outgoing_federation_event(
mut pdu_json: CanonicalJsonObject, mut pdu_json: CanonicalJsonObject,
) -> Box<RawJsonValue> { ) -> Box<RawJsonValue> {
if let Some(unsigned) = pdu_json if let Some(unsigned) = pdu_json
@ -334,7 +334,7 @@ impl PduEvent {
to_raw_value(&pdu_json).expect("CanonicalJson is valid serde_json::Value") to_raw_value(&pdu_json).expect("CanonicalJson is valid serde_json::Value")
} }
pub fn from_id_val( pub(crate) fn from_id_val(
event_id: &EventId, event_id: &EventId,
mut json: CanonicalJsonObject, mut json: CanonicalJsonObject,
) -> Result<Self, serde_json::Error> { ) -> Result<Self, serde_json::Error> {
@ -436,11 +436,11 @@ pub(crate) fn gen_event_id_canonical_json(
/// Build the start of a PDU in order to add it to the Database. /// Build the start of a PDU in order to add it to the Database.
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct PduBuilder { pub(crate) struct PduBuilder {
#[serde(rename = "type")] #[serde(rename = "type")]
pub event_type: TimelineEventType, pub(crate) event_type: TimelineEventType,
pub content: Box<RawJsonValue>, pub(crate) content: Box<RawJsonValue>,
pub unsigned: Option<BTreeMap<String, serde_json::Value>>, pub(crate) unsigned: Option<BTreeMap<String, serde_json::Value>>,
pub state_key: Option<String>, pub(crate) state_key: Option<String>,
pub redacts: Option<Arc<EventId>>, pub(crate) redacts: Option<Arc<EventId>>,
} }

View file

@ -1,5 +1,5 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use ruma::{events::AnySyncTimelineEvent, push::PushConditionPowerLevelsCtx}; use ruma::{events::AnySyncTimelineEvent, push::PushConditionPowerLevelsCtx};
use crate::{services, Error, PduEvent, Result}; use crate::{services, Error, PduEvent, Result};
@ -22,29 +22,33 @@ use ruma::{
use std::{fmt::Debug, mem}; use std::{fmt::Debug, mem};
use tracing::{info, warn}; use tracing::{info, warn};
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
pub fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> { pub(crate) fn set_pusher(
&self,
sender: &UserId,
pusher: set_pusher::v3::PusherAction,
) -> Result<()> {
self.db.set_pusher(sender, pusher) self.db.set_pusher(sender, pusher)
} }
pub fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result<Option<Pusher>> { pub(crate) fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result<Option<Pusher>> {
self.db.get_pusher(sender, pushkey) self.db.get_pusher(sender, pushkey)
} }
pub fn get_pushers(&self, sender: &UserId) -> Result<Vec<Pusher>> { pub(crate) fn get_pushers(&self, sender: &UserId) -> Result<Vec<Pusher>> {
self.db.get_pushers(sender) self.db.get_pushers(sender)
} }
pub fn get_pushkeys(&self, sender: &UserId) -> Box<dyn Iterator<Item = Result<String>>> { pub(crate) fn get_pushkeys(&self, sender: &UserId) -> Box<dyn Iterator<Item = Result<String>>> {
self.db.get_pushkeys(sender) self.db.get_pushkeys(sender)
} }
#[tracing::instrument(skip(self, destination, request))] #[tracing::instrument(skip(self, destination, request))]
pub async fn send_request<T: OutgoingRequest>( pub(crate) async fn send_request<T: OutgoingRequest>(
&self, &self,
destination: &str, destination: &str,
request: T, request: T,
@ -128,7 +132,7 @@ impl Service {
} }
#[tracing::instrument(skip(self, user, unread, pusher, ruleset, pdu))] #[tracing::instrument(skip(self, user, unread, pusher, ruleset, pdu))]
pub async fn send_push_notice( pub(crate) async fn send_push_notice(
&self, &self,
user: &UserId, user: &UserId,
unread: UInt, unread: UInt,
@ -184,7 +188,7 @@ impl Service {
} }
#[tracing::instrument(skip(self, user, ruleset, pdu))] #[tracing::instrument(skip(self, user, ruleset, pdu))]
pub fn get_actions<'a>( pub(crate) fn get_actions<'a>(
&self, &self,
user: &UserId, user: &UserId,
ruleset: &'a Ruleset, ruleset: &'a Ruleset,

View file

@ -4,7 +4,7 @@ use ruma::{
UserId, UserId,
}; };
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()>; fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()>;
fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result<Option<Pusher>>; fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result<Option<Pusher>>;

View file

@ -1,24 +1,24 @@
pub mod alias; pub(crate) mod alias;
pub mod auth_chain; pub(crate) mod auth_chain;
pub mod directory; pub(crate) mod directory;
pub mod edus; pub(crate) mod edus;
pub mod event_handler; pub(crate) mod event_handler;
pub mod lazy_loading; pub(crate) mod lazy_loading;
pub mod metadata; pub(crate) mod metadata;
pub mod outlier; pub(crate) mod outlier;
pub mod pdu_metadata; pub(crate) mod pdu_metadata;
pub mod search; pub(crate) mod search;
pub mod short; pub(crate) mod short;
pub mod spaces; pub(crate) mod spaces;
pub mod state; pub(crate) mod state;
pub mod state_accessor; pub(crate) mod state_accessor;
pub mod state_cache; pub(crate) mod state_cache;
pub mod state_compressor; pub(crate) mod state_compressor;
pub mod threads; pub(crate) mod threads;
pub mod timeline; pub(crate) mod timeline;
pub mod user; pub(crate) mod user;
pub trait Data: pub(crate) trait Data:
alias::Data alias::Data
+ auth_chain::Data + auth_chain::Data
+ directory::Data + directory::Data
@ -39,24 +39,24 @@ pub trait Data:
{ {
} }
pub struct Service { pub(crate) struct Service {
pub alias: alias::Service, pub(crate) alias: alias::Service,
pub auth_chain: auth_chain::Service, pub(crate) auth_chain: auth_chain::Service,
pub directory: directory::Service, pub(crate) directory: directory::Service,
pub edus: edus::Service, pub(crate) edus: edus::Service,
pub event_handler: event_handler::Service, pub(crate) event_handler: event_handler::Service,
pub lazy_loading: lazy_loading::Service, pub(crate) lazy_loading: lazy_loading::Service,
pub metadata: metadata::Service, pub(crate) metadata: metadata::Service,
pub outlier: outlier::Service, pub(crate) outlier: outlier::Service,
pub pdu_metadata: pdu_metadata::Service, pub(crate) pdu_metadata: pdu_metadata::Service,
pub search: search::Service, pub(crate) search: search::Service,
pub short: short::Service, pub(crate) short: short::Service,
pub state: state::Service, pub(crate) state: state::Service,
pub state_accessor: state_accessor::Service, pub(crate) state_accessor: state_accessor::Service,
pub state_cache: state_cache::Service, pub(crate) state_cache: state_cache::Service,
pub state_compressor: state_compressor::Service, pub(crate) state_compressor: state_compressor::Service,
pub timeline: timeline::Service, pub(crate) timeline: timeline::Service,
pub threads: threads::Service, pub(crate) threads: threads::Service,
pub spaces: spaces::Service, pub(crate) spaces: spaces::Service,
pub user: user::Service, pub(crate) user: user::Service,
} }

View file

@ -1,32 +1,32 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use crate::Result; use crate::Result;
use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId};
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> { pub(crate) fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> {
self.db.set_alias(alias, room_id) self.db.set_alias(alias, room_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> { pub(crate) fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> {
self.db.remove_alias(alias) self.db.remove_alias(alias)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<OwnedRoomId>> { pub(crate) fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<OwnedRoomId>> {
self.db.resolve_local_alias(alias) self.db.resolve_local_alias(alias)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn local_aliases_for_room<'a>( pub(crate) fn local_aliases_for_room<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<OwnedRoomAliasId>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedRoomAliasId>> + 'a> {

View file

@ -1,7 +1,7 @@
use crate::Result; use crate::Result;
use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
/// Creates or updates the alias to the given room id. /// Creates or updates the alias to the given room id.
fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()>; fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()>;

View file

@ -4,28 +4,35 @@ use std::{
sync::Arc, sync::Arc,
}; };
pub use data::Data; pub(crate) use data::Data;
use ruma::{api::client::error::ErrorKind, EventId, RoomId}; use ruma::{api::client::error::ErrorKind, EventId, RoomId};
use tracing::{debug, error, warn}; use tracing::{debug, error, warn};
use crate::{services, Error, Result}; use crate::{services, Error, Result};
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
pub fn get_cached_eventid_authchain(&self, key: &[u64]) -> Result<Option<Arc<HashSet<u64>>>> { pub(crate) fn get_cached_eventid_authchain(
&self,
key: &[u64],
) -> Result<Option<Arc<HashSet<u64>>>> {
self.db.get_cached_eventid_authchain(key) self.db.get_cached_eventid_authchain(key)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn cache_auth_chain(&self, key: Vec<u64>, auth_chain: Arc<HashSet<u64>>) -> Result<()> { pub(crate) fn cache_auth_chain(
&self,
key: Vec<u64>,
auth_chain: Arc<HashSet<u64>>,
) -> Result<()> {
self.db.cache_auth_chain(key, auth_chain) self.db.cache_auth_chain(key, auth_chain)
} }
#[tracing::instrument(skip(self, starting_events))] #[tracing::instrument(skip(self, starting_events))]
pub async fn get_auth_chain<'a>( pub(crate) async fn get_auth_chain<'a>(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
starting_events: Vec<Arc<EventId>>, starting_events: Vec<Arc<EventId>>,

View file

@ -1,7 +1,7 @@
use crate::Result; use crate::Result;
use std::{collections::HashSet, sync::Arc}; use std::{collections::HashSet, sync::Arc};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn get_cached_eventid_authchain( fn get_cached_eventid_authchain(
&self, &self,
shorteventid: &[u64], shorteventid: &[u64],

View file

@ -1,32 +1,32 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use ruma::{OwnedRoomId, RoomId}; use ruma::{OwnedRoomId, RoomId};
use crate::Result; use crate::Result;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn set_public(&self, room_id: &RoomId) -> Result<()> { pub(crate) fn set_public(&self, room_id: &RoomId) -> Result<()> {
self.db.set_public(room_id) self.db.set_public(room_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn set_not_public(&self, room_id: &RoomId) -> Result<()> { pub(crate) fn set_not_public(&self, room_id: &RoomId) -> Result<()> {
self.db.set_not_public(room_id) self.db.set_not_public(room_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn is_public_room(&self, room_id: &RoomId) -> Result<bool> { pub(crate) fn is_public_room(&self, room_id: &RoomId) -> Result<bool> {
self.db.is_public_room(room_id) self.db.is_public_room(room_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn public_rooms(&self) -> impl Iterator<Item = Result<OwnedRoomId>> + '_ { pub(crate) fn public_rooms(&self) -> impl Iterator<Item = Result<OwnedRoomId>> + '_ {
self.db.public_rooms() self.db.public_rooms()
} }
} }

View file

@ -1,7 +1,7 @@
use crate::Result; use crate::Result;
use ruma::{OwnedRoomId, RoomId}; use ruma::{OwnedRoomId, RoomId};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
/// Adds the room to the public room directory /// Adds the room to the public room directory
fn set_public(&self, room_id: &RoomId) -> Result<()>; fn set_public(&self, room_id: &RoomId) -> Result<()>;

View file

@ -1,9 +1,9 @@
pub mod read_receipt; pub(crate) mod read_receipt;
pub mod typing; pub(crate) mod typing;
pub trait Data: read_receipt::Data + 'static {} pub(crate) trait Data: read_receipt::Data + 'static {}
pub struct Service { pub(crate) struct Service {
pub read_receipt: read_receipt::Service, pub(crate) read_receipt: read_receipt::Service,
pub typing: typing::Service, pub(crate) typing: typing::Service,
} }

View file

@ -1,17 +1,17 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use crate::Result; use crate::Result;
use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId};
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
/// Replaces the previous read receipt. /// Replaces the previous read receipt.
pub fn readreceipt_update( pub(crate) fn readreceipt_update(
&self, &self,
user_id: &UserId, user_id: &UserId,
room_id: &RoomId, room_id: &RoomId,
@ -22,7 +22,7 @@ impl Service {
/// Returns an iterator over the most recent read_receipts in a room that happened after the event with id `since`. /// Returns an iterator over the most recent read_receipts in a room that happened after the event with id `since`.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn readreceipts_since<'a>( pub(crate) fn readreceipts_since<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
since: u64, since: u64,
@ -38,18 +38,31 @@ impl Service {
/// Sets a private read marker at `count`. /// Sets a private read marker at `count`.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> { 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) self.db.private_read_set(room_id, user_id, count)
} }
/// Returns the private read marker. /// Returns the private read marker.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> { 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) self.db.private_read_get(room_id, user_id)
} }
/// Returns the count of the last typing update in this room. /// Returns the count of the last typing update in this room.
pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> { pub(crate) fn last_privateread_update(
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<u64> {
self.db.last_privateread_update(user_id, room_id) self.db.last_privateread_update(user_id, room_id)
} }
} }

View file

@ -1,7 +1,7 @@
use crate::Result; use crate::Result;
use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
/// Replaces the previous read receipt. /// Replaces the previous read receipt.
fn readreceipt_update( fn readreceipt_update(
&self, &self,

View file

@ -4,16 +4,21 @@ use tokio::sync::{broadcast, RwLock};
use crate::{services, utils, Result}; use crate::{services, utils, Result};
pub struct Service { pub(crate) struct Service {
pub typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout pub(crate) typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout
pub last_typing_update: RwLock<BTreeMap<OwnedRoomId, u64>>, // timestamp of the last change to typing users pub(crate) last_typing_update: RwLock<BTreeMap<OwnedRoomId, u64>>, // timestamp of the last change to typing users
pub typing_update_sender: broadcast::Sender<OwnedRoomId>, pub(crate) typing_update_sender: broadcast::Sender<OwnedRoomId>,
} }
impl Service { impl Service {
/// Sets a user as typing until the timeout timestamp is reached or roomtyping_remove is /// Sets a user as typing until the timeout timestamp is reached or roomtyping_remove is
/// called. /// called.
pub async fn typing_add(&self, user_id: &UserId, room_id: &RoomId, timeout: u64) -> Result<()> { pub(crate) async fn typing_add(
&self,
user_id: &UserId,
room_id: &RoomId,
timeout: u64,
) -> Result<()> {
self.typing self.typing
.write() .write()
.await .await
@ -29,7 +34,7 @@ impl Service {
} }
/// Removes a user from typing before the timeout is reached. /// Removes a user from typing before the timeout is reached.
pub async fn typing_remove(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { pub(crate) async fn typing_remove(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> {
self.typing self.typing
.write() .write()
.await .await
@ -44,7 +49,7 @@ impl Service {
Ok(()) Ok(())
} }
pub async fn wait_for_update(&self, room_id: &RoomId) -> Result<()> { pub(crate) async fn wait_for_update(&self, room_id: &RoomId) -> Result<()> {
let mut receiver = self.typing_update_sender.subscribe(); let mut receiver = self.typing_update_sender.subscribe();
while let Ok(next) = receiver.recv().await { while let Ok(next) = receiver.recv().await {
if next == room_id { if next == room_id {
@ -87,7 +92,7 @@ impl Service {
} }
/// Returns the count of the last typing update in this room. /// Returns the count of the last typing update in this room.
pub async fn last_typing_update(&self, room_id: &RoomId) -> Result<u64> { pub(crate) async fn last_typing_update(&self, room_id: &RoomId) -> Result<u64> {
self.typings_maintain(room_id).await?; self.typings_maintain(room_id).await?;
Ok(self Ok(self
.last_typing_update .last_typing_update
@ -99,7 +104,7 @@ impl Service {
} }
/// Returns a new typing EDU. /// Returns a new typing EDU.
pub async fn typings_all( pub(crate) async fn typings_all(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> { ) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> {

View file

@ -43,7 +43,7 @@ use crate::{service::*, services, Error, PduEvent, Result};
use super::state_compressor::CompressedStateEvent; use super::state_compressor::CompressedStateEvent;
pub struct Service; pub(crate) struct Service;
impl Service { impl Service {
/// When receiving an event one needs to: /// When receiving an event one needs to:
@ -480,7 +480,7 @@ impl Service {
} }
#[tracing::instrument(skip(self, incoming_pdu, val, create_event, pub_key_map))] #[tracing::instrument(skip(self, incoming_pdu, val, create_event, pub_key_map))]
pub async fn upgrade_outlier_to_timeline_pdu( pub(crate) async fn upgrade_outlier_to_timeline_pdu(
&self, &self,
incoming_pdu: Arc<PduEvent>, incoming_pdu: Arc<PduEvent>,
val: BTreeMap<String, CanonicalJsonValue>, val: BTreeMap<String, CanonicalJsonValue>,
@ -1636,7 +1636,7 @@ impl Service {
} }
/// Returns Ok if the acl allows the server /// Returns Ok if the acl allows the server
pub fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> { pub(crate) fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> {
let acl_event = match services().rooms.state_accessor.room_state_get( let acl_event = match services().rooms.state_accessor.room_state_get(
room_id, room_id,
&StateEventType::RoomServerAcl, &StateEventType::RoomServerAcl,
@ -1677,7 +1677,7 @@ impl Service {
/// Search the DB for the signing keys of the given server, if we don't have them /// Search the DB for the signing keys of the given server, if we don't have them
/// fetch them from the server and save to our DB. /// fetch them from the server and save to our DB.
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
pub async fn fetch_signing_keys( pub(crate) async fn fetch_signing_keys(
&self, &self,
origin: &ServerName, origin: &ServerName,
signature_ids: Vec<String>, signature_ids: Vec<String>,

View file

@ -1,7 +1,7 @@
mod data; mod data;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
pub use data::Data; pub(crate) use data::Data;
use ruma::{DeviceId, OwnedDeviceId, OwnedRoomId, OwnedUserId, RoomId, UserId}; use ruma::{DeviceId, OwnedDeviceId, OwnedRoomId, OwnedUserId, RoomId, UserId};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -9,17 +9,17 @@ use crate::Result;
use super::timeline::PduCount; use super::timeline::PduCount;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub lazy_load_waiting: pub(crate) lazy_load_waiting:
Mutex<HashMap<(OwnedUserId, OwnedDeviceId, OwnedRoomId, PduCount), HashSet<OwnedUserId>>>, Mutex<HashMap<(OwnedUserId, OwnedDeviceId, OwnedRoomId, PduCount), HashSet<OwnedUserId>>>,
} }
impl Service { impl Service {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn lazy_load_was_sent_before( pub(crate) fn lazy_load_was_sent_before(
&self, &self,
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
@ -31,7 +31,7 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub async fn lazy_load_mark_sent( pub(crate) async fn lazy_load_mark_sent(
&self, &self,
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
@ -51,7 +51,7 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub async fn lazy_load_confirm_delivery( pub(crate) async fn lazy_load_confirm_delivery(
&self, &self,
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
@ -78,7 +78,7 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn lazy_load_reset( pub(crate) fn lazy_load_reset(
&self, &self,
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,

View file

@ -1,7 +1,7 @@
use crate::Result; use crate::Result;
use ruma::{DeviceId, RoomId, UserId}; use ruma::{DeviceId, RoomId, UserId};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn lazy_load_was_sent_before( fn lazy_load_was_sent_before(
&self, &self,
user_id: &UserId, user_id: &UserId,

View file

@ -1,30 +1,30 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use ruma::{OwnedRoomId, RoomId}; use ruma::{OwnedRoomId, RoomId};
use crate::Result; use crate::Result;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
/// Checks if a room exists. /// Checks if a room exists.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn exists(&self, room_id: &RoomId) -> Result<bool> { pub(crate) fn exists(&self, room_id: &RoomId) -> Result<bool> {
self.db.exists(room_id) self.db.exists(room_id)
} }
pub fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> { pub(crate) fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
self.db.iter_ids() self.db.iter_ids()
} }
pub fn is_disabled(&self, room_id: &RoomId) -> Result<bool> { pub(crate) fn is_disabled(&self, room_id: &RoomId) -> Result<bool> {
self.db.is_disabled(room_id) self.db.is_disabled(room_id)
} }
pub fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()> { pub(crate) fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()> {
self.db.disable_room(room_id, disabled) self.db.disable_room(room_id, disabled)
} }
} }

View file

@ -1,7 +1,7 @@
use crate::Result; use crate::Result;
use ruma::{OwnedRoomId, RoomId}; use ruma::{OwnedRoomId, RoomId};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
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>;

View file

@ -1,28 +1,35 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use ruma::{CanonicalJsonObject, EventId}; use ruma::{CanonicalJsonObject, EventId};
use crate::{PduEvent, Result}; use crate::{PduEvent, Result};
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
/// Returns the pdu from the outlier tree. /// Returns the pdu from the outlier tree.
pub fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>> { pub(crate) fn get_outlier_pdu_json(
&self,
event_id: &EventId,
) -> Result<Option<CanonicalJsonObject>> {
self.db.get_outlier_pdu_json(event_id) self.db.get_outlier_pdu_json(event_id)
} }
/// Returns the pdu from the outlier tree. /// Returns the pdu from the outlier tree.
pub fn get_pdu_outlier(&self, event_id: &EventId) -> Result<Option<PduEvent>> { pub(crate) fn get_pdu_outlier(&self, event_id: &EventId) -> Result<Option<PduEvent>> {
self.db.get_outlier_pdu(event_id) self.db.get_outlier_pdu(event_id)
} }
/// Append the PDU as an outlier. /// Append the PDU as an outlier.
#[tracing::instrument(skip(self, pdu))] #[tracing::instrument(skip(self, pdu))]
pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> { pub(crate) fn add_pdu_outlier(
&self,
event_id: &EventId,
pdu: &CanonicalJsonObject,
) -> Result<()> {
self.db.add_pdu_outlier(event_id, pdu) self.db.add_pdu_outlier(event_id, pdu)
} }
} }

View file

@ -2,7 +2,7 @@ use ruma::{CanonicalJsonObject, EventId};
use crate::{PduEvent, Result}; use crate::{PduEvent, Result};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
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>>;
fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()>; fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()>;

View file

@ -1,7 +1,7 @@
mod data; mod data;
use std::sync::Arc; use std::sync::Arc;
pub use data::Data; pub(crate) use data::Data;
use ruma::{ use ruma::{
api::client::relations::get_relating_events, api::client::relations::get_relating_events,
events::{relation::RelationType, TimelineEventType}, events::{relation::RelationType, TimelineEventType},
@ -13,8 +13,8 @@ use crate::{services, PduEvent, Result};
use super::timeline::PduCount; use super::timeline::PduCount;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
@ -29,7 +29,7 @@ struct ExtractRelatesToEventId {
impl Service { impl Service {
#[tracing::instrument(skip(self, from, to))] #[tracing::instrument(skip(self, from, to))]
pub fn add_relation(&self, from: PduCount, to: PduCount) -> Result<()> { pub(crate) fn add_relation(&self, from: PduCount, to: PduCount) -> Result<()> {
match (from, to) { match (from, to) {
(PduCount::Normal(f), PduCount::Normal(t)) => self.db.add_relation(f, t), (PduCount::Normal(f), PduCount::Normal(t)) => self.db.add_relation(f, t),
_ => { _ => {
@ -41,7 +41,7 @@ impl Service {
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn paginate_relations_with_filter( pub(crate) fn paginate_relations_with_filter(
&self, &self,
sender_user: &UserId, sender_user: &UserId,
room_id: &RoomId, room_id: &RoomId,
@ -152,7 +152,7 @@ impl Service {
} }
} }
pub fn relations_until<'a>( pub(crate) fn relations_until<'a>(
&'a self, &'a self,
user_id: &'a UserId, user_id: &'a UserId,
room_id: &'a RoomId, room_id: &'a RoomId,
@ -169,22 +169,26 @@ impl Service {
} }
#[tracing::instrument(skip(self, room_id, event_ids))] #[tracing::instrument(skip(self, room_id, event_ids))]
pub fn mark_as_referenced(&self, room_id: &RoomId, event_ids: &[Arc<EventId>]) -> Result<()> { pub(crate) fn mark_as_referenced(
&self,
room_id: &RoomId,
event_ids: &[Arc<EventId>],
) -> Result<()> {
self.db.mark_as_referenced(room_id, event_ids) self.db.mark_as_referenced(room_id, event_ids)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result<bool> { pub(crate) fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result<bool> {
self.db.is_event_referenced(room_id, event_id) self.db.is_event_referenced(room_id, event_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> { pub(crate) fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> {
self.db.mark_event_soft_failed(event_id) self.db.mark_event_soft_failed(event_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn is_event_soft_failed(&self, event_id: &EventId) -> Result<bool> { pub(crate) fn is_event_soft_failed(&self, event_id: &EventId) -> Result<bool> {
self.db.is_event_soft_failed(event_id) self.db.is_event_soft_failed(event_id)
} }
} }

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use crate::{service::rooms::timeline::PduCount, PduEvent, Result}; use crate::{service::rooms::timeline::PduCount, PduEvent, Result};
use ruma::{EventId, RoomId, UserId}; use ruma::{EventId, RoomId, UserId};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn add_relation(&self, from: u64, to: u64) -> Result<()>; fn add_relation(&self, from: u64, to: u64) -> Result<()>;
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn relations_until<'a>( fn relations_until<'a>(

View file

@ -1,22 +1,27 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use crate::Result; use crate::Result;
use ruma::RoomId; use ruma::RoomId;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn index_pdu<'a>(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> { pub(crate) fn index_pdu<'a>(
&self,
shortroomid: u64,
pdu_id: &[u8],
message_body: &str,
) -> Result<()> {
self.db.index_pdu(shortroomid, pdu_id, message_body) self.db.index_pdu(shortroomid, pdu_id, message_body)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn search_pdus<'a>( pub(crate) fn search_pdus<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
search_string: &str, search_string: &str,

View file

@ -1,7 +1,7 @@
use crate::Result; use crate::Result;
use ruma::RoomId; use ruma::RoomId;
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
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<()>;
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]

View file

@ -1,21 +1,21 @@
mod data; mod data;
use std::sync::Arc; use std::sync::Arc;
pub use data::Data; pub(crate) use data::Data;
use ruma::{events::StateEventType, EventId, RoomId}; use ruma::{events::StateEventType, EventId, RoomId};
use crate::Result; use crate::Result;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
pub fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64> { pub(crate) fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64> {
self.db.get_or_create_shorteventid(event_id) self.db.get_or_create_shorteventid(event_id)
} }
pub fn get_shortstatekey( pub(crate) fn get_shortstatekey(
&self, &self,
event_type: &StateEventType, event_type: &StateEventType,
state_key: &str, state_key: &str,
@ -23,7 +23,7 @@ impl Service {
self.db.get_shortstatekey(event_type, state_key) self.db.get_shortstatekey(event_type, state_key)
} }
pub fn get_or_create_shortstatekey( pub(crate) fn get_or_create_shortstatekey(
&self, &self,
event_type: &StateEventType, event_type: &StateEventType,
state_key: &str, state_key: &str,
@ -31,24 +31,27 @@ impl Service {
self.db.get_or_create_shortstatekey(event_type, state_key) self.db.get_or_create_shortstatekey(event_type, state_key)
} }
pub fn get_eventid_from_short(&self, shorteventid: u64) -> Result<Arc<EventId>> { pub(crate) fn get_eventid_from_short(&self, shorteventid: u64) -> Result<Arc<EventId>> {
self.db.get_eventid_from_short(shorteventid) self.db.get_eventid_from_short(shorteventid)
} }
pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(StateEventType, String)> { pub(crate) fn get_statekey_from_short(
&self,
shortstatekey: u64,
) -> Result<(StateEventType, String)> {
self.db.get_statekey_from_short(shortstatekey) self.db.get_statekey_from_short(shortstatekey)
} }
/// Returns (shortstatehash, already_existed) /// Returns (shortstatehash, already_existed)
pub fn get_or_create_shortstatehash(&self, state_hash: &[u8]) -> Result<(u64, bool)> { pub(crate) fn get_or_create_shortstatehash(&self, state_hash: &[u8]) -> Result<(u64, bool)> {
self.db.get_or_create_shortstatehash(state_hash) self.db.get_or_create_shortstatehash(state_hash)
} }
pub fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> { pub(crate) fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.get_shortroomid(room_id) self.db.get_shortroomid(room_id)
} }
pub fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result<u64> { pub(crate) fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result<u64> {
self.db.get_or_create_shortroomid(room_id) self.db.get_or_create_shortroomid(room_id)
} }
} }

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use crate::Result; use crate::Result;
use ruma::{events::StateEventType, EventId, RoomId}; use ruma::{events::StateEventType, EventId, RoomId};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64>; fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64>;
fn get_shortstatekey( fn get_shortstatekey(

View file

@ -31,23 +31,23 @@ use tracing::{debug, error, warn};
use crate::{services, Error, PduEvent, Result}; use crate::{services, Error, PduEvent, Result};
pub enum CachedJoinRule { pub(crate) enum CachedJoinRule {
//Simplified(SpaceRoomJoinRule), //Simplified(SpaceRoomJoinRule),
Full(JoinRule), Full(JoinRule),
} }
pub struct CachedSpaceChunk { pub(crate) struct CachedSpaceChunk {
chunk: SpaceHierarchyRoomsChunk, chunk: SpaceHierarchyRoomsChunk,
children: Vec<OwnedRoomId>, children: Vec<OwnedRoomId>,
join_rule: CachedJoinRule, join_rule: CachedJoinRule,
} }
pub struct Service { pub(crate) struct Service {
pub roomid_spacechunk_cache: Mutex<LruCache<OwnedRoomId, Option<CachedSpaceChunk>>>, pub(crate) roomid_spacechunk_cache: Mutex<LruCache<OwnedRoomId, Option<CachedSpaceChunk>>>,
} }
impl Service { impl Service {
pub async fn get_hierarchy( pub(crate) async fn get_hierarchy(
&self, &self,
sender_user: &UserId, sender_user: &UserId,
room_id: &RoomId, room_id: &RoomId,

View file

@ -4,7 +4,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
pub use data::Data; pub(crate) use data::Data;
use ruma::{ use ruma::{
api::client::error::ErrorKind, api::client::error::ErrorKind,
events::{ events::{
@ -23,13 +23,13 @@ use crate::{services, utils::calculate_hash, Error, PduEvent, Result};
use super::state_compressor::CompressedStateEvent; use super::state_compressor::CompressedStateEvent;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
/// Set the room to the given statehash and update caches. /// Set the room to the given statehash and update caches.
pub async fn force_state( pub(crate) async fn force_state(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
shortstatehash: u64, shortstatehash: u64,
@ -115,7 +115,7 @@ impl Service {
/// This adds all current state events (not including the incoming event) /// This adds all current state events (not including the incoming event)
/// to `stateid_pduid` and adds the incoming event to `eventid_statehash`. /// to `stateid_pduid` and adds the incoming event to `eventid_statehash`.
#[tracing::instrument(skip(self, state_ids_compressed))] #[tracing::instrument(skip(self, state_ids_compressed))]
pub fn set_event_state( pub(crate) fn set_event_state(
&self, &self,
event_id: &EventId, event_id: &EventId,
room_id: &RoomId, room_id: &RoomId,
@ -187,7 +187,7 @@ impl Service {
/// This adds all current state events (not including the incoming event) /// This adds all current state events (not including the incoming event)
/// to `stateid_pduid` and adds the incoming event to `eventid_statehash`. /// to `stateid_pduid` and adds the incoming event to `eventid_statehash`.
#[tracing::instrument(skip(self, new_pdu))] #[tracing::instrument(skip(self, new_pdu))]
pub fn append_to_state(&self, new_pdu: &PduEvent) -> Result<u64> { pub(crate) fn append_to_state(&self, new_pdu: &PduEvent) -> Result<u64> {
let shorteventid = services() let shorteventid = services()
.rooms .rooms
.short .short
@ -259,7 +259,7 @@ impl Service {
} }
#[tracing::instrument(skip(self, invite_event))] #[tracing::instrument(skip(self, invite_event))]
pub fn calculate_invite_state( pub(crate) fn calculate_invite_state(
&self, &self,
invite_event: &PduEvent, invite_event: &PduEvent,
) -> Result<Vec<Raw<AnyStrippedStateEvent>>> { ) -> Result<Vec<Raw<AnyStrippedStateEvent>>> {
@ -314,7 +314,7 @@ impl Service {
/// Set the state hash to a new version, but does not update state_cache. /// Set the state hash to a new version, but does not update state_cache.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn set_room_state( pub(crate) fn set_room_state(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
shortstatehash: u64, shortstatehash: u64,
@ -325,7 +325,7 @@ impl Service {
/// Returns the room's version. /// Returns the room's version.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn get_room_version(&self, room_id: &RoomId) -> Result<RoomVersionId> { pub(crate) fn get_room_version(&self, room_id: &RoomId) -> Result<RoomVersionId> {
let create_event = services().rooms.state_accessor.room_state_get( let create_event = services().rooms.state_accessor.room_state_get(
room_id, room_id,
&StateEventType::RoomCreate, &StateEventType::RoomCreate,
@ -346,15 +346,18 @@ impl Service {
Ok(create_event_content.room_version) Ok(create_event_content.room_version)
} }
pub fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>> { pub(crate) fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.get_room_shortstatehash(room_id) self.db.get_room_shortstatehash(room_id)
} }
pub fn get_forward_extremities(&self, room_id: &RoomId) -> Result<HashSet<Arc<EventId>>> { pub(crate) fn get_forward_extremities(
&self,
room_id: &RoomId,
) -> Result<HashSet<Arc<EventId>>> {
self.db.get_forward_extremities(room_id) self.db.get_forward_extremities(room_id)
} }
pub fn set_forward_extremities( pub(crate) fn set_forward_extremities(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_ids: Vec<OwnedEventId>, event_ids: Vec<OwnedEventId>,
@ -366,7 +369,7 @@ impl Service {
/// This fetches auth events from the current state. /// This fetches auth events from the current state.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn get_auth_events( pub(crate) fn get_auth_events(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
kind: &TimelineEventType, kind: &TimelineEventType,

View file

@ -3,7 +3,7 @@ use ruma::{EventId, OwnedEventId, RoomId};
use std::{collections::HashSet, sync::Arc}; use std::{collections::HashSet, sync::Arc};
use tokio::sync::MutexGuard; use tokio::sync::MutexGuard;
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
/// Returns the last state hash key added to the db for the given room. /// Returns the last state hash key added to the db for the given room.
fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>>; fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>>;

View file

@ -4,7 +4,7 @@ use std::{
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
pub use data::Data; pub(crate) use data::Data;
use lru_cache::LruCache; use lru_cache::LruCache;
use ruma::{ use ruma::{
events::{ events::{
@ -26,21 +26,24 @@ use tracing::{error, warn};
use crate::{service::pdu::PduBuilder, services, Error, PduEvent, Result}; use crate::{service::pdu::PduBuilder, services, Error, PduEvent, Result};
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
pub server_visibility_cache: Mutex<LruCache<(OwnedServerName, u64), bool>>, pub(crate) server_visibility_cache: Mutex<LruCache<(OwnedServerName, u64), bool>>,
pub user_visibility_cache: Mutex<LruCache<(OwnedUserId, u64), bool>>, pub(crate) user_visibility_cache: Mutex<LruCache<(OwnedUserId, u64), bool>>,
} }
impl Service { impl Service {
/// Builds a StateMap by iterating over all keys that start /// Builds a StateMap by iterating over all keys that start
/// with state_hash, this gives the full state for the given state_hash. /// with state_hash, this gives the full state for the given state_hash.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub async fn state_full_ids(&self, shortstatehash: u64) -> Result<HashMap<u64, Arc<EventId>>> { pub(crate) async fn state_full_ids(
&self,
shortstatehash: u64,
) -> Result<HashMap<u64, Arc<EventId>>> {
self.db.state_full_ids(shortstatehash).await self.db.state_full_ids(shortstatehash).await
} }
pub async fn state_full( pub(crate) async fn state_full(
&self, &self,
shortstatehash: u64, shortstatehash: u64,
) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> { ) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> {
@ -49,7 +52,7 @@ impl Service {
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn state_get_id( pub(crate) fn state_get_id(
&self, &self,
shortstatehash: u64, shortstatehash: u64,
event_type: &StateEventType, event_type: &StateEventType,
@ -59,7 +62,7 @@ impl Service {
} }
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
pub fn state_get( pub(crate) fn state_get(
&self, &self,
shortstatehash: u64, shortstatehash: u64,
event_type: &StateEventType, event_type: &StateEventType,
@ -100,7 +103,7 @@ impl Service {
/// Whether a server is allowed to see an event through federation, based on /// Whether a server is allowed to see an event through federation, based on
/// the room's history_visibility at that event's state. /// the room's history_visibility at that event's state.
#[tracing::instrument(skip(self, origin, room_id, event_id))] #[tracing::instrument(skip(self, origin, room_id, event_id))]
pub fn server_can_see_event( pub(crate) fn server_can_see_event(
&self, &self,
origin: &ServerName, origin: &ServerName,
room_id: &RoomId, room_id: &RoomId,
@ -164,7 +167,7 @@ impl Service {
/// Whether a user is allowed to see an event, based on /// Whether a user is allowed to see an event, based on
/// the room's history_visibility at that event's state. /// the room's history_visibility at that event's state.
#[tracing::instrument(skip(self, user_id, room_id, event_id))] #[tracing::instrument(skip(self, user_id, room_id, event_id))]
pub fn user_can_see_event( pub(crate) fn user_can_see_event(
&self, &self,
user_id: &UserId, user_id: &UserId,
room_id: &RoomId, room_id: &RoomId,
@ -224,7 +227,11 @@ impl Service {
/// Whether a user is allowed to see an event, based on /// Whether a user is allowed to see an event, based on
/// the room's history_visibility at that event's state. /// the room's history_visibility at that event's state.
#[tracing::instrument(skip(self, user_id, room_id))] #[tracing::instrument(skip(self, user_id, room_id))]
pub fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> { pub(crate) fn user_can_see_state_events(
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<bool> {
let currently_member = services().rooms.state_cache.is_joined(user_id, room_id)?; let currently_member = services().rooms.state_cache.is_joined(user_id, room_id)?;
let history_visibility = self let history_visibility = self
@ -241,13 +248,13 @@ impl Service {
} }
/// Returns the state hash for this pdu. /// Returns the state hash for this pdu.
pub fn pdu_shortstatehash(&self, event_id: &EventId) -> Result<Option<u64>> { pub(crate) fn pdu_shortstatehash(&self, event_id: &EventId) -> Result<Option<u64>> {
self.db.pdu_shortstatehash(event_id) self.db.pdu_shortstatehash(event_id)
} }
/// Returns the full room state. /// Returns the full room state.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub async fn room_state_full( pub(crate) async fn room_state_full(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> { ) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> {
@ -256,7 +263,7 @@ impl Service {
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn room_state_get_id( pub(crate) fn room_state_get_id(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_type: &StateEventType, event_type: &StateEventType,
@ -267,7 +274,7 @@ impl Service {
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn room_state_get( pub(crate) fn room_state_get(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_type: &StateEventType, event_type: &StateEventType,
@ -276,7 +283,7 @@ impl Service {
self.db.room_state_get(room_id, event_type, state_key) self.db.room_state_get(room_id, event_type, state_key)
} }
pub fn get_name(&self, room_id: &RoomId) -> Result<Option<String>> { pub(crate) fn get_name(&self, room_id: &RoomId) -> Result<Option<String>> {
services() services()
.rooms .rooms
.state_accessor .state_accessor
@ -294,7 +301,7 @@ impl Service {
}) })
} }
pub fn get_avatar(&self, room_id: &RoomId) -> Result<JsOption<RoomAvatarEventContent>> { pub(crate) fn get_avatar(&self, room_id: &RoomId) -> Result<JsOption<RoomAvatarEventContent>> {
services() services()
.rooms .rooms
.state_accessor .state_accessor
@ -305,7 +312,7 @@ impl Service {
}) })
} }
pub async fn user_can_invite( pub(crate) async fn user_can_invite(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
sender: &UserId, sender: &UserId,
@ -330,7 +337,7 @@ impl Service {
.is_ok()) .is_ok())
} }
pub fn get_member( pub(crate) fn get_member(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
user_id: &UserId, user_id: &UserId,
@ -350,7 +357,7 @@ impl Service {
/// If `federation` is `true`, it allows redaction events from any user of the same server /// If `federation` is `true`, it allows redaction events from any user of the same server
/// as the original event sender, [as required by room versions >= /// as the original event sender, [as required by room versions >=
/// v3](https://spec.matrix.org/v1.10/rooms/v11/#handling-redactions) /// v3](https://spec.matrix.org/v1.10/rooms/v11/#handling-redactions)
pub fn user_can_redact( pub(crate) fn user_can_redact(
&self, &self,
redacts: &EventId, redacts: &EventId,
sender: &UserId, sender: &UserId,

View file

@ -6,7 +6,7 @@ use ruma::{events::StateEventType, EventId, RoomId};
use crate::{PduEvent, Result}; use crate::{PduEvent, Result};
#[async_trait] #[async_trait]
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
/// Builds a StateMap by iterating over all keys that start /// Builds a StateMap by iterating over all keys that start
/// with state_hash, this gives the full state for the given state_hash. /// with state_hash, this gives the full state for the given state_hash.
async fn state_full_ids(&self, shortstatehash: u64) -> Result<HashMap<u64, Arc<EventId>>>; async fn state_full_ids(&self, shortstatehash: u64) -> Result<HashMap<u64, Arc<EventId>>>;

View file

@ -1,7 +1,7 @@
mod data; mod data;
use std::{collections::HashSet, sync::Arc}; use std::{collections::HashSet, sync::Arc};
pub use data::Data; pub(crate) use data::Data;
use ruma::{ use ruma::{
events::{ events::{
@ -18,14 +18,14 @@ use tracing::warn;
use crate::{service::appservice::RegistrationInfo, services, Error, Result}; use crate::{service::appservice::RegistrationInfo, services, Error, Result};
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
/// Update current membership data. /// Update current membership data.
#[tracing::instrument(skip(self, last_state))] #[tracing::instrument(skip(self, last_state))]
pub fn update_membership( pub(crate) fn update_membership(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
user_id: &UserId, user_id: &UserId,
@ -192,17 +192,17 @@ impl Service {
} }
#[tracing::instrument(skip(self, room_id))] #[tracing::instrument(skip(self, room_id))]
pub fn update_joined_count(&self, room_id: &RoomId) -> Result<()> { pub(crate) fn update_joined_count(&self, room_id: &RoomId) -> Result<()> {
self.db.update_joined_count(room_id) self.db.update_joined_count(room_id)
} }
#[tracing::instrument(skip(self, room_id))] #[tracing::instrument(skip(self, room_id))]
pub fn get_our_real_users(&self, room_id: &RoomId) -> Result<Arc<HashSet<OwnedUserId>>> { pub(crate) fn get_our_real_users(&self, room_id: &RoomId) -> Result<Arc<HashSet<OwnedUserId>>> {
self.db.get_our_real_users(room_id) self.db.get_our_real_users(room_id)
} }
#[tracing::instrument(skip(self, room_id, appservice))] #[tracing::instrument(skip(self, room_id, appservice))]
pub fn appservice_in_room( pub(crate) fn appservice_in_room(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
appservice: &RegistrationInfo, appservice: &RegistrationInfo,
@ -212,13 +212,13 @@ impl Service {
/// Makes a user forget a room. /// Makes a user forget a room.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn forget(&self, room_id: &RoomId, user_id: &UserId) -> Result<()> { pub(crate) fn forget(&self, room_id: &RoomId, user_id: &UserId) -> Result<()> {
self.db.forget(room_id, user_id) self.db.forget(room_id, user_id)
} }
/// Returns an iterator of all servers participating in this room. /// Returns an iterator of all servers participating in this room.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn room_servers<'a>( pub(crate) fn room_servers<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> impl Iterator<Item = Result<OwnedServerName>> + 'a { ) -> impl Iterator<Item = Result<OwnedServerName>> + 'a {
@ -226,13 +226,17 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn server_in_room<'a>(&'a self, server: &ServerName, room_id: &RoomId) -> Result<bool> { pub(crate) fn server_in_room<'a>(
&'a self,
server: &ServerName,
room_id: &RoomId,
) -> Result<bool> {
self.db.server_in_room(server, room_id) self.db.server_in_room(server, room_id)
} }
/// Returns an iterator of all rooms a server participates in (as far as we know). /// Returns an iterator of all rooms a server participates in (as far as we know).
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn server_rooms<'a>( pub(crate) fn server_rooms<'a>(
&'a self, &'a self,
server: &ServerName, server: &ServerName,
) -> impl Iterator<Item = Result<OwnedRoomId>> + 'a { ) -> impl Iterator<Item = Result<OwnedRoomId>> + 'a {
@ -241,7 +245,7 @@ impl Service {
/// Returns an iterator over all joined members of a room. /// Returns an iterator over all joined members of a room.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn room_members<'a>( pub(crate) fn room_members<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> impl Iterator<Item = Result<OwnedUserId>> + 'a { ) -> impl Iterator<Item = Result<OwnedUserId>> + 'a {
@ -249,18 +253,18 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> { pub(crate) fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.room_joined_count(room_id) self.db.room_joined_count(room_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn room_invited_count(&self, room_id: &RoomId) -> Result<Option<u64>> { pub(crate) fn room_invited_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.room_invited_count(room_id) self.db.room_invited_count(room_id)
} }
/// Returns an iterator over all User IDs who ever joined a room. /// Returns an iterator over all User IDs who ever joined a room.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn room_useroncejoined<'a>( pub(crate) fn room_useroncejoined<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> impl Iterator<Item = Result<OwnedUserId>> + 'a { ) -> impl Iterator<Item = Result<OwnedUserId>> + 'a {
@ -269,7 +273,7 @@ impl Service {
/// Returns an iterator over all invited members of a room. /// Returns an iterator over all invited members of a room.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn room_members_invited<'a>( pub(crate) fn room_members_invited<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> impl Iterator<Item = Result<OwnedUserId>> + 'a { ) -> impl Iterator<Item = Result<OwnedUserId>> + 'a {
@ -277,18 +281,22 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> { pub(crate) fn get_invite_count(
&self,
room_id: &RoomId,
user_id: &UserId,
) -> Result<Option<u64>> {
self.db.get_invite_count(room_id, user_id) self.db.get_invite_count(room_id, user_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> { pub(crate) fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
self.db.get_left_count(room_id, user_id) self.db.get_left_count(room_id, user_id)
} }
/// Returns an iterator over all rooms this user joined. /// Returns an iterator over all rooms this user joined.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn rooms_joined<'a>( pub(crate) fn rooms_joined<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> impl Iterator<Item = Result<OwnedRoomId>> + 'a { ) -> impl Iterator<Item = Result<OwnedRoomId>> + 'a {
@ -297,7 +305,7 @@ impl Service {
/// Returns an iterator over all rooms a user was invited to. /// Returns an iterator over all rooms a user was invited to.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn rooms_invited<'a>( pub(crate) fn rooms_invited<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a { ) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a {
@ -305,7 +313,7 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn invite_state( pub(crate) fn invite_state(
&self, &self,
user_id: &UserId, user_id: &UserId,
room_id: &RoomId, room_id: &RoomId,
@ -314,7 +322,7 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn left_state( pub(crate) fn left_state(
&self, &self,
user_id: &UserId, user_id: &UserId,
room_id: &RoomId, room_id: &RoomId,
@ -324,7 +332,7 @@ impl Service {
/// Returns an iterator over all rooms a user left. /// Returns an iterator over all rooms a user left.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn rooms_left<'a>( pub(crate) fn rooms_left<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a { ) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a {
@ -332,22 +340,22 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> { pub(crate) fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
self.db.once_joined(user_id, room_id) self.db.once_joined(user_id, room_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> { pub(crate) fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
self.db.is_joined(user_id, room_id) self.db.is_joined(user_id, room_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> { pub(crate) fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
self.db.is_invited(user_id, room_id) self.db.is_invited(user_id, room_id)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> { pub(crate) fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
self.db.is_left(user_id, room_id) self.db.is_left(user_id, room_id)
} }
} }

View file

@ -7,7 +7,7 @@ use ruma::{
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
}; };
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn mark_as_once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn mark_as_once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>;
fn mark_as_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn mark_as_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>;
fn mark_as_invited( fn mark_as_invited(

View file

@ -1,11 +1,11 @@
pub mod data; pub(crate) mod data;
use std::{ use std::{
collections::HashSet, collections::HashSet,
mem::size_of, mem::size_of,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
pub use data::Data; pub(crate) use data::Data;
use lru_cache::LruCache; use lru_cache::LruCache;
use ruma::{EventId, RoomId}; use ruma::{EventId, RoomId};
@ -13,11 +13,11 @@ use crate::{services, utils, Result};
use self::data::StateDiff; use self::data::StateDiff;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub stateinfo_cache: Mutex< pub(crate) stateinfo_cache: Mutex<
LruCache< LruCache<
u64, u64,
Vec<( Vec<(
@ -30,13 +30,13 @@ pub struct Service {
>, >,
} }
pub type CompressedStateEvent = [u8; 2 * size_of::<u64>()]; pub(crate) type CompressedStateEvent = [u8; 2 * size_of::<u64>()];
impl Service { impl Service {
/// Returns a stack with info on shortstatehash, full state, added diff and removed diff for the selected shortstatehash and each parent layer. /// Returns a stack with info on shortstatehash, full state, added diff and removed diff for the selected shortstatehash and each parent layer.
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn load_shortstatehash_info( pub(crate) fn load_shortstatehash_info(
&self, &self,
shortstatehash: u64, shortstatehash: u64,
) -> Result< ) -> Result<
@ -89,7 +89,7 @@ impl Service {
} }
} }
pub fn compress_state_event( pub(crate) fn compress_state_event(
&self, &self,
shortstatekey: u64, shortstatekey: u64,
event_id: &EventId, event_id: &EventId,
@ -106,7 +106,7 @@ impl Service {
} }
/// Returns shortstatekey, event id /// Returns shortstatekey, event id
pub fn parse_compressed_state_event( pub(crate) fn parse_compressed_state_event(
&self, &self,
compressed_event: &CompressedStateEvent, compressed_event: &CompressedStateEvent,
) -> Result<(u64, Arc<EventId>)> { ) -> Result<(u64, Arc<EventId>)> {
@ -141,7 +141,7 @@ impl Service {
diff_to_sibling, diff_to_sibling,
parent_states parent_states
))] ))]
pub fn save_state_from_diff( pub(crate) fn save_state_from_diff(
&self, &self,
shortstatehash: u64, shortstatehash: u64,
statediffnew: Arc<HashSet<CompressedStateEvent>>, statediffnew: Arc<HashSet<CompressedStateEvent>>,
@ -257,7 +257,7 @@ impl Service {
/// Returns the new shortstatehash, and the state diff from the previous room state /// Returns the new shortstatehash, and the state diff from the previous room state
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub fn save_state( pub(crate) fn save_state(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
new_state_ids_compressed: Arc<HashSet<CompressedStateEvent>>, new_state_ids_compressed: Arc<HashSet<CompressedStateEvent>>,

View file

@ -3,13 +3,13 @@ use std::{collections::HashSet, sync::Arc};
use super::CompressedStateEvent; use super::CompressedStateEvent;
use crate::Result; use crate::Result;
pub struct StateDiff { pub(crate) struct StateDiff {
pub parent: Option<u64>, pub(crate) parent: Option<u64>,
pub added: Arc<HashSet<CompressedStateEvent>>, pub(crate) added: Arc<HashSet<CompressedStateEvent>>,
pub removed: Arc<HashSet<CompressedStateEvent>>, pub(crate) removed: Arc<HashSet<CompressedStateEvent>>,
} }
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn get_statediff(&self, shortstatehash: u64) -> Result<StateDiff>; fn get_statediff(&self, shortstatehash: u64) -> Result<StateDiff>;
fn save_statediff(&self, shortstatehash: u64, diff: StateDiff) -> Result<()>; fn save_statediff(&self, shortstatehash: u64, diff: StateDiff) -> Result<()>;
} }

View file

@ -1,6 +1,6 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use ruma::{ use ruma::{
api::client::{error::ErrorKind, threads::get_threads::v1::IncludeThreads}, api::client::{error::ErrorKind, threads::get_threads::v1::IncludeThreads},
events::relation::BundledThread, events::relation::BundledThread,
@ -11,12 +11,12 @@ use serde_json::json;
use crate::{services, Error, PduEvent, Result}; use crate::{services, Error, PduEvent, Result};
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
pub fn threads_until<'a>( pub(crate) fn threads_until<'a>(
&'a self, &'a self,
user_id: &'a UserId, user_id: &'a UserId,
room_id: &'a RoomId, room_id: &'a RoomId,
@ -26,7 +26,7 @@ impl Service {
self.db.threads_until(user_id, room_id, until, include) self.db.threads_until(user_id, room_id, until, include)
} }
pub fn add_to_thread(&self, root_event_id: &EventId, pdu: &PduEvent) -> Result<()> { pub(crate) fn add_to_thread(&self, root_event_id: &EventId, pdu: &PduEvent) -> Result<()> {
let root_id = &services() let root_id = &services()
.rooms .rooms
.timeline .timeline

View file

@ -1,7 +1,7 @@
use crate::{PduEvent, Result}; use crate::{PduEvent, Result};
use ruma::{api::client::threads::get_threads::v1::IncludeThreads, OwnedUserId, RoomId, UserId}; use ruma::{api::client::threads::get_threads::v1::IncludeThreads, OwnedUserId, RoomId, UserId};
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn threads_until<'a>( fn threads_until<'a>(
&'a self, &'a self,

View file

@ -6,7 +6,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
pub use data::Data; pub(crate) use data::Data;
use ruma::{ use ruma::{
api::{client::error::ErrorKind, federation}, api::{client::error::ErrorKind, federation},
@ -42,20 +42,20 @@ use crate::{
use super::state_compressor::CompressedStateEvent; use super::state_compressor::CompressedStateEvent;
#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)] #[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]
pub enum PduCount { pub(crate) enum PduCount {
Backfilled(u64), Backfilled(u64),
Normal(u64), Normal(u64),
} }
impl PduCount { impl PduCount {
pub fn min() -> Self { pub(crate) fn min() -> Self {
Self::Backfilled(u64::MAX) Self::Backfilled(u64::MAX)
} }
pub fn max() -> Self { pub(crate) fn max() -> Self {
Self::Normal(u64::MAX) Self::Normal(u64::MAX)
} }
pub fn try_from_string(token: &str) -> Result<Self> { pub(crate) fn try_from_string(token: &str) -> Result<Self> {
if let Some(stripped) = token.strip_prefix('-') { if let Some(stripped) = token.strip_prefix('-') {
stripped.parse().map(PduCount::Backfilled) stripped.parse().map(PduCount::Backfilled)
} else { } else {
@ -64,7 +64,7 @@ impl PduCount {
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid pagination token.")) .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid pagination token."))
} }
pub fn stringify(&self) -> String { pub(crate) fn stringify(&self) -> String {
match self { match self {
PduCount::Backfilled(x) => format!("-{x}"), PduCount::Backfilled(x) => format!("-{x}"),
PduCount::Normal(x) => x.to_string(), PduCount::Normal(x) => x.to_string(),
@ -89,15 +89,15 @@ impl Ord for PduCount {
} }
} }
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
pub lasttimelinecount_cache: Mutex<HashMap<OwnedRoomId, PduCount>>, pub(crate) lasttimelinecount_cache: Mutex<HashMap<OwnedRoomId, PduCount>>,
} }
impl Service { impl Service {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn first_pdu_in_room(&self, room_id: &RoomId) -> Result<Option<Arc<PduEvent>>> { pub(crate) fn first_pdu_in_room(&self, room_id: &RoomId) -> Result<Option<Arc<PduEvent>>> {
self.all_pdus(user_id!("@doesntmatter:grapevine"), room_id)? self.all_pdus(user_id!("@doesntmatter:grapevine"), room_id)?
.next() .next()
.map(|o| o.map(|(_, p)| Arc::new(p))) .map(|o| o.map(|(_, p)| Arc::new(p)))
@ -105,19 +105,23 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result<PduCount> { pub(crate) fn last_timeline_count(
&self,
sender_user: &UserId,
room_id: &RoomId,
) -> Result<PduCount> {
self.db.last_timeline_count(sender_user, room_id) self.db.last_timeline_count(sender_user, room_id)
} }
/// Returns the `count` of this pdu's id. /// Returns the `count` of this pdu's id.
pub fn get_pdu_count(&self, event_id: &EventId) -> Result<Option<PduCount>> { pub(crate) fn get_pdu_count(&self, event_id: &EventId) -> Result<Option<PduCount>> {
self.db.get_pdu_count(event_id) self.db.get_pdu_count(event_id)
} }
// TODO Is this the same as the function above? // TODO Is this the same as the function above?
/* /*
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn latest_pdu_count(&self, room_id: &RoomId) -> Result<u64> { pub(crate) fn latest_pdu_count(&self, room_id: &RoomId) -> Result<u64> {
let prefix = self let prefix = self
.get_shortroomid(room_id)? .get_shortroomid(room_id)?
.expect("room exists") .expect("room exists")
@ -138,12 +142,12 @@ impl Service {
*/ */
/// Returns the json of a pdu. /// Returns the json of a pdu.
pub fn get_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>> { pub(crate) fn get_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>> {
self.db.get_pdu_json(event_id) self.db.get_pdu_json(event_id)
} }
/// Returns the json of a pdu. /// Returns the json of a pdu.
pub fn get_non_outlier_pdu_json( pub(crate) fn get_non_outlier_pdu_json(
&self, &self,
event_id: &EventId, event_id: &EventId,
) -> Result<Option<CanonicalJsonObject>> { ) -> Result<Option<CanonicalJsonObject>> {
@ -151,39 +155,42 @@ impl Service {
} }
/// Returns the pdu's id. /// Returns the pdu's id.
pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> { pub(crate) fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> {
self.db.get_pdu_id(event_id) self.db.get_pdu_id(event_id)
} }
/// Returns the pdu. /// Returns the pdu.
/// ///
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline. /// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
pub fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result<Option<PduEvent>> { pub(crate) fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result<Option<PduEvent>> {
self.db.get_non_outlier_pdu(event_id) self.db.get_non_outlier_pdu(event_id)
} }
/// Returns the pdu. /// Returns the pdu.
/// ///
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline. /// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
pub fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>> { pub(crate) fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>> {
self.db.get_pdu(event_id) self.db.get_pdu(event_id)
} }
/// Returns the pdu. /// Returns the pdu.
/// ///
/// This does __NOT__ check the outliers `Tree`. /// This does __NOT__ check the outliers `Tree`.
pub fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result<Option<PduEvent>> { pub(crate) fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result<Option<PduEvent>> {
self.db.get_pdu_from_id(pdu_id) self.db.get_pdu_from_id(pdu_id)
} }
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`. /// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
pub fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result<Option<CanonicalJsonObject>> { pub(crate) fn get_pdu_json_from_id(
&self,
pdu_id: &[u8],
) -> Result<Option<CanonicalJsonObject>> {
self.db.get_pdu_json_from_id(pdu_id) self.db.get_pdu_json_from_id(pdu_id)
} }
/// Removes a pdu and creates a new one with the same id. /// Removes a pdu and creates a new one with the same id.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn replace_pdu( pub(crate) fn replace_pdu(
&self, &self,
pdu_id: &[u8], pdu_id: &[u8],
pdu_json: &CanonicalJsonObject, pdu_json: &CanonicalJsonObject,
@ -199,7 +206,7 @@ impl Service {
/// ///
/// Returns pdu id /// Returns pdu id
#[tracing::instrument(skip(self, pdu, pdu_json, leaves))] #[tracing::instrument(skip(self, pdu, pdu_json, leaves))]
pub async fn append_pdu<'a>( pub(crate) async fn append_pdu<'a>(
&self, &self,
pdu: &PduEvent, pdu: &PduEvent,
mut pdu_json: CanonicalJsonObject, mut pdu_json: CanonicalJsonObject,
@ -624,7 +631,7 @@ impl Service {
Ok(pdu_id) Ok(pdu_id)
} }
pub fn create_hash_and_sign_event( pub(crate) fn create_hash_and_sign_event(
&self, &self,
pdu_builder: PduBuilder, pdu_builder: PduBuilder,
sender: &UserId, sender: &UserId,
@ -807,7 +814,7 @@ impl Service {
/// Creates a new persisted data unit and adds it to a room. This function takes a /// Creates a new persisted data unit and adds it to a room. This function takes a
/// roomid_mutex_state, meaning that only this function is able to mutate the room state. /// roomid_mutex_state, meaning that only this function is able to mutate the room state.
#[tracing::instrument(skip(self, state_lock))] #[tracing::instrument(skip(self, state_lock))]
pub async fn build_and_append_pdu( pub(crate) async fn build_and_append_pdu(
&self, &self,
pdu_builder: PduBuilder, pdu_builder: PduBuilder,
sender: &UserId, sender: &UserId,
@ -1007,7 +1014,7 @@ impl Service {
/// Append the incoming event setting the state snapshot to the state from the /// Append the incoming event setting the state snapshot to the state from the
/// server that sent the event. /// server that sent the event.
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
pub async fn append_incoming_pdu<'a>( pub(crate) async fn append_incoming_pdu<'a>(
&self, &self,
pdu: &PduEvent, pdu: &PduEvent,
pdu_json: CanonicalJsonObject, pdu_json: CanonicalJsonObject,
@ -1047,7 +1054,7 @@ impl Service {
} }
/// Returns an iterator over all PDUs in a room. /// Returns an iterator over all PDUs in a room.
pub fn all_pdus<'a>( pub(crate) fn all_pdus<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
room_id: &RoomId, room_id: &RoomId,
@ -1058,7 +1065,7 @@ impl Service {
/// Returns an iterator over all events and their tokens in a room that happened before the /// Returns an iterator over all events and their tokens in a room that happened before the
/// event with id `until` in reverse-chronological order. /// event with id `until` in reverse-chronological order.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn pdus_until<'a>( pub(crate) fn pdus_until<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
room_id: &RoomId, room_id: &RoomId,
@ -1070,7 +1077,7 @@ impl Service {
/// Returns an iterator over all events and their token in a room that happened after the event /// Returns an iterator over all events and their token in a room that happened after the event
/// with id `from` in chronological order. /// with id `from` in chronological order.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn pdus_after<'a>( pub(crate) fn pdus_after<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
room_id: &RoomId, room_id: &RoomId,
@ -1081,7 +1088,7 @@ impl Service {
/// Replace a PDU with the redacted form. /// Replace a PDU with the redacted form.
#[tracing::instrument(skip(self, reason))] #[tracing::instrument(skip(self, reason))]
pub fn redact_pdu(&self, event_id: &EventId, reason: &PduEvent) -> Result<()> { pub(crate) fn redact_pdu(&self, event_id: &EventId, reason: &PduEvent) -> Result<()> {
// TODO: Don't reserialize, keep original json // TODO: Don't reserialize, keep original json
if let Some(pdu_id) = self.get_pdu_id(event_id)? { if let Some(pdu_id) = self.get_pdu_id(event_id)? {
let mut pdu = self let mut pdu = self
@ -1100,7 +1107,11 @@ impl Service {
} }
#[tracing::instrument(skip(self, room_id))] #[tracing::instrument(skip(self, room_id))]
pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Result<()> { pub(crate) async fn backfill_if_required(
&self,
room_id: &RoomId,
from: PduCount,
) -> Result<()> {
let first_pdu = self let first_pdu = self
.all_pdus(user_id!("@doesntmatter:grapevine"), room_id)? .all_pdus(user_id!("@doesntmatter:grapevine"), room_id)?
.next() .next()
@ -1165,7 +1176,7 @@ impl Service {
} }
#[tracing::instrument(skip(self, pdu))] #[tracing::instrument(skip(self, pdu))]
pub async fn backfill_pdu( pub(crate) async fn backfill_pdu(
&self, &self,
origin: &ServerName, origin: &ServerName,
pdu: Box<RawJsonValue>, pdu: Box<RawJsonValue>,

View file

@ -6,7 +6,7 @@ use crate::{PduEvent, Result};
use super::PduCount; use super::PduCount;
pub trait Data: Send + Sync { pub(crate) trait Data: Send + Sync {
fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result<PduCount>; fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result<PduCount>;
/// Returns the `count` of this pdu's id. /// Returns the `count` of this pdu's id.

View file

@ -1,32 +1,36 @@
mod data; mod data;
pub use data::Data; pub(crate) use data::Data;
use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId};
use crate::Result; use crate::Result;
pub struct Service { pub(crate) struct Service {
pub db: &'static dyn Data, pub(crate) db: &'static dyn Data,
} }
impl Service { impl Service {
pub fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { pub(crate) fn reset_notification_counts(
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<()> {
self.db.reset_notification_counts(user_id, room_id) self.db.reset_notification_counts(user_id, room_id)
} }
pub fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> { pub(crate) fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
self.db.notification_count(user_id, room_id) self.db.notification_count(user_id, room_id)
} }
pub fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> { pub(crate) fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
self.db.highlight_count(user_id, room_id) self.db.highlight_count(user_id, room_id)
} }
pub fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> { pub(crate) fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
self.db.last_notification_read(user_id, room_id) self.db.last_notification_read(user_id, room_id)
} }
pub fn associate_token_shortstatehash( pub(crate) fn associate_token_shortstatehash(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
token: u64, token: u64,
@ -36,11 +40,15 @@ impl Service {
.associate_token_shortstatehash(room_id, token, shortstatehash) .associate_token_shortstatehash(room_id, token, shortstatehash)
} }
pub fn get_token_shortstatehash(&self, room_id: &RoomId, token: u64) -> Result<Option<u64>> { pub(crate) fn get_token_shortstatehash(
&self,
room_id: &RoomId,
token: u64,
) -> Result<Option<u64>> {
self.db.get_token_shortstatehash(room_id, token) self.db.get_token_shortstatehash(room_id, token)
} }
pub fn get_shared_rooms( pub(crate) fn get_shared_rooms(
&self, &self,
users: Vec<OwnedUserId>, users: Vec<OwnedUserId>,
) -> Result<impl Iterator<Item = Result<OwnedRoomId>>> { ) -> Result<impl Iterator<Item = Result<OwnedRoomId>>> {

Some files were not shown because too many files have changed in this diff Show more