Reuse get_interested_parties

This commit is contained in:
Erik Johnston 2017-04-12 10:11:43 +01:00
parent 9c712a366f
commit c7ddb5ef7a
2 changed files with 8 additions and 19 deletions

View file

@ -269,13 +269,13 @@ class TransactionQueue(object):
self._processing_pending_presence = True self._processing_pending_presence = True
try: try:
while True: while True:
states = self.pending_presence states_map = self.pending_presence
self.pending_presence = {} self.pending_presence = {}
if not states: if not states_map:
break break
yield self._process_presence_inner(states) yield self._process_presence_inner(states_map.values())
finally: finally:
self._processing_pending_presence = False self._processing_pending_presence = False

View file

@ -641,7 +641,7 @@ class PresenceHandler(object):
"""Sends state updates to remote servers. """Sends state updates to remote servers.
Args: Args:
hosts_to_states (list(UserPresenceState)) states (list(UserPresenceState))
""" """
self.federation.send_presence(states) self.federation.send_presence(states)
@ -1337,29 +1337,18 @@ def get_interested_remotes(store, states):
each row the list of UserPresenceState should be sent to each each row the list of UserPresenceState should be sent to each
destination destination
""" """
hosts_and_states = [] # Final result to return hosts_and_states = []
# First we look up the rooms each user is in (as well as any explicit # First we look up the rooms each user is in (as well as any explicit
# subscriptions), then for each distinct room we look up the remote # subscriptions), then for each distinct room we look up the remote
# hosts in those rooms. # hosts in those rooms.
room_ids_to_states = {} room_ids_to_states, users_to_states = yield get_interested_parties(store, states)
users_to_states = {}
for state in states.itervalues():
room_ids = yield store.get_rooms_for_user(state.user_id)
for room_id in room_ids:
room_ids_to_states.setdefault(room_id, []).append(state)
plist = yield store.get_presence_list_observers_accepted( for room_id, states in room_ids_to_states.iteritems():
state.user_id,
)
for u in plist:
users_to_states.setdefault(u, []).append(state)
for room_id, states in room_ids_to_states.items():
hosts = yield store.get_hosts_in_room(room_id) hosts = yield store.get_hosts_in_room(room_id)
hosts_and_states.append((hosts, states)) hosts_and_states.append((hosts, states))
for user_id, states in users_to_states.items(): for user_id, states in users_to_states.iteritems():
host = get_domain_from_id(user_id) host = get_domain_from_id(user_id)
hosts_and_states.append(([host], states)) hosts_and_states.append(([host], states))