diff --git a/tests/conftest.py b/tests/conftest.py index a2f8cfa..20f7fe2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -150,7 +150,7 @@ async def capabilities(self, request): if (from_, secret) not in pytest.values['msgapi']['api_identities']: return web.Response(status=401) elif id_ == 'ECHOECHO': - return web.Response(body=b'text,image,video,file') + return web.Response(body=b'text,image,video,file,quatsch') elif id_ == '*MOCKING': return web.Response(body=b'text,image,video,file') return web.Response(status=404) diff --git a/threema/gateway/_gateway.py b/threema/gateway/_gateway.py index 6d8d0e3..462b990 100644 --- a/threema/gateway/_gateway.py +++ b/threema/gateway/_gateway.py @@ -12,7 +12,6 @@ IDServerError, KeyServerError, MessageServerError, - ReceptionCapabilitiesError, ReceptionCapabilitiesServerError, ) from .key import Key @@ -36,9 +35,15 @@ class ReceptionCapability(enum.Enum): """ text = 'text' image = 'image' - video = 'video' + group = 'group' audio = 'audio' + video = 'video' file = 'file' + poll = 'ballot' + one_to_one_audio_call = 'call' + one_to_one_video_call = 'videocall' + perfect_forward_security = 'pfs' + group_call = 'groupcall' @aio_run_proxy @@ -224,7 +229,8 @@ async def get_id(self, **mode): @async_ttl_cache(ttl=5 * 60) async def get_reception_capabilities(self, id_): """ - Get the reception capabilities of a Threema ID. + Get the reception capabilities of a Threema ID. Unknown capabilities are + being discarded. Arguments: - `id_`: A Threema ID. @@ -234,13 +240,14 @@ async def get_reception_capabilities(self, id_): get_coroutine = self._get(self.urls['get_reception_capabilities'].format(id_)) response = await get_coroutine if response.status == 200: - try: - text = await response.text() - return {ReceptionCapability(capability.strip()) - for capability in text.split(',')} - except ValueError as exc: - await response.release() - raise ReceptionCapabilitiesError('Invalid reception capability') from exc + text = await response.text() + capabilities = set() + for capability in text.split(','): + try: + capabilities.add(ReceptionCapability(capability.strip())) + except ValueError: + pass + return capabilities else: await raise_server_error(response, ReceptionCapabilitiesServerError) diff --git a/threema/gateway/exception.py b/threema/gateway/exception.py index 20f10b6..40cbe3f 100644 --- a/threema/gateway/exception.py +++ b/threema/gateway/exception.py @@ -11,7 +11,6 @@ 'IDServerError', 'GatewayKeyError', 'KeyServerError', - 'ReceptionCapabilitiesError', 'ReceptionCapabilitiesServerError', 'CreditsServerError', 'DirectionError', @@ -117,15 +116,7 @@ class KeyServerError(GatewayKeyError, GatewayServerError): } -class ReceptionCapabilitiesError(GatewayError): - """ - An invalid reception capability has been returned. - """ - - -class ReceptionCapabilitiesServerError( - ReceptionCapabilitiesError, GatewayServerError -): +class ReceptionCapabilitiesServerError(GatewayServerError): """ The server responded with an error code while fetching the reception capabilities of a Threema ID.