Update ruma to latest, renamed server keys and removed PduStub

next
Devin Ragotzy 2020-12-04 18:16:17 -05:00 committed by Timo Kösters
parent b869aab5d0
commit 164b1633d8
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
19 changed files with 123 additions and 87 deletions

69
Cargo.lock generated
View File

@ -1210,6 +1210,12 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "paste"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7151b083b0664ed58ed669fcdd92f01c3d2fdbf10af4931a301474950b52bfa9"
[[package]] [[package]]
name = "pear" name = "pear"
version = "0.2.0-dev" version = "0.2.0-dev"
@ -1611,7 +1617,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.0.1" 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 = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -1629,24 +1635,22 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.17.0-alpha.1" 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 = [ dependencies = [
"http", "http",
"percent-encoding", "percent-encoding",
"ruma-api-macros", "ruma-api-macros",
"ruma-common",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
"strum",
"thiserror", "thiserror",
] ]
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.17.0-alpha.1" 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 = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1657,12 +1661,13 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.2.0-alpha.1" 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 = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
] ]
@ -1670,7 +1675,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.10.0-alpha.1" 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 = [ dependencies = [
"assign", "assign",
"http", "http",
@ -1684,38 +1689,25 @@ dependencies = [
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
"strum",
] ]
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.2.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common-macros", "maplit",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "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]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.22.0-alpha.1" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -1724,13 +1716,12 @@ dependencies = [
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
"strum",
] ]
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.22.0-alpha.1" 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 = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1741,7 +1732,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.0.3" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1756,8 +1747,9 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.17.4" 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 = [ dependencies = [
"paste",
"rand", "rand",
"ruma-identifiers-macros", "ruma-identifiers-macros",
"ruma-identifiers-validation", "ruma-identifiers-validation",
@ -1769,7 +1761,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.17.4" 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 = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1780,28 +1772,39 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.1.1" 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 = [ dependencies = [
"serde", "serde",
"strum",
] ]
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.2.3" 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 = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"itoa", "itoa",
"js_int", "js_int",
"ruma-serde-macros",
"serde", "serde",
"serde_json", "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]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.6.0-dev.1" 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 = [ dependencies = [
"base64 0.12.3", "base64 0.12.3",
"ring", "ring",
@ -2059,7 +2062,7 @@ checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483"
[[package]] [[package]]
name = "state-res" name = "state-res"
version = "0.1.0" 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 = [ dependencies = [
"itertools", "itertools",
"js_int", "js_int",

View File

@ -18,14 +18,14 @@ edition = "2018"
rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] } rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
# Used for matrix spec type definitions and helpers # 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 = { 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"] } # ruma = { path = "../ruma/ruma", features = ["unstable-exhaustive-types", "rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"] }
# Used when doing state resolution # 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/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 = { 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 # Used for long polling
tokio = "0.2.22" tokio = "0.2.22"

View File

@ -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 <code>/join #conduit:matrix.org</code>. <strong>Important: Please don't join any other Matrix rooms over federation without permission from the room's admins.</strong> Some actions might trigger bugs in other server implementations, breaking the chat for everyone else.".to_owned(), 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 <code>/join #conduit:matrix.org</code>. <strong>Important: Please don't join any other Matrix rooms over federation without permission from the room's admins.</strong> Some actions might trigger bugs in other server implementations, breaking the chat for everyone else.".to_owned(),
}), }),
relates_to: None, relates_to: None,
new_content: None,
}, },
)) ))
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),

View File

@ -6,7 +6,7 @@ use ruma::{
r0::config::{get_global_account_data, set_global_account_data}, r0::config::{get_global_account_data, set_global_account_data},
}, },
events::{custom::CustomEventContent, BasicEvent}, events::{custom::CustomEventContent, BasicEvent},
Raw, serde::Raw,
}; };
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]

View File

@ -20,7 +20,8 @@ use ruma::{
room::{avatar, canonical_alias, guest_access, history_visibility, name, topic}, room::{avatar, canonical_alias, guest_access, history_visibility, name, topic},
EventType, EventType,
}, },
Raw, ServerName, serde::Raw,
ServerName,
}; };
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]
@ -83,7 +84,13 @@ pub async fn set_room_visibility_route(
) -> ConduitResult<set_room_visibility::Response> { ) -> ConduitResult<set_room_visibility::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");
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 => { room::Visibility::Public => {
db.rooms.set_public(&body.room_id, true)?; db.rooms.set_public(&body.room_id, true)?;
info!("{} made {} public", sender_user, body.room_id); info!("{} made {} public", sender_user, body.room_id);
@ -294,7 +301,9 @@ pub async fn get_public_rooms_filtered_helper(
.url, .url,
) )
}) })
.transpose()?, .transpose()?
// url is now an Option<String> so we must flatten
.flatten(),
}; };
Ok(chunk) Ok(chunk)
}) })

View File

@ -18,8 +18,8 @@ use ruma::{
federation, federation,
}, },
events::{pdu::Pdu, room::member, EventType}, events::{pdu::Pdu, room::member, EventType},
serde::{to_canonical_value, CanonicalJsonObject}, serde::{to_canonical_value, CanonicalJsonObject, Raw},
EventId, Raw, RoomId, RoomVersionId, ServerName, UserId, EventId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use state_res::StateEvent; use state_res::StateEvent;
use std::{ use std::{
@ -541,7 +541,7 @@ async fn join_room_by_id_helper(
federation::membership::create_join_event::v2::Request { federation::membership::create_join_event::v2::Request {
room_id, room_id,
event_id: &event_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?; .await?;

View File

@ -32,7 +32,7 @@ pub async fn set_presence_route(
.try_into() .try_into()
.expect("time is valid"), .expect("time is valid"),
), ),
presence: body.presence, presence: body.presence.clone(),
status_msg: body.status_msg.clone(), status_msg: body.status_msg.clone(),
}, },
sender: sender_user.clone(), sender: sender_user.clone(),

View File

@ -8,7 +8,7 @@ use ruma::{
}, },
}, },
events::EventType, events::EventType,
Raw, serde::Raw,
}; };
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]

View File

@ -10,7 +10,8 @@ use ruma::{
room::{guest_access, history_visibility, join_rules, member, name, topic}, room::{guest_access, history_visibility, join_rules, member, name, topic},
EventType, EventType,
}, },
Raw, RoomAliasId, RoomId, RoomVersionId, serde::Raw,
RoomAliasId, RoomId, RoomVersionId,
}; };
use std::{cmp::max, collections::BTreeMap, convert::TryFrom}; use std::{cmp::max, collections::BTreeMap, convert::TryFrom};
@ -141,9 +142,13 @@ pub async fn create_room_route(
// 4. Events set by preset // 4. Events set by preset
// Figure out preset. We need it for preset specific events // Figure out preset. We need it for preset specific events
let preset = body.preset.unwrap_or_else(|| match body.visibility { let preset = body
.preset
.clone()
.unwrap_or_else(|| match &body.visibility {
room::Visibility::Private => create_room::RoomPreset::PrivateChat, room::Visibility::Private => create_room::RoomPreset::PrivateChat,
room::Visibility::Public => create_room::RoomPreset::PublicChat, room::Visibility::Public => create_room::RoomPreset::PublicChat,
room::Visibility::_Custom(s) => create_room::RoomPreset::_Custom(s.into()),
}); });
// 4.1 Join Rules // 4.1 Join Rules

View File

@ -3,7 +3,8 @@ use crate::{ConduitResult, Database, Error, Ruma};
use ruma::{ use ruma::{
api::client::r0::sync::sync_events, api::client::r0::sync::sync_events,
events::{room::member::MembershipState, AnySyncEphemeralRoomEvent, EventType}, events::{room::member::MembershipState, AnySyncEphemeralRoomEvent, EventType},
Raw, RoomId, UserId, serde::Raw,
RoomId, UserId,
}; };
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]

View File

@ -2,7 +2,8 @@ use crate::{utils, Error, Result};
use ruma::{ use ruma::{
api::client::error::ErrorKind, api::client::error::ErrorKind,
events::{AnyEvent as EduEvent, EventType}, events::{AnyEvent as EduEvent, EventType},
Raw, RoomId, UserId, serde::Raw,
RoomId, UserId,
}; };
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use sled::IVec; use sled::IVec;

View File

@ -3,7 +3,10 @@ use std::convert::{TryFrom, TryInto};
use crate::pdu::PduBuilder; use crate::pdu::PduBuilder;
use log::warn; use log::warn;
use rocket::futures::{channel::mpsc, stream::StreamExt}; 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; use tokio::select;
pub enum AdminCommand { pub enum AdminCommand {

View File

@ -15,8 +15,8 @@ use ruma::{
}, },
EventType, EventType,
}, },
serde::{to_canonical_value, CanonicalJsonObject}, serde::{to_canonical_value, CanonicalJsonObject, Raw},
EventId, Raw, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use sled::IVec; use sled::IVec;
use state_res::{event_auth, Error as StateError, Requester, StateEvent, StateMap, StateStore}; use state_res::{event_auth, Error as StateError, Requester, StateEvent, StateMap, StateStore};
@ -102,7 +102,7 @@ impl StateStore for Rooms {
.and_then(|pdu: StateEvent| { .and_then(|pdu: StateEvent| {
// conduit's PDU's always contain a room_id but some // conduit's PDU's always contain a room_id but some
// of ruma's do not so this must be an Option // 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)) Ok(Arc::new(pdu))
} else { } else {
Err(StateError::NotFound( Err(StateError::NotFound(
@ -278,7 +278,7 @@ impl Rooms {
for ((event_type, state_key), pdu_id) in state { for ((event_type, state_key), pdu_id) in state {
let mut state_id = prefix.clone(); 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.push(0xff);
state_id.extend_from_slice(&state_key.as_bytes()); state_id.extend_from_slice(&state_key.as_bytes());
self.stateid_pduid.insert(state_id, pdu_id)?; self.stateid_pduid.insert(state_id, pdu_id)?;
@ -592,6 +592,7 @@ impl Rooms {
body: format!("Command: {}, Args: {:?}", command, args), body: format!("Command: {}, Args: {:?}", command, args),
formatted: None, formatted: None,
relates_to: None, relates_to: None,
new_content: None,
}, },
)); ));
} }
@ -633,7 +634,7 @@ impl Rooms {
if let Some(state_key) = &new_pdu.state_key { if let Some(state_key) = &new_pdu.state_key {
let mut new_state = old_state; 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.push(0xff);
pdu_key.extend_from_slice(state_key.as_bytes()); pdu_key.extend_from_slice(state_key.as_bytes());
new_state.insert(pdu_key.into(), new_pdu_id.into()); new_state.insert(pdu_key.into(), new_pdu_id.into());

View File

@ -6,7 +6,8 @@ use ruma::{
AnyEvent as EduEvent, SyncEphemeralRoomEvent, AnyEvent as EduEvent, SyncEphemeralRoomEvent,
}, },
presence::PresenceState, presence::PresenceState,
Raw, RoomId, UserId, serde::Raw,
RoomId, UserId,
}; };
use std::{ use std::{
collections::HashMap, collections::HashMap,

View File

@ -10,7 +10,8 @@ use ruma::{
}, },
encryption::DeviceKeys, encryption::DeviceKeys,
events::{AnyToDeviceEvent, EventType}, events::{AnyToDeviceEvent, EventType},
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, Raw, UserId, serde::Raw,
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId,
}; };
use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime}; use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime};

View File

@ -143,11 +143,7 @@ impl log::Log for ConduitLogger {
} }
self.db.admin.send(AdminCommand::SendTextMessage( self.db.admin.send(AdminCommand::SendTextMessage(
message::TextMessageEventContent { message::TextMessageEventContent::plain(output),
body: output,
formatted: None,
relates_to: None,
},
)); ));
} }
} }

View File

@ -5,8 +5,8 @@ use ruma::{
pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent, pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent,
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
}, },
serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue}, serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw},
EventId, Raw, RoomId, RoomVersionId, ServerKeyId, ServerName, UserId, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;
@ -36,7 +36,7 @@ pub struct PduEvent {
#[serde(default, skip_serializing_if = "serde_json::Map::is_empty")] #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")]
pub unsigned: serde_json::Map<String, serde_json::Value>, pub unsigned: serde_json::Map<String, serde_json::Value>,
pub hashes: EventHash, pub hashes: EventHash,
pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerKeyId, String>>, pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>,
} }
impl PduEvent { impl PduEvent {
@ -205,9 +205,10 @@ impl PduEvent {
serde_json::from_value(json).expect("Raw::from_value always works") 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( pub fn convert_to_outgoing_federation_event(
mut pdu_json: CanonicalJsonObject, mut pdu_json: CanonicalJsonObject,
) -> Raw<ruma::events::pdu::PduStub> { ) -> Raw<ruma::events::pdu::Pdu> {
if let Some(CanonicalJsonValue::Object(unsigned)) = pdu_json.get_mut("unsigned") { if let Some(CanonicalJsonValue::Object(unsigned)) = pdu_json.get_mut("unsigned") {
unsigned.remove("transaction_id"); unsigned.remove("transaction_id");
} }
@ -232,7 +233,7 @@ impl From<&state_res::StateEvent> for PduEvent {
fn from(pdu: &state_res::StateEvent) -> Self { fn from(pdu: &state_res::StateEvent) -> Self {
Self { Self {
event_id: pdu.event_id(), event_id: pdu.event_id(),
room_id: pdu.room_id().unwrap().clone(), room_id: pdu.room_id().clone(),
sender: pdu.sender().clone(), sender: pdu.sender().clone(),
origin_server_ts: (pdu origin_server_ts: (pdu
.origin_server_ts() .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`. /// 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( pub(crate) fn process_incoming_pdu(
pdu: &ruma::Raw<ruma::events::pdu::Pdu>, pdu: &Raw<ruma::events::pdu::Pdu>,
) -> (EventId, CanonicalJsonObject) { ) -> (EventId, CanonicalJsonObject) {
let mut value = let mut value =
serde_json::from_str(pdu.json().get()).expect("A Raw<...> is always valid JSON"); serde_json::from_str(pdu.json().get()).expect("A Raw<...> is always valid JSON");

View File

@ -1,15 +1,18 @@
use ruma::{ use ruma::{
push::{ push::{
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule, Action, ConditionalPushRule, ConditionalPushRuleInit, ContentPushRule, OverridePushRule,
PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak, PatternedPushRule, PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak,
UnderridePushRule,
}, },
UserId, UserId,
}; };
pub fn default_pushrules(user_id: &UserId) -> Ruleset { pub fn default_pushrules(user_id: &UserId) -> Ruleset {
let mut rules = Ruleset::default(); 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(), master_rule(),
suppress_notices_rule(), suppress_notices_rule(),
invite_for_me_rule(), invite_for_me_rule(),
@ -17,14 +20,20 @@ pub fn default_pushrules(user_id: &UserId) -> Ruleset {
contains_display_name_rule(), contains_display_name_rule(),
tombstone_rule(), tombstone_rule(),
roomnotif_rule(), roomnotif_rule(),
]; ] {
rules.underride = vec![ rules.add(OverridePushRule(rule));
}
for rule in vec![
call_rule(), call_rule(),
encrypted_room_one_to_one_rule(), encrypted_room_one_to_one_rule(),
room_one_to_one_rule(), room_one_to_one_rule(),
message_rule(), message_rule(),
encrypted_rule(), encrypted_rule(),
]; ] {
rules.add(UnderridePushRule(rule));
}
rules rules
} }

View File

@ -11,7 +11,8 @@ use ruma::{
federation::{ federation::{
directory::{get_public_rooms, get_public_rooms_filtered}, directory::{get_public_rooms, get_public_rooms_filtered},
discovery::{ 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, event::get_missing_events,
query::get_profile_information, query::get_profile_information,
@ -20,11 +21,11 @@ use ruma::{
OutgoingRequest, OutgoingRequest,
}, },
directory::{IncomingFilter, IncomingRoomNetwork}, directory::{IncomingFilter, IncomingRoomNetwork},
EventId, RoomId, ServerName, UserId, EventId, RoomId, ServerName, ServerSigningKeyId, UserId,
}; };
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
convert::{TryFrom, TryInto}, convert::TryFrom,
fmt::Debug, fmt::Debug,
sync::Arc, sync::Arc,
time::{Duration, SystemTime}, time::{Duration, SystemTime},
@ -243,16 +244,17 @@ pub fn get_server_keys(db: State<'_, Database>) -> Json<String> {
let mut verify_keys = BTreeMap::new(); let mut verify_keys = BTreeMap::new();
verify_keys.insert( verify_keys.insert(
format!("ed25519:{}", db.globals.keypair().version()) ServerSigningKeyId::try_from(
.try_into() format!("ed25519:{}", db.globals.keypair().version()).as_str(),
.expect("DB stores valid ServerKeyId's"), )
.expect("found invalid server signing keys in DB"),
VerifyKey { VerifyKey {
key: base64::encode_config(db.globals.keypair().public_key(), base64::STANDARD_NO_PAD), key: base64::encode_config(db.globals.keypair().public_key(), base64::STANDARD_NO_PAD),
}, },
); );
let mut response = serde_json::from_slice( let mut response = serde_json::from_slice(
http::Response::try_from(get_server_keys::v2::Response { http::Response::try_from(get_server_keys::v2::Response {
server_key: ServerKey { server_key: ServerSigningKeys {
server_name: db.globals.server_name().to_owned(), server_name: db.globals.server_name().to_owned(),
verify_keys, verify_keys,
old_verify_keys: BTreeMap::new(), old_verify_keys: BTreeMap::new(),
@ -430,7 +432,7 @@ pub async fn send_transaction_message_route<'a>(
// would return a M_BAD_JSON error. // would return a M_BAD_JSON error.
let mut resolved_map = BTreeMap::new(); let mut resolved_map = BTreeMap::new();
for pdu in &body.pdus { 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. // 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; 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 value.get("state_key").is_none() {
if !db.rooms.is_joined(&pdu.sender, room_id)? { if !db.rooms.is_joined(&pdu.sender, room_id)? {
warn!("Sender is not joined {}", pdu.kind); warn!("Sender is not joined {}", pdu.kind);
@ -679,7 +681,9 @@ pub fn get_profile_information_route<'a>(
let mut displayname = None; let mut displayname = None;
let mut avatar_url = 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::DisplayName) => displayname = db.users.displayname(&body.user_id)?,
Some(ProfileField::AvatarUrl) => avatar_url = db.users.avatar_url(&body.user_id)?, Some(ProfileField::AvatarUrl) => avatar_url = db.users.avatar_url(&body.user_id)?,
None => { None => {