From b6b67715edc496ea95fd8005ee5b5685adcf2601 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 4 Jan 2017 13:34:35 +0000 Subject: [PATCH 1/2] Send ALL membership events to the server that was affected. Send all membership changes to the server that was affected. This ensures that if the last member of a room on a server was kicked or banned they get told about it. --- synapse/federation/transaction_queue.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/synapse/federation/transaction_queue.py b/synapse/federation/transaction_queue.py index 51b656d74..b00dda290 100644 --- a/synapse/federation/transaction_queue.py +++ b/synapse/federation/transaction_queue.py @@ -19,7 +19,7 @@ from twisted.internet import defer from .persistence import TransactionActions from .units import Transaction, Edu -from synapse.api.constants import EventTypes, Membership +from synapse.api.constants import EventTypes from synapse.api.errors import HttpResponseException from synapse.util.async import run_on_reactor from synapse.util.logcontext import preserve_context_over_fn @@ -161,9 +161,11 @@ class TransactionQueue(object): get_domain_from_id(user_id) for user_id in users_in_room ) + # Send all membership changes to the server that was affected. + # This ensures that if the last member of a room on a server + # was kicked or banned they get told about it. if event.type == EventTypes.Member: - if event.content["membership"] == Membership.JOIN: - destinations.add(get_domain_from_id(event.state_key)) + destinations.add(get_domain_from_id(event.state_key)) logger.debug("Sending %s to %r", event, destinations) From e02bdaf08ba12a5c1ef15d721a7505ffd870c608 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 4 Jan 2017 15:13:40 +0000 Subject: [PATCH 2/2] Get the destinations from the state from before the event Rather than the state after then event. --- synapse/federation/transaction_queue.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/synapse/federation/transaction_queue.py b/synapse/federation/transaction_queue.py index b00dda290..891c245bb 100644 --- a/synapse/federation/transaction_queue.py +++ b/synapse/federation/transaction_queue.py @@ -19,7 +19,6 @@ from twisted.internet import defer from .persistence import TransactionActions from .units import Transaction, Edu -from synapse.api.constants import EventTypes from synapse.api.errors import HttpResponseException from synapse.util.async import run_on_reactor from synapse.util.logcontext import preserve_context_over_fn @@ -153,20 +152,22 @@ class TransactionQueue(object): break for event in events: + # Get the state from before the event. + # We need to make sure that this is the state from before + # the event and not from after it. + # Otherwise if the last member on a server in a room is + # banned then it won't receive the event because it won't + # be in the room after the ban. users_in_room = yield self.state.get_current_user_in_room( - event.room_id, latest_event_ids=[event.event_id], + event.room_id, latest_event_ids=[ + prev_id for prev_id, _ in event.prev_events + ], ) destinations = set( get_domain_from_id(user_id) for user_id in users_in_room ) - # Send all membership changes to the server that was affected. - # This ensures that if the last member of a room on a server - # was kicked or banned they get told about it. - if event.type == EventTypes.Member: - destinations.add(get_domain_from_id(event.state_key)) - logger.debug("Sending %s to %r", event, destinations) self._send_pdu(event, destinations)