From 164b1633d8b9bfe0dfba03dca8703adf422d586b Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Fri, 4 Dec 2020 18:16:17 -0500 Subject: [PATCH] Update ruma to latest, renamed server keys and removed PduStub --- Cargo.lock | 69 +++++++++++++++++---------------- Cargo.toml | 4 +- src/client_server/account.rs | 1 + src/client_server/config.rs | 2 +- src/client_server/directory.rs | 15 +++++-- src/client_server/membership.rs | 6 +-- src/client_server/presence.rs | 2 +- src/client_server/profile.rs | 2 +- src/client_server/room.rs | 15 ++++--- src/client_server/sync.rs | 3 +- src/database/account_data.rs | 3 +- src/database/admin.rs | 5 ++- src/database/rooms.rs | 11 +++--- src/database/rooms/edus.rs | 3 +- src/database/users.rs | 3 +- src/error.rs | 6 +-- src/pdu.rs | 13 ++++--- src/push_rules.rs | 23 +++++++---- src/server_server.rs | 24 +++++++----- 19 files changed, 123 insertions(+), 87 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afb3abf..efc34e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1210,6 +1210,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "paste" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7151b083b0664ed58ed669fcdd92f01c3d2fdbf10af4931a301474950b52bfa9" + [[package]] name = "pear" version = "0.2.0-dev" @@ -1611,7 +1617,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.0.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "assign", "js_int", @@ -1629,24 +1635,22 @@ dependencies = [ [[package]] name = "ruma-api" version = "0.17.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "http", "percent-encoding", "ruma-api-macros", - "ruma-common", "ruma-identifiers", "ruma-serde", "serde", "serde_json", - "strum", "thiserror", ] [[package]] name = "ruma-api-macros" version = "0.17.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1657,12 +1661,13 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.2.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "ruma-api", "ruma-common", "ruma-events", "ruma-identifiers", + "ruma-serde", "serde", "serde_json", ] @@ -1670,7 +1675,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.10.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "assign", "http", @@ -1684,38 +1689,25 @@ dependencies = [ "ruma-serde", "serde", "serde_json", - "strum", ] [[package]] name = "ruma-common" version = "0.2.0" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "js_int", - "ruma-common-macros", + "maplit", "ruma-identifiers", "ruma-serde", "serde", "serde_json", - "strum", -] - -[[package]] -name = "ruma-common-macros" -version = "0.2.0" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", ] [[package]] name = "ruma-events" version = "0.22.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "js_int", "ruma-common", @@ -1724,13 +1716,12 @@ dependencies = [ "ruma-serde", "serde", "serde_json", - "strum", ] [[package]] name = "ruma-events-macros" version = "0.22.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1741,7 +1732,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.0.3" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "js_int", "ruma-api", @@ -1756,8 +1747,9 @@ dependencies = [ [[package]] name = "ruma-identifiers" version = "0.17.4" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ + "paste", "rand", "ruma-identifiers-macros", "ruma-identifiers-validation", @@ -1769,7 +1761,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-macros" version = "0.17.4" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "proc-macro2", "quote", @@ -1780,28 +1772,39 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.1.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "serde", - "strum", ] [[package]] name = "ruma-serde" version = "0.2.3" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "form_urlencoded", "itoa", "js_int", + "ruma-serde-macros", "serde", "serde_json", ] +[[package]] +name = "ruma-serde-macros" +version = "0.2.0" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "ruma-signatures" version = "0.6.0-dev.1" -source = "git+https://github.com/ruma/ruma?rev=c15382ca41262058302959eac4029ab4a1ea5889#c15382ca41262058302959eac4029ab4a1ea5889" +source = "git+https://github.com/ruma/ruma?rev=e8882fe8142d7b55ed4c8ccc6150946945f9e237#e8882fe8142d7b55ed4c8ccc6150946945f9e237" dependencies = [ "base64 0.12.3", "ring", @@ -2059,7 +2062,7 @@ checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483" [[package]] name = "state-res" version = "0.1.0" -source = "git+https://github.com/ruma/state-res?branch=timo-spec-comp#d2a85669cc6056679ce6ca0fde4658a879ad2b08" +source = "git+https://github.com/ruma/state-res?branch=timo-spec-comp#99214e6fa6b9843b0d9e1f6ef0698d7fdb234fb2" dependencies = [ "itertools", "js_int", diff --git a/Cargo.toml b/Cargo.toml index e7b87fa..4902c7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,14 +18,14 @@ edition = "2018" rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] } # Used for matrix spec type definitions and helpers -ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks", "unstable-exhaustive-types"], rev = "c15382ca41262058302959eac4029ab4a1ea5889" } +ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks", "unstable-exhaustive-types"], rev = "e8882fe8142d7b55ed4c8ccc6150946945f9e237" } # ruma = { git = "https://github.com/DevinR528/ruma", features = ["rand", "client-api", "federation-api", "unstable-exhaustive-types", "unstable-pre-spec", "unstable-synapse-quirks"], branch = "unstable-join" } # ruma = { path = "../ruma/ruma", features = ["unstable-exhaustive-types", "rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"] } # Used when doing state resolution # state-res = { git = "https://github.com/timokoesters/state-res", branch = "spec-comp", features = ["unstable-pre-spec"] } state-res = { git = "https://github.com/ruma/state-res", branch = "timo-spec-comp", features = ["unstable-pre-spec", "gen-eventid"] } -# state-res = { path = "../../state-res", features = ["unstable-pre-spec"] } +# state-res = { path = "../../state-res", features = ["unstable-pre-spec", "gen-eventid"] } # Used for long polling tokio = "0.2.22" diff --git a/src/client_server/account.rs b/src/client_server/account.rs index ab90de5..76bbebb 100644 --- a/src/client_server/account.rs +++ b/src/client_server/account.rs @@ -492,6 +492,7 @@ pub async fn register_route( body: "Thanks for trying out Conduit! This software is still in development, so expect many bugs and missing features. If you have federation enabled, you can join the Conduit chat room by typing /join #conduit:matrix.org. Important: Please don't join any other Matrix rooms over federation without permission from the room's admins. Some actions might trigger bugs in other server implementations, breaking the chat for everyone else.".to_owned(), }), relates_to: None, + new_content: None, }, )) .expect("event is valid, we just created it"), diff --git a/src/client_server/config.rs b/src/client_server/config.rs index dd8de64..f1d233a 100644 --- a/src/client_server/config.rs +++ b/src/client_server/config.rs @@ -6,7 +6,7 @@ use ruma::{ r0::config::{get_global_account_data, set_global_account_data}, }, events::{custom::CustomEventContent, BasicEvent}, - Raw, + serde::Raw, }; #[cfg(feature = "conduit_bin")] diff --git a/src/client_server/directory.rs b/src/client_server/directory.rs index d8af2e3..559071a 100644 --- a/src/client_server/directory.rs +++ b/src/client_server/directory.rs @@ -20,7 +20,8 @@ use ruma::{ room::{avatar, canonical_alias, guest_access, history_visibility, name, topic}, EventType, }, - Raw, ServerName, + serde::Raw, + ServerName, }; #[cfg(feature = "conduit_bin")] @@ -83,7 +84,13 @@ pub async fn set_room_visibility_route( ) -> ConduitResult { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - match body.visibility { + match &body.visibility { + room::Visibility::_Custom(_s) => { + return Err(Error::BadRequest( + ErrorKind::InvalidParam, + "Room visibility type is not supported.", + )); + } room::Visibility::Public => { db.rooms.set_public(&body.room_id, true)?; info!("{} made {} public", sender_user, body.room_id); @@ -294,7 +301,9 @@ pub async fn get_public_rooms_filtered_helper( .url, ) }) - .transpose()?, + .transpose()? + // url is now an Option so we must flatten + .flatten(), }; Ok(chunk) }) diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs index b5e4042..6d3a690 100644 --- a/src/client_server/membership.rs +++ b/src/client_server/membership.rs @@ -18,8 +18,8 @@ use ruma::{ federation, }, events::{pdu::Pdu, room::member, EventType}, - serde::{to_canonical_value, CanonicalJsonObject}, - EventId, Raw, RoomId, RoomVersionId, ServerName, UserId, + serde::{to_canonical_value, CanonicalJsonObject, Raw}, + EventId, RoomId, RoomVersionId, ServerName, UserId, }; use state_res::StateEvent; use std::{ @@ -541,7 +541,7 @@ async fn join_room_by_id_helper( federation::membership::create_join_event::v2::Request { room_id, event_id: &event_id, - pdu_stub: PduEvent::convert_to_outgoing_federation_event(join_event.clone()), + pdu: PduEvent::convert_to_outgoing_federation_event(join_event.clone()), }, ) .await?; diff --git a/src/client_server/presence.rs b/src/client_server/presence.rs index e597c69..15c746e 100644 --- a/src/client_server/presence.rs +++ b/src/client_server/presence.rs @@ -32,7 +32,7 @@ pub async fn set_presence_route( .try_into() .expect("time is valid"), ), - presence: body.presence, + presence: body.presence.clone(), status_msg: body.status_msg.clone(), }, sender: sender_user.clone(), diff --git a/src/client_server/profile.rs b/src/client_server/profile.rs index 22d13cb..828d259 100644 --- a/src/client_server/profile.rs +++ b/src/client_server/profile.rs @@ -8,7 +8,7 @@ use ruma::{ }, }, events::EventType, - Raw, + serde::Raw, }; #[cfg(feature = "conduit_bin")] diff --git a/src/client_server/room.rs b/src/client_server/room.rs index a50f69c..f92fc8d 100644 --- a/src/client_server/room.rs +++ b/src/client_server/room.rs @@ -10,7 +10,8 @@ use ruma::{ room::{guest_access, history_visibility, join_rules, member, name, topic}, EventType, }, - Raw, RoomAliasId, RoomId, RoomVersionId, + serde::Raw, + RoomAliasId, RoomId, RoomVersionId, }; use std::{cmp::max, collections::BTreeMap, convert::TryFrom}; @@ -141,10 +142,14 @@ pub async fn create_room_route( // 4. Events set by preset // Figure out preset. We need it for preset specific events - let preset = body.preset.unwrap_or_else(|| match body.visibility { - room::Visibility::Private => create_room::RoomPreset::PrivateChat, - room::Visibility::Public => create_room::RoomPreset::PublicChat, - }); + let preset = body + .preset + .clone() + .unwrap_or_else(|| match &body.visibility { + room::Visibility::Private => create_room::RoomPreset::PrivateChat, + room::Visibility::Public => create_room::RoomPreset::PublicChat, + room::Visibility::_Custom(s) => create_room::RoomPreset::_Custom(s.into()), + }); // 4.1 Join Rules db.rooms.build_and_append_pdu( diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs index 360691a..d7c24dc 100644 --- a/src/client_server/sync.rs +++ b/src/client_server/sync.rs @@ -3,7 +3,8 @@ use crate::{ConduitResult, Database, Error, Ruma}; use ruma::{ api::client::r0::sync::sync_events, events::{room::member::MembershipState, AnySyncEphemeralRoomEvent, EventType}, - Raw, RoomId, UserId, + serde::Raw, + RoomId, UserId, }; #[cfg(feature = "conduit_bin")] diff --git a/src/database/account_data.rs b/src/database/account_data.rs index 9a6a050..855ebfe 100644 --- a/src/database/account_data.rs +++ b/src/database/account_data.rs @@ -2,7 +2,8 @@ use crate::{utils, Error, Result}; use ruma::{ api::client::error::ErrorKind, events::{AnyEvent as EduEvent, EventType}, - Raw, RoomId, UserId, + serde::Raw, + RoomId, UserId, }; use serde::{de::DeserializeOwned, Serialize}; use sled::IVec; diff --git a/src/database/admin.rs b/src/database/admin.rs index 87a60a1..10b6221 100644 --- a/src/database/admin.rs +++ b/src/database/admin.rs @@ -3,7 +3,10 @@ use std::convert::{TryFrom, TryInto}; use crate::pdu::PduBuilder; use log::warn; use rocket::futures::{channel::mpsc, stream::StreamExt}; -use ruma::{events::room::message, events::EventType, UserId}; +use ruma::{ + events::{room::message, EventType}, + UserId, +}; use tokio::select; pub enum AdminCommand { diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 0618fd6..fb139a6 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -15,8 +15,8 @@ use ruma::{ }, EventType, }, - serde::{to_canonical_value, CanonicalJsonObject}, - EventId, Raw, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, + serde::{to_canonical_value, CanonicalJsonObject, Raw}, + EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, }; use sled::IVec; use state_res::{event_auth, Error as StateError, Requester, StateEvent, StateMap, StateStore}; @@ -102,7 +102,7 @@ impl StateStore for Rooms { .and_then(|pdu: StateEvent| { // conduit's PDU's always contain a room_id but some // of ruma's do not so this must be an Option - if pdu.room_id() == Some(room_id) { + if pdu.room_id() == room_id { Ok(Arc::new(pdu)) } else { Err(StateError::NotFound( @@ -278,7 +278,7 @@ impl Rooms { for ((event_type, state_key), pdu_id) in state { let mut state_id = prefix.clone(); - state_id.extend_from_slice(&event_type.as_str().as_bytes()); + state_id.extend_from_slice(&event_type.as_ref().as_bytes()); state_id.push(0xff); state_id.extend_from_slice(&state_key.as_bytes()); self.stateid_pduid.insert(state_id, pdu_id)?; @@ -592,6 +592,7 @@ impl Rooms { body: format!("Command: {}, Args: {:?}", command, args), formatted: None, relates_to: None, + new_content: None, }, )); } @@ -633,7 +634,7 @@ impl Rooms { if let Some(state_key) = &new_pdu.state_key { let mut new_state = old_state; - let mut pdu_key = new_pdu.kind.as_str().as_bytes().to_vec(); + let mut pdu_key = new_pdu.kind.as_ref().as_bytes().to_vec(); pdu_key.push(0xff); pdu_key.extend_from_slice(state_key.as_bytes()); new_state.insert(pdu_key.into(), new_pdu_id.into()); diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs index 29f5407..bf0cdfc 100644 --- a/src/database/rooms/edus.rs +++ b/src/database/rooms/edus.rs @@ -6,7 +6,8 @@ use ruma::{ AnyEvent as EduEvent, SyncEphemeralRoomEvent, }, presence::PresenceState, - Raw, RoomId, UserId, + serde::Raw, + RoomId, UserId, }; use std::{ collections::HashMap, diff --git a/src/database/users.rs b/src/database/users.rs index 885c041..0421ae2 100644 --- a/src/database/users.rs +++ b/src/database/users.rs @@ -10,7 +10,8 @@ use ruma::{ }, encryption::DeviceKeys, events::{AnyToDeviceEvent, EventType}, - DeviceId, DeviceKeyAlgorithm, DeviceKeyId, Raw, UserId, + serde::Raw, + DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId, }; use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime}; diff --git a/src/error.rs b/src/error.rs index 4c24fd7..316ca74 100644 --- a/src/error.rs +++ b/src/error.rs @@ -143,11 +143,7 @@ impl log::Log for ConduitLogger { } self.db.admin.send(AdminCommand::SendTextMessage( - message::TextMessageEventContent { - body: output, - formatted: None, - relates_to: None, - }, + message::TextMessageEventContent::plain(output), )); } } diff --git a/src/pdu.rs b/src/pdu.rs index e56e81a..75ef492 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -5,8 +5,8 @@ use ruma::{ pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent, }, - serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue}, - EventId, Raw, RoomId, RoomVersionId, ServerKeyId, ServerName, UserId, + serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw}, + EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId, }; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -36,7 +36,7 @@ pub struct PduEvent { #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")] pub unsigned: serde_json::Map, pub hashes: EventHash, - pub signatures: BTreeMap, BTreeMap>, + pub signatures: BTreeMap, BTreeMap>, } impl PduEvent { @@ -205,9 +205,10 @@ impl PduEvent { serde_json::from_value(json).expect("Raw::from_value always works") } + /// This does not return a full `Pdu` it is only to satisfy ruma's types. pub fn convert_to_outgoing_federation_event( mut pdu_json: CanonicalJsonObject, - ) -> Raw { + ) -> Raw { if let Some(CanonicalJsonValue::Object(unsigned)) = pdu_json.get_mut("unsigned") { unsigned.remove("transaction_id"); } @@ -232,7 +233,7 @@ impl From<&state_res::StateEvent> for PduEvent { fn from(pdu: &state_res::StateEvent) -> Self { Self { event_id: pdu.event_id(), - room_id: pdu.room_id().unwrap().clone(), + room_id: pdu.room_id().clone(), sender: pdu.sender().clone(), origin_server_ts: (pdu .origin_server_ts() @@ -288,7 +289,7 @@ impl PduEvent { /// /// Returns a tuple of the new `EventId` and the PDU with the eventId inserted as a `serde_json::Value`. pub(crate) fn process_incoming_pdu( - pdu: &ruma::Raw, + pdu: &Raw, ) -> (EventId, CanonicalJsonObject) { let mut value = serde_json::from_str(pdu.json().get()).expect("A Raw<...> is always valid JSON"); diff --git a/src/push_rules.rs b/src/push_rules.rs index 32c709e..76a1a61 100644 --- a/src/push_rules.rs +++ b/src/push_rules.rs @@ -1,15 +1,18 @@ use ruma::{ push::{ - Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule, - PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak, + Action, ConditionalPushRule, ConditionalPushRuleInit, ContentPushRule, OverridePushRule, + PatternedPushRule, PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak, + UnderridePushRule, }, UserId, }; pub fn default_pushrules(user_id: &UserId) -> Ruleset { let mut rules = Ruleset::default(); - rules.content = vec![contains_user_name_rule(&user_id)]; - rules.override_ = vec![ + + rules.add(ContentPushRule(contains_user_name_rule(&user_id))); + + for rule in vec![ master_rule(), suppress_notices_rule(), invite_for_me_rule(), @@ -17,14 +20,20 @@ pub fn default_pushrules(user_id: &UserId) -> Ruleset { contains_display_name_rule(), tombstone_rule(), roomnotif_rule(), - ]; - rules.underride = vec![ + ] { + rules.add(OverridePushRule(rule)); + } + + for rule in vec![ call_rule(), encrypted_room_one_to_one_rule(), room_one_to_one_rule(), message_rule(), encrypted_rule(), - ]; + ] { + rules.add(UnderridePushRule(rule)); + } + rules } diff --git a/src/server_server.rs b/src/server_server.rs index a7f6391..fe36e7c 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -11,7 +11,8 @@ use ruma::{ federation::{ directory::{get_public_rooms, get_public_rooms_filtered}, discovery::{ - get_server_keys, get_server_version::v1 as get_server_version, ServerKey, VerifyKey, + get_server_keys, get_server_version::v1 as get_server_version, ServerSigningKeys, + VerifyKey, }, event::get_missing_events, query::get_profile_information, @@ -20,11 +21,11 @@ use ruma::{ OutgoingRequest, }, directory::{IncomingFilter, IncomingRoomNetwork}, - EventId, RoomId, ServerName, UserId, + EventId, RoomId, ServerName, ServerSigningKeyId, UserId, }; use std::{ collections::BTreeMap, - convert::{TryFrom, TryInto}, + convert::TryFrom, fmt::Debug, sync::Arc, time::{Duration, SystemTime}, @@ -243,16 +244,17 @@ pub fn get_server_keys(db: State<'_, Database>) -> Json { let mut verify_keys = BTreeMap::new(); verify_keys.insert( - format!("ed25519:{}", db.globals.keypair().version()) - .try_into() - .expect("DB stores valid ServerKeyId's"), + ServerSigningKeyId::try_from( + format!("ed25519:{}", db.globals.keypair().version()).as_str(), + ) + .expect("found invalid server signing keys in DB"), VerifyKey { key: base64::encode_config(db.globals.keypair().public_key(), base64::STANDARD_NO_PAD), }, ); let mut response = serde_json::from_slice( http::Response::try_from(get_server_keys::v2::Response { - server_key: ServerKey { + server_key: ServerSigningKeys { server_name: db.globals.server_name().to_owned(), verify_keys, old_verify_keys: BTreeMap::new(), @@ -430,7 +432,7 @@ pub async fn send_transaction_message_route<'a>( // would return a M_BAD_JSON error. let mut resolved_map = BTreeMap::new(); for pdu in &body.pdus { - // Ruma/PduEvent/StateEvent satifies - 1. Is a valid event, otherwise it is dropped. + // Ruma/PduEvent/StateEvent satisfies - 1. Is a valid event, otherwise it is dropped. // state-res checks signatures - 2. Passes signature checks, otherwise event is dropped. @@ -450,7 +452,7 @@ pub async fn send_transaction_message_route<'a>( continue; } - // If it is not a state event, we can skip state-res + // If it is not a state event, we can skip state-res... maybe if value.get("state_key").is_none() { if !db.rooms.is_joined(&pdu.sender, room_id)? { warn!("Sender is not joined {}", pdu.kind); @@ -679,7 +681,9 @@ pub fn get_profile_information_route<'a>( let mut displayname = None; let mut avatar_url = None; - match body.field { + match &body.field { + // TODO: what to do with custom + Some(ProfileField::_Custom(_s)) => {} Some(ProfileField::DisplayName) => displayname = db.users.displayname(&body.user_id)?, Some(ProfileField::AvatarUrl) => avatar_url = db.users.avatar_url(&body.user_id)?, None => {