improvement: update ruma

next
Timo Kösters 2021-04-22 11:26:20 +02:00
parent 1f84013b2a
commit 6e84d317b2
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
8 changed files with 106 additions and 125 deletions

60
Cargo.lock generated
View File

@ -1545,8 +1545,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.0.2" version = "0.0.3"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -1565,8 +1565,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.17.0-alpha.2" version = "0.17.0-alpha.4"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"http", "http",
"percent-encoding", "percent-encoding",
@ -1580,8 +1580,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.17.0-alpha.2" version = "0.17.0-alpha.4"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1591,8 +1591,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.2.0-alpha.2" version = "0.2.0-alpha.3"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1605,8 +1605,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.10.0-alpha.2" version = "0.10.0-alpha.3"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"assign", "assign",
"http", "http",
@ -1624,8 +1624,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.4.0" version = "0.5.0"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"js_int", "js_int",
@ -1640,8 +1640,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.22.0-alpha.2" version = "0.22.0-alpha.3"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -1654,8 +1654,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.22.0-alpha.2" version = "0.22.0-alpha.3"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1665,8 +1665,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.1.0-alpha.1" version = "0.1.0-alpha.2"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1681,7 +1681,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.19.0" version = "0.19.0"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"paste", "paste",
"rand", "rand",
@ -1695,7 +1695,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.19.0" version = "0.19.0"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1705,13 +1705,13 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.2.3" version = "0.3.0"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.0.1" version = "0.1.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1723,8 +1723,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.0.1" version = "0.1.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1739,7 +1739,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.3.1" version = "0.3.1"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"itoa", "itoa",
@ -1752,7 +1752,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde-macros" name = "ruma-serde-macros"
version = "0.3.1" version = "0.3.1"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1763,7 +1763,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/ruma/ruma?rev=c1693569f15920e408aa6a26b7f3cc7fc6693a63#c1693569f15920e408aa6a26b7f3cc7fc6693a63" source = "git+https://github.com/ruma/ruma?rev=4f16b9357c15d649075393a723f23cf560251754#4f16b9357c15d649075393a723f23cf560251754"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"ring", "ring",
@ -2053,7 +2053,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?rev=4516d73e8c7495330619bfb5b42c3bbf704293d8#4516d73e8c7495330619bfb5b42c3bbf704293d8" source = "git+https://github.com/ruma/state-res?rev=aa53d07f51ffb7258f5c1e499bddffd4c630f7df#aa53d07f51ffb7258f5c1e499bddffd4c630f7df"
dependencies = [ dependencies = [
"itertools 0.10.0", "itertools 0.10.0",
"log", "log",

View File

@ -18,12 +18,12 @@ rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "93e62c86e
#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", rev = "c1693569f15920e408aa6a26b7f3cc7fc6693a63", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } ruma = { git = "https://github.com/ruma/ruma", rev = "4f16b9357c15d649075393a723f23cf560251754", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { git = "https://github.com/timokoesters/ruma", rev = "220d5b4a76b3b781f7f8297fbe6b14473b04214b", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "220d5b4a76b3b781f7f8297fbe6b14473b04214b", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { path = "../ruma/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] }
# Used when doing state resolution # Used when doing state resolution
state-res = { git = "https://github.com/ruma/state-res", rev = "4516d73e8c7495330619bfb5b42c3bbf704293d8", features = ["unstable-pre-spec"] } state-res = { git = "https://github.com/ruma/state-res", rev = "aa53d07f51ffb7258f5c1e499bddffd4c630f7df", features = ["unstable-pre-spec"] }
#state-res = { path = "../state-res", features = ["unstable-pre-spec"] } #state-res = { path = "../state-res", features = ["unstable-pre-spec"] }
# Used for long polling and federation sender, should be the same as rocket::tokio # Used for long polling and federation sender, should be the same as rocket::tokio

View File

@ -5,7 +5,7 @@ use ruma::{
error::ErrorKind, error::ErrorKind,
r0::message::{get_message_events, send_message_event}, r0::message::{get_message_events, send_message_event},
}, },
events::EventContent, events::EventType,
EventId, EventId,
}; };
use std::{ use std::{
@ -55,7 +55,7 @@ pub async fn send_message_event_route(
let event_id = db.rooms.build_and_append_pdu( let event_id = db.rooms.build_and_append_pdu(
PduBuilder { PduBuilder {
event_type: body.content.event_type().into(), event_type: EventType::from(&body.event_type),
content: serde_json::from_str( content: serde_json::from_str(
body.json_body body.json_body
.as_ref() .as_ref()

View File

@ -26,7 +26,12 @@ use rocket::{get, post};
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/login"))] #[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/login"))]
#[tracing::instrument] #[tracing::instrument]
pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response> { pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response> {
Ok(get_login_types::Response::new(vec![get_login_types::LoginType::Password]).into()) Ok(
get_login_types::Response::new(vec![get_login_types::LoginType::Password(
Default::default(),
)])
.into(),
)
} }
/// # `POST /_matrix/client/r0/login` /// # `POST /_matrix/client/r0/login`

View File

@ -6,9 +6,13 @@ use ruma::{
r0::state::{get_state_events, get_state_events_for_key, send_state_event}, r0::state::{get_state_events, get_state_events_for_key, send_state_event},
}, },
events::{ events::{
room::history_visibility::{HistoryVisibility, HistoryVisibilityEventContent}, room::{
AnyStateEventContent, EventContent, EventType, canonical_alias::CanonicalAliasEventContent,
history_visibility::{HistoryVisibility, HistoryVisibilityEventContent},
},
AnyStateEventContent, EventType,
}, },
serde::Raw,
EventId, RoomId, UserId, EventId, RoomId, UserId,
}; };
@ -26,21 +30,13 @@ pub async fn send_state_event_for_key_route(
) -> ConduitResult<send_state_event::Response> { ) -> ConduitResult<send_state_event::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let content = serde_json::from_str::<serde_json::Value>(
body.json_body
.as_ref()
.ok_or(Error::BadRequest(ErrorKind::BadJson, "Invalid JSON body."))?
.get(),
)
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid JSON body."))?;
let event_id = send_state_event_for_key_helper( let event_id = send_state_event_for_key_helper(
&db, &db,
sender_user, sender_user,
&body.content,
content,
&body.room_id, &body.room_id,
Some(body.state_key.to_owned()), EventType::from(&body.event_type),
&body.body.body, // Yes, I hate it too
body.state_key.to_owned(),
) )
.await?; .await?;
@ -58,31 +54,15 @@ pub async fn send_state_event_for_empty_key_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<send_state_event::Request<'_>>, body: Ruma<send_state_event::Request<'_>>,
) -> ConduitResult<send_state_event::Response> { ) -> ConduitResult<send_state_event::Response> {
// This just calls send_state_event_for_key_route let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let Ruma {
body,
sender_user,
json_body,
..
} = body;
let json = serde_json::from_str::<serde_json::Value>(
json_body
.as_ref()
.ok_or(Error::BadRequest(ErrorKind::BadJson, "Invalid JSON body."))?
.get(),
)
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid JSON body."))?;
let event_id = send_state_event_for_key_helper( let event_id = send_state_event_for_key_helper(
&db, &db,
sender_user sender_user,
.as_ref()
.expect("no user for send state empty key route"),
&body.content,
json,
&body.room_id, &body.room_id,
Some("".into()), EventType::from(&body.event_type),
&body.body.body,
body.state_key.to_owned(),
) )
.await?; .await?;
@ -183,7 +163,7 @@ pub async fn get_state_events_for_key_route(
))?; ))?;
Ok(get_state_events_for_key::Response { Ok(get_state_events_for_key::Response {
content: serde_json::value::to_raw_value(&event.content) content: serde_json::from_value(event.content)
.map_err(|_| Error::bad_database("Invalid event content in database"))?, .map_err(|_| Error::bad_database("Invalid event content in database"))?,
} }
.into()) .into())
@ -234,7 +214,7 @@ pub async fn get_state_events_for_empty_key_route(
))?; ))?;
Ok(get_state_events_for_key::Response { Ok(get_state_events_for_key::Response {
content: serde_json::value::to_raw_value(&event.content) content: serde_json::from_value(event.content)
.map_err(|_| Error::bad_database("Invalid event content in database"))?, .map_err(|_| Error::bad_database("Invalid event content in database"))?,
} }
.into()) .into())
@ -243,17 +223,19 @@ pub async fn get_state_events_for_empty_key_route(
pub async fn send_state_event_for_key_helper( pub async fn send_state_event_for_key_helper(
db: &Database, db: &Database,
sender: &UserId, sender: &UserId,
content: &AnyStateEventContent,
json: serde_json::Value,
room_id: &RoomId, room_id: &RoomId,
state_key: Option<String>, event_type: EventType,
json: &Raw<AnyStateEventContent>,
state_key: String,
) -> Result<EventId> { ) -> Result<EventId> {
let sender_user = sender; let sender_user = sender;
if let AnyStateEventContent::RoomCanonicalAlias(canonical_alias) = content { if let Ok(canonical_alias) =
serde_json::from_str::<CanonicalAliasEventContent>(json.json().get())
{
let mut aliases = canonical_alias.alt_aliases.clone(); let mut aliases = canonical_alias.alt_aliases.clone();
if let Some(alias) = canonical_alias.alias.clone() { if let Some(alias) = canonical_alias.alias {
aliases.push(alias); aliases.push(alias);
} }
@ -276,10 +258,10 @@ pub async fn send_state_event_for_key_helper(
let event_id = db.rooms.build_and_append_pdu( let event_id = db.rooms.build_and_append_pdu(
PduBuilder { PduBuilder {
event_type: content.event_type().into(), event_type,
content: json, content: serde_json::from_str(json.json().get()).expect("content is valid json"),
unsigned: None, unsigned: None,
state_key, state_key: Some(state_key),
redacts: None, redacts: None,
}, },
&sender_user, &sender_user,

View File

@ -2,7 +2,7 @@ use crate::{Database, Error, PduEvent, Result};
use log::{error, info, warn}; use log::{error, info, warn};
use ruma::{ use ruma::{
api::{ api::{
client::r0::push::{Pusher, PusherKind}, client::r0::push::{get_pushers, set_pusher, PusherKind},
push_gateway::send_event_notification::{ push_gateway::send_event_notification::{
self, self,
v1::{Device, Notification, NotificationCounts, NotificationPriority}, v1::{Device, Notification, NotificationCounts, NotificationPriority},
@ -30,7 +30,7 @@ impl PushData {
}) })
} }
pub fn set_pusher(&self, sender: &UserId, pusher: Pusher) -> Result<()> { pub fn set_pusher(&self, sender: &UserId, pusher: set_pusher::Pusher) -> Result<()> {
let mut key = sender.as_bytes().to_vec(); let mut key = sender.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(pusher.pushkey.as_bytes()); key.extend_from_slice(pusher.pushkey.as_bytes());
@ -52,7 +52,7 @@ impl PushData {
Ok(()) Ok(())
} }
pub fn get_pusher(&self, senderkey: &[u8]) -> Result<Option<Pusher>> { pub fn get_pusher(&self, senderkey: &[u8]) -> Result<Option<get_pushers::Pusher>> {
self.senderkey_pusher self.senderkey_pusher
.get(senderkey)? .get(senderkey)?
.map(|push| { .map(|push| {
@ -62,7 +62,7 @@ impl PushData {
.transpose() .transpose()
} }
pub fn get_pushers(&self, sender: &UserId) -> Result<Vec<Pusher>> { pub fn get_pushers(&self, sender: &UserId) -> Result<Vec<get_pushers::Pusher>> {
let mut prefix = sender.as_bytes().to_vec(); let mut prefix = sender.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
@ -164,7 +164,7 @@ where
pub async fn send_push_notice( pub async fn send_push_notice(
user: &UserId, user: &UserId,
unread: UInt, unread: UInt,
pusher: &Pusher, pusher: &get_pushers::Pusher,
ruleset: Ruleset, ruleset: Ruleset,
pdu: &PduEvent, pdu: &PduEvent,
db: &Database, db: &Database,
@ -205,7 +205,7 @@ pub fn get_actions<'a>(
ruleset: &'a Ruleset, ruleset: &'a Ruleset,
pdu: &PduEvent, pdu: &PduEvent,
db: &Database, db: &Database,
) -> Result<impl 'a + Iterator<Item = Action>> { ) -> Result<&'a [Action]> {
let power_levels: PowerLevelsEventContent = db let power_levels: PowerLevelsEventContent = db
.rooms .rooms
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")? .room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
@ -228,20 +228,18 @@ pub fn get_actions<'a>(
notification_power_levels: power_levels.notifications, notification_power_levels: power_levels.notifications,
}; };
Ok(ruleset Ok(ruleset.get_actions(&pdu.to_sync_room_event(), &ctx))
.get_actions(&pdu.to_sync_room_event(), &ctx)
.map(Clone::clone))
} }
async fn send_notice( async fn send_notice(
unread: UInt, unread: UInt,
pusher: &Pusher, pusher: &get_pushers::Pusher,
tweaks: Vec<Tweak>, tweaks: Vec<Tweak>,
event: &PduEvent, event: &PduEvent,
db: &Database, db: &Database,
) -> Result<()> { ) -> Result<()> {
// TODO: email // TODO: email
if pusher.kind == Some(PusherKind::Email) { if pusher.kind == PusherKind::Email {
return Ok(()); return Ok(());
} }
@ -250,7 +248,7 @@ async fn send_notice(
// 1. if "event_id_only" is the only format kind it seems we should never add more info // 1. if "event_id_only" is the only format kind it seems we should never add more info
// 2. can pusher/devices have conflicting formats // 2. can pusher/devices have conflicting formats
let event_id_only = pusher.data.format == Some(PushFormat::EventIdOnly); let event_id_only = pusher.data.format == Some(PushFormat::EventIdOnly);
let url = if let Some(url) = pusher.data.url.as_ref() { let url = if let Some(url) = &pusher.data.url {
url url
} else { } else {
error!("Http Pusher must have URL specified."); error!("Http Pusher must have URL specified.");

View File

@ -4,7 +4,6 @@ use ruma::{
identifiers::{DeviceId, UserId}, identifiers::{DeviceId, UserId},
Outgoing, Outgoing,
}; };
use std::collections::BTreeMap;
use std::ops::Deref; use std::ops::Deref;
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]
@ -27,6 +26,7 @@ use {
signatures::CanonicalJsonValue, signatures::CanonicalJsonValue,
ServerName, ServerName,
}, },
std::collections::BTreeMap,
std::convert::TryFrom, std::convert::TryFrom,
std::io::Cursor, std::io::Cursor,
}; };
@ -265,7 +265,10 @@ where
match ruma::signatures::verify_json(&pub_key_map, &request_map) { match ruma::signatures::verify_json(&pub_key_map, &request_map) {
Ok(()) => (None, None, false), Ok(()) => (None, None, false),
Err(e) => { Err(e) => {
warn!("Failed to verify json request: {}: {:?} {:?}", e, pub_key_map, request_map); warn!(
"Failed to verify json request: {}: {:?} {:?}",
e, pub_key_map, request_map
);
// Forbidden // Forbidden
return Failure((Status::raw(580), ())); return Failure((Status::raw(580), ()));

View File

@ -21,7 +21,7 @@ use ruma::{
create_join_event_template, create_join_event_template,
}, },
query::{get_profile_information, get_room_information}, query::{get_profile_information, get_room_information},
transactions::send_transaction_message, transactions::{edu::Edu, send_transaction_message},
}, },
IncomingResponse, OutgoingRequest, OutgoingResponse, IncomingResponse, OutgoingRequest, OutgoingResponse,
}, },
@ -585,39 +585,32 @@ pub async fn send_transaction_message_route<'a>(
return Err(Error::bad_config("Federation is disabled.")); return Err(Error::bad_config("Federation is disabled."));
} }
for edu in &body.edus { for edu in body
match serde_json::from_str::<send_transaction_message::v1::Edu>(edu.json().get()) { .edus
Ok(edu) => match edu.edu_type.as_str() { .iter()
"m.typing" => { .map(|edu| serde_json::from_str::<Edu>(edu.json().get()))
if let Some(typing) = edu.content.get("typing") { .filter_map(|r| r.ok())
if typing.as_bool().unwrap_or_default() { {
db.rooms.edus.typing_add( match edu {
&UserId::try_from(edu.content["user_id"].as_str().unwrap()) Edu::Presence(_) => {}
.unwrap(), Edu::Receipt(_) => {}
&RoomId::try_from(edu.content["room_id"].as_str().unwrap()) Edu::Typing(typing) => {
.unwrap(), if typing.typing {
3000 + utils::millis_since_unix_epoch(), db.rooms.edus.typing_add(
&db.globals, &typing.user_id,
)?; &typing.room_id,
} else { 3000 + utils::millis_since_unix_epoch(),
db.rooms.edus.typing_remove( &db.globals,
&UserId::try_from(edu.content["user_id"].as_str().unwrap()) )?;
.unwrap(), } else {
&RoomId::try_from(edu.content["room_id"].as_str().unwrap()) db.rooms
.unwrap(), .edus
&db.globals, .typing_remove(&typing.user_id, &typing.room_id, &db.globals)?;
)?;
}
}
} }
"m.presence" => {}
"m.receipt" => {}
"m.device_list_update" => {}
_ => {}
},
Err(_err) => {
continue;
} }
Edu::DeviceListUpdate(_) => {}
Edu::DirectToDevice(_) => {}
Edu::_Custom(_) => {}
} }
} }