mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-01-27 08:56:59 -05:00
Only poll remote users if they are in our presence list, rather than in a common room
This commit is contained in:
parent
1b7686329e
commit
aaf4fd98ee
@ -263,26 +263,17 @@ class PresenceHandler(BaseHandler):
|
|||||||
statuscache = self._get_or_make_usercache(user)
|
statuscache = self._get_or_make_usercache(user)
|
||||||
|
|
||||||
if user.is_mine:
|
if user.is_mine:
|
||||||
remote_domains = set(
|
self.push_update_to_local_and_remote(
|
||||||
(yield self.store.get_joined_hosts_for_room(room_id))
|
observed_user=user,
|
||||||
|
room_ids=[room_id],
|
||||||
|
statuscache=self._get_or_offline_usercache(user),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.push_update_to_clients_2(
|
||||||
|
observed_user=user,
|
||||||
|
room_ids=[room_id],
|
||||||
|
statuscache=self._get_or_offline_usercache(user),
|
||||||
)
|
)
|
||||||
|
|
||||||
if not remote_domains:
|
|
||||||
defer.returnValue(None)
|
|
||||||
|
|
||||||
deferreds = []
|
|
||||||
for domain in remote_domains:
|
|
||||||
logger.debug(" | push to remote domain %s", domain)
|
|
||||||
deferreds.append(self._push_presence_remote(user, domain,
|
|
||||||
state=statuscache.get_state())
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
self.push_update_to_clients_2(
|
|
||||||
observed_user=user,
|
|
||||||
room_ids=[room_id],
|
|
||||||
statuscache=self._get_or_offline_usercache(user),
|
|
||||||
)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def send_invite(self, observer_user, observed_user):
|
def send_invite(self, observer_user, observed_user):
|
||||||
@ -398,6 +389,7 @@ class PresenceHandler(BaseHandler):
|
|||||||
|
|
||||||
if target_user:
|
if target_user:
|
||||||
target_users = set([target_user])
|
target_users = set([target_user])
|
||||||
|
room_ids = []
|
||||||
else:
|
else:
|
||||||
presence = yield self.store.get_presence_list(
|
presence = yield self.store.get_presence_list(
|
||||||
user.localpart, accepted=True
|
user.localpart, accepted=True
|
||||||
@ -411,23 +403,24 @@ class PresenceHandler(BaseHandler):
|
|||||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
room_ids = yield rm_handler.get_rooms_for_user(user)
|
room_ids = yield rm_handler.get_rooms_for_user(user)
|
||||||
|
|
||||||
for room_id in room_ids:
|
|
||||||
for member in (yield rm_handler.get_room_members(room_id)):
|
|
||||||
target_users.add(member)
|
|
||||||
|
|
||||||
if state is None:
|
if state is None:
|
||||||
state = yield self.store.get_presence_state(user.localpart)
|
state = yield self.store.get_presence_state(user.localpart)
|
||||||
|
|
||||||
localusers, remoteusers = partitionbool(
|
_, remote_domains = yield self.push_update_to_local_and_remote(
|
||||||
target_users,
|
observed_user=user,
|
||||||
lambda u: u.is_mine
|
users_to_push=target_users,
|
||||||
|
room_ids=room_ids,
|
||||||
|
statuscache=self._get_or_make_usercache(user),
|
||||||
)
|
)
|
||||||
|
|
||||||
for target_user in localusers:
|
for target_user in target_users:
|
||||||
self._start_polling_local(user, target_user)
|
if target_user.is_mine:
|
||||||
|
self._start_polling_local(user, target_user)
|
||||||
|
|
||||||
deferreds = []
|
deferreds = []
|
||||||
remoteusers_by_domain = partition(remoteusers, lambda u: u.domain)
|
remote_users = [u for u in target_users if not u.is_mine]
|
||||||
|
remoteusers_by_domain = partition(remote_users, lambda u: u.domain)
|
||||||
|
# Only poll for people in our get_presence_list
|
||||||
for domain in remoteusers_by_domain:
|
for domain in remoteusers_by_domain:
|
||||||
remoteusers = remoteusers_by_domain[domain]
|
remoteusers = remoteusers_by_domain[domain]
|
||||||
|
|
||||||
@ -449,12 +442,6 @@ class PresenceHandler(BaseHandler):
|
|||||||
|
|
||||||
self._local_pushmap[target_localpart].add(user)
|
self._local_pushmap[target_localpart].add(user)
|
||||||
|
|
||||||
self.push_update_to_clients(
|
|
||||||
observer_user=user,
|
|
||||||
observed_user=target_user,
|
|
||||||
statuscache=self._get_or_offline_usercache(target_user),
|
|
||||||
)
|
|
||||||
|
|
||||||
def _start_polling_remote(self, user, domain, remoteusers):
|
def _start_polling_remote(self, user, domain, remoteusers):
|
||||||
to_poll = set()
|
to_poll = set()
|
||||||
|
|
||||||
@ -551,21 +538,15 @@ class PresenceHandler(BaseHandler):
|
|||||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
room_ids = yield rm_handler.get_rooms_for_user(user)
|
room_ids = yield rm_handler.get_rooms_for_user(user)
|
||||||
|
|
||||||
remote_domains = set()
|
if not localusers and not room_ids:
|
||||||
for room_id in room_ids:
|
|
||||||
remote_domains.update(
|
|
||||||
(yield self.store.get_joined_hosts_for_room(room_id))
|
|
||||||
)
|
|
||||||
|
|
||||||
if not localusers and not remotedomains:
|
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
|
|
||||||
deferreds = []
|
yield self.push_update_to_local_and_remote(
|
||||||
for domain in remotedomains:
|
observed_user=user,
|
||||||
logger.debug(" | push to remote domain %s", domain)
|
users_to_push=localusers,
|
||||||
deferreds.append(self._push_presence_remote(user, domain,
|
room_ids=room_ids,
|
||||||
state=statuscache.get_state())
|
statuscache=statuscache,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.push_update_to_clients_2(
|
self.push_update_to_clients_2(
|
||||||
observed_user=user,
|
observed_user=user,
|
||||||
@ -668,14 +649,46 @@ class PresenceHandler(BaseHandler):
|
|||||||
|
|
||||||
yield defer.DeferredList(deferreds)
|
yield defer.DeferredList(deferreds)
|
||||||
|
|
||||||
def push_update_to_clients(self, observer_user, observed_user,
|
@defer.inlineCallbacks
|
||||||
statuscache):
|
def push_update_to_local_and_remote(self, observed_user,
|
||||||
statuscache.make_event(user=observed_user, clock=self.clock)
|
users_to_push=[], room_ids=[],
|
||||||
|
statuscache=None):
|
||||||
|
|
||||||
self.notifier.on_new_user_event(
|
localusers, remoteusers = partitionbool(
|
||||||
[observer_user],
|
users_to_push,
|
||||||
|
lambda u: u.is_mine
|
||||||
)
|
)
|
||||||
|
|
||||||
|
localusers = set(localusers)
|
||||||
|
|
||||||
|
self.push_update_to_clients_2(
|
||||||
|
observed_user,
|
||||||
|
users_to_push=localusers,
|
||||||
|
room_ids=room_ids,
|
||||||
|
statuscache=statuscache,
|
||||||
|
)
|
||||||
|
|
||||||
|
remote_domains = set([r.domain for r in remoteusers])
|
||||||
|
for room_id in room_ids:
|
||||||
|
remote_domains.update(
|
||||||
|
(yield self.store.get_joined_hosts_for_room(room_id))
|
||||||
|
)
|
||||||
|
|
||||||
|
remote_domains.discard(self.hs.hostname)
|
||||||
|
|
||||||
|
deferreds = []
|
||||||
|
for domain in remote_domains:
|
||||||
|
logger.debug(" | push to remote domain %s", domain)
|
||||||
|
deferreds.append(
|
||||||
|
self._push_presence_remote(
|
||||||
|
observed_user, domain, state=statuscache.get_state()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
yield defer.DeferredList(deferreds)
|
||||||
|
|
||||||
|
defer.returnValue((localusers, remote_domains))
|
||||||
|
|
||||||
def push_update_to_clients_2(self, observed_user, users_to_push=[],
|
def push_update_to_clients_2(self, observed_user, users_to_push=[],
|
||||||
room_ids=[], statuscache=None):
|
room_ids=[], statuscache=None):
|
||||||
statuscache.make_event(user=observed_user, clock=self.clock)
|
statuscache.make_event(user=observed_user, clock=self.clock)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user