finish upgrade ruma

Nyaaori/private-read-receipts
Timo Kösters 2 years ago
parent d39ce1401d
commit f1d2574651
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4

@ -9,7 +9,7 @@ use ruma::{
}, },
}, },
events::{push_rules::PushRulesEvent, GlobalAccountDataEventType}, events::{push_rules::PushRulesEvent, GlobalAccountDataEventType},
push::{ConditionalPushRuleInit, PatternedPushRuleInit, SimplePushRuleInit}, push::{ConditionalPushRuleInit, NewPushRule, PatternedPushRuleInit, SimplePushRuleInit},
}; };
/// # `GET /_matrix/client/r0/pushrules` /// # `GET /_matrix/client/r0/pushrules`
@ -132,66 +132,65 @@ pub async fn set_pushrule_route(
.map_err(|_| Error::bad_database("Invalid account data event in db."))?; .map_err(|_| Error::bad_database("Invalid account data event in db."))?;
let global = &mut account_data.content.global; let global = &mut account_data.content.global;
match body.kind { match body.rule {
RuleKind::Override => { NewPushRule::Override(rule) => {
global.override_.replace( global.override_.replace(
ConditionalPushRuleInit { ConditionalPushRuleInit {
actions: body.actions, actions: rule.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id, rule_id: rule.rule_id,
conditions: body.conditions, conditions: rule.conditions,
} }
.into(), .into(),
); );
} }
RuleKind::Underride => { NewPushRule::Underride(rule) => {
global.underride.replace( global.underride.replace(
ConditionalPushRuleInit { ConditionalPushRuleInit {
actions: body.actions, actions: rule.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id, rule_id: rule.rule_id,
conditions: body.conditions, conditions: rule.conditions,
} }
.into(), .into(),
); );
} }
RuleKind::Sender => { NewPushRule::Sender(rule) => {
global.sender.replace( global.sender.replace(
SimplePushRuleInit { SimplePushRuleInit {
actions: body.actions, actions: rule.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id, rule_id: rule.rule_id,
} }
.into(), .into(),
); );
} }
RuleKind::Room => { NewPushRule::Room(rule) => {
global.room.replace( global.room.replace(
SimplePushRuleInit { SimplePushRuleInit {
actions: body.actions, actions: rule.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id, rule_id: rule.rule_id,
} }
.into(), .into(),
); );
} }
RuleKind::Content => { NewPushRule::Content(rule) => {
global.content.replace( global.content.replace(
PatternedPushRuleInit { PatternedPushRuleInit {
actions: body.actions, actions: rule.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id, rule_id: rule.rule_id,
pattern: body.pattern.unwrap_or_default(), pattern: rule.pattern,
} }
.into(), .into(),
); );
} }
_ => {}
} }
services().account_data.update( services().account_data.update(
@ -212,7 +211,7 @@ pub async fn get_pushrule_actions_route(
) -> Result<get_pushrule_actions::v3::Response> { ) -> Result<get_pushrule_actions::v3::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");
if body.scope != "global" { if body.scope != RuleScope::Global {
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Scopes other than 'global' are not supported.", "Scopes other than 'global' are not supported.",

@ -29,7 +29,7 @@ use http::{
use opentelemetry::trace::{FutureExt, Tracer}; use opentelemetry::trace::{FutureExt, Tracer};
use ruma::api::{ use ruma::api::{
client::{ client::{
error::{Error as RumaError, ErrorKind}, error::{Error as RumaError, ErrorBody, ErrorKind},
uiaa::UiaaResponse, uiaa::UiaaResponse,
}, },
IncomingRequest, IncomingRequest,
@ -223,8 +223,10 @@ async fn unrecognized_method<B>(
if inner.status() == axum::http::StatusCode::METHOD_NOT_ALLOWED { if inner.status() == axum::http::StatusCode::METHOD_NOT_ALLOWED {
warn!("Method not allowed: {method} {uri}"); warn!("Method not allowed: {method} {uri}");
return Ok(RumaResponse(UiaaResponse::MatrixError(RumaError { return Ok(RumaResponse(UiaaResponse::MatrixError(RumaError {
kind: ErrorKind::Unrecognized, body: ErrorBody::Standard {
message: "M_UNRECOGNIZED: Unrecognized request".to_owned(), kind: ErrorKind::Unrecognized,
message: "M_UNRECOGNIZED: Unrecognized request".to_owned(),
},
status_code: StatusCode::METHOD_NOT_ALLOWED, status_code: StatusCode::METHOD_NOT_ALLOWED,
})) }))
.into_response()); .into_response());

@ -239,12 +239,12 @@ impl Service {
device.tweaks = tweaks.clone(); device.tweaks = tweaks.clone();
} }
let d = &[device]; let d = vec![device];
let mut notifi = Notification::new(d); let mut notifi = Notification::new(d);
notifi.prio = NotificationPriority::Low; notifi.prio = NotificationPriority::Low;
notifi.event_id = Some(&event.event_id); notifi.event_id = Some((*event.event_id).to_owned());
notifi.room_id = Some(&event.room_id); notifi.room_id = Some((*event.room_id).to_owned());
// TODO: missed calls // TODO: missed calls
notifi.counts = NotificationCounts::new(unread, uint!(0)); notifi.counts = NotificationCounts::new(unread, uint!(0));
@ -260,18 +260,16 @@ impl Service {
self.send_request(&http.url, send_event_notification::v1::Request::new(notifi)) self.send_request(&http.url, send_event_notification::v1::Request::new(notifi))
.await?; .await?;
} else { } else {
notifi.sender = Some(&event.sender); notifi.sender = Some(event.sender.clone());
notifi.event_type = Some(&event.kind); notifi.event_type = Some(event.kind.clone());
let content = serde_json::value::to_raw_value(&event.content).ok(); notifi.content = serde_json::value::to_raw_value(&event.content).ok();
notifi.content = content.as_deref();
if event.kind == RoomEventType::RoomMember { if event.kind == RoomEventType::RoomMember {
notifi.user_is_target = notifi.user_is_target =
event.state_key.as_deref() == Some(event.sender.as_str()); event.state_key.as_deref() == Some(event.sender.as_str());
} }
let user_name = services().users.displayname(&event.sender)?; notifi.sender_display_name = services().users.displayname(&event.sender)?;
notifi.sender_display_name = user_name.as_deref();
let room_name = if let Some(room_name_pdu) = services() let room_name = if let Some(room_name_pdu) = services()
.rooms .rooms
@ -287,7 +285,7 @@ impl Service {
None None
}; };
notifi.room_name = room_name.as_deref(); notifi.room_name = room_name;
self.send_request(&http.url, send_event_notification::v1::Request::new(notifi)) self.send_request(&http.url, send_event_notification::v1::Request::new(notifi))
.await?; .await?;

@ -1113,7 +1113,7 @@ impl Service {
.send_federation_request( .send_federation_request(
origin, origin,
get_event::v1::Request { get_event::v1::Request {
event_id: next_id.into(), event_id: (*next_id).to_owned(),
}, },
) )
.await .await

@ -164,7 +164,7 @@ impl Service {
.content .content
.ignored_users .ignored_users
.iter() .iter()
.any(|user| user == sender) .any(|(user, _details)| user == sender)
}); });
if is_ignored { if is_ignored {

@ -102,7 +102,10 @@ impl Error {
if let Self::FederationError(origin, error) = self { if let Self::FederationError(origin, error) = self {
let mut error = error.clone(); let mut error = error.clone();
error.message = format!("Answer from {}: {}", origin, error.message); error.body = ErrorBody::Standard {
kind: Unknown,
message: format!("Answer from {}: {}", origin, error),
};
return RumaResponse(UiaaResponse::MatrixError(error)); return RumaResponse(UiaaResponse::MatrixError(error));
} }

Loading…
Cancel
Save