diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2016-09-08 17:43:53 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2016-09-08 17:43:53 +0100 |
commit | 2f267ee160b1f7ce591f4f10ddb5f9239110a2f6 (patch) | |
tree | fb8d12d9ae1932e4f085989f8c02e3274858c93c /synapse/handlers/appservice.py | |
parent | Merge pull request #1085 from matrix-org/erikj/reindex_state_groups (diff) | |
download | synapse-2f267ee160b1f7ce591f4f10ddb5f9239110a2f6.tar.xz |
Collect up all the "instances" lists of individual AS protocol results into one combined answer to the client
Diffstat (limited to '')
-rw-r--r-- | synapse/handlers/appservice.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index b440280b74..25447284eb 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -179,9 +179,37 @@ class ApplicationServicesHandler(object): def get_3pe_protocols(self): services = yield self.store.get_app_services() protocols = {} + + # Collect up all the individual protocol responses out of the ASes for s in services: for p in s.protocols: - protocols[p] = yield self.appservice_api.get_3pe_protocol(s, p) + info = yield self.appservice_api.get_3pe_protocol(s, p) + + # Ignore any result that doesn't contain an "instances" list + if "instances" not in info: + continue + if not isinstance(info["instances"], list): + continue + + if p not in protocols: + protocols[p] = [] + protocols[p].append(info) + + def _merge_instances(infos): + if len(infos) == 0: + return {} + + # Merge the 'instances' lists of multiple results, but just take + # the other fields from the first as they ought to be identical + combined = dict(infos[0]) + + for info in infos[1:]: + combined["instances"].extend(info["instances"]) + + return combined + + for p in protocols.keys(): + protocols[p] = _merge_instances(protocols[p]) defer.returnValue(protocols) |