Merge pull request 'Switch to the ruma meta-crate' (#106) from jplatte/conduit:master into master

Reviewed-by: Timo Kösters <timo@koesters.xyz>
next
Timo Kösters 2020-06-06 08:58:13 +02:00
commit 8f6b446193
14 changed files with 197 additions and 202 deletions

75
Cargo.lock generated
View File

@ -160,13 +160,7 @@ dependencies = [
"rand", "rand",
"reqwest", "reqwest",
"rocket", "rocket",
"ruma-api", "ruma",
"ruma-client-api",
"ruma-common",
"ruma-events 0.21.3 (git+https://github.com/ruma/ruma-events?rev=c1ee72d)",
"ruma-federation-api",
"ruma-identifiers",
"ruma-signatures",
"rust-argon2 0.8.2", "rust-argon2 0.8.2",
"serde", "serde",
"serde_json", "serde_json",
@ -1266,11 +1260,24 @@ dependencies = [
"unicode-xid 0.2.0", "unicode-xid 0.2.0",
] ]
[[package]]
name = "ruma"
version = "0.1.0"
source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4"
dependencies = [
"ruma-api",
"ruma-client-api",
"ruma-common",
"ruma-events",
"ruma-federation-api",
"ruma-identifiers",
"ruma-signatures",
]
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.16.1" version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4"
checksum = "82ffdb7fb9cf6af2b1d0d8254d922560ecb70081d7e70931c9b996b6b4839db5"
dependencies = [ dependencies = [
"http", "http",
"percent-encoding 2.1.0", "percent-encoding 2.1.0",
@ -1285,8 +1292,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.16.1" version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4"
checksum = "52b82b4567b9af9b40a86f7778821c016ea961f55e4fee255f8f24bb28ee7452"
dependencies = [ dependencies = [
"proc-macro2 1.0.18", "proc-macro2 1.0.18",
"quote 1.0.6", "quote 1.0.6",
@ -1296,13 +1302,13 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/ruma/ruma-client-api.git?rev=632eb9d520028816c5fb7224bd0aca8d1e3793f1#632eb9d520028816c5fb7224bd0aca8d1e3793f1" source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4"
dependencies = [ dependencies = [
"http", "http",
"js_int", "js_int",
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
"ruma-events 0.21.3 (git+https://github.com/ruma/ruma-events?rev=c1ee72d)", "ruma-events",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
@ -1313,8 +1319,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.1.3" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4"
checksum = "6cb49e83277e82c69cc258cedc7e68b3d72ba378f1cb6105cbfcc8831e422b4d"
dependencies = [ dependencies = [
"matches", "matches",
"ruma-serde", "ruma-serde",
@ -1330,7 +1335,7 @@ source = "git+https://github.com/ruma/ruma-events?rev=c1ee72d#c1ee72db0f3107a97f
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
"ruma-events-macros 0.21.3 (git+https://github.com/ruma/ruma-events?rev=c1ee72d)", "ruma-events-macros",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
@ -1338,21 +1343,6 @@ dependencies = [
"strum", "strum",
] ]
[[package]]
name = "ruma-events"
version = "0.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ddf82c2231e4c53443424df34e868e4b09c20de7a76780d47a133a3b3f8ad9c"
dependencies = [
"js_int",
"ruma-common",
"ruma-events-macros 0.21.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ruma-identifiers",
"ruma-serde",
"serde",
"serde_json",
]
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.21.3" version = "0.21.3"
@ -1363,26 +1353,16 @@ dependencies = [
"syn 1.0.30", "syn 1.0.30",
] ]
[[package]]
name = "ruma-events-macros"
version = "0.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88e5c5b242fe4ee0cc56879057353621196d0988dd359579cad8f43471e483b7"
dependencies = [
"proc-macro2 1.0.18",
"quote 1.0.6",
"syn 1.0.30",
]
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.0.1" version = "0.0.2"
source = "git+https://github.com/ruma/ruma-federation-api.git?rev=4cf4aa6ef74b25ad8c14d99d7774129f023df163#4cf4aa6ef74b25ad8c14d99d7774129f023df163" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff655a4cb7d43b60b18e07a601889836c1c12854bb16f4c083826b664fdc55aa"
dependencies = [ dependencies = [
"js_int", "js_int",
"matches", "matches",
"ruma-api", "ruma-api",
"ruma-events 0.21.3 (registry+https://github.com/rust-lang/crates.io-index)", "ruma-events",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
@ -1402,8 +1382,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4"
checksum = "8c71dabb8e2709ca4f59201cb72d7fe8d590e7e3f55feb348e851c18354938af"
dependencies = [ dependencies = [
"dtoa", "dtoa",
"itoa", "itoa",
@ -1416,7 +1395,7 @@ dependencies = [
[[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-signatures.git?rev=1ca545cba8dfd43e0fc8e3c18e1311fb73390a97#1ca545cba8dfd43e0fc8e3c18e1311fb73390a97" source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4"
dependencies = [ dependencies = [
"base64 0.12.1", "base64 0.12.1",
"ring", "ring",

View File

@ -12,14 +12,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
ruma-client-api = { git = "https://github.com/ruma/ruma-client-api.git", rev = "632eb9d520028816c5fb7224bd0aca8d1e3793f1" }
ruma-identifiers = { version = "0.16.2", features = ["rand"] }
ruma-api = "0.16.1"
ruma-events = { git = "https://github.com/ruma/ruma-events.git", rev = "c1ee72d" }
ruma-signatures = { git = "https://github.com/ruma/ruma-signatures.git", rev = "1ca545cba8dfd43e0fc8e3c18e1311fb73390a97" }
ruma-federation-api = { git = "https://github.com/ruma/ruma-federation-api.git", rev = "4cf4aa6ef74b25ad8c14d99d7774129f023df163" }
ruma-common = "0.1.3"
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", branch = "async", features = ["tls"] } rocket = { git = "https://github.com/SergioBenitez/Rocket.git", branch = "async", features = ["tls"] }
http = "0.2.1" http = "0.2.1"
log = "0.4.8" log = "0.4.8"
@ -35,3 +27,15 @@ reqwest = "0.10.6"
base64 = "0.12.1" base64 = "0.12.1"
thiserror = "1.0.19" thiserror = "1.0.19"
image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] } image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] }
[dependencies.ruma]
git = "https://github.com/ruma/ruma"
rev = "f6fb971329a4a5a7faeebf7ea47a86cd19e580f4"
features = ["rand", "client-api", "federation-api"]
# These are required only until ruma-events and ruma-federation-api are merged into ruma/ruma
[patch.crates-io]
ruma-api = { git = "https://github.com/ruma/ruma", rev = "f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" }
ruma-events = { git = "https://github.com/ruma/ruma-events", rev = "c1ee72d" }
ruma-serde = { git = "https://github.com/ruma/ruma", rev = "f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" }

View File

@ -7,7 +7,8 @@ use std::{
use crate::{utils, Database, MatrixResult, Ruma}; use crate::{utils, Database, MatrixResult, Ruma};
use log::{debug, warn}; use log::{debug, warn};
use rocket::{delete, get, options, post, put, State}; use rocket::{delete, get, options, post, put, State};
use ruma_client_api::{ use ruma::{
api::client::{
error::{Error, ErrorKind}, error::{Error, ErrorKind},
r0::{ r0::{
account::{get_username_availability, register}, account::{get_username_availability, register},
@ -49,13 +50,14 @@ use ruma_client_api::{
user_directory::search_users, user_directory::search_users,
}, },
unversioned::get_supported_versions, unversioned::get_supported_versions,
}; },
use ruma_events::{ events::{
collections::only::Event as EduEvent, collections::only::Event as EduEvent,
room::{canonical_alias, guest_access, history_visibility, join_rules, member, redaction}, room::{canonical_alias, guest_access, history_visibility, join_rules, member, redaction},
EventJson, EventType, EventJson, EventType,
},
identifiers::{DeviceId, RoomAliasId, RoomId, RoomVersionId, UserId},
}; };
use ruma_identifiers::{DeviceId, RoomAliasId, RoomId, RoomVersionId, UserId};
use serde_json::{json, value::RawValue}; use serde_json::{json, value::RawValue};
const GUEST_NAME_LENGTH: usize = 10; const GUEST_NAME_LENGTH: usize = 10;
@ -197,12 +199,12 @@ pub fn register_route(
None, None,
&user_id, &user_id,
&EventType::PushRules, &EventType::PushRules,
serde_json::to_value(ruma_events::push_rules::PushRulesEvent { serde_json::to_value(ruma::events::push_rules::PushRulesEvent {
content: ruma_events::push_rules::PushRulesEventContent { content: ruma::events::push_rules::PushRulesEventContent {
global: ruma_events::push_rules::Ruleset { global: ruma::events::push_rules::Ruleset {
content: vec![], content: vec![],
override_: vec![ruma_events::push_rules::ConditionalPushRule { override_: vec![ruma::events::push_rules::ConditionalPushRule {
actions: vec![ruma_events::push_rules::Action::DontNotify], actions: vec![ruma::events::push_rules::Action::DontNotify],
default: true, default: true,
enabled: false, enabled: false,
rule_id: ".m.rule.master".to_owned(), rule_id: ".m.rule.master".to_owned(),
@ -210,17 +212,17 @@ pub fn register_route(
}], }],
room: vec![], room: vec![],
sender: vec![], sender: vec![],
underride: vec![ruma_events::push_rules::ConditionalPushRule { underride: vec![ruma::events::push_rules::ConditionalPushRule {
actions: vec![ actions: vec![
ruma_events::push_rules::Action::Notify, ruma::events::push_rules::Action::Notify,
ruma_events::push_rules::Action::SetTweak( ruma::events::push_rules::Action::SetTweak(
ruma_common::push::Tweak::Sound("default".to_owned()), ruma::push::Tweak::Sound("default".to_owned()),
), ),
], ],
default: true, default: true,
enabled: true, enabled: true,
rule_id: ".m.rule.message".to_owned(), rule_id: ".m.rule.message".to_owned(),
conditions: vec![ruma_events::push_rules::PushCondition::EventMatch { conditions: vec![ruma::events::push_rules::PushCondition::EventMatch {
key: "type".to_owned(), key: "type".to_owned(),
pattern: "m.room.message".to_owned(), pattern: "m.room.message".to_owned(),
}], }],
@ -522,7 +524,7 @@ pub fn set_displayname_route(
room_id.clone(), room_id.clone(),
user_id.clone(), user_id.clone(),
EventType::RoomMember, EventType::RoomMember,
serde_json::to_value(ruma_events::room::member::MemberEventContent { serde_json::to_value(ruma::events::room::member::MemberEventContent {
displayname: body.displayname.clone(), displayname: body.displayname.clone(),
..serde_json::from_value::<EventJson<_>>( ..serde_json::from_value::<EventJson<_>>(
db.rooms db.rooms
@ -549,13 +551,13 @@ pub fn set_displayname_route(
// Presence update // Presence update
db.global_edus db.global_edus
.update_presence( .update_presence(
ruma_events::presence::PresenceEvent { ruma::events::presence::PresenceEvent {
content: ruma_events::presence::PresenceEventContent { content: ruma::events::presence::PresenceEventContent {
avatar_url: db.users.avatar_url(&user_id).unwrap(), avatar_url: db.users.avatar_url(&user_id).unwrap(),
currently_active: None, currently_active: None,
displayname: db.users.displayname(&user_id).unwrap(), displayname: db.users.displayname(&user_id).unwrap(),
last_active_ago: Some(utils::millis_since_unix_epoch().try_into().unwrap()), last_active_ago: Some(utils::millis_since_unix_epoch().try_into().unwrap()),
presence: ruma_events::presence::PresenceState::Online, presence: ruma::events::presence::PresenceState::Online,
status_msg: None, status_msg: None,
}, },
sender: user_id.clone(), sender: user_id.clone(),
@ -613,7 +615,7 @@ pub fn set_avatar_url_route(
room_id.clone(), room_id.clone(),
user_id.clone(), user_id.clone(),
EventType::RoomMember, EventType::RoomMember,
serde_json::to_value(ruma_events::room::member::MemberEventContent { serde_json::to_value(ruma::events::room::member::MemberEventContent {
avatar_url: body.avatar_url.clone(), avatar_url: body.avatar_url.clone(),
..serde_json::from_value::<EventJson<_>>( ..serde_json::from_value::<EventJson<_>>(
db.rooms db.rooms
@ -640,13 +642,13 @@ pub fn set_avatar_url_route(
// Presence update // Presence update
db.global_edus db.global_edus
.update_presence( .update_presence(
ruma_events::presence::PresenceEvent { ruma::events::presence::PresenceEvent {
content: ruma_events::presence::PresenceEventContent { content: ruma::events::presence::PresenceEventContent {
avatar_url: db.users.avatar_url(&user_id).unwrap(), avatar_url: db.users.avatar_url(&user_id).unwrap(),
currently_active: None, currently_active: None,
displayname: db.users.displayname(&user_id).unwrap(), displayname: db.users.displayname(&user_id).unwrap(),
last_active_ago: Some(utils::millis_since_unix_epoch().try_into().unwrap()), last_active_ago: Some(utils::millis_since_unix_epoch().try_into().unwrap()),
presence: ruma_events::presence::PresenceState::Online, presence: ruma::events::presence::PresenceState::Online,
status_msg: None, status_msg: None,
}, },
sender: user_id.clone(), sender: user_id.clone(),
@ -706,8 +708,8 @@ pub fn set_presence_route(
db.global_edus db.global_edus
.update_presence( .update_presence(
ruma_events::presence::PresenceEvent { ruma::events::presence::PresenceEvent {
content: ruma_events::presence::PresenceEventContent { content: ruma::events::presence::PresenceEventContent {
avatar_url: db.users.avatar_url(&user_id).unwrap(), avatar_url: db.users.avatar_url(&user_id).unwrap(),
currently_active: None, currently_active: None,
displayname: db.users.displayname(&user_id).unwrap(), displayname: db.users.displayname(&user_id).unwrap(),
@ -848,8 +850,8 @@ pub fn set_read_marker_route(
Some(&body.room_id), Some(&body.room_id),
&user_id, &user_id,
&EventType::FullyRead, &EventType::FullyRead,
serde_json::to_value(ruma_events::fully_read::FullyReadEvent { serde_json::to_value(ruma::events::fully_read::FullyReadEvent {
content: ruma_events::fully_read::FullyReadEventContent { content: ruma::events::fully_read::FullyReadEventContent {
event_id: body.fully_read.clone(), event_id: body.fully_read.clone(),
}, },
room_id: Some(body.room_id.clone()), room_id: Some(body.room_id.clone()),
@ -877,14 +879,14 @@ pub fn set_read_marker_route(
let mut user_receipts = BTreeMap::new(); let mut user_receipts = BTreeMap::new();
user_receipts.insert( user_receipts.insert(
user_id.clone(), user_id.clone(),
ruma_events::receipt::Receipt { ruma::events::receipt::Receipt {
ts: Some(SystemTime::now()), ts: Some(SystemTime::now()),
}, },
); );
let mut receipt_content = BTreeMap::new(); let mut receipt_content = BTreeMap::new();
receipt_content.insert( receipt_content.insert(
event.clone(), event.clone(),
ruma_events::receipt::Receipts { ruma::events::receipt::Receipts {
read: Some(user_receipts), read: Some(user_receipts),
}, },
); );
@ -894,7 +896,7 @@ pub fn set_read_marker_route(
.roomlatest_update( .roomlatest_update(
&user_id, &user_id,
&body.room_id, &body.room_id,
EduEvent::Receipt(ruma_events::receipt::ReceiptEvent { EduEvent::Receipt(ruma::events::receipt::ReceiptEvent {
content: receipt_content, content: receipt_content,
room_id: None, // None because it can be inferred room_id: None, // None because it can be inferred
}), }),
@ -977,7 +979,7 @@ pub fn create_room_route(
room_id.clone(), room_id.clone(),
user_id.clone(), user_id.clone(),
EventType::RoomCreate, EventType::RoomCreate,
serde_json::to_value(ruma_events::room::create::CreateEventContent { serde_json::to_value(ruma::events::room::create::CreateEventContent {
creator: user_id.clone(), creator: user_id.clone(),
federate: body.creation_content.as_ref().map_or(true, |c| c.federate), federate: body.creation_content.as_ref().map_or(true, |c| c.federate),
predecessor: body predecessor: body
@ -1033,7 +1035,7 @@ pub fn create_room_route(
serde_json::from_str(power_levels.json().get()) serde_json::from_str(power_levels.json().get())
.expect("TODO: handle. we hope the client sends a valid power levels json") .expect("TODO: handle. we hope the client sends a valid power levels json")
} else { } else {
serde_json::to_value(ruma_events::room::power_levels::PowerLevelsEventContent { serde_json::to_value(ruma::events::room::power_levels::PowerLevelsEventContent {
ban: 50.into(), ban: 50.into(),
events: BTreeMap::new(), events: BTreeMap::new(),
events_default: 0.into(), events_default: 0.into(),
@ -1043,7 +1045,7 @@ pub fn create_room_route(
state_default: 50.into(), state_default: 50.into(),
users, users,
users_default: 0.into(), users_default: 0.into(),
notifications: ruma_events::room::power_levels::NotificationPowerLevels { notifications: ruma::events::room::power_levels::NotificationPowerLevels {
room: 50.into(), room: 50.into(),
}, },
}) })
@ -1159,7 +1161,7 @@ pub fn create_room_route(
user_id.clone(), user_id.clone(),
EventType::RoomName, EventType::RoomName,
serde_json::to_value( serde_json::to_value(
ruma_events::room::name::NameEventContent::new(name.clone()).unwrap(), ruma::events::room::name::NameEventContent::new(name.clone()).unwrap(),
) )
.unwrap(), .unwrap(),
None, None,
@ -1176,7 +1178,7 @@ pub fn create_room_route(
room_id.clone(), room_id.clone(),
user_id.clone(), user_id.clone(),
EventType::RoomTopic, EventType::RoomTopic,
serde_json::to_value(ruma_events::room::topic::TopicEventContent { serde_json::to_value(ruma::events::room::topic::TopicEventContent {
topic: topic.clone(), topic: topic.clone(),
}) })
.unwrap(), .unwrap(),
@ -1433,7 +1435,7 @@ pub fn leave_room_route(
let state = db.rooms.room_state(&body.room_id).unwrap(); let state = db.rooms.room_state(&body.room_id).unwrap();
let mut event = let mut event =
serde_json::from_value::<EventJson<ruma_events::room::member::MemberEventContent>>( serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>(
state state
.get(&(EventType::RoomMember, user_id.to_string())) .get(&(EventType::RoomMember, user_id.to_string()))
.unwrap() // TODO: error handling .unwrap() // TODO: error handling
@ -1444,7 +1446,7 @@ pub fn leave_room_route(
.deserialize() .deserialize()
.unwrap(); .unwrap();
event.membership = ruma_events::room::member::MembershipState::Leave; event.membership = ruma::events::room::member::MembershipState::Leave;
db.rooms db.rooms
.append_pdu( .append_pdu(
@ -1472,7 +1474,7 @@ pub fn kick_user_route(
let state = db.rooms.room_state(&body.room_id).unwrap(); let state = db.rooms.room_state(&body.room_id).unwrap();
let mut event = let mut event =
serde_json::from_value::<EventJson<ruma_events::room::member::MemberEventContent>>( serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>(
state state
.get(&(EventType::RoomMember, user_id.to_string())) .get(&(EventType::RoomMember, user_id.to_string()))
.unwrap() // TODO: error handling .unwrap() // TODO: error handling
@ -1483,7 +1485,7 @@ pub fn kick_user_route(
.deserialize() .deserialize()
.unwrap(); .unwrap();
event.membership = ruma_events::room::member::MembershipState::Leave; event.membership = ruma::events::room::member::MembershipState::Leave;
// TODO: reason // TODO: reason
db.rooms db.rooms
@ -1512,7 +1514,7 @@ pub fn ban_user_route(
let state = db.rooms.room_state(&body.room_id).unwrap(); let state = db.rooms.room_state(&body.room_id).unwrap();
let mut event = let mut event =
serde_json::from_value::<EventJson<ruma_events::room::member::MemberEventContent>>( serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>(
state state
.get(&(EventType::RoomMember, user_id.to_string())) .get(&(EventType::RoomMember, user_id.to_string()))
.unwrap() // TODO: error handling .unwrap() // TODO: error handling
@ -1523,7 +1525,7 @@ pub fn ban_user_route(
.deserialize() .deserialize()
.unwrap(); .unwrap();
event.membership = ruma_events::room::member::MembershipState::Ban; event.membership = ruma::events::room::member::MembershipState::Ban;
// TODO: reason // TODO: reason
db.rooms db.rooms
@ -1552,7 +1554,7 @@ pub fn unban_user_route(
let state = db.rooms.room_state(&body.room_id).unwrap(); let state = db.rooms.room_state(&body.room_id).unwrap();
let mut event = let mut event =
serde_json::from_value::<EventJson<ruma_events::room::member::MemberEventContent>>( serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>(
state state
.get(&(EventType::RoomMember, user_id.to_string())) .get(&(EventType::RoomMember, user_id.to_string()))
.unwrap() // TODO: error handling .unwrap() // TODO: error handling
@ -1563,7 +1565,7 @@ pub fn unban_user_route(
.deserialize() .deserialize()
.unwrap(); .unwrap();
event.membership = ruma_events::room::member::MembershipState::Leave; event.membership = ruma::events::room::member::MembershipState::Leave;
db.rooms db.rooms
.append_pdu( .append_pdu(
@ -1727,7 +1729,7 @@ pub async fn get_public_rooms_filtered_route(
aliases: Vec::new(), aliases: Vec::new(),
canonical_alias: state.get(&(EventType::RoomCanonicalAlias, "".to_owned())).and_then(|s| { canonical_alias: state.get(&(EventType::RoomCanonicalAlias, "".to_owned())).and_then(|s| {
serde_json::from_value::< serde_json::from_value::<
EventJson<ruma_events::room::canonical_alias::CanonicalAliasEventContent>, EventJson<ruma::events::room::canonical_alias::CanonicalAliasEventContent>,
>(s.content.clone()) >(s.content.clone())
.unwrap() .unwrap()
.deserialize() .deserialize()
@ -1735,7 +1737,7 @@ pub async fn get_public_rooms_filtered_route(
.alias .alias
}), }),
name: state.get(&(EventType::RoomName, "".to_owned())).map(|s| { name: state.get(&(EventType::RoomName, "".to_owned())).map(|s| {
serde_json::from_value::<EventJson<ruma_events::room::name::NameEventContent>>( serde_json::from_value::<EventJson<ruma::events::room::name::NameEventContent>>(
s.content.clone(), s.content.clone(),
) )
.unwrap() .unwrap()
@ -1749,7 +1751,7 @@ pub async fn get_public_rooms_filtered_route(
room_id, room_id,
topic: state.get(&(EventType::RoomTopic, "".to_owned())).map(|s| { topic: state.get(&(EventType::RoomTopic, "".to_owned())).map(|s| {
serde_json::from_value::< serde_json::from_value::<
EventJson<ruma_events::room::topic::TopicEventContent>, EventJson<ruma::events::room::topic::TopicEventContent>,
>(s.content.clone()) >(s.content.clone())
.unwrap() .unwrap()
.deserialize() .deserialize()
@ -1758,7 +1760,7 @@ pub async fn get_public_rooms_filtered_route(
}), }),
world_readable: state.get(&(EventType::RoomHistoryVisibility, "".to_owned())).map_or(false, |s| { world_readable: state.get(&(EventType::RoomHistoryVisibility, "".to_owned())).map_or(false, |s| {
serde_json::from_value::< serde_json::from_value::<
EventJson<ruma_events::room::history_visibility::HistoryVisibilityEventContent>, EventJson<ruma::events::room::history_visibility::HistoryVisibilityEventContent>,
>(s.content.clone()) >(s.content.clone())
.unwrap() .unwrap()
.deserialize() .deserialize()
@ -1767,7 +1769,7 @@ pub async fn get_public_rooms_filtered_route(
}), }),
guest_can_join: state.get(&(EventType::RoomGuestAccess, "".to_owned())).map_or(false, |s| { guest_can_join: state.get(&(EventType::RoomGuestAccess, "".to_owned())).map_or(false, |s| {
serde_json::from_value::< serde_json::from_value::<
EventJson<ruma_events::room::guest_access::GuestAccessEventContent>, EventJson<ruma::events::room::guest_access::GuestAccessEventContent>,
>(s.content.clone()) >(s.content.clone())
.unwrap() .unwrap()
.deserialize() .deserialize()
@ -1776,7 +1778,7 @@ pub async fn get_public_rooms_filtered_route(
}), }),
avatar_url: state.get(&(EventType::RoomAvatar, "".to_owned())).map(|s| { avatar_url: state.get(&(EventType::RoomAvatar, "".to_owned())).map(|s| {
serde_json::from_value::< serde_json::from_value::<
EventJson<ruma_events::room::avatar::AvatarEventContent>, EventJson<ruma::events::room::avatar::AvatarEventContent>,
>(s.content.clone()) >(s.content.clone())
.unwrap() .unwrap()
.deserialize() .deserialize()
@ -1794,10 +1796,10 @@ pub async fn get_public_rooms_filtered_route(
&server_server::send_request( &server_server::send_request(
&db, &db,
"privacytools.io".to_owned(), "privacytools.io".to_owned(),
ruma_federation_api::v1::get_public_rooms::Request { ruma::api::federation::v1::get_public_rooms::Request {
limit: Some(20_u32.into()), limit: Some(20_u32.into()),
since: None, since: None,
room_network: ruma_federation_api::v1::get_public_rooms::RoomNetwork::Matrix, room_network: ruma::api::federation::v1::get_public_rooms::RoomNetwork::Matrix,
}, },
) )
.await .await
@ -2155,12 +2157,12 @@ pub fn sync_route(
send_member_count = true; send_member_count = true;
if !send_full_state && pdu.state_key == Some(user_id.to_string()) { if !send_full_state && pdu.state_key == Some(user_id.to_string()) {
let content = serde_json::from_value::< let content = serde_json::from_value::<
EventJson<ruma_events::room::member::MemberEventContent>, EventJson<ruma::events::room::member::MemberEventContent>,
>(pdu.content.clone()) >(pdu.content.clone())
.unwrap() .unwrap()
.deserialize() .deserialize()
.unwrap(); .unwrap();
if content.membership == ruma_events::room::member::MembershipState::Join { if content.membership == ruma::events::room::member::MembershipState::Join {
send_full_state = true; send_full_state = true;
// Both send_member_count and send_full_state are set. There's nothing more // Both send_member_count and send_full_state are set. There's nothing more
// to do // to do
@ -2191,14 +2193,14 @@ pub fn sync_route(
.filter(|pdu| pdu.kind == EventType::RoomMember) .filter(|pdu| pdu.kind == EventType::RoomMember)
.filter_map(|pdu| { .filter_map(|pdu| {
let content = serde_json::from_value::< let content = serde_json::from_value::<
EventJson<ruma_events::room::member::MemberEventContent>, EventJson<ruma::events::room::member::MemberEventContent>,
>(pdu.content.clone()) >(pdu.content.clone())
.unwrap() .unwrap()
.deserialize() .deserialize()
.unwrap(); .unwrap();
let current_content = serde_json::from_value::< let current_content = serde_json::from_value::<
EventJson<ruma_events::room::member::MemberEventContent>, EventJson<ruma::events::room::member::MemberEventContent>,
>( >(
state state
.get(&( .get(&(
@ -2218,12 +2220,12 @@ pub fn sync_route(
// The membership was and still is invite or join // The membership was and still is invite or join
if matches!( if matches!(
content.membership, content.membership,
ruma_events::room::member::MembershipState::Join ruma::events::room::member::MembershipState::Join
| ruma_events::room::member::MembershipState::Invite | ruma::events::room::member::MembershipState::Invite
) && matches!( ) && matches!(
current_content.membership, current_content.membership,
ruma_events::room::member::MembershipState::Join ruma::events::room::member::MembershipState::Join
| ruma_events::room::member::MembershipState::Invite | ruma::events::room::member::MembershipState::Invite
) { ) {
Some(pdu.state_key.unwrap()) Some(pdu.state_key.unwrap())
} else { } else {

View File

@ -1,6 +1,8 @@
use crate::{utils, Error, Result}; use crate::{utils, Error, Result};
use ruma_events::{collections::only::Event as EduEvent, EventJson, EventType}; use ruma::{
use ruma_identifiers::{RoomId, UserId}; events::{collections::only::Event as EduEvent, EventJson, EventType},
identifiers::{RoomId, UserId},
};
use std::{collections::HashMap, convert::TryFrom}; use std::{collections::HashMap, convert::TryFrom};
pub struct AccountData { pub struct AccountData {

View File

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma_events::EventJson; use ruma::events::EventJson;
pub struct GlobalEdus { pub struct GlobalEdus {
//pub globalallid_globalall: sled::Tree, // ToDevice, GlobalAllId = UserId + Count //pub globalallid_globalall: sled::Tree, // ToDevice, GlobalAllId = UserId + Count
@ -10,7 +10,7 @@ impl GlobalEdus {
/// Adds a global event which will be saved until a new event replaces it (e.g. presence updates). /// Adds a global event which will be saved until a new event replaces it (e.g. presence updates).
pub fn update_presence( pub fn update_presence(
&self, &self,
presence: ruma_events::presence::PresenceEvent, presence: ruma::events::presence::PresenceEvent,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
// Remove old entry // Remove old entry
@ -42,7 +42,8 @@ impl GlobalEdus {
pub fn presence_since( pub fn presence_since(
&self, &self,
since: u64, since: u64,
) -> Result<impl Iterator<Item = Result<EventJson<ruma_events::presence::PresenceEvent>>>> { ) -> Result<impl Iterator<Item = Result<EventJson<ruma::events::presence::PresenceEvent>>>>
{
let first_possible_edu = (since + 1).to_be_bytes().to_vec(); // +1 so we don't send the event at since let first_possible_edu = (since + 1).to_be_bytes().to_vec(); // +1 so we don't send the event at since
Ok(self Ok(self

View File

@ -5,13 +5,13 @@ pub const COUNTER: &str = "c";
pub struct Globals { pub struct Globals {
pub(super) globals: sled::Tree, pub(super) globals: sled::Tree,
server_name: String, server_name: String,
keypair: ruma_signatures::Ed25519KeyPair, keypair: ruma::signatures::Ed25519KeyPair,
reqwest_client: reqwest::Client, reqwest_client: reqwest::Client,
} }
impl Globals { impl Globals {
pub fn load(globals: sled::Tree, server_name: String) -> Self { pub fn load(globals: sled::Tree, server_name: String) -> Self {
let keypair = ruma_signatures::Ed25519KeyPair::new( let keypair = ruma::signatures::Ed25519KeyPair::new(
&*globals &*globals
.update_and_fetch("keypair", utils::generate_keypair) .update_and_fetch("keypair", utils::generate_keypair)
.unwrap() .unwrap()
@ -34,7 +34,7 @@ impl Globals {
} }
/// Returns this server's keypair. /// Returns this server's keypair.
pub fn keypair(&self) -> &ruma_signatures::Ed25519KeyPair { pub fn keypair(&self) -> &ruma::signatures::Ed25519KeyPair {
&self.keypair &self.keypair
} }

View File

@ -4,15 +4,17 @@ pub use edus::RoomEdus;
use crate::{utils, Error, PduEvent, Result}; use crate::{utils, Error, PduEvent, Result};
use log::error; use log::error;
use ruma_events::{ use ruma::{
events::{
room::{ room::{
join_rules, member, join_rules, member,
power_levels::{self, PowerLevelsEventContent}, power_levels::{self, PowerLevelsEventContent},
redaction, redaction,
}, },
EventJson, EventType, EventJson, EventType,
},
identifiers::{EventId, RoomAliasId, RoomId, UserId},
}; };
use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId};
use sled::IVec; use sled::IVec;
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::{BTreeMap, HashMap},
@ -203,7 +205,7 @@ impl Rooms {
users: BTreeMap::new(), users: BTreeMap::new(),
users_default: 0.into(), users_default: 0.into(),
notifications: notifications:
ruma_events::room::power_levels::NotificationPowerLevels { ruma::events::room::power_levels::NotificationPowerLevels {
room: 50.into(), room: 50.into(),
}, },
}) })
@ -419,7 +421,7 @@ impl Rooms {
auth_events: Vec::new(), auth_events: Vec::new(),
redacts: redacts.clone(), redacts: redacts.clone(),
unsigned, unsigned,
hashes: ruma_federation_api::EventHash { hashes: ruma::api::federation::EventHash {
sha256: "aaa".to_owned(), sha256: "aaa".to_owned(),
}, },
signatures: HashMap::new(), signatures: HashMap::new(),
@ -428,13 +430,13 @@ impl Rooms {
// Generate event id // Generate event id
pdu.event_id = EventId::try_from(&*format!( pdu.event_id = EventId::try_from(&*format!(
"${}", "${}",
ruma_signatures::reference_hash(&serde_json::to_value(&pdu)?) ruma::signatures::reference_hash(&serde_json::to_value(&pdu)?)
.expect("ruma can calculate reference hashes") .expect("ruma can calculate reference hashes")
)) ))
.expect("ruma's reference hashes are correct"); .expect("ruma's reference hashes are correct");
let mut pdu_json = serde_json::to_value(&pdu)?; let mut pdu_json = serde_json::to_value(&pdu)?;
ruma_signatures::hash_and_sign_event( ruma::signatures::hash_and_sign_event(
globals.server_name(), globals.server_name(),
globals.keypair(), globals.keypair(),
&mut pdu_json, &mut pdu_json,

View File

@ -1,6 +1,8 @@
use crate::{utils, Error, Result}; use crate::{utils, Error, Result};
use ruma_events::{collections::only::Event as EduEvent, EventJson}; use ruma::{
use ruma_identifiers::{RoomId, UserId}; events::{collections::only::Event as EduEvent, EventJson},
identifiers::{RoomId, UserId},
};
use std::convert::TryFrom; use std::convert::TryFrom;
pub struct RoomEdus { pub struct RoomEdus {
@ -190,7 +192,7 @@ impl RoomEdus {
} }
/// Returns an iterator over all active events (e.g. typing notifications). /// Returns an iterator over all active events (e.g. typing notifications).
pub fn roomactives_all(&self, room_id: &RoomId) -> Result<ruma_events::typing::TypingEvent> { pub fn roomactives_all(&self, room_id: &RoomId) -> Result<ruma::events::typing::TypingEvent> {
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -205,8 +207,8 @@ impl RoomEdus {
user_ids.push(user_id?); user_ids.push(user_id?);
} }
Ok(ruma_events::typing::TypingEvent { Ok(ruma::events::typing::TypingEvent {
content: ruma_events::typing::TypingEventContent { user_ids }, content: ruma::events::typing::TypingEventContent { user_ids },
room_id: None, // Can be inferred room_id: None, // Can be inferred
}) })
} }

View File

@ -1,11 +1,13 @@
use crate::{utils, Error, Result}; use crate::{utils, Error, Result};
use js_int::UInt; use js_int::UInt;
use ruma_client_api::r0::{ use ruma::{
api::client::r0::{
device::Device, device::Device,
keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey}, keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey},
},
events::{to_device::AnyToDeviceEvent, EventJson, EventType},
identifiers::{DeviceId, UserId},
}; };
use ruma_events::{to_device::AnyToDeviceEvent, EventJson, EventType};
use ruma_identifiers::{DeviceId, UserId};
use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime}; use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime};
pub struct Users { pub struct Users {

View File

@ -22,12 +22,12 @@ pub enum Error {
#[error("tried to parse invalid identifier")] #[error("tried to parse invalid identifier")]
RumaIdentifierError { RumaIdentifierError {
#[from] #[from]
source: ruma_identifiers::Error, source: ruma::identifiers::Error,
}, },
#[error("tried to parse invalid event")] #[error("tried to parse invalid event")]
RumaEventError { RumaEventError {
#[from] #[from]
source: ruma_events::InvalidEvent, source: ruma::events::InvalidEvent,
}, },
#[error("could not generate image")] #[error("could not generate image")]
ImageError { ImageError {

View File

@ -1,11 +1,13 @@
use js_int::UInt; use js_int::UInt;
use ruma_events::{ use ruma::{
api::federation::EventHash,
events::{
collections::all::{RoomEvent, StateEvent}, collections::all::{RoomEvent, StateEvent},
stripped::AnyStrippedStateEvent, stripped::AnyStrippedStateEvent,
EventJson, EventType, EventJson, EventType,
},
identifiers::{EventId, RoomId, UserId},
}; };
use ruma_federation_api::EventHash;
use ruma_identifiers::{EventId, RoomId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -7,8 +7,7 @@ use rocket::{
Outcome::*, Outcome::*,
Request, State, Request, State,
}; };
use ruma_api::Endpoint; use ruma::{api::Endpoint, identifiers::UserId};
use ruma_identifiers::UserId;
use std::{convert::TryInto, io::Cursor, ops::Deref}; use std::{convert::TryInto, io::Cursor, ops::Deref};
use tokio::io::AsyncReadExt; use tokio::io::AsyncReadExt;
@ -109,7 +108,7 @@ impl<T> Deref for Ruma<T> {
} }
/// This struct converts ruma responses into rocket http responses. /// This struct converts ruma responses into rocket http responses.
pub struct MatrixResult<T, E = ruma_client_api::Error>(pub std::result::Result<T, E>); pub struct MatrixResult<T, E = ruma::api::client::Error>(pub std::result::Result<T, E>);
impl<T, E> TryInto<http::Response<Vec<u8>>> for MatrixResult<T, E> impl<T, E> TryInto<http::Response<Vec<u8>>> for MatrixResult<T, E>
where where

View File

@ -2,9 +2,9 @@ use crate::{Database, MatrixResult};
use http::header::{HeaderValue, AUTHORIZATION}; use http::header::{HeaderValue, AUTHORIZATION};
use log::error; use log::error;
use rocket::{get, response::content::Json, State}; use rocket::{get, response::content::Json, State};
use ruma_api::Endpoint; use ruma::api::Endpoint;
use ruma_client_api::error::Error; use ruma::api::client::error::Error;
use ruma_federation_api::discovery::{ use ruma::api::federation::discovery::{
get_server_keys::v2 as get_server_keys, get_server_version::v1 as get_server_version, get_server_keys::v2 as get_server_keys, get_server_version::v1 as get_server_version,
}; };
use serde_json::json; use serde_json::json;
@ -61,7 +61,7 @@ pub async fn send_request<T: Endpoint>(
request_map.insert("destination".to_owned(), destination.into()); request_map.insert("destination".to_owned(), destination.into());
let mut request_json = request_map.into(); let mut request_json = request_map.into();
ruma_signatures::sign_json( ruma::signatures::sign_json(
db.globals.server_name(), db.globals.server_name(),
db.globals.keypair(), db.globals.keypair(),
&mut request_json, &mut request_json,
@ -168,7 +168,7 @@ pub fn get_server_keys(db: State<'_, Database>) -> Json<String> {
.body(), .body(),
) )
.unwrap(); .unwrap();
ruma_signatures::sign_json( ruma::signatures::sign_json(
db.globals.server_name(), db.globals.server_name(),
db.globals.keypair(), db.globals.keypair(),
&mut response, &mut response,

View File

@ -29,7 +29,7 @@ pub fn increment(old: Option<&[u8]>) -> Option<Vec<u8>> {
pub fn generate_keypair(old: Option<&[u8]>) -> Option<Vec<u8>> { pub fn generate_keypair(old: Option<&[u8]>) -> Option<Vec<u8>> {
Some( Some(
old.map(|s| s.to_vec()) old.map(|s| s.to_vec())
.unwrap_or_else(|| ruma_signatures::Ed25519KeyPair::generate().unwrap()), .unwrap_or_else(|| ruma::signatures::Ed25519KeyPair::generate().unwrap()),
) )
} }