From b519bc696257d082c7e84b95a31ce03063d13261 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sun, 31 May 2020 19:40:01 +0200 Subject: [PATCH 1/2] fix: only show notifications for messages --- src/client_server.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client_server.rs b/src/client_server.rs index 150555c7..3635bf3f 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -2003,7 +2003,14 @@ pub fn sync_route( let notification_count = if let Some(last_read) = db.rooms.edus.room_read_get(&room_id, &user_id).unwrap() { - Some((db.rooms.pdus_since(&room_id, last_read).unwrap().count() as u32).into()) + Some( + (db.rooms + .pdus_since(&room_id, last_read) + .unwrap() + .filter(|pdu| matches!(pdu.as_ref().unwrap().kind.clone(), EventType::RoomMessage | EventType::RoomEncrypted)) + .count() as u32) + .into(), + ) } else { None }; @@ -2079,7 +2086,7 @@ pub fn sync_route( }, }, unread_notifications: sync_events::UnreadNotificationsCount { - highlight_count: notification_count, + highlight_count: None, notification_count, }, timeline: sync_events::Timeline { From 5a47c754273e3d7c7c7a984d9966a88f9f8196ac Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 1 Jun 2020 20:58:49 +0200 Subject: [PATCH 2/2] fix: make redactions permanent --- src/client_server.rs | 4 ++-- src/database/rooms.rs | 25 ++++++++++++++++++++----- src/pdu.rs | 6 ++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/client_server.rs b/src/client_server.rs index 3635bf3f..e56a7c54 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -2260,12 +2260,12 @@ pub fn get_message_events_route( .map(|pdu| pdu.to_room_event()) .collect::>(); - MatrixResult(Ok(dbg!(get_message_events::Response { + MatrixResult(Ok(get_message_events::Response { start: Some(body.from.clone()), end: prev_batch, chunk: room_events, state: Vec::new(), - }))) + })) } else { MatrixResult(Err(Error { kind: ErrorKind::Unknown, diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 1c25c259..5b9f1e2c 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -8,6 +8,7 @@ use ruma_events::{ room::{ join_rules, member, power_levels::{self, PowerLevelsEventContent}, + redaction, }, EventJson, EventType, }; @@ -207,7 +208,6 @@ impl Rooms { globals: &super::globals::Globals, ) -> Result { // TODO: Make sure this isn't called twice in parallel - let prev_events = self.get_pdu_leaves(&room_id)?; // Is the event authorized? @@ -404,7 +404,6 @@ impl Rooms { authorized } EventType::RoomCreate => prev_events.is_empty(), - // Not allow any of the following events if the sender is not joined. _ if sender_membership != member::MembershipState::Join => false, @@ -450,15 +449,15 @@ impl Rooms { origin_server_ts: utils::millis_since_unix_epoch() .try_into() .expect("this only fails many years in the future"), - kind: event_type, - content, + kind: event_type.clone(), + content: content.clone(), state_key, prev_events, depth: depth .try_into() .expect("depth can overflow and should be deprecated..."), auth_events: Vec::new(), - redacts, + redacts: redacts.clone(), unsigned, hashes: ruma_federation_api::EventHash { sha256: "aaa".to_owned(), @@ -506,6 +505,22 @@ impl Rooms { self.roomstateid_pdu.insert(key, &*pdu_json.to_string())?; } + match event_type { + EventType::RoomRedaction => { + if let Some(redact_id) = &redacts { + // TODO: Reason + let _reason = serde_json::from_value::< + EventJson, + >(content)? + .deserialize()? + .reason; + + self.redact_pdu(&redact_id)?; + } + } + _ => {} + } + self.edus.room_read_set(&room_id, &sender, index)?; Ok(pdu.event_id) diff --git a/src/pdu.rs b/src/pdu.rs index 3e1ac0ac..12496425 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -7,6 +7,7 @@ use ruma_events::{ use ruma_federation_api::EventHash; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; +use serde_json::json; use std::collections::HashMap; #[derive(Deserialize, Serialize)] @@ -62,6 +63,11 @@ impl PduEvent { } } + self.unsigned.insert( + "redacted_because".to_owned(), + json!({"content": {}, "type": "m.room.redaction"}), + ); + self.content = new_content.into(); }