mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 22:14:55 -04:00
Avoid so much copypasta between 3PU and 3PL query by unifying around a ThirdPartyEntityKind enumeration
This commit is contained in:
parent
2a91799fcc
commit
b515f844ee
4 changed files with 35 additions and 43 deletions
|
@ -17,6 +17,7 @@ from twisted.internet import defer
|
|||
from synapse.api.errors import CodeMessageException
|
||||
from synapse.http.client import SimpleHttpClient
|
||||
from synapse.events.utils import serialize_event
|
||||
from synapse.types import ThirdPartyEntityKind
|
||||
|
||||
import logging
|
||||
import urllib
|
||||
|
@ -72,25 +73,21 @@ class ApplicationServiceApi(SimpleHttpClient):
|
|||
defer.returnValue(False)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def query_3pu(self, service, protocol, fields):
|
||||
uri = "%s/3pu/%s" % (service.url, urllib.quote(protocol))
|
||||
response = None
|
||||
try:
|
||||
response = yield self.get_json(uri, fields)
|
||||
defer.returnValue(response)
|
||||
except Exception as ex:
|
||||
logger.warning("query_3pu to %s threw exception %s", uri, ex)
|
||||
defer.returnValue([])
|
||||
def query_3pe(self, service, kind, protocol, fields):
|
||||
if kind == ThirdPartyEntityKind.USER:
|
||||
uri = "%s/3pu/%s" % (service.url, urllib.quote(protocol))
|
||||
elif kind == ThirdPartyEntityKind.LOCATION:
|
||||
uri = "%s/3pl/%s" % (service.url, urllib.quote(protocol))
|
||||
else:
|
||||
raise ValueError(
|
||||
"Unrecognised 'kind' argument %r to query_3pe()", kind
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def query_3pl(self, service, protocol, fields):
|
||||
uri = "%s/3pl/%s" % (service.url, urllib.quote(protocol))
|
||||
response = None
|
||||
try:
|
||||
response = yield self.get_json(uri, fields)
|
||||
defer.returnValue(response)
|
||||
except Exception as ex:
|
||||
logger.warning("query_3pl to %s threw exception %s", uri, ex)
|
||||
logger.warning("query_3pe to %s threw exception %s", uri, ex)
|
||||
defer.returnValue([])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue