From 47abe6686ebfb83331dfdabd871d8920b35afaaa Mon Sep 17 00:00:00 2001 From: Guillem Nieto Date: Sun, 2 Aug 2020 09:24:47 +0200 Subject: [PATCH 1/2] Send invites only if invited during the sync request Fixes: https://git.koesters.xyz/timo/conduit/issues/175 --- src/client_server/sync.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs index 71e3422..0f683c8 100644 --- a/src/client_server/sync.rs +++ b/src/client_server/sync.rs @@ -391,6 +391,31 @@ pub async fn sync_events_route( let mut invited_rooms = BTreeMap::new(); for room_id in db.rooms.rooms_invited(&sender_id) { let room_id = room_id?; + let mut invited_since_last_sync = false; + for pdu in db + .rooms + .pdus_since(&sender_id, &room_id, since)? + .filter_map(|r| r.ok()) + { + if pdu.kind == EventType::RoomMember { + if pdu.state_key == Some(sender_id.to_string()) { + let content = serde_json::from_value::< + Raw, + >(pdu.content.clone()) + .expect("Raw::from_value always works") + .deserialize() + .map_err(|_| Error::bad_database("Invalid PDU in database."))?; + if content.membership == ruma::events::room::member::MembershipState::Invite { + invited_since_last_sync = true; + break; + } + } + } + } + + if !invited_since_last_sync { + continue; + } let invited_room = sync_events::InvitedRoom { invite_state: sync_events::InviteState { From b5755936471c10d39239620e42d275aaaa5630ab Mon Sep 17 00:00:00 2001 From: Guillem Nieto Date: Sun, 2 Aug 2020 09:38:20 +0200 Subject: [PATCH 2/2] Do not ignore db errors --- src/client_server/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs index 0f683c8..4e670ec 100644 --- a/src/client_server/sync.rs +++ b/src/client_server/sync.rs @@ -84,8 +84,8 @@ pub async fn sync_events_route( for pdu in db .rooms .pdus_since(&sender_id, &room_id, since)? - .filter_map(|r| r.ok()) { + let pdu = pdu?; send_notification_counts = true; if pdu.kind == EventType::RoomMember { send_member_count = true; @@ -395,8 +395,8 @@ pub async fn sync_events_route( for pdu in db .rooms .pdus_since(&sender_id, &room_id, since)? - .filter_map(|r| r.ok()) { + let pdu = pdu?; if pdu.kind == EventType::RoomMember { if pdu.state_key == Some(sender_id.to_string()) { let content = serde_json::from_value::<