0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-22 09:14:01 +01:00

Generate presence event-stream JSON structures directly

This commit is contained in:
Paul "LeoNerd" Evans 2015-04-23 18:27:25 +01:00
parent 6d15401341
commit 191f7f09ce

View file

@ -836,6 +836,8 @@ class PresenceEventSource(object):
presence = self.hs.get_handlers().presence_handler presence = self.hs.get_handlers().presence_handler
cachemap = presence._user_cachemap cachemap = presence._user_cachemap
clock = self.clock
latest_serial = None
updates = [] updates = []
# TODO(paul): use a DeferredList ? How to limit concurrency. # TODO(paul): use a DeferredList ? How to limit concurrency.
@ -845,18 +847,17 @@ class PresenceEventSource(object):
if cached.serial <= from_key: if cached.serial <= from_key:
continue continue
if (yield self.is_visible(observer_user, observed_user)): if not (yield self.is_visible(observer_user, observed_user)):
updates.append((observed_user, cached)) continue
if latest_serial is None or cached.serial > latest_serial:
latest_serial = cached.serial
updates.append(cached.make_event(user=observed_user, clock=clock))
# TODO(paul): limit # TODO(paul): limit
if updates: if updates:
clock = self.clock defer.returnValue((updates, latest_serial))
latest_serial = max([x[1].serial for x in updates])
data = [x[1].make_event(user=x[0], clock=clock) for x in updates]
defer.returnValue((data, latest_serial))
else: else:
defer.returnValue(([], presence._user_cachemap_latest_serial)) defer.returnValue(([], presence._user_cachemap_latest_serial))