Bump ruma

This commit is contained in:
Timo Kösters 2022-10-09 17:25:06 +02:00 committed by Nyaaori
parent 275c6b447d
commit 6b131202b9
No known key found for this signature in database
GPG key ID: E7819C3ED4D1F82E
68 changed files with 446 additions and 347 deletions

106
Cargo.lock generated
View file

@ -181,6 +181,12 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "base64ct"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2b2456fd614d856680dcd9fcc660a51a820fa09daef2e49772b56a193c8474"
[[package]] [[package]]
name = "bincode" name = "bincode"
version = "1.3.3" version = "1.3.3"
@ -429,9 +435,9 @@ dependencies = [
[[package]] [[package]]
name = "const-oid" name = "const-oid"
version = "0.6.2" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b" checksum = "722e23542a15cea1f65d4a1419c4cfd7a26706c70871a13a04238ca3f40f1661"
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
@ -567,9 +573,9 @@ dependencies = [
[[package]] [[package]]
name = "curve25519-dalek" name = "curve25519-dalek"
version = "3.2.1" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"digest 0.9.0", "digest 0.9.0",
@ -586,11 +592,12 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
[[package]] [[package]]
name = "der" name = "der"
version = "0.4.5" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79b71cca7d95d7681a4b3b9cdf63c8dbc3730d0584c2c74e31416d64a90493f4" checksum = "13dd2ae565c0a381dde7fade45fce95984c568bdcb4700a4fdbe3175e0380b2f"
dependencies = [ dependencies = [
"const-oid", "const-oid",
"zeroize",
] ]
[[package]] [[package]]
@ -1145,12 +1152,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "indoc"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adab1eaa3408fb7f0c777a73e7465fd5656136fc93b670eb6df3c88c2c1344e3"
[[package]] [[package]]
name = "inlinable_string" name = "inlinable_string"
version = "0.1.15" version = "0.1.15"
@ -1229,6 +1230,15 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "js_option"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68421373957a1593a767013698dbf206e2b221eefe97a44d98d18672ff38423c"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "jsonwebtoken" name = "jsonwebtoken"
version = "8.1.1" version = "8.1.1"
@ -1757,13 +1767,12 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]] [[package]]
name = "pkcs8" name = "pkcs8"
version = "0.7.6" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447" checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba"
dependencies = [ dependencies = [
"der", "der",
"spki", "spki",
"zeroize",
] ]
[[package]] [[package]]
@ -2054,11 +2063,12 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.5.0" version = "0.7.4"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
"js_option",
"ruma-appservice-api", "ruma-appservice-api",
"ruma-client-api", "ruma-client-api",
"ruma-common", "ruma-common",
@ -2071,8 +2081,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.5.0" version = "0.7.0"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"ruma-common", "ruma-common",
"serde", "serde",
@ -2081,8 +2091,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.13.0" version = "0.15.1"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"assign", "assign",
"bytes", "bytes",
@ -2097,19 +2107,20 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.8.0" version = "0.10.3"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"base64", "base64",
"bytes", "bytes",
"form_urlencoded", "form_urlencoded",
"http", "http",
"indexmap", "indexmap",
"indoc",
"itoa", "itoa",
"js_int", "js_int",
"js_option",
"percent-encoding", "percent-encoding",
"rand 0.8.5", "rand 0.8.5",
"regex",
"ruma-identifiers-validation", "ruma-identifiers-validation",
"ruma-macros", "ruma-macros",
"serde", "serde",
@ -2123,8 +2134,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.4.0" version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -2134,17 +2145,17 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.7.0" version = "0.9.0"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"js_int",
"thiserror", "thiserror",
"url",
] ]
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.4.0" version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -2153,20 +2164,23 @@ dependencies = [
[[package]] [[package]]
name = "ruma-macros" name = "ruma-macros"
version = "0.1.0" version = "0.10.3"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"once_cell",
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
"quote", "quote",
"ruma-identifiers-validation", "ruma-identifiers-validation",
"serde",
"syn", "syn",
"toml",
] ]
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.4.0" version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -2176,8 +2190,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.10.0" version = "0.12.0"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"base64", "base64",
"ed25519-dalek", "ed25519-dalek",
@ -2187,13 +2201,12 @@ dependencies = [
"serde_json", "serde_json",
"sha2", "sha2",
"thiserror", "thiserror",
"tracing",
] ]
[[package]] [[package]]
name = "ruma-state-res" name = "ruma-state-res"
version = "0.6.0" version = "0.8.0"
source = "git+https://github.com/ruma/ruma?rev=d614ad1422d6c4b3437ebc318ca8514ae338fd6d#d614ad1422d6c4b3437ebc318ca8514ae338fd6d" source = "git+https://github.com/ruma/ruma?rev=86b58cafb8abe29eecd0272d90b40bbb61a7919b#86b58cafb8abe29eecd0272d90b40bbb61a7919b"
dependencies = [ dependencies = [
"itertools", "itertools",
"js_int", "js_int",
@ -2499,10 +2512,11 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]] [[package]]
name = "spki" name = "spki"
version = "0.4.1" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32" checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b"
dependencies = [ dependencies = [
"base64ct",
"der", "der",
] ]
@ -3002,9 +3016,9 @@ dependencies = [
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "0.8.2" version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83"
dependencies = [ dependencies = [
"getrandom 0.2.7", "getrandom 0.2.7",
] ]
@ -3235,9 +3249,9 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.3.0" version = "1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f"
dependencies = [ dependencies = [
"zeroize_derive", "zeroize_derive",
] ]

View file

@ -21,7 +21,7 @@ tower-http = { version = "0.3.4", features = ["add-extension", "cors", "compress
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
#ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "d614ad1422d6c4b3437ebc318ca8514ae338fd6d", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-pre-spec", "unstable-exhaustive-types"] } ruma = { git = "https://github.com/ruma/ruma", rev = "86b58cafb8abe29eecd0272d90b40bbb61a7919b", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-exhaustive-types"] }
#ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }

View file

@ -193,6 +193,8 @@ pub async fn register_route(
access_token: None, access_token: None,
user_id, user_id,
device_id: None, device_id: None,
refresh_token: None,
expires_in: None,
}); });
} }
@ -238,6 +240,8 @@ pub async fn register_route(
access_token: Some(token), access_token: Some(token),
user_id, user_id,
device_id: Some(device_id), device_id: Some(device_id),
refresh_token: None,
expires_in: None,
}) })
} }

View file

@ -19,6 +19,7 @@ use ruma::{
room::{ room::{
avatar::RoomAvatarEventContent, avatar::RoomAvatarEventContent,
canonical_alias::RoomCanonicalAliasEventContent, canonical_alias::RoomCanonicalAliasEventContent,
create::RoomCreateEventContent,
guest_access::{GuestAccess, RoomGuestAccessEventContent}, guest_access::{GuestAccess, RoomGuestAccessEventContent},
history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
join_rules::{JoinRule, RoomJoinRulesEventContent}, join_rules::{JoinRule, RoomJoinRulesEventContent},
@ -135,6 +136,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
since, since,
filter: Filter { filter: Filter {
generic_search_term: filter.generic_search_term.as_deref(), generic_search_term: filter.generic_search_term.as_deref(),
room_types: filter.room_types.clone(),
}, },
room_network: RoomNetwork::Matrix, room_network: RoomNetwork::Matrix,
}, },
@ -287,6 +289,20 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.transpose()? .transpose()?
.flatten() .flatten()
.ok_or_else(|| Error::bad_database("Missing room join rule event for room."))?, .ok_or_else(|| Error::bad_database("Missing room join rule event for room."))?,
room_type: services()
.rooms
.state_accessor
.room_state_get(&room_id, &StateEventType::RoomCreate, "")?
.map(|s| {
serde_json::from_str::<RoomCreateEventContent>(s.content.get()).map_err(
|e| {
error!("Invalid room create event in database: {}", e);
Error::BadDatabase("Invalid room create event in database.")
},
)
})
.transpose()?
.and_then(|e| e.room_type),
room_id, room_id,
}; };
Ok(chunk) Ok(chunk)

View file

@ -14,7 +14,7 @@ use ruma::{
federation, federation,
}, },
serde::Raw, serde::Raw,
DeviceId, DeviceKeyAlgorithm, UserId, DeviceId, DeviceKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
}; };
use serde_json::json; use serde_json::json;
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
@ -253,7 +253,7 @@ pub async fn get_key_changes_route(
pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>( pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>(
sender_user: Option<&UserId>, sender_user: Option<&UserId>,
device_keys_input: &BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>, device_keys_input: &BTreeMap<OwnedUserId, Vec<OwnedDeviceId>>,
allowed_signatures: F, allowed_signatures: F,
) -> Result<get_keys::v3::Response> { ) -> Result<get_keys::v3::Response> {
let mut master_keys = BTreeMap::new(); let mut master_keys = BTreeMap::new();
@ -396,7 +396,7 @@ fn add_unsigned_device_display_name(
} }
pub(crate) async fn claim_keys_helper( pub(crate) async fn claim_keys_helper(
one_time_keys_input: &BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>, one_time_keys_input: &BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, DeviceKeyAlgorithm>>,
) -> Result<claim_keys::v3::Response> { ) -> Result<claim_keys::v3::Response> {
let mut one_time_keys = BTreeMap::new(); let mut one_time_keys = BTreeMap::new();

View file

@ -10,12 +10,14 @@ use ruma::{
}, },
federation::{self, membership::create_invite}, federation::{self, membership::create_invite},
}, },
canonical_json::to_canonical_value,
events::{ events::{
room::member::{MembershipState, RoomMemberEventContent}, room::member::{MembershipState, RoomMemberEventContent},
RoomEventType, StateEventType, RoomEventType, StateEventType,
}, },
serde::{to_canonical_value, Base64, CanonicalJsonObject, CanonicalJsonValue}, serde::Base64,
EventId, RoomId, RoomVersionId, ServerName, UserId, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, OwnedServerName,
RoomId, RoomVersionId, UserId,
}; };
use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use std::{ use std::{
@ -83,7 +85,7 @@ pub async fn join_room_by_id_or_alias_route(
let sender_user = body.sender_user.as_deref().expect("user is authenticated"); let sender_user = body.sender_user.as_deref().expect("user is authenticated");
let body = body.body; let body = body.body;
let (servers, room_id) = match Box::<RoomId>::try_from(body.room_id_or_alias) { let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias) {
Ok(room_id) => { Ok(room_id) => {
let mut servers = body.server_name.clone(); let mut servers = body.server_name.clone();
servers.extend( servers.extend(
@ -458,7 +460,7 @@ pub async fn joined_members_route(
async fn join_room_by_id_helper( async fn join_room_by_id_helper(
sender_user: Option<&UserId>, sender_user: Option<&UserId>,
room_id: &RoomId, room_id: &RoomId,
servers: &[Box<ServerName>], servers: &[OwnedServerName],
_third_party_signed: Option<&IncomingThirdPartySigned>, _third_party_signed: Option<&IncomingThirdPartySigned>,
) -> Result<join_room_by_id::v3::Response> { ) -> Result<join_room_by_id::v3::Response> {
let sender_user = sender_user.expect("user is authenticated"); let sender_user = sender_user.expect("user is authenticated");
@ -673,7 +675,12 @@ async fn join_room_by_id_helper(
room_id, room_id,
state state
.into_iter() .into_iter()
.map(|(k, id)| services().rooms.state_compressor.compress_state_event(k, &id)) .map(|(k, id)| {
services()
.rooms
.state_compressor
.compress_state_event(k, &id)
})
.collect::<Result<_>>()?, .collect::<Result<_>>()?,
)?; )?;
@ -737,7 +744,7 @@ fn validate_and_add_event_id(
pdu: &RawJsonValue, pdu: &RawJsonValue,
room_version: &RoomVersionId, room_version: &RoomVersionId,
pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, Base64>>>, pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, Base64>>>,
) -> Result<(Box<EventId>, CanonicalJsonObject)> { ) -> Result<(OwnedEventId, CanonicalJsonObject)> {
let mut value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| { let mut value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| {
error!("Invalid PDU in server response: {:?}: {:?}", pdu, e); error!("Invalid PDU in server response: {:?}: {:?}", pdu, e);
Error::BadServerResponse("Invalid PDU in server response") Error::BadServerResponse("Invalid PDU in server response")
@ -896,7 +903,7 @@ pub(crate) async fn invite_helper<'a>(
warn!("Server {} changed invite event, that's not allowed in the spec: ours: {:?}, theirs: {:?}", user_id.server_name(), pdu_json, value); warn!("Server {} changed invite event, that's not allowed in the spec: ours: {:?}, theirs: {:?}", user_id.server_name(), pdu_json, value);
} }
let origin: Box<ServerName> = serde_json::from_value( let origin: OwnedServerName = serde_json::from_value(
serde_json::to_value(value.get("origin").ok_or(Error::BadRequest( serde_json::to_value(value.get("origin").ok_or(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Event needs an origin field.", "Event needs an origin field.",

View file

@ -1,8 +1,7 @@
use crate::{services, Error, Result, Ruma}; use crate::{services, Error, Result, Ruma};
use ruma::{ use ruma::{
api::client::{error::ErrorKind, read_marker::set_read_marker, receipt::create_receipt}, api::client::{error::ErrorKind, read_marker::set_read_marker, receipt::create_receipt},
events::RoomAccountDataEventType, events::{receipt::ReceiptType, RoomAccountDataEventType},
receipt::ReceiptType,
MilliSecondsSinceUnixEpoch, MilliSecondsSinceUnixEpoch,
}; };
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -18,19 +17,28 @@ pub async fn set_read_marker_route(
) -> 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");
let fully_read_event = ruma::events::fully_read::FullyReadEvent { if let Some(fully_read) = &body.fully_read {
content: ruma::events::fully_read::FullyReadEventContent { let fully_read_event = ruma::events::fully_read::FullyReadEvent {
event_id: body.fully_read.clone(), content: ruma::events::fully_read::FullyReadEventContent {
}, event_id: fully_read.clone(),
}; },
services().account_data.update( };
Some(&body.room_id), services().account_data.update(
sender_user, Some(&body.room_id),
RoomAccountDataEventType::FullyRead, sender_user,
&serde_json::to_value(fully_read_event).expect("to json value always works"), RoomAccountDataEventType::FullyRead,
)?; &serde_json::to_value(fully_read_event).expect("to json value always works"),
)?;
}
if let Some(event) = &body.read_receipt { if body.private_read_receipt.is_some() || body.read_receipt.is_some() {
services()
.rooms
.user
.reset_notification_counts(sender_user, &body.room_id)?;
}
if let Some(event) = &body.private_read_receipt {
services().rooms.edus.read_receipt.private_read_set( services().rooms.edus.read_receipt.private_read_set(
&body.room_id, &body.room_id,
sender_user, sender_user,
@ -43,11 +51,9 @@ pub async fn set_read_marker_route(
"Event does not exist.", "Event does not exist.",
))?, ))?,
)?; )?;
services() }
.rooms
.user
.reset_notification_counts(sender_user, &body.room_id)?;
if let Some(event) = &body.read_receipt {
let mut user_receipts = BTreeMap::new(); let mut user_receipts = BTreeMap::new();
user_receipts.insert( user_receipts.insert(
sender_user.clone(), sender_user.clone(),
@ -83,44 +89,69 @@ pub async fn create_receipt_route(
) -> 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");
services().rooms.edus.read_receipt.private_read_set( if matches!(
&body.room_id, &body.receipt_type,
sender_user, create_receipt::v3::ReceiptType::Read | create_receipt::v3::ReceiptType::ReadPrivate
) {
services() services()
.rooms .rooms
.timeline .user
.get_pdu_count(&body.event_id)? .reset_notification_counts(sender_user, &body.room_id)?;
.ok_or(Error::BadRequest( }
ErrorKind::InvalidParam,
"Event does not exist.",
))?,
)?;
services()
.rooms
.user
.reset_notification_counts(sender_user, &body.room_id)?;
let mut user_receipts = BTreeMap::new(); match body.receipt_type {
user_receipts.insert( create_receipt::v3::ReceiptType::FullyRead => {
sender_user.clone(), let fully_read_event = ruma::events::fully_read::FullyReadEvent {
ruma::events::receipt::Receipt { content: ruma::events::fully_read::FullyReadEventContent {
ts: Some(MilliSecondsSinceUnixEpoch::now()), event_id: body.event_id.clone(),
}, },
); };
let mut receipts = BTreeMap::new(); services().account_data.update(
receipts.insert(ReceiptType::Read, user_receipts); Some(&body.room_id),
sender_user,
RoomAccountDataEventType::FullyRead,
&serde_json::to_value(fully_read_event).expect("to json value always works"),
)?;
}
create_receipt::v3::ReceiptType::Read => {
let mut user_receipts = BTreeMap::new();
user_receipts.insert(
sender_user.clone(),
ruma::events::receipt::Receipt {
ts: Some(MilliSecondsSinceUnixEpoch::now()),
},
);
let mut receipts = BTreeMap::new();
receipts.insert(ReceiptType::Read, user_receipts);
let mut receipt_content = BTreeMap::new(); let mut receipt_content = BTreeMap::new();
receipt_content.insert(body.event_id.to_owned(), receipts); receipt_content.insert(body.event_id.to_owned(), receipts);
services().rooms.edus.read_receipt.readreceipt_update( services().rooms.edus.read_receipt.readreceipt_update(
sender_user, sender_user,
&body.room_id, &body.room_id,
ruma::events::receipt::ReceiptEvent { ruma::events::receipt::ReceiptEvent {
content: ruma::events::receipt::ReceiptEventContent(receipt_content), content: ruma::events::receipt::ReceiptEventContent(receipt_content),
room_id: body.room_id.clone(), room_id: body.room_id.clone(),
}, },
)?; )?;
}
create_receipt::v3::ReceiptType::ReadPrivate => {
services().rooms.edus.read_receipt.private_read_set(
&body.room_id,
sender_user,
services()
.rooms
.timeline
.get_pdu_count(&body.event_id)?
.ok_or(Error::BadRequest(
ErrorKind::InvalidParam,
"Event does not exist.",
))?,
)?;
}
_ => return Err(Error::bad_database("Unsupported receipt type")),
}
Ok(create_receipt::v3::Response {}) Ok(create_receipt::v3::Response {})
} }

View file

@ -1,6 +1,8 @@
use crate::{ use crate::{
api::client_server::invite_helper, service::pdu::PduBuilder, services, Error, Result, Ruma, api::client_server::invite_helper, service::pdu::PduBuilder, services, Error, Result, Ruma,
}; };
use ruma::serde::JsonObject;
use ruma::OwnedRoomAliasId;
use ruma::{ use ruma::{
api::client::{ api::client::{
error::ErrorKind, error::ErrorKind,
@ -21,9 +23,7 @@ use ruma::{
}, },
RoomEventType, StateEventType, RoomEventType, StateEventType,
}, },
int, int, CanonicalJsonObject, RoomAliasId, RoomId,
serde::{CanonicalJsonObject, JsonObject},
RoomAliasId, RoomId,
}; };
use serde_json::{json, value::to_raw_value}; use serde_json::{json, value::to_raw_value};
use std::{cmp::max, collections::BTreeMap, sync::Arc}; use std::{cmp::max, collections::BTreeMap, sync::Arc};
@ -77,7 +77,7 @@ pub async fn create_room_route(
)); ));
} }
let alias: Option<Box<RoomAliasId>> = let alias: Option<OwnedRoomAliasId> =
body.room_alias_name body.room_alias_name
.as_ref() .as_ref()
.map_or(Ok(None), |localpart| { .map_or(Ok(None), |localpart| {

View file

@ -147,6 +147,8 @@ pub async fn login_route(body: Ruma<login::v3::IncomingRequest>) -> Result<login
home_server: Some(services().globals.server_name().to_owned()), home_server: Some(services().globals.server_name().to_owned()),
device_id, device_id,
well_known: None, well_known: None,
refresh_token: None,
expires_in: None,
}) })
} }

View file

@ -2,7 +2,7 @@ use crate::{services, Error, Result, Ruma, RumaResponse};
use ruma::{ use ruma::{
api::client::{ api::client::{
filter::{IncomingFilterDefinition, LazyLoadOptions}, filter::{IncomingFilterDefinition, LazyLoadOptions},
sync::sync_events, sync::sync_events::{self, DeviceLists, UnreadNotificationsCount},
uiaa::UiaaResponse, uiaa::UiaaResponse,
}, },
events::{ events::{
@ -10,7 +10,7 @@ use ruma::{
RoomEventType, StateEventType, RoomEventType, StateEventType,
}, },
serde::Raw, serde::Raw,
DeviceId, RoomId, UserId, DeviceId, OwnedDeviceId, OwnedUserId, RoomId, UserId,
}; };
use std::{ use std::{
collections::{hash_map::Entry, BTreeMap, HashMap, HashSet}, collections::{hash_map::Entry, BTreeMap, HashMap, HashSet},
@ -122,8 +122,8 @@ pub async fn sync_events_route(
} }
async fn sync_helper_wrapper( async fn sync_helper_wrapper(
sender_user: Box<UserId>, sender_user: OwnedUserId,
sender_device: Box<DeviceId>, sender_device: OwnedDeviceId,
body: sync_events::v3::IncomingRequest, body: sync_events::v3::IncomingRequest,
tx: Sender<Option<Result<sync_events::v3::Response>>>, tx: Sender<Option<Result<sync_events::v3::Response>>>,
) { ) {
@ -155,15 +155,14 @@ async fn sync_helper_wrapper(
} }
async fn sync_helper( async fn sync_helper(
sender_user: Box<UserId>, sender_user: OwnedUserId,
sender_device: Box<DeviceId>, sender_device: OwnedDeviceId,
body: sync_events::v3::IncomingRequest, body: sync_events::v3::IncomingRequest,
// bool = caching allowed // bool = caching allowed
) -> Result<(sync_events::v3::Response, bool), Error> { ) -> Result<(sync_events::v3::Response, bool), Error> {
use sync_events::v3::{ use sync_events::v3::{
DeviceLists, Ephemeral, GlobalAccountData, IncomingFilter, InviteState, InvitedRoom, Ephemeral, GlobalAccountData, IncomingFilter, InviteState, InvitedRoom, JoinedRoom,
JoinedRoom, LeftRoom, Presence, RoomAccountData, RoomSummary, Rooms, State, Timeline, LeftRoom, Presence, RoomAccountData, RoomSummary, Rooms, State, Timeline, ToDevice,
ToDevice, UnreadNotificationsCount,
}; };
// TODO: match body.set_presence { // TODO: match body.set_presence {
@ -444,7 +443,7 @@ async fn sync_helper(
}; };
// This check is in case a bad user ID made it into the database // This check is in case a bad user ID made it into the database
if let Ok(uid) = UserId::parse(state_key.as_ref()) { if let Ok(uid) = UserId::parse(&state_key) {
lazy_loaded.insert(uid); lazy_loaded.insert(uid);
} }
state_events.push(pdu); state_events.push(pdu);

View file

@ -17,8 +17,7 @@ use bytes::{BufMut, Bytes, BytesMut};
use http::StatusCode; use http::StatusCode;
use ruma::{ use ruma::{
api::{client::error::ErrorKind, AuthScheme, IncomingRequest, OutgoingResponse}, api::{client::error::ErrorKind, AuthScheme, IncomingRequest, OutgoingResponse},
signatures::CanonicalJsonValue, CanonicalJsonValue, DeviceId, OwnedDeviceId, OwnedServerName, ServerName, UserId,
DeviceId, ServerName, UserId,
}; };
use serde::Deserialize; use serde::Deserialize;
use tracing::{debug, error, warn}; use tracing::{debug, error, warn};
@ -81,7 +80,7 @@ where
let (sender_user, sender_device, sender_servername, from_appservice) = let (sender_user, sender_device, sender_servername, from_appservice) =
if let Some((_id, registration)) = appservice_registration { if let Some((_id, registration)) = appservice_registration {
match metadata.authentication { match metadata.authentication {
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => { AuthScheme::AccessToken => {
let user_id = query_params.user_id.map_or_else( let user_id = query_params.user_id.map_or_else(
|| { || {
UserId::parse_with_server_name( UserId::parse_with_server_name(
@ -112,7 +111,7 @@ where
} }
} else { } else {
match metadata.authentication { match metadata.authentication {
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => { AuthScheme::AccessToken => {
let token = match token { let token = match token {
Some(token) => token, Some(token) => token,
_ => { _ => {
@ -132,7 +131,7 @@ where
} }
Some((user_id, device_id)) => ( Some((user_id, device_id)) => (
Some(user_id), Some(user_id),
Some(Box::<DeviceId>::from(device_id)), Some(OwnedDeviceId::from(device_id)),
None, None,
false, false,
), ),
@ -298,7 +297,7 @@ where
} }
struct XMatrix { struct XMatrix {
origin: Box<ServerName>, origin: OwnedServerName,
key: String, // KeyName? key: String, // KeyName?
sig: String, sig: String,
} }

View file

@ -1,6 +1,7 @@
use crate::Error; use crate::Error;
use ruma::{ use ruma::{
api::client::uiaa::UiaaResponse, signatures::CanonicalJsonValue, DeviceId, ServerName, UserId, api::client::uiaa::UiaaResponse, CanonicalJsonValue, OwnedDeviceId, OwnedServerName,
OwnedUserId,
}; };
use std::ops::Deref; use std::ops::Deref;
@ -10,9 +11,9 @@ mod axum;
/// Extractor for Ruma request structs /// Extractor for Ruma request structs
pub struct Ruma<T> { pub struct Ruma<T> {
pub body: T, pub body: T,
pub sender_user: Option<Box<UserId>>, pub sender_user: Option<OwnedUserId>,
pub sender_device: Option<Box<DeviceId>>, pub sender_device: Option<OwnedDeviceId>,
pub sender_servername: Option<Box<ServerName>>, pub 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 json_body: Option<CanonicalJsonValue>,
pub from_appservice: bool, pub from_appservice: bool,

View file

@ -33,18 +33,17 @@ use ruma::{
}, },
directory::{IncomingFilter, IncomingRoomNetwork}, directory::{IncomingFilter, IncomingRoomNetwork},
events::{ events::{
receipt::{ReceiptEvent, ReceiptEventContent}, receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType},
room::{ room::{
join_rules::{JoinRule, RoomJoinRulesEventContent}, join_rules::{JoinRule, RoomJoinRulesEventContent},
member::{MembershipState, RoomMemberEventContent}, member::{MembershipState, RoomMemberEventContent},
}, },
RoomEventType, StateEventType, RoomEventType, StateEventType,
}, },
receipt::ReceiptType,
serde::{Base64, JsonObject, Raw}, serde::{Base64, JsonObject, Raw},
signatures::CanonicalJsonValue,
to_device::DeviceIdOrAllDevices, to_device::DeviceIdOrAllDevices,
EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId,
OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId, ServerName, ServerSigningKeyId,
}; };
use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use std::{ use std::{
@ -280,7 +279,7 @@ where
.write() .write()
.unwrap() .unwrap()
.insert( .insert(
Box::<ServerName>::from(destination), OwnedServerName::from(destination),
(actual_destination, host), (actual_destination, host),
); );
} }
@ -528,7 +527,7 @@ pub async fn get_server_keys_route() -> Result<impl IntoResponse> {
return Err(Error::bad_config("Federation is disabled.")); return Err(Error::bad_config("Federation is disabled."));
} }
let mut verify_keys: BTreeMap<Box<ServerSigningKeyId>, 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())
.try_into() .try_into()
@ -669,7 +668,7 @@ pub async fn send_transaction_message_route(
}; };
// 0. Check the server is in the room // 0. Check the server is in the room
let room_id = match value let room_id: OwnedRoomId = match value
.get("room_id") .get("room_id")
.and_then(|id| RoomId::parse(id.as_str()?).ok()) .and_then(|id| RoomId::parse(id.as_str()?).ok())
{ {
@ -1007,7 +1006,7 @@ pub async fn get_missing_events_route(
continue; continue;
} }
queued_events.extend_from_slice( queued_events.extend_from_slice(
&serde_json::from_value::<Vec<Box<EventId>>>( &serde_json::from_value::<Vec<OwnedEventId>>(
serde_json::to_value(pdu.get("prev_events").cloned().ok_or_else(|| { serde_json::to_value(pdu.get("prev_events").cloned().ok_or_else(|| {
Error::bad_database("Event in db has no prev_events field.") Error::bad_database("Event in db has no prev_events field.")
})?) })?)
@ -1411,7 +1410,7 @@ async fn create_join_event(
} }
}; };
let origin: Box<ServerName> = serde_json::from_value( let origin: OwnedServerName = serde_json::from_value(
serde_json::to_value(value.get("origin").ok_or(Error::BadRequest( serde_json::to_value(value.get("origin").ok_or(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Event needs an origin field.", "Event needs an origin field.",
@ -1474,6 +1473,7 @@ async fn create_join_event(
.filter_map(|(_, id)| services().rooms.timeline.get_pdu_json(id).ok().flatten()) .filter_map(|(_, id)| services().rooms.timeline.get_pdu_json(id).ok().flatten())
.map(PduEvent::convert_to_outgoing_federation_event) .map(PduEvent::convert_to_outgoing_federation_event)
.collect(), .collect(),
origin: services().globals.server_name().to_string(),
}) })
} }
@ -1564,10 +1564,10 @@ pub async fn create_invite_route(
// Add event_id back // Add event_id back
signed_event.insert( signed_event.insert(
"event_id".to_owned(), "event_id".to_owned(),
CanonicalJsonValue::String(event_id.into()), CanonicalJsonValue::String(event_id.to_string()),
); );
let sender: Box<_> = serde_json::from_value( let sender: OwnedUserId = serde_json::from_value(
signed_event signed_event
.get("sender") .get("sender")
.ok_or(Error::BadRequest( .ok_or(Error::BadRequest(

View file

@ -4,7 +4,7 @@ use std::{
net::{IpAddr, Ipv4Addr}, net::{IpAddr, Ipv4Addr},
}; };
use ruma::{RoomVersionId, ServerName}; use ruma::{OwnedServerName, RoomVersionId, ServerName};
use serde::{de::IgnoredAny, Deserialize}; use serde::{de::IgnoredAny, Deserialize};
use tracing::warn; use tracing::warn;
@ -20,7 +20,7 @@ pub struct Config {
pub port: u16, pub port: u16,
pub tls: Option<TlsConfig>, pub tls: Option<TlsConfig>,
pub server_name: Box<ServerName>, pub server_name: OwnedServerName,
#[serde(default = "default_database_backend")] #[serde(default = "default_database_backend")]
pub database_backend: String, pub database_backend: String,
pub database_path: String, pub database_path: String,
@ -58,7 +58,7 @@ pub struct Config {
pub proxy: ProxyConfig, pub proxy: ProxyConfig,
pub jwt_secret: Option<String>, pub jwt_secret: Option<String>,
#[serde(default = "Vec::new")] #[serde(default = "Vec::new")]
pub trusted_servers: Vec<Box<ServerName>>, pub trusted_servers: Vec<OwnedServerName>,
#[serde(default = "default_log")] #[serde(default = "default_log")]
pub log: String, pub log: String,
#[serde(default)] #[serde(default)]

View file

@ -5,7 +5,8 @@ use futures_util::{stream::FuturesUnordered, StreamExt};
use ruma::{ use ruma::{
api::federation::discovery::{ServerSigningKeys, VerifyKey}, api::federation::discovery::{ServerSigningKeys, VerifyKey},
signatures::Ed25519KeyPair, signatures::Ed25519KeyPair,
DeviceId, MilliSecondsSinceUnixEpoch, ServerName, ServerSigningKeyId, UserId, DeviceId, MilliSecondsSinceUnixEpoch, OwnedServerSigningKeyId, ServerName, ServerSigningKeyId,
UserId,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -163,7 +164,7 @@ impl service::globals::Data for KeyValueDatabase {
&self, &self,
origin: &ServerName, origin: &ServerName,
new_keys: ServerSigningKeys, new_keys: ServerSigningKeys,
) -> Result<BTreeMap<Box<ServerSigningKeyId>, VerifyKey>> { ) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>> {
// Not atomic, but this is not critical // Not atomic, but this is not critical
let signingkeys = self.server_signingkeys.get(origin.as_bytes())?; let signingkeys = self.server_signingkeys.get(origin.as_bytes())?;
@ -202,7 +203,7 @@ impl service::globals::Data for KeyValueDatabase {
fn signing_keys_for( fn signing_keys_for(
&self, &self,
origin: &ServerName, origin: &ServerName,
) -> Result<BTreeMap<Box<ServerSigningKeyId>, VerifyKey>> { ) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>> {
let signingkeys = self let signingkeys = self
.server_signingkeys .server_signingkeys
.get(origin.as_bytes())? .get(origin.as_bytes())?

View file

@ -6,7 +6,7 @@ use ruma::{
error::ErrorKind, error::ErrorKind,
}, },
serde::Raw, serde::Raw,
RoomId, UserId, OwnedRoomId, RoomId, UserId,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -198,13 +198,13 @@ impl service::key_backups::Data for KeyValueDatabase {
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
) -> Result<BTreeMap<Box<RoomId>, RoomKeyBackup>> { ) -> Result<BTreeMap<OwnedRoomId, RoomKeyBackup>> {
let mut prefix = user_id.as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(version.as_bytes()); prefix.extend_from_slice(version.as_bytes());
prefix.push(0xff); prefix.push(0xff);
let mut rooms = BTreeMap::<Box<RoomId>, RoomKeyBackup>::new(); let mut rooms = BTreeMap::<OwnedRoomId, RoomKeyBackup>::new();
for result in self for result in self
.backupkeyid_backup .backupkeyid_backup

View file

@ -1,4 +1,4 @@
use ruma::{api::client::error::ErrorKind, RoomAliasId, RoomId}; use ruma::{api::client::error::ErrorKind, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -31,7 +31,7 @@ impl service::rooms::alias::Data for KeyValueDatabase {
Ok(()) Ok(())
} }
fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<Box<RoomId>>> { fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<OwnedRoomId>> {
self.alias_roomid self.alias_roomid
.get(alias.alias().as_bytes())? .get(alias.alias().as_bytes())?
.map(|bytes| { .map(|bytes| {
@ -46,7 +46,7 @@ impl service::rooms::alias::Data for KeyValueDatabase {
fn local_aliases_for_room<'a>( fn local_aliases_for_room<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<RoomAliasId>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedRoomAliasId>> + 'a> {
let mut prefix = room_id.as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);

View file

@ -1,4 +1,4 @@
use ruma::RoomId; use ruma::{OwnedRoomId, RoomId};
use crate::{database::KeyValueDatabase, service, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, utils, Error, Result};
@ -15,7 +15,7 @@ impl service::rooms::directory::Data for KeyValueDatabase {
Ok(self.publicroomids.get(room_id.as_bytes())?.is_some()) Ok(self.publicroomids.get(room_id.as_bytes())?.is_some())
} }
fn public_rooms<'a>(&'a self) -> Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a> { fn public_rooms<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
Box::new(self.publicroomids.iter().map(|(bytes, _)| { Box::new(self.publicroomids.iter().map(|(bytes, _)| {
RoomId::parse( RoomId::parse(
utils::string_from_bytes(&bytes).map_err(|_| { utils::string_from_bytes(&bytes).map_err(|_| {

View file

@ -1,6 +1,8 @@
use std::collections::HashMap; use std::collections::HashMap;
use ruma::{events::presence::PresenceEvent, presence::PresenceState, RoomId, UInt, UserId}; use ruma::{
events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, RoomId, UInt, UserId,
};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -76,7 +78,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
since: u64, since: u64,
) -> Result<HashMap<Box<UserId>, PresenceEvent>> { ) -> Result<HashMap<OwnedUserId, PresenceEvent>> {
let mut prefix = room_id.as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);

View file

@ -1,7 +1,7 @@
use std::mem; use std::mem;
use ruma::{ use ruma::{
events::receipt::ReceiptEvent, serde::Raw, signatures::CanonicalJsonObject, RoomId, UserId, events::receipt::ReceiptEvent, serde::Raw, CanonicalJsonObject, OwnedUserId, RoomId, UserId,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -55,7 +55,7 @@ impl service::rooms::edus::read_receipt::Data for KeyValueDatabase {
) -> Box< ) -> Box<
dyn Iterator< dyn Iterator<
Item = Result<( Item = Result<(
Box<UserId>, OwnedUserId,
u64, u64,
Raw<ruma::events::AnySyncEphemeralRoomEvent>, Raw<ruma::events::AnySyncEphemeralRoomEvent>,
)>, )>,

View file

@ -1,6 +1,6 @@
use std::collections::HashSet; use std::collections::HashSet;
use ruma::{RoomId, UserId}; use ruma::{OwnedUserId, RoomId, UserId};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -66,7 +66,7 @@ impl service::rooms::edus::typing::Data for KeyValueDatabase {
.unwrap_or(0)) .unwrap_or(0))
} }
fn typings_all(&self, room_id: &RoomId) -> Result<HashSet<Box<UserId>>> { fn typings_all(&self, room_id: &RoomId) -> Result<HashSet<OwnedUserId>> {
let mut prefix = room_id.as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);

View file

@ -1,4 +1,4 @@
use ruma::RoomId; use ruma::{OwnedRoomId, RoomId};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -18,7 +18,7 @@ impl service::rooms::metadata::Data for KeyValueDatabase {
.is_some()) .is_some())
} }
fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a> { fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
Box::new(self.roomid_shortroomid.iter().map(|(bytes, _)| { Box::new(self.roomid_shortroomid.iter().map(|(bytes, _)| {
RoomId::parse( RoomId::parse(
utils::string_from_bytes(&bytes).map_err(|_| { utils::string_from_bytes(&bytes).map_err(|_| {

View file

@ -1,4 +1,4 @@
use ruma::{signatures::CanonicalJsonObject, EventId}; use ruma::{CanonicalJsonObject, EventId};
use crate::{database::KeyValueDatabase, service, Error, PduEvent, Result}; use crate::{database::KeyValueDatabase, service, Error, PduEvent, Result};

View file

@ -1,4 +1,4 @@
use ruma::{EventId, RoomId}; use ruma::{EventId, OwnedEventId, RoomId};
use std::collections::HashSet; use std::collections::HashSet;
use std::sync::Arc; use std::sync::Arc;
@ -52,7 +52,7 @@ impl service::rooms::state::Data for KeyValueDatabase {
fn set_forward_extremities<'a>( fn set_forward_extremities<'a>(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_ids: Vec<Box<EventId>>, event_ids: Vec<OwnedEventId>,
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex _mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
) -> Result<()> { ) -> Result<()> {
let mut prefix = room_id.as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();

View file

@ -4,7 +4,7 @@ use regex::Regex;
use ruma::{ use ruma::{
events::{AnyStrippedStateEvent, AnySyncStateEvent}, events::{AnyStrippedStateEvent, AnySyncStateEvent},
serde::Raw, serde::Raw,
RoomId, ServerName, UserId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -163,7 +163,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
} }
#[tracing::instrument(skip(self, room_id))] #[tracing::instrument(skip(self, room_id))]
fn get_our_real_users(&self, room_id: &RoomId) -> Result<Arc<HashSet<Box<UserId>>>> { fn get_our_real_users(&self, room_id: &RoomId) -> Result<Arc<HashSet<OwnedUserId>>> {
let maybe = self let maybe = self
.our_real_users_cache .our_real_users_cache
.read() .read()
@ -262,7 +262,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn room_servers<'a>( fn room_servers<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<ServerName>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedServerName>> + 'a> {
let mut prefix = room_id.as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -295,7 +295,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn server_rooms<'a>( fn server_rooms<'a>(
&'a self, &'a self,
server: &ServerName, server: &ServerName,
) -> Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
let mut prefix = server.as_bytes().to_vec(); let mut prefix = server.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -317,7 +317,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn room_members<'a>( fn room_members<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a> {
let mut prefix = room_id.as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -363,7 +363,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn room_useroncejoined<'a>( fn room_useroncejoined<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a> {
let mut prefix = room_id.as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -393,7 +393,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn room_members_invited<'a>( fn room_members_invited<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a> {
let mut prefix = room_id.as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -451,7 +451,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn rooms_joined<'a>( fn rooms_joined<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
Box::new( Box::new(
self.userroomid_joined self.userroomid_joined
.scan_prefix(user_id.as_bytes().to_vec()) .scan_prefix(user_id.as_bytes().to_vec())
@ -476,7 +476,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn rooms_invited<'a>( fn rooms_invited<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<(Box<RoomId>, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a> { ) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a> {
let mut prefix = user_id.as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -554,7 +554,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn rooms_left<'a>( fn rooms_left<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<(Box<RoomId>, Vec<Raw<AnySyncStateEvent>>)>> + 'a> { ) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a> {
let mut prefix = user_id.as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);

View file

@ -1,7 +1,7 @@
use std::{collections::hash_map, mem::size_of, sync::Arc}; use std::{collections::hash_map, mem::size_of, sync::Arc};
use ruma::{ use ruma::{
api::client::error::ErrorKind, signatures::CanonicalJsonObject, EventId, RoomId, UserId, api::client::error::ErrorKind, CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId,
}; };
use tracing::error; use tracing::error;
@ -344,8 +344,8 @@ impl service::rooms::timeline::Data for KeyValueDatabase {
fn increment_notification_counts( fn increment_notification_counts(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
notifies: Vec<Box<UserId>>, notifies: Vec<OwnedUserId>,
highlights: Vec<Box<UserId>>, highlights: Vec<OwnedUserId>,
) -> Result<()> { ) -> Result<()> {
let mut notifies_batch = Vec::new(); let mut notifies_batch = Vec::new();
let mut highlights_batch = Vec::new(); let mut highlights_batch = Vec::new();

View file

@ -1,4 +1,4 @@
use ruma::{RoomId, UserId}; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
@ -85,8 +85,8 @@ impl service::rooms::user::Data for KeyValueDatabase {
fn get_shared_rooms<'a>( fn get_shared_rooms<'a>(
&'a self, &'a self,
users: Vec<Box<UserId>>, users: Vec<OwnedUserId>,
) -> Result<Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a>> { ) -> Result<Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a>> {
let iterators = users.into_iter().map(move |user_id| { let iterators = users.into_iter().map(move |user_id| {
let mut prefix = user_id.as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -110,7 +110,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
}); });
// We use the default compare function because keys are sorted correctly (not reversed) // We use the default compare function because keys are sorted correctly (not reversed)
Ok(Box::new(Box::new( Ok(Box::new(
utils::common_elements(iterators, Ord::cmp) utils::common_elements(iterators, Ord::cmp)
.expect("users is not empty") .expect("users is not empty")
.map(|bytes| { .map(|bytes| {
@ -119,6 +119,6 @@ impl service::rooms::user::Data for KeyValueDatabase {
})?) })?)
.map_err(|_| Error::bad_database("Invalid RoomId in userroomid_joined.")) .map_err(|_| Error::bad_database("Invalid RoomId in userroomid_joined."))
}), }),
))) ))
} }
} }

View file

@ -1,7 +1,6 @@
use ruma::{ use ruma::{
api::client::{error::ErrorKind, uiaa::UiaaInfo}, api::client::{error::ErrorKind, uiaa::UiaaInfo},
signatures::CanonicalJsonValue, CanonicalJsonValue, DeviceId, UserId,
DeviceId, UserId,
}; };
use crate::{database::KeyValueDatabase, service, Error, Result}; use crate::{database::KeyValueDatabase, service, Error, Result};

View file

@ -5,8 +5,10 @@ use ruma::{
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
events::{AnyToDeviceEvent, StateEventType}, events::{AnyToDeviceEvent, StateEventType},
serde::Raw, serde::Raw,
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, MxcUri, UInt, UserId, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, MxcUri, OwnedUserId,
UInt, UserId,
}; };
use ruma::{OwnedDeviceId, OwnedDeviceKeyId, OwnedMxcUri};
use tracing::warn; use tracing::warn;
use crate::{ use crate::{
@ -39,7 +41,7 @@ impl service::users::Data for KeyValueDatabase {
} }
/// Find out which user an access token belongs to. /// Find out which user an access token belongs to.
fn find_from_token(&self, token: &str) -> Result<Option<(Box<UserId>, String)>> { fn find_from_token(&self, token: &str) -> Result<Option<(OwnedUserId, String)>> {
self.token_userdeviceid self.token_userdeviceid
.get(token.as_bytes())? .get(token.as_bytes())?
.map_or(Ok(None), |bytes| { .map_or(Ok(None), |bytes| {
@ -66,7 +68,7 @@ impl service::users::Data for KeyValueDatabase {
} }
/// Returns an iterator over all users on this homeserver. /// Returns an iterator over all users on this homeserver.
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a> { fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a> {
Box::new(self.userid_password.iter().map(|(bytes, _)| { Box::new(self.userid_password.iter().map(|(bytes, _)| {
UserId::parse(utils::string_from_bytes(&bytes).map_err(|_| { UserId::parse(utils::string_from_bytes(&bytes).map_err(|_| {
Error::bad_database("User ID in userid_password is invalid unicode.") Error::bad_database("User ID in userid_password is invalid unicode.")
@ -141,7 +143,7 @@ impl service::users::Data for KeyValueDatabase {
} }
/// Get the avatar_url of a user. /// Get the avatar_url of a user.
fn avatar_url(&self, user_id: &UserId) -> Result<Option<Box<MxcUri>>> { fn avatar_url(&self, user_id: &UserId) -> Result<Option<OwnedMxcUri>> {
self.userid_avatarurl self.userid_avatarurl
.get(user_id.as_bytes())? .get(user_id.as_bytes())?
.map(|bytes| { .map(|bytes| {
@ -154,7 +156,7 @@ impl service::users::Data for KeyValueDatabase {
} }
/// Sets a new avatar_url or removes it if avatar_url is None. /// Sets a new avatar_url or removes it if avatar_url is None.
fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<Box<MxcUri>>) -> Result<()> { fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<OwnedMxcUri>) -> Result<()> {
if let Some(avatar_url) = avatar_url { if let Some(avatar_url) = avatar_url {
self.userid_avatarurl self.userid_avatarurl
.insert(user_id.as_bytes(), avatar_url.to_string().as_bytes())?; .insert(user_id.as_bytes(), avatar_url.to_string().as_bytes())?;
@ -258,7 +260,7 @@ impl service::users::Data for KeyValueDatabase {
fn all_device_ids<'a>( fn all_device_ids<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<Box<DeviceId>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedDeviceId>> + 'a> {
let mut prefix = user_id.as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
// All devices have metadata // All devices have metadata
@ -356,7 +358,7 @@ impl service::users::Data for KeyValueDatabase {
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
key_algorithm: &DeviceKeyAlgorithm, key_algorithm: &DeviceKeyAlgorithm,
) -> Result<Option<(Box<DeviceKeyId>, Raw<OneTimeKey>)>> { ) -> Result<Option<(OwnedDeviceKeyId, Raw<OneTimeKey>)>> {
let mut prefix = user_id.as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(device_id.as_bytes()); prefix.extend_from_slice(device_id.as_bytes());
@ -407,7 +409,7 @@ impl service::users::Data for KeyValueDatabase {
.scan_prefix(userdeviceid) .scan_prefix(userdeviceid)
.map(|(bytes, _)| { .map(|(bytes, _)| {
Ok::<_, Error>( Ok::<_, Error>(
serde_json::from_slice::<Box<DeviceKeyId>>( serde_json::from_slice::<OwnedDeviceKeyId>(
&*bytes.rsplit(|&b| b == 0xff).next().ok_or_else(|| { &*bytes.rsplit(|&b| b == 0xff).next().ok_or_else(|| {
Error::bad_database("OneTimeKey ID in db is invalid.") Error::bad_database("OneTimeKey ID in db is invalid.")
})?, })?,
@ -579,7 +581,7 @@ impl service::users::Data for KeyValueDatabase {
.ok_or_else(|| Error::bad_database("key in keyid_key has no signatures field."))? .ok_or_else(|| Error::bad_database("key in keyid_key has no signatures field."))?
.as_object_mut() .as_object_mut()
.ok_or_else(|| Error::bad_database("key in keyid_key has invalid signatures field."))? .ok_or_else(|| Error::bad_database("key in keyid_key has invalid signatures field."))?
.entry(sender_id.to_owned()) .entry(sender_id.to_string())
.or_insert_with(|| serde_json::Map::new().into()); .or_insert_with(|| serde_json::Map::new().into());
signatures signatures
@ -603,7 +605,7 @@ impl service::users::Data for KeyValueDatabase {
user_or_room_id: &str, user_or_room_id: &str,
from: u64, from: u64,
to: Option<u64>, to: Option<u64>,
) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a> { ) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a> {
let mut prefix = user_or_room_id.as_bytes().to_vec(); let mut prefix = user_or_room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);

View file

@ -6,13 +6,17 @@ use abstraction::KeyValueDatabaseEngine;
use abstraction::KvTree; use abstraction::KvTree;
use directories::ProjectDirs; use directories::ProjectDirs;
use lru_cache::LruCache; use lru_cache::LruCache;
use ruma::CanonicalJsonValue;
use ruma::OwnedDeviceId;
use ruma::OwnedEventId;
use ruma::OwnedRoomId;
use ruma::OwnedUserId;
use ruma::{ use ruma::{
events::{ events::{
push_rules::PushRulesEventContent, room::message::RoomMessageEventContent, push_rules::PushRulesEventContent, room::message::RoomMessageEventContent,
GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType, GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType,
}, },
push::Ruleset, push::Ruleset,
signatures::CanonicalJsonValue,
DeviceId, EventId, RoomId, UserId, DeviceId, EventId, RoomId, UserId,
}; };
use std::{ use std::{
@ -58,7 +62,7 @@ pub struct KeyValueDatabase {
//pub uiaa: uiaa::Uiaa, //pub 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<(Box<UserId>, Box<DeviceId>, String), CanonicalJsonValue>>, RwLock<BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>>,
//pub edus: RoomEdus, //pub edus: RoomEdus,
pub(super) readreceiptid_readreceipt: Arc<dyn KvTree>, // ReadReceiptId = RoomId + Count + UserId pub(super) readreceiptid_readreceipt: Arc<dyn KvTree>, // ReadReceiptId = RoomId + Count + UserId
@ -152,15 +156,15 @@ pub struct KeyValueDatabase {
pub(super) senderkey_pusher: Arc<dyn KvTree>, pub(super) senderkey_pusher: Arc<dyn KvTree>,
pub(super) cached_registrations: Arc<RwLock<HashMap<String, serde_yaml::Value>>>, pub(super) cached_registrations: Arc<RwLock<HashMap<String, serde_yaml::Value>>>,
pub(super) pdu_cache: Mutex<LruCache<Box<EventId>, Arc<PduEvent>>>, pub(super) pdu_cache: Mutex<LruCache<OwnedEventId, Arc<PduEvent>>>,
pub(super) shorteventid_cache: Mutex<LruCache<u64, Arc<EventId>>>, pub(super) shorteventid_cache: Mutex<LruCache<u64, Arc<EventId>>>,
pub(super) auth_chain_cache: Mutex<LruCache<Vec<u64>, Arc<HashSet<u64>>>>, pub(super) auth_chain_cache: Mutex<LruCache<Vec<u64>, Arc<HashSet<u64>>>>,
pub(super) eventidshort_cache: Mutex<LruCache<Box<EventId>, u64>>, pub(super) eventidshort_cache: Mutex<LruCache<OwnedEventId, u64>>,
pub(super) statekeyshort_cache: Mutex<LruCache<(StateEventType, String), u64>>, pub(super) statekeyshort_cache: Mutex<LruCache<(StateEventType, String), u64>>,
pub(super) shortstatekey_cache: Mutex<LruCache<u64, (StateEventType, String)>>, pub(super) shortstatekey_cache: Mutex<LruCache<u64, (StateEventType, String)>>,
pub(super) our_real_users_cache: RwLock<HashMap<Box<RoomId>, Arc<HashSet<Box<UserId>>>>>, pub(super) our_real_users_cache: RwLock<HashMap<OwnedRoomId, Arc<HashSet<OwnedUserId>>>>,
pub(super) appservice_in_room_cache: RwLock<HashMap<Box<RoomId>, HashMap<String, bool>>>, pub(super) appservice_in_room_cache: RwLock<HashMap<OwnedRoomId, HashMap<String, bool>>>,
pub(super) lasttimelinecount_cache: Mutex<HashMap<Box<RoomId>, u64>>, pub(super) lasttimelinecount_cache: Mutex<HashMap<OwnedRoomId, u64>>,
} }
impl KeyValueDatabase { impl KeyValueDatabase {
@ -531,7 +535,7 @@ impl KeyValueDatabase {
if services().globals.database_version()? < 7 { if services().globals.database_version()? < 7 {
// Upgrade state store // Upgrade state store
let mut last_roomstates: HashMap<Box<RoomId>, u64> = HashMap::new(); let mut last_roomstates: HashMap<OwnedRoomId, u64> = HashMap::new();
let mut current_sstatehash: Option<u64> = None; let mut current_sstatehash: Option<u64> = None;
let mut current_room = None; let mut current_room = None;
let mut current_state = HashSet::new(); let mut current_state = HashSet::new();

View file

@ -23,7 +23,7 @@ use ruma::{
}, },
RoomEventType, RoomEventType,
}, },
EventId, RoomAliasId, RoomId, RoomName, RoomVersionId, ServerName, UserId, EventId, OwnedRoomAliasId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use serde_json::value::to_raw_value; use serde_json::value::to_raw_value;
use tokio::sync::{mpsc, Mutex, MutexGuard}; use tokio::sync::{mpsc, Mutex, MutexGuard};
@ -977,8 +977,7 @@ impl Service {
)?; )?;
// 5. Events implied by name and topic // 5. Events implied by name and topic
let room_name = RoomName::parse(format!("{} Admin Room", services().globals.server_name())) let room_name = format!("{} Admin Room", services().globals.server_name());
.expect("Room name is valid");
services().rooms.timeline.build_and_append_pdu( services().rooms.timeline.build_and_append_pdu(
PduBuilder { PduBuilder {
event_type: RoomEventType::RoomName, event_type: RoomEventType::RoomName,
@ -1010,7 +1009,7 @@ impl Service {
)?; )?;
// 6. Room alias // 6. Room alias
let alias: Box<RoomAliasId> = format!("#admins:{}", services().globals.server_name()) let alias: OwnedRoomAliasId = format!("#admins:{}", services().globals.server_name())
.try_into() .try_into()
.expect("#admins:server_name is a valid alias name"); .expect("#admins:server_name is a valid alias name");

View file

@ -4,7 +4,7 @@ use async_trait::async_trait;
use ruma::{ use ruma::{
api::federation::discovery::{ServerSigningKeys, VerifyKey}, api::federation::discovery::{ServerSigningKeys, VerifyKey},
signatures::Ed25519KeyPair, signatures::Ed25519KeyPair,
DeviceId, ServerName, ServerSigningKeyId, UserId, DeviceId, OwnedServerSigningKeyId, ServerName, ServerSigningKeyId, UserId,
}; };
use crate::Result; use crate::Result;
@ -22,13 +22,13 @@ pub trait Data: Send + Sync {
&self, &self,
origin: &ServerName, origin: &ServerName,
new_keys: ServerSigningKeys, new_keys: ServerSigningKeys,
) -> Result<BTreeMap<Box<ServerSigningKeyId>, VerifyKey>>; ) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>>;
/// 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.
fn signing_keys_for( fn signing_keys_for(
&self, &self,
origin: &ServerName, origin: &ServerName,
) -> Result<BTreeMap<Box<ServerSigningKeyId>, VerifyKey>>; ) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>>;
fn database_version(&self) -> Result<u64>; fn database_version(&self) -> Result<u64>;
fn bump_database_version(&self, new_version: u64) -> Result<()>; fn bump_database_version(&self, new_version: u64) -> Result<()>;
} }

View file

@ -1,5 +1,8 @@
mod data; mod data;
pub use data::Data; pub use data::Data;
use ruma::{
OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId,
};
use crate::api::server_server::FedDest; use crate::api::server_server::FedDest;
@ -24,7 +27,7 @@ use tokio::sync::{broadcast, watch::Receiver, Mutex as TokioMutex, Semaphore};
use tracing::error; use tracing::error;
use trust_dns_resolver::TokioAsyncResolver; use trust_dns_resolver::TokioAsyncResolver;
type WellKnownMap = HashMap<Box<ServerName>, (FedDest, String)>; type WellKnownMap = HashMap<OwnedServerName, (FedDest, String)>;
type TlsNameMap = HashMap<String, (Vec<IpAddr>, u16)>; type TlsNameMap = HashMap<String, (Vec<IpAddr>, u16)>;
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
type SyncHandle = ( type SyncHandle = (
@ -45,14 +48,14 @@ pub struct Service {
default_client: reqwest::Client, default_client: reqwest::Client,
pub stable_room_versions: Vec<RoomVersionId>, pub stable_room_versions: Vec<RoomVersionId>,
pub unstable_room_versions: Vec<RoomVersionId>, pub unstable_room_versions: Vec<RoomVersionId>,
pub bad_event_ratelimiter: Arc<RwLock<HashMap<Box<EventId>, RateLimitState>>>, pub bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>,
pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>, pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>,
pub servername_ratelimiter: Arc<RwLock<HashMap<Box<ServerName>, Arc<Semaphore>>>>, pub servername_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, Arc<Semaphore>>>>,
pub sync_receivers: RwLock<HashMap<(Box<UserId>, Box<DeviceId>), SyncHandle>>, pub sync_receivers: RwLock<HashMap<(OwnedUserId, OwnedDeviceId), SyncHandle>>,
pub roomid_mutex_insert: RwLock<HashMap<Box<RoomId>, Arc<Mutex<()>>>>, pub roomid_mutex_insert: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub roomid_mutex_state: RwLock<HashMap<Box<RoomId>, Arc<TokioMutex<()>>>>, pub roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<TokioMutex<()>>>>,
pub roomid_mutex_federation: RwLock<HashMap<Box<RoomId>, Arc<TokioMutex<()>>>>, // this lock will be held longer pub roomid_mutex_federation: RwLock<HashMap<OwnedRoomId, Arc<TokioMutex<()>>>>, // this lock will be held longer
pub roomid_federationhandletime: RwLock<HashMap<Box<RoomId>, (Box<EventId>, Instant)>>, pub roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>,
pub stateres_mutex: Arc<Mutex<()>>, pub stateres_mutex: Arc<Mutex<()>>,
pub rotate: RotationHandler, pub rotate: RotationHandler,
} }
@ -242,7 +245,7 @@ impl Service {
self.config.default_room_version.clone() self.config.default_room_version.clone()
} }
pub fn trusted_servers(&self) -> &[Box<ServerName>] { pub fn trusted_servers(&self) -> &[OwnedServerName] {
&self.config.trusted_servers &self.config.trusted_servers
} }
@ -295,7 +298,7 @@ impl Service {
&self, &self,
origin: &ServerName, origin: &ServerName,
new_keys: ServerSigningKeys, new_keys: ServerSigningKeys,
) -> Result<BTreeMap<Box<ServerSigningKeyId>, VerifyKey>> { ) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>> {
self.db.add_signing_key(origin, new_keys) self.db.add_signing_key(origin, new_keys)
} }
@ -303,7 +306,7 @@ impl Service {
pub fn signing_keys_for( pub fn signing_keys_for(
&self, &self,
origin: &ServerName, origin: &ServerName,
) -> Result<BTreeMap<Box<ServerSigningKeyId>, VerifyKey>> { ) -> Result<BTreeMap<OwnedServerSigningKeyId, VerifyKey>> {
self.db.signing_keys_for(origin) self.db.signing_keys_for(origin)
} }

View file

@ -4,7 +4,7 @@ use crate::Result;
use ruma::{ use ruma::{
api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
serde::Raw, serde::Raw,
RoomId, UserId, OwnedRoomId, RoomId, UserId,
}; };
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
@ -47,7 +47,7 @@ pub trait Data: Send + Sync {
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
) -> Result<BTreeMap<Box<RoomId>, RoomKeyBackup>>; ) -> Result<BTreeMap<OwnedRoomId, RoomKeyBackup>>;
fn get_room( fn get_room(
&self, &self,

View file

@ -5,7 +5,7 @@ use crate::Result;
use ruma::{ use ruma::{
api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
serde::Raw, serde::Raw,
RoomId, UserId, OwnedRoomId, RoomId, UserId,
}; };
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -78,7 +78,7 @@ impl Service {
&self, &self,
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
) -> Result<BTreeMap<Box<RoomId>, RoomKeyBackup>> { ) -> Result<BTreeMap<OwnedRoomId, RoomKeyBackup>> {
self.db.get_all(user_id, version) self.db.get_all(user_id, version)
} }

View file

@ -1,11 +1,13 @@
use crate::{services, Error}; use crate::{services, Error};
use ruma::{ use ruma::{
events::{ events::{
room::member::RoomMemberEventContent, AnyEphemeralRoomEvent, AnyRoomEvent, AnyStateEvent, room::member::RoomMemberEventContent, AnyEphemeralRoomEvent, AnyStateEvent,
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, RoomEventType, StateEvent, AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
RoomEventType, StateEvent,
}, },
serde::{CanonicalJsonObject, CanonicalJsonValue, Raw}, serde::Raw,
state_res, EventId, MilliSecondsSinceUnixEpoch, RoomId, UInt, UserId, state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch,
OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{ use serde_json::{
@ -25,8 +27,8 @@ pub struct EventHash {
#[derive(Clone, Deserialize, Serialize, Debug)] #[derive(Clone, Deserialize, Serialize, Debug)]
pub struct PduEvent { pub struct PduEvent {
pub event_id: Arc<EventId>, pub event_id: Arc<EventId>,
pub room_id: Box<RoomId>, pub room_id: OwnedRoomId,
pub sender: Box<UserId>, pub sender: OwnedUserId,
pub origin_server_ts: UInt, pub origin_server_ts: UInt,
#[serde(rename = "type")] #[serde(rename = "type")]
pub kind: RoomEventType, pub kind: RoomEventType,
@ -102,7 +104,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_sync_room_event(&self) -> Raw<AnySyncRoomEvent> { pub fn to_sync_room_event(&self) -> Raw<AnySyncTimelineEvent> {
let mut json = json!({ let mut json = json!({
"content": self.content, "content": self.content,
"type": self.kind, "type": self.kind,
@ -146,7 +148,7 @@ impl PduEvent {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn to_room_event(&self) -> Raw<AnyRoomEvent> { pub fn to_room_event(&self) -> Raw<AnyTimelineEvent> {
let mut json = json!({ let mut json = json!({
"content": self.content, "content": self.content,
"type": self.kind, "type": self.kind,
@ -332,7 +334,7 @@ impl Ord for PduEvent {
/// Returns a tuple of the new `EventId` and the PDU as a `BTreeMap<String, CanonicalJsonValue>`. /// Returns a tuple of the new `EventId` and the PDU as a `BTreeMap<String, CanonicalJsonValue>`.
pub(crate) fn gen_event_id_canonical_json( pub(crate) fn gen_event_id_canonical_json(
pdu: &RawJsonValue, pdu: &RawJsonValue,
) -> crate::Result<(Box<EventId>, CanonicalJsonObject)> { ) -> crate::Result<(OwnedEventId, CanonicalJsonObject)> {
let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| { let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| {
warn!("Error parsing incoming event {:?}: {:?}", pdu, e); warn!("Error parsing incoming event {:?}: {:?}", pdu, e);
Error::BadServerResponse("Invalid PDU in server response") Error::BadServerResponse("Invalid PDU in server response")

View file

@ -1,5 +1,6 @@
mod data; mod data;
pub use data::Data; pub use data::Data;
use ruma::events::AnySyncTimelineEvent;
use crate::{services, Error, PduEvent, Result}; use crate::{services, Error, PduEvent, Result};
use bytes::BytesMut; use bytes::BytesMut;
@ -15,7 +16,7 @@ use ruma::{
}, },
events::{ events::{
room::{name::RoomNameEventContent, power_levels::RoomPowerLevelsEventContent}, room::{name::RoomNameEventContent, power_levels::RoomPowerLevelsEventContent},
AnySyncRoomEvent, RoomEventType, StateEventType, RoomEventType, StateEventType,
}, },
push::{Action, PushConditionRoomCtx, PushFormat, Ruleset, Tweak}, push::{Action, PushConditionRoomCtx, PushFormat, Ruleset, Tweak},
serde::Raw, serde::Raw,
@ -195,12 +196,13 @@ impl Service {
user: &UserId, user: &UserId,
ruleset: &'a Ruleset, ruleset: &'a Ruleset,
power_levels: &RoomPowerLevelsEventContent, power_levels: &RoomPowerLevelsEventContent,
pdu: &Raw<AnySyncRoomEvent>, pdu: &Raw<AnySyncTimelineEvent>,
room_id: &RoomId, room_id: &RoomId,
) -> Result<&'a [Action]> { ) -> Result<&'a [Action]> {
let ctx = PushConditionRoomCtx { let ctx = PushConditionRoomCtx {
room_id: room_id.to_owned(), room_id: room_id.to_owned(),
member_count: 10_u32.into(), // TODO: get member count efficiently member_count: 10_u32.into(), // TODO: get member count efficiently
user_id: user.to_owned(),
user_display_name: services() user_display_name: services()
.users .users
.displayname(user)? .displayname(user)?
@ -242,7 +244,7 @@ impl Service {
let mut data_minus_url = pusher.data.clone(); let mut data_minus_url = pusher.data.clone();
// The url must be stripped off according to spec // The url must be stripped off according to spec
data_minus_url.url = None; data_minus_url.url = None;
device.data = data_minus_url; device.data = data_minus_url.into();
// Tweaks are only added if the format is NOT event_id_only // Tweaks are only added if the format is NOT event_id_only
if !event_id_only { if !event_id_only {

View file

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma::{RoomAliasId, RoomId}; use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId};
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
/// Creates or updates the alias to the given room id. /// Creates or updates the alias to the given room id.
@ -9,11 +9,11 @@ pub trait Data: Send + Sync {
fn remove_alias(&self, alias: &RoomAliasId) -> Result<()>; fn remove_alias(&self, alias: &RoomAliasId) -> Result<()>;
/// Looks up the roomid for the given alias. /// Looks up the roomid for the given alias.
fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<Box<RoomId>>>; fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<OwnedRoomId>>;
/// Returns all local aliases that point to the given room /// Returns all local aliases that point to the given room
fn local_aliases_for_room<'a>( fn local_aliases_for_room<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<RoomAliasId>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedRoomAliasId>> + 'a>;
} }

View file

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

View file

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma::RoomId; use ruma::{OwnedRoomId, RoomId};
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
/// Adds the room to the public room directory /// Adds the room to the public room directory
@ -12,5 +12,5 @@ pub trait Data: Send + Sync {
fn is_public_room(&self, room_id: &RoomId) -> Result<bool>; fn is_public_room(&self, room_id: &RoomId) -> Result<bool>;
/// Returns the unsorted public room directory /// Returns the unsorted public room directory
fn public_rooms<'a>(&'a self) -> Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a>; fn public_rooms<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a>;
} }

View file

@ -1,7 +1,7 @@
mod data; mod data;
pub use data::Data; pub use data::Data;
use ruma::RoomId; use ruma::{OwnedRoomId, RoomId};
use crate::Result; use crate::Result;
@ -26,7 +26,7 @@ impl Service {
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn public_rooms(&self) -> impl Iterator<Item = Result<Box<RoomId>>> + '_ { pub fn public_rooms(&self) -> impl Iterator<Item = Result<OwnedRoomId>> + '_ {
self.db.public_rooms() self.db.public_rooms()
} }
} }

View file

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::Result; use crate::Result;
use ruma::{events::presence::PresenceEvent, RoomId, UserId}; use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId};
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
/// Adds a presence event which will be saved until a new event replaces it. /// Adds a presence event which will be saved until a new event replaces it.
@ -34,5 +34,5 @@ pub trait Data: Send + Sync {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
since: u64, since: u64,
) -> Result<HashMap<Box<UserId>, PresenceEvent>>; ) -> Result<HashMap<OwnedUserId, PresenceEvent>>;
} }

View file

@ -2,7 +2,7 @@ mod data;
use std::collections::HashMap; use std::collections::HashMap;
pub use data::Data; pub use data::Data;
use ruma::{events::presence::PresenceEvent, RoomId, UserId}; use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId};
use crate::Result; use crate::Result;
@ -116,7 +116,7 @@ impl Service {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
since: u64, since: u64,
) -> Result<HashMap<Box<UserId>, PresenceEvent>> { ) -> Result<HashMap<OwnedUserId, PresenceEvent>> {
self.db.presence_since(room_id, since) self.db.presence_since(room_id, since)
} }
} }

View file

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma::{events::receipt::ReceiptEvent, serde::Raw, RoomId, UserId}; use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId};
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
/// Replaces the previous read receipt. /// Replaces the previous read receipt.
@ -18,7 +18,7 @@ pub trait Data: Send + Sync {
) -> Box< ) -> Box<
dyn Iterator< dyn Iterator<
Item = Result<( Item = Result<(
Box<UserId>, OwnedUserId,
u64, u64,
Raw<ruma::events::AnySyncEphemeralRoomEvent>, Raw<ruma::events::AnySyncEphemeralRoomEvent>,
)>, )>,

View file

@ -3,7 +3,7 @@ mod data;
pub use data::Data; pub use data::Data;
use crate::Result; use crate::Result;
use ruma::{events::receipt::ReceiptEvent, serde::Raw, RoomId, UserId}; use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId};
pub struct Service { pub struct Service {
pub db: &'static dyn Data, pub db: &'static dyn Data,
@ -28,7 +28,7 @@ impl Service {
since: u64, since: u64,
) -> impl Iterator< ) -> impl Iterator<
Item = Result<( Item = Result<(
Box<UserId>, OwnedUserId,
u64, u64,
Raw<ruma::events::AnySyncEphemeralRoomEvent>, Raw<ruma::events::AnySyncEphemeralRoomEvent>,
)>, )>,

View file

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma::{RoomId, UserId}; use ruma::{OwnedUserId, RoomId, UserId};
use std::collections::HashSet; use std::collections::HashSet;
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
@ -14,5 +14,5 @@ pub trait Data: Send + Sync {
fn last_typing_update(&self, room_id: &RoomId) -> Result<u64>; fn last_typing_update(&self, room_id: &RoomId) -> Result<u64>;
/// Returns all user ids currently typing. /// Returns all user ids currently typing.
fn typings_all(&self, room_id: &RoomId) -> Result<HashSet<Box<UserId>>>; fn typings_all(&self, room_id: &RoomId) -> Result<HashSet<OwnedUserId>>;
} }

View file

@ -3,7 +3,7 @@ type AsyncRecursiveType<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
use ruma::{ use ruma::{
api::federation::discovery::{get_remote_server_keys, get_server_keys}, api::federation::discovery::{get_remote_server_keys, get_server_keys},
signatures::CanonicalJsonObject, CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, OwnedServerSigningKeyId,
RoomVersionId, RoomVersionId,
}; };
use std::{ use std::{
@ -30,7 +30,6 @@ use ruma::{
}, },
int, int,
serde::Base64, serde::Base64,
signatures::CanonicalJsonValue,
state_res::{self, RoomVersion, StateMap}, state_res::{self, RoomVersion, StateMap},
uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId, uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId,
}; };
@ -300,7 +299,7 @@ impl Service {
Ok(ruma::signatures::Verified::Signatures) => { Ok(ruma::signatures::Verified::Signatures) => {
// Redact // Redact
warn!("Calculated hash does not match: {}", event_id); warn!("Calculated hash does not match: {}", event_id);
match ruma::signatures::redact(&value, room_version_id) { match ruma::canonical_json::redact(&value, room_version_id) {
Ok(obj) => obj, Ok(obj) => obj,
Err(_) => { Err(_) => {
return Err(Error::BadRequest( return Err(Error::BadRequest(
@ -974,7 +973,11 @@ impl Service {
.rooms .rooms
.state_compressor .state_compressor
.save_state(room_id, new_room_state)?; .save_state(room_id, new_room_state)?;
services().rooms.state.force_state(room_id, sstatehash, new, removed, &state_lock).await?; services()
.rooms
.state
.force_state(room_id, sstatehash, new, removed, &state_lock)
.await?;
} }
} }
@ -1322,7 +1325,7 @@ impl Service {
fn get_server_keys_from_cache( fn get_server_keys_from_cache(
&self, &self,
pdu: &RawJsonValue, pdu: &RawJsonValue,
servers: &mut BTreeMap<Box<ServerName>, BTreeMap<Box<ServerSigningKeyId>, QueryCriteria>>, servers: &mut BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
room_version: &RoomVersionId, room_version: &RoomVersionId,
pub_key_map: &mut RwLockWriteGuard<'_, BTreeMap<String, BTreeMap<String, Base64>>>, pub_key_map: &mut RwLockWriteGuard<'_, BTreeMap<String, BTreeMap<String, Base64>>>,
) -> Result<()> { ) -> Result<()> {
@ -1414,8 +1417,8 @@ impl Service {
pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, Base64>>>, pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, Base64>>>,
) -> Result<()> { ) -> Result<()> {
let mut servers: BTreeMap< let mut servers: BTreeMap<
Box<ServerName>, OwnedServerName,
BTreeMap<Box<ServerSigningKeyId>, QueryCriteria>, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
> = BTreeMap::new(); > = BTreeMap::new();
{ {

View file

@ -5,7 +5,7 @@ use std::{
}; };
pub use data::Data; pub use data::Data;
use ruma::{DeviceId, RoomId, UserId}; use ruma::{DeviceId, OwnedDeviceId, OwnedRoomId, OwnedUserId, RoomId, UserId};
use crate::Result; use crate::Result;
@ -13,7 +13,7 @@ pub struct Service {
pub db: &'static dyn Data, pub db: &'static dyn Data,
pub lazy_load_waiting: pub lazy_load_waiting:
Mutex<HashMap<(Box<UserId>, Box<DeviceId>, Box<RoomId>, u64), HashSet<Box<UserId>>>>, Mutex<HashMap<(OwnedUserId, OwnedDeviceId, OwnedRoomId, u64), HashSet<OwnedUserId>>>,
} }
impl Service { impl Service {
@ -35,7 +35,7 @@ impl Service {
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
room_id: &RoomId, room_id: &RoomId,
lazy_load: HashSet<Box<UserId>>, lazy_load: HashSet<OwnedUserId>,
count: u64, count: u64,
) { ) {
self.lazy_load_waiting.lock().unwrap().insert( self.lazy_load_waiting.lock().unwrap().insert(

View file

@ -1,9 +1,9 @@
use crate::Result; use crate::Result;
use ruma::RoomId; use ruma::{OwnedRoomId, RoomId};
pub trait Data: Send + Sync { pub 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<Box<RoomId>>> + '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>;
fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()>; fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()>;
} }

View file

@ -1,7 +1,7 @@
mod data; mod data;
pub use data::Data; pub use data::Data;
use ruma::RoomId; use ruma::{OwnedRoomId, RoomId};
use crate::Result; use crate::Result;
@ -16,7 +16,7 @@ impl Service {
self.db.exists(room_id) self.db.exists(room_id)
} }
pub fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a> { pub fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
self.db.iter_ids() self.db.iter_ids()
} }

View file

@ -1,4 +1,4 @@
use ruma::{signatures::CanonicalJsonObject, EventId}; use ruma::{CanonicalJsonObject, EventId};
use crate::{PduEvent, Result}; use crate::{PduEvent, Result};

View file

@ -1,7 +1,7 @@
mod data; mod data;
pub use data::Data; pub use data::Data;
use ruma::{signatures::CanonicalJsonObject, EventId}; use ruma::{CanonicalJsonObject, EventId};
use crate::{PduEvent, Result}; use crate::{PduEvent, Result};

View file

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma::{EventId, RoomId}; use ruma::{EventId, OwnedEventId, RoomId};
use std::collections::HashSet; use std::collections::HashSet;
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::MutexGuard; use tokio::sync::MutexGuard;
@ -26,7 +26,7 @@ pub trait Data: Send + Sync {
fn set_forward_extremities<'a>( fn set_forward_extremities<'a>(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_ids: Vec<Box<EventId>>, event_ids: Vec<OwnedEventId>,
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex _mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
) -> Result<()>; ) -> Result<()>;
} }

View file

@ -12,7 +12,7 @@ use ruma::{
}, },
serde::Raw, serde::Raw,
state_res::{self, StateMap}, state_res::{self, StateMap},
EventId, RoomId, RoomVersionId, UserId, EventId, OwnedEventId, RoomId, RoomVersionId, UserId,
}; };
use serde::Deserialize; use serde::Deserialize;
use tokio::sync::MutexGuard; use tokio::sync::MutexGuard;
@ -346,7 +346,7 @@ impl Service {
pub fn set_forward_extremities<'a>( pub fn set_forward_extremities<'a>(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_ids: Vec<Box<EventId>>, event_ids: Vec<OwnedEventId>,
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
) -> Result<()> { ) -> Result<()> {
self.db self.db

View file

@ -4,7 +4,7 @@ use crate::Result;
use ruma::{ use ruma::{
events::{AnyStrippedStateEvent, AnySyncStateEvent}, events::{AnyStrippedStateEvent, AnySyncStateEvent},
serde::Raw, serde::Raw,
RoomId, ServerName, UserId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
}; };
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
@ -20,7 +20,7 @@ pub trait Data: Send + Sync {
fn update_joined_count(&self, room_id: &RoomId) -> Result<()>; fn update_joined_count(&self, room_id: &RoomId) -> Result<()>;
fn get_our_real_users(&self, room_id: &RoomId) -> Result<Arc<HashSet<Box<UserId>>>>; fn get_our_real_users(&self, room_id: &RoomId) -> Result<Arc<HashSet<OwnedUserId>>>;
fn appservice_in_room( fn appservice_in_room(
&self, &self,
@ -35,7 +35,7 @@ pub trait Data: Send + Sync {
fn room_servers<'a>( fn room_servers<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<ServerName>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedServerName>> + 'a>;
fn server_in_room<'a>(&'a self, server: &ServerName, room_id: &RoomId) -> Result<bool>; fn server_in_room<'a>(&'a self, server: &ServerName, room_id: &RoomId) -> Result<bool>;
@ -43,13 +43,13 @@ pub trait Data: Send + Sync {
fn server_rooms<'a>( fn server_rooms<'a>(
&'a self, &'a self,
server: &ServerName, server: &ServerName,
) -> Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a>;
/// Returns an iterator over all joined members of a room. /// Returns an iterator over all joined members of a room.
fn room_members<'a>( fn room_members<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a>;
fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>>; fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>>;
@ -59,13 +59,13 @@ pub trait Data: Send + Sync {
fn room_useroncejoined<'a>( fn room_useroncejoined<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a>;
/// Returns an iterator over all invited members of a room. /// Returns an iterator over all invited members of a room.
fn room_members_invited<'a>( fn room_members_invited<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a>;
fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>>; fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>>;
@ -75,13 +75,13 @@ pub trait Data: Send + Sync {
fn rooms_joined<'a>( fn rooms_joined<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a>;
/// Returns an iterator over all rooms a user was invited to. /// Returns an iterator over all rooms a user was invited to.
fn rooms_invited<'a>( fn rooms_invited<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<(Box<RoomId>, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a>; ) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a>;
fn invite_state( fn invite_state(
&self, &self,
@ -99,7 +99,7 @@ pub trait Data: Send + Sync {
fn rooms_left<'a>( fn rooms_left<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<(Box<RoomId>, Vec<Raw<AnySyncStateEvent>>)>> + 'a>; ) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a>;
fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool>; fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool>;

View file

@ -12,7 +12,7 @@ use ruma::{
RoomAccountDataEventType, StateEventType, RoomAccountDataEventType, StateEventType,
}, },
serde::Raw, serde::Raw,
RoomId, ServerName, UserId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
}; };
use crate::{services, Error, Result}; use crate::{services, Error, Result};
@ -192,7 +192,7 @@ impl Service {
} }
#[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<Box<UserId>>>> { pub 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)
} }
@ -216,7 +216,7 @@ impl Service {
pub fn room_servers<'a>( pub fn room_servers<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> impl Iterator<Item = Result<Box<ServerName>>> + 'a { ) -> impl Iterator<Item = Result<OwnedServerName>> + 'a {
self.db.room_servers(room_id) self.db.room_servers(room_id)
} }
@ -230,7 +230,7 @@ impl Service {
pub fn server_rooms<'a>( pub fn server_rooms<'a>(
&'a self, &'a self,
server: &ServerName, server: &ServerName,
) -> impl Iterator<Item = Result<Box<RoomId>>> + 'a { ) -> impl Iterator<Item = Result<OwnedRoomId>> + 'a {
self.db.server_rooms(server) self.db.server_rooms(server)
} }
@ -239,7 +239,7 @@ impl Service {
pub fn room_members<'a>( pub fn room_members<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> impl Iterator<Item = Result<Box<UserId>>> + 'a { ) -> impl Iterator<Item = Result<OwnedUserId>> + 'a {
self.db.room_members(room_id) self.db.room_members(room_id)
} }
@ -258,7 +258,7 @@ impl Service {
pub fn room_useroncejoined<'a>( pub fn room_useroncejoined<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> impl Iterator<Item = Result<Box<UserId>>> + 'a { ) -> impl Iterator<Item = Result<OwnedUserId>> + 'a {
self.db.room_useroncejoined(room_id) self.db.room_useroncejoined(room_id)
} }
@ -267,7 +267,7 @@ impl Service {
pub fn room_members_invited<'a>( pub fn room_members_invited<'a>(
&'a self, &'a self,
room_id: &RoomId, room_id: &RoomId,
) -> impl Iterator<Item = Result<Box<UserId>>> + 'a { ) -> impl Iterator<Item = Result<OwnedUserId>> + 'a {
self.db.room_members_invited(room_id) self.db.room_members_invited(room_id)
} }
@ -286,7 +286,7 @@ impl Service {
pub fn rooms_joined<'a>( pub fn rooms_joined<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> impl Iterator<Item = Result<Box<RoomId>>> + 'a { ) -> impl Iterator<Item = Result<OwnedRoomId>> + 'a {
self.db.rooms_joined(user_id) self.db.rooms_joined(user_id)
} }
@ -295,7 +295,7 @@ impl Service {
pub fn rooms_invited<'a>( pub fn rooms_invited<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> impl Iterator<Item = Result<(Box<RoomId>, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a { ) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a {
self.db.rooms_invited(user_id) self.db.rooms_invited(user_id)
} }
@ -322,7 +322,7 @@ impl Service {
pub fn rooms_left<'a>( pub fn rooms_left<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> impl Iterator<Item = Result<(Box<RoomId>, Vec<Raw<AnySyncStateEvent>>)>> + 'a { ) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a {
self.db.rooms_left(user_id) self.db.rooms_left(user_id)
} }

View file

@ -251,7 +251,11 @@ impl Service {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
new_state_ids_compressed: HashSet<CompressedStateEvent>, new_state_ids_compressed: HashSet<CompressedStateEvent>,
) -> Result<(u64, HashSet<CompressedStateEvent>, HashSet<CompressedStateEvent>)> { ) -> Result<(
u64,
HashSet<CompressedStateEvent>,
HashSet<CompressedStateEvent>,
)> {
let previous_shortstatehash = services().rooms.state.get_room_shortstatehash(room_id)?; let previous_shortstatehash = services().rooms.state.get_room_shortstatehash(room_id)?;
let state_hash = utils::calculate_hash( let state_hash = utils::calculate_hash(

View file

@ -1,6 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use ruma::{signatures::CanonicalJsonObject, EventId, RoomId, UserId}; use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId};
use crate::{PduEvent, Result}; use crate::{PduEvent, Result};
@ -81,7 +81,7 @@ pub trait Data: Send + Sync {
fn increment_notification_counts( fn increment_notification_counts(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
notifies: Vec<Box<UserId>>, notifies: Vec<OwnedUserId>,
highlights: Vec<Box<UserId>>, highlights: Vec<OwnedUserId>,
) -> Result<()>; ) -> Result<()>;
} }

View file

@ -7,10 +7,15 @@ use std::sync::{Arc, Mutex};
pub use data::Data; pub use data::Data;
use regex::Regex; use regex::Regex;
use ruma::canonical_json::to_canonical_value;
use ruma::events::room::power_levels::RoomPowerLevelsEventContent; use ruma::events::room::power_levels::RoomPowerLevelsEventContent;
use ruma::push::Ruleset; use ruma::push::Ruleset;
use ruma::signatures::CanonicalJsonValue;
use ruma::state_res::RoomVersion; use ruma::state_res::RoomVersion;
use ruma::CanonicalJsonObject;
use ruma::CanonicalJsonValue;
use ruma::OwnedEventId;
use ruma::OwnedRoomId;
use ruma::OwnedServerName;
use ruma::{ use ruma::{
api::client::error::ErrorKind, api::client::error::ErrorKind,
events::{ events::{
@ -19,8 +24,6 @@ use ruma::{
GlobalAccountDataEventType, RoomEventType, StateEventType, GlobalAccountDataEventType, RoomEventType, StateEventType,
}, },
push::{Action, Tweak}, push::{Action, Tweak},
serde::to_canonical_value,
signatures::CanonicalJsonObject,
state_res, uint, EventId, RoomAliasId, RoomId, ServerName, UserId, state_res, uint, EventId, RoomAliasId, RoomId, ServerName, UserId,
}; };
use serde::Deserialize; use serde::Deserialize;
@ -38,7 +41,7 @@ use super::state_compressor::CompressedStateEvent;
pub struct Service { pub struct Service {
pub db: &'static dyn Data, pub db: &'static dyn Data,
pub lasttimelinecount_cache: Mutex<HashMap<Box<RoomId>, u64>>, pub lasttimelinecount_cache: Mutex<HashMap<OwnedRoomId, u64>>,
} }
impl Service { impl Service {
@ -146,7 +149,7 @@ impl Service {
&self, &self,
pdu: &PduEvent, pdu: &PduEvent,
mut pdu_json: CanonicalJsonObject, mut pdu_json: CanonicalJsonObject,
leaves: Vec<Box<EventId>>, leaves: Vec<OwnedEventId>,
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
) -> Result<Vec<u8>> { ) -> Result<Vec<u8>> {
let shortroomid = services() let shortroomid = services()
@ -702,7 +705,7 @@ impl Service {
.state .state
.set_room_state(room_id, statehashid, state_lock)?; .set_room_state(room_id, statehashid, state_lock)?;
let mut servers: HashSet<Box<ServerName>> = services() let mut servers: HashSet<OwnedServerName> = services()
.rooms .rooms
.state_cache .state_cache
.room_servers(room_id) .room_servers(room_id)
@ -716,7 +719,7 @@ impl Service {
.as_ref() .as_ref()
.and_then(|state_key| UserId::parse(state_key.as_str()).ok()) .and_then(|state_key| UserId::parse(state_key.as_str()).ok())
{ {
servers.insert(Box::from(state_key_uid.server_name())); servers.insert(state_key_uid.server_name().to_owned());
} }
} }
@ -735,7 +738,7 @@ impl Service {
&self, &self,
pdu: &PduEvent, pdu: &PduEvent,
pdu_json: CanonicalJsonObject, pdu_json: CanonicalJsonObject,
new_room_leaves: Vec<Box<EventId>>, new_room_leaves: Vec<OwnedEventId>,
state_ids_compressed: HashSet<CompressedStateEvent>, state_ids_compressed: HashSet<CompressedStateEvent>,
soft_fail: bool, soft_fail: bool,
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex

View file

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma::{RoomId, UserId}; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId};
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>;
@ -19,6 +19,6 @@ pub trait Data: Send + Sync {
fn get_shared_rooms<'a>( fn get_shared_rooms<'a>(
&'a self, &'a self,
users: Vec<Box<UserId>>, users: Vec<OwnedUserId>,
) -> Result<Box<dyn Iterator<Item = Result<Box<RoomId>>> + 'a>>; ) -> Result<Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a>>;
} }

View file

@ -1,7 +1,7 @@
mod data; mod data;
pub use data::Data; pub use data::Data;
use ruma::{RoomId, UserId}; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId};
use crate::Result; use crate::Result;
@ -38,8 +38,8 @@ impl Service {
pub fn get_shared_rooms<'a>( pub fn get_shared_rooms<'a>(
&'a self, &'a self,
users: Vec<Box<UserId>>, users: Vec<OwnedUserId>,
) -> Result<impl Iterator<Item = Result<Box<RoomId>>> + 'a> { ) -> Result<impl Iterator<Item = Result<OwnedRoomId>> + 'a> {
self.db.get_shared_rooms(users) self.db.get_shared_rooms(users)
} }
} }

View file

@ -30,10 +30,11 @@ use ruma::{
OutgoingRequest, OutgoingRequest,
}, },
device_id, device_id,
events::{push_rules::PushRulesEvent, AnySyncEphemeralRoomEvent, GlobalAccountDataEventType}, events::{
push, push_rules::PushRulesEvent, receipt::ReceiptType, AnySyncEphemeralRoomEvent,
receipt::ReceiptType, GlobalAccountDataEventType,
uint, MilliSecondsSinceUnixEpoch, ServerName, UInt, UserId, },
push, uint, MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedUserId, ServerName, UInt, UserId,
}; };
use tokio::{ use tokio::{
select, select,
@ -44,8 +45,8 @@ use tracing::{error, warn};
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum OutgoingKind { pub enum OutgoingKind {
Appservice(String), Appservice(String),
Push(Box<UserId>, String), // user and pushkey Push(OwnedUserId, String), // user and pushkey
Normal(Box<ServerName>), Normal(OwnedServerName),
} }
impl OutgoingKind { impl OutgoingKind {
@ -381,7 +382,7 @@ impl Service {
} }
#[tracing::instrument(skip(self, servers, pdu_id))] #[tracing::instrument(skip(self, servers, pdu_id))]
pub fn send_pdu<I: Iterator<Item = Box<ServerName>>>( pub fn send_pdu<I: Iterator<Item = OwnedServerName>>(
&self, &self,
servers: I, servers: I,
pdu_id: &[u8], pdu_id: &[u8],

View file

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma::{api::client::uiaa::UiaaInfo, signatures::CanonicalJsonValue, DeviceId, UserId}; use ruma::{api::client::uiaa::UiaaInfo, CanonicalJsonValue, DeviceId, UserId};
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
fn set_uiaa_request( fn set_uiaa_request(

View file

@ -7,8 +7,7 @@ use ruma::{
error::ErrorKind, error::ErrorKind,
uiaa::{AuthType, IncomingAuthData, IncomingPassword, IncomingUserIdentifier, UiaaInfo}, uiaa::{AuthType, IncomingAuthData, IncomingPassword, IncomingUserIdentifier, UiaaInfo},
}, },
signatures::CanonicalJsonValue, CanonicalJsonValue, DeviceId, UserId,
DeviceId, UserId,
}; };
use tracing::error; use tracing::error;

View file

@ -4,7 +4,8 @@ use ruma::{
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
events::AnyToDeviceEvent, events::AnyToDeviceEvent,
serde::Raw, serde::Raw,
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MxcUri, UInt, UserId, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, OwnedDeviceId, OwnedDeviceKeyId, OwnedMxcUri,
OwnedUserId, UInt, UserId,
}; };
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -19,10 +20,10 @@ pub trait Data: Send + Sync {
fn count(&self) -> Result<usize>; fn count(&self) -> Result<usize>;
/// Find out which user an access token belongs to. /// Find out which user an access token belongs to.
fn find_from_token(&self, token: &str) -> Result<Option<(Box<UserId>, String)>>; fn find_from_token(&self, token: &str) -> Result<Option<(OwnedUserId, String)>>;
/// Returns an iterator over all users on this homeserver. /// Returns an iterator over all users on this homeserver.
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a>; fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a>;
/// Returns a list of local users as list of usernames. /// Returns a list of local users as list of usernames.
/// ///
@ -42,10 +43,10 @@ pub trait Data: Send + Sync {
fn set_displayname(&self, user_id: &UserId, displayname: Option<String>) -> Result<()>; fn set_displayname(&self, user_id: &UserId, displayname: Option<String>) -> Result<()>;
/// Get the avatar_url of a user. /// Get the avatar_url of a user.
fn avatar_url(&self, user_id: &UserId) -> Result<Option<Box<MxcUri>>>; fn avatar_url(&self, user_id: &UserId) -> Result<Option<OwnedMxcUri>>;
/// Sets a new avatar_url or removes it if avatar_url is None. /// Sets a new avatar_url or removes it if avatar_url is None.
fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<Box<MxcUri>>) -> Result<()>; fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<OwnedMxcUri>) -> Result<()>;
/// Get the blurhash of a user. /// Get the blurhash of a user.
fn blurhash(&self, user_id: &UserId) -> Result<Option<String>>; fn blurhash(&self, user_id: &UserId) -> Result<Option<String>>;
@ -69,7 +70,7 @@ pub trait Data: Send + Sync {
fn all_device_ids<'a>( fn all_device_ids<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<Box<DeviceId>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedDeviceId>> + 'a>;
/// Replaces the access token of one device. /// Replaces the access token of one device.
fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()>; fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()>;
@ -89,7 +90,7 @@ pub trait Data: Send + Sync {
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
key_algorithm: &DeviceKeyAlgorithm, key_algorithm: &DeviceKeyAlgorithm,
) -> Result<Option<(Box<DeviceKeyId>, Raw<OneTimeKey>)>>; ) -> Result<Option<(OwnedDeviceKeyId, Raw<OneTimeKey>)>>;
fn count_one_time_keys( fn count_one_time_keys(
&self, &self,
@ -125,7 +126,7 @@ pub trait Data: Send + Sync {
user_or_room_id: &str, user_or_room_id: &str,
from: u64, from: u64,
to: Option<u64>, to: Option<u64>,
) -> Box<dyn Iterator<Item = Result<Box<UserId>>> + 'a>; ) -> Box<dyn Iterator<Item = Result<OwnedUserId>> + 'a>;
fn mark_device_key_update(&self, user_id: &UserId) -> Result<()>; fn mark_device_key_update(&self, user_id: &UserId) -> Result<()>;

View file

@ -7,7 +7,8 @@ use ruma::{
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
events::AnyToDeviceEvent, events::AnyToDeviceEvent,
serde::Raw, serde::Raw,
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MxcUri, RoomAliasId, UInt, UserId, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MxcUri, OwnedDeviceId, OwnedDeviceKeyId,
OwnedMxcUri, OwnedUserId, RoomAliasId, UInt, UserId,
}; };
use crate::{services, Error, Result}; use crate::{services, Error, Result};
@ -56,12 +57,12 @@ impl Service {
} }
/// Find out which user an access token belongs to. /// Find out which user an access token belongs to.
pub fn find_from_token(&self, token: &str) -> Result<Option<(Box<UserId>, String)>> { pub fn find_from_token(&self, token: &str) -> Result<Option<(OwnedUserId, String)>> {
self.db.find_from_token(token) self.db.find_from_token(token)
} }
/// Returns an iterator over all users on this homeserver. /// Returns an iterator over all users on this homeserver.
pub fn iter(&self) -> impl Iterator<Item = Result<Box<UserId>>> + '_ { pub fn iter(&self) -> impl Iterator<Item = Result<OwnedUserId>> + '_ {
self.db.iter() self.db.iter()
} }
@ -93,12 +94,12 @@ impl Service {
} }
/// Get the avatar_url of a user. /// Get the avatar_url of a user.
pub fn avatar_url(&self, user_id: &UserId) -> Result<Option<Box<MxcUri>>> { pub fn avatar_url(&self, user_id: &UserId) -> Result<Option<OwnedMxcUri>> {
self.db.avatar_url(user_id) self.db.avatar_url(user_id)
} }
/// Sets a new avatar_url or removes it if avatar_url is None. /// Sets a new avatar_url or removes it if avatar_url is None.
pub fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<Box<MxcUri>>) -> Result<()> { pub fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<OwnedMxcUri>) -> Result<()> {
self.db.set_avatar_url(user_id, avatar_url) self.db.set_avatar_url(user_id, avatar_url)
} }
@ -133,7 +134,7 @@ impl Service {
pub fn all_device_ids<'a>( pub fn all_device_ids<'a>(
&'a self, &'a self,
user_id: &UserId, user_id: &UserId,
) -> impl Iterator<Item = Result<Box<DeviceId>>> + 'a { ) -> impl Iterator<Item = Result<OwnedDeviceId>> + 'a {
self.db.all_device_ids(user_id) self.db.all_device_ids(user_id)
} }
@ -162,7 +163,7 @@ impl Service {
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
key_algorithm: &DeviceKeyAlgorithm, key_algorithm: &DeviceKeyAlgorithm,
) -> Result<Option<(Box<DeviceKeyId>, Raw<OneTimeKey>)>> { ) -> Result<Option<(OwnedDeviceKeyId, Raw<OneTimeKey>)>> {
self.db.take_one_time_key(user_id, device_id, key_algorithm) self.db.take_one_time_key(user_id, device_id, key_algorithm)
} }
@ -209,7 +210,7 @@ impl Service {
user_or_room_id: &str, user_or_room_id: &str,
from: u64, from: u64,
to: Option<u64>, to: Option<u64>,
) -> impl Iterator<Item = Result<Box<UserId>>> + 'a { ) -> impl Iterator<Item = Result<OwnedUserId>> + 'a {
self.db.keys_changed(user_or_room_id, from, to) self.db.keys_changed(user_or_room_id, from, to)
} }

View file

@ -6,7 +6,7 @@ use ruma::{
error::{Error as RumaError, ErrorKind}, error::{Error as RumaError, ErrorKind},
uiaa::{UiaaInfo, UiaaResponse}, uiaa::{UiaaInfo, UiaaResponse},
}, },
ServerName, OwnedServerName, ServerName,
}; };
use thiserror::Error; use thiserror::Error;
use tracing::{error, warn}; use tracing::{error, warn};
@ -55,7 +55,7 @@ pub enum Error {
source: reqwest::Error, source: reqwest::Error,
}, },
#[error("{0}")] #[error("{0}")]
FederationError(Box<ServerName>, RumaError), FederationError(OwnedServerName, RumaError),
#[error("Could not do this io: {source}")] #[error("Could not do this io: {source}")]
IoError { IoError {
#[from] #[from]

View file

@ -4,7 +4,7 @@ use argon2::{Config, Variant};
use cmp::Ordering; use cmp::Ordering;
use rand::prelude::*; use rand::prelude::*;
use ring::digest; use ring::digest;
use ruma::serde::{try_from_json_map, CanonicalJsonError, CanonicalJsonObject}; use ruma::{canonical_json::try_from_json_map, CanonicalJsonError, CanonicalJsonObject};
use std::{ use std::{
cmp, fmt, cmp, fmt,
str::FromStr, str::FromStr,