diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2016-08-25 15:10:06 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2016-08-25 15:29:36 +0100 |
commit | 5474824975b5372665b0921960a0c3887a49efdb (patch) | |
tree | b03ed94de9b1d5037e202caf41c813aea93cceff | |
parent | Move static knowledge of protocol metadata into AS handler; cache the result (diff) | |
download | synapse-5474824975b5372665b0921960a0c3887a49efdb.tar.xz |
Actually query over AS API for 3PE lookup metadata
Diffstat (limited to '')
-rw-r--r-- | synapse/appservice/api.py | 20 | ||||
-rw-r--r-- | synapse/handlers/appservice.py | 14 |
2 files changed, 21 insertions, 13 deletions
diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index 07ec33b9a1..1de0e7240f 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -52,6 +52,13 @@ class ApplicationServiceApi(SimpleHttpClient): pushing. """ + PROTOCOL_META = { + # TODO(paul): Declare kinds of metadata in here + "gitter": { + "user_fields": ["username"], + } + } + def __init__(self, hs): super(ApplicationServiceApi, self).__init__(hs) self.clock = hs.get_clock() @@ -132,6 +139,19 @@ class ApplicationServiceApi(SimpleHttpClient): defer.returnValue([]) @defer.inlineCallbacks + def get_3pe_protocol(self, service, protocol): + # TODO: cache + uri = "%s/thirdparty/protocol/%s" % (service.url, urllib.quote(protocol)) + try: + response = yield self.get_json(uri, {}) + defer.returnValue(response) + except Exception as ex: + logger.warning("query_3pe_protocol to %s threw exception %s", + uri, ex + ) + defer.returnValue({}) + + @defer.inlineCallbacks def push_bulk(self, service, events, txn_id=None): events = self._serialize(events) diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index 1c5c5ec302..efb9da798d 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -37,13 +37,6 @@ def log_failure(failure): class ApplicationServicesHandler(object): - PROTOCOL_META = { - # TODO(paul): Declare kinds of metadata in here - "gitter": { - "user_fields": ["username"], - } - } - def __init__(self, hs): self.store = hs.get_datastore() self.is_mine_id = hs.is_mine_id @@ -195,12 +188,7 @@ class ApplicationServicesHandler(object): protocols = {} for s in services: for p in s.protocols: - if p in self.PROTOCOL_META: - protocols[p] = self.PROTOCOL_META[p] - else: - # We don't know any metadata for it, but we'd best at least - # still declare that we know it exists - protocols[p] = {} + protocols[p] = yield self.appservice_api.get_3pe_protocol(s, p) self.supported_protocols = protocols defer.returnValue(protocols) |