Merge pull request 'Send invites only if invited during the sync request' (#176) from gnieto/conduit:fix/send-invite-when-needed into master
Reviewed-on: https://git.koesters.xyz/timo/conduit/pulls/176 Reviewed-by: Timo Kösters <timo@koesters.xyz>next
commit
4a8bc93b1a
|
@ -84,8 +84,8 @@ pub async fn sync_events_route(
|
||||||
for pdu in db
|
for pdu in db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_since(&sender_id, &room_id, since)?
|
.pdus_since(&sender_id, &room_id, since)?
|
||||||
.filter_map(|r| r.ok())
|
|
||||||
{
|
{
|
||||||
|
let pdu = pdu?;
|
||||||
send_notification_counts = true;
|
send_notification_counts = true;
|
||||||
if pdu.kind == EventType::RoomMember {
|
if pdu.kind == EventType::RoomMember {
|
||||||
send_member_count = true;
|
send_member_count = true;
|
||||||
|
@ -391,6 +391,31 @@ pub async fn sync_events_route(
|
||||||
let mut invited_rooms = BTreeMap::new();
|
let mut invited_rooms = BTreeMap::new();
|
||||||
for room_id in db.rooms.rooms_invited(&sender_id) {
|
for room_id in db.rooms.rooms_invited(&sender_id) {
|
||||||
let room_id = room_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)?
|
||||||
|
{
|
||||||
|
let pdu = pdu?;
|
||||||
|
if pdu.kind == EventType::RoomMember {
|
||||||
|
if pdu.state_key == Some(sender_id.to_string()) {
|
||||||
|
let content = serde_json::from_value::<
|
||||||
|
Raw<ruma::events::room::member::MemberEventContent>,
|
||||||
|
>(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 {
|
let invited_room = sync_events::InvitedRoom {
|
||||||
invite_state: sync_events::InviteState {
|
invite_state: sync_events::InviteState {
|
||||||
|
|
Loading…
Reference in New Issue