1414# limitations under the License.
1515import logging
1616import urllib
17+ from typing import TYPE_CHECKING , Optional
1718
1819from prometheus_client import Counter
1920
20- from twisted .internet import defer
21-
2221from synapse .api .constants import EventTypes , ThirdPartyEntityKind
2322from synapse .api .errors import CodeMessageException
2423from synapse .events .utils import serialize_event
2524from synapse .http .client import SimpleHttpClient
26- from synapse .types import ThirdPartyInstanceID
25+ from synapse .types import JsonDict , ThirdPartyInstanceID
2726from synapse .util .caches .response_cache import ResponseCache
2827
28+ if TYPE_CHECKING :
29+ from synapse .appservice import ApplicationService
30+
2931logger = logging .getLogger (__name__ )
3032
3133sent_transactions_counter = Counter (
@@ -163,19 +165,20 @@ async def query_3pe(self, service, kind, protocol, fields):
163165 logger .warning ("query_3pe to %s threw exception %s" , uri , ex )
164166 return []
165167
166- def get_3pe_protocol (self , service , protocol ):
168+ async def get_3pe_protocol (
169+ self , service : "ApplicationService" , protocol : str
170+ ) -> Optional [JsonDict ]:
167171 if service .url is None :
168172 return {}
169173
170- @defer .inlineCallbacks
171- def _get ():
174+ async def _get () -> Optional [JsonDict ]:
172175 uri = "%s%s/thirdparty/protocol/%s" % (
173176 service .url ,
174177 APP_SERVICE_PREFIX ,
175178 urllib .parse .quote (protocol ),
176179 )
177180 try :
178- info = yield defer . ensureDeferred ( self .get_json (uri , {}) )
181+ info = await self .get_json (uri , {})
179182
180183 if not _is_valid_3pe_metadata (info ):
181184 logger .warning (
@@ -196,7 +199,7 @@ def _get():
196199 return None
197200
198201 key = (service .id , protocol )
199- return self .protocol_meta_cache .wrap (key , _get )
202+ return await self .protocol_meta_cache .wrap (key , _get )
200203
201204 async def push_bulk (self , service , events , txn_id = None ):
202205 if service .url is None :
0 commit comments