improvement: update ruma
This commit is contained in:
parent
1f84013b2a
commit
6e84d317b2
8 changed files with 106 additions and 125 deletions
|
@ -5,7 +5,7 @@ use ruma::{
|
|||
error::ErrorKind,
|
||||
r0::message::{get_message_events, send_message_event},
|
||||
},
|
||||
events::EventContent,
|
||||
events::EventType,
|
||||
EventId,
|
||||
};
|
||||
use std::{
|
||||
|
@ -55,7 +55,7 @@ pub async fn send_message_event_route(
|
|||
|
||||
let event_id = db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: body.content.event_type().into(),
|
||||
event_type: EventType::from(&body.event_type),
|
||||
content: serde_json::from_str(
|
||||
body.json_body
|
||||
.as_ref()
|
||||
|
|
|
@ -26,7 +26,12 @@ use rocket::{get, post};
|
|||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/login"))]
|
||||
#[tracing::instrument]
|
||||
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`
|
||||
|
|
|
@ -6,9 +6,13 @@ use ruma::{
|
|||
r0::state::{get_state_events, get_state_events_for_key, send_state_event},
|
||||
},
|
||||
events::{
|
||||
room::history_visibility::{HistoryVisibility, HistoryVisibilityEventContent},
|
||||
AnyStateEventContent, EventContent, EventType,
|
||||
room::{
|
||||
canonical_alias::CanonicalAliasEventContent,
|
||||
history_visibility::{HistoryVisibility, HistoryVisibilityEventContent},
|
||||
},
|
||||
AnyStateEventContent, EventType,
|
||||
},
|
||||
serde::Raw,
|
||||
EventId, RoomId, UserId,
|
||||
};
|
||||
|
||||
|
@ -26,21 +30,13 @@ pub async fn send_state_event_for_key_route(
|
|||
) -> ConduitResult<send_state_event::Response> {
|
||||
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(
|
||||
&db,
|
||||
sender_user,
|
||||
&body.content,
|
||||
content,
|
||||
&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?;
|
||||
|
||||
|
@ -58,31 +54,15 @@ pub async fn send_state_event_for_empty_key_route(
|
|||
db: State<'_, Database>,
|
||||
body: Ruma<send_state_event::Request<'_>>,
|
||||
) -> ConduitResult<send_state_event::Response> {
|
||||
// This just calls send_state_event_for_key_route
|
||||
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 sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
let event_id = send_state_event_for_key_helper(
|
||||
&db,
|
||||
sender_user
|
||||
.as_ref()
|
||||
.expect("no user for send state empty key route"),
|
||||
&body.content,
|
||||
json,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
Some("".into()),
|
||||
EventType::from(&body.event_type),
|
||||
&body.body.body,
|
||||
body.state_key.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -183,7 +163,7 @@ pub async fn get_state_events_for_key_route(
|
|||
))?;
|
||||
|
||||
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"))?,
|
||||
}
|
||||
.into())
|
||||
|
@ -234,7 +214,7 @@ pub async fn get_state_events_for_empty_key_route(
|
|||
))?;
|
||||
|
||||
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"))?,
|
||||
}
|
||||
.into())
|
||||
|
@ -243,17 +223,19 @@ pub async fn get_state_events_for_empty_key_route(
|
|||
pub async fn send_state_event_for_key_helper(
|
||||
db: &Database,
|
||||
sender: &UserId,
|
||||
content: &AnyStateEventContent,
|
||||
json: serde_json::Value,
|
||||
room_id: &RoomId,
|
||||
state_key: Option<String>,
|
||||
event_type: EventType,
|
||||
json: &Raw<AnyStateEventContent>,
|
||||
state_key: String,
|
||||
) -> Result<EventId> {
|
||||
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();
|
||||
|
||||
if let Some(alias) = canonical_alias.alias.clone() {
|
||||
if let Some(alias) = canonical_alias.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(
|
||||
PduBuilder {
|
||||
event_type: content.event_type().into(),
|
||||
content: json,
|
||||
event_type,
|
||||
content: serde_json::from_str(json.json().get()).expect("content is valid json"),
|
||||
unsigned: None,
|
||||
state_key,
|
||||
state_key: Some(state_key),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{Database, Error, PduEvent, Result};
|
|||
use log::{error, info, warn};
|
||||
use ruma::{
|
||||
api::{
|
||||
client::r0::push::{Pusher, PusherKind},
|
||||
client::r0::push::{get_pushers, set_pusher, PusherKind},
|
||||
push_gateway::send_event_notification::{
|
||||
self,
|
||||
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();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(pusher.pushkey.as_bytes());
|
||||
|
@ -52,7 +52,7 @@ impl PushData {
|
|||
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
|
||||
.get(senderkey)?
|
||||
.map(|push| {
|
||||
|
@ -62,7 +62,7 @@ impl PushData {
|
|||
.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();
|
||||
prefix.push(0xff);
|
||||
|
||||
|
@ -164,7 +164,7 @@ where
|
|||
pub async fn send_push_notice(
|
||||
user: &UserId,
|
||||
unread: UInt,
|
||||
pusher: &Pusher,
|
||||
pusher: &get_pushers::Pusher,
|
||||
ruleset: Ruleset,
|
||||
pdu: &PduEvent,
|
||||
db: &Database,
|
||||
|
@ -205,7 +205,7 @@ pub fn get_actions<'a>(
|
|||
ruleset: &'a Ruleset,
|
||||
pdu: &PduEvent,
|
||||
db: &Database,
|
||||
) -> Result<impl 'a + Iterator<Item = Action>> {
|
||||
) -> Result<&'a [Action]> {
|
||||
let power_levels: PowerLevelsEventContent = db
|
||||
.rooms
|
||||
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
|
||||
|
@ -228,20 +228,18 @@ pub fn get_actions<'a>(
|
|||
notification_power_levels: power_levels.notifications,
|
||||
};
|
||||
|
||||
Ok(ruleset
|
||||
.get_actions(&pdu.to_sync_room_event(), &ctx)
|
||||
.map(Clone::clone))
|
||||
Ok(ruleset.get_actions(&pdu.to_sync_room_event(), &ctx))
|
||||
}
|
||||
|
||||
async fn send_notice(
|
||||
unread: UInt,
|
||||
pusher: &Pusher,
|
||||
pusher: &get_pushers::Pusher,
|
||||
tweaks: Vec<Tweak>,
|
||||
event: &PduEvent,
|
||||
db: &Database,
|
||||
) -> Result<()> {
|
||||
// TODO: email
|
||||
if pusher.kind == Some(PusherKind::Email) {
|
||||
if pusher.kind == PusherKind::Email {
|
||||
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
|
||||
// 2. can pusher/devices have conflicting formats
|
||||
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
|
||||
} else {
|
||||
error!("Http Pusher must have URL specified.");
|
||||
|
|
|
@ -4,7 +4,6 @@ use ruma::{
|
|||
identifiers::{DeviceId, UserId},
|
||||
Outgoing,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
|
@ -27,6 +26,7 @@ use {
|
|||
signatures::CanonicalJsonValue,
|
||||
ServerName,
|
||||
},
|
||||
std::collections::BTreeMap,
|
||||
std::convert::TryFrom,
|
||||
std::io::Cursor,
|
||||
};
|
||||
|
@ -265,7 +265,10 @@ where
|
|||
match ruma::signatures::verify_json(&pub_key_map, &request_map) {
|
||||
Ok(()) => (None, None, false),
|
||||
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
|
||||
return Failure((Status::raw(580), ()));
|
||||
|
|
|
@ -21,7 +21,7 @@ use ruma::{
|
|||
create_join_event_template,
|
||||
},
|
||||
query::{get_profile_information, get_room_information},
|
||||
transactions::send_transaction_message,
|
||||
transactions::{edu::Edu, send_transaction_message},
|
||||
},
|
||||
IncomingResponse, OutgoingRequest, OutgoingResponse,
|
||||
},
|
||||
|
@ -585,39 +585,32 @@ pub async fn send_transaction_message_route<'a>(
|
|||
return Err(Error::bad_config("Federation is disabled."));
|
||||
}
|
||||
|
||||
for edu in &body.edus {
|
||||
match serde_json::from_str::<send_transaction_message::v1::Edu>(edu.json().get()) {
|
||||
Ok(edu) => match edu.edu_type.as_str() {
|
||||
"m.typing" => {
|
||||
if let Some(typing) = edu.content.get("typing") {
|
||||
if typing.as_bool().unwrap_or_default() {
|
||||
db.rooms.edus.typing_add(
|
||||
&UserId::try_from(edu.content["user_id"].as_str().unwrap())
|
||||
.unwrap(),
|
||||
&RoomId::try_from(edu.content["room_id"].as_str().unwrap())
|
||||
.unwrap(),
|
||||
3000 + utils::millis_since_unix_epoch(),
|
||||
&db.globals,
|
||||
)?;
|
||||
} else {
|
||||
db.rooms.edus.typing_remove(
|
||||
&UserId::try_from(edu.content["user_id"].as_str().unwrap())
|
||||
.unwrap(),
|
||||
&RoomId::try_from(edu.content["room_id"].as_str().unwrap())
|
||||
.unwrap(),
|
||||
&db.globals,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
for edu in body
|
||||
.edus
|
||||
.iter()
|
||||
.map(|edu| serde_json::from_str::<Edu>(edu.json().get()))
|
||||
.filter_map(|r| r.ok())
|
||||
{
|
||||
match edu {
|
||||
Edu::Presence(_) => {}
|
||||
Edu::Receipt(_) => {}
|
||||
Edu::Typing(typing) => {
|
||||
if typing.typing {
|
||||
db.rooms.edus.typing_add(
|
||||
&typing.user_id,
|
||||
&typing.room_id,
|
||||
3000 + utils::millis_since_unix_epoch(),
|
||||
&db.globals,
|
||||
)?;
|
||||
} else {
|
||||
db.rooms
|
||||
.edus
|
||||
.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(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue