Skip to content

Commit 4008b5b

Browse files
committed
Fix reception capabilities
- Fix parsing of unknown reception capabilities - Add new `ReceptionCapability` items - Remove `ReceptionCapabilitiesError` (breaking)
1 parent 40652e0 commit 4008b5b

3 files changed

Lines changed: 19 additions & 21 deletions

File tree

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async def capabilities(self, request):
150150
if (from_, secret) not in pytest.values['msgapi']['api_identities']:
151151
return web.Response(status=401)
152152
elif id_ == 'ECHOECHO':
153-
return web.Response(body=b'text,image,video,file')
153+
return web.Response(body=b'text,image,video,file,quatsch')
154154
elif id_ == '*MOCKING':
155155
return web.Response(body=b'text,image,video,file')
156156
return web.Response(status=404)

threema/gateway/_gateway.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
IDServerError,
1313
KeyServerError,
1414
MessageServerError,
15-
ReceptionCapabilitiesError,
1615
ReceptionCapabilitiesServerError,
1716
)
1817
from .key import Key
@@ -36,9 +35,15 @@ class ReceptionCapability(enum.Enum):
3635
"""
3736
text = 'text'
3837
image = 'image'
39-
video = 'video'
38+
group = 'group'
4039
audio = 'audio'
40+
video = 'video'
4141
file = 'file'
42+
poll = 'ballot'
43+
one_to_one_audio_call = 'call'
44+
one_to_one_video_call = 'videocall'
45+
perfect_forward_security = 'pfs'
46+
group_call = 'groupcall'
4247

4348

4449
@aio_run_proxy
@@ -224,7 +229,8 @@ async def get_id(self, **mode):
224229
@async_ttl_cache(ttl=5 * 60)
225230
async def get_reception_capabilities(self, id_):
226231
"""
227-
Get the reception capabilities of a Threema ID.
232+
Get the reception capabilities of a Threema ID. Unknown capabilities are
233+
being discarded.
228234
229235
Arguments:
230236
- `id_`: A Threema ID.
@@ -234,13 +240,14 @@ async def get_reception_capabilities(self, id_):
234240
get_coroutine = self._get(self.urls['get_reception_capabilities'].format(id_))
235241
response = await get_coroutine
236242
if response.status == 200:
237-
try:
238-
text = await response.text()
239-
return {ReceptionCapability(capability.strip())
240-
for capability in text.split(',')}
241-
except ValueError as exc:
242-
await response.release()
243-
raise ReceptionCapabilitiesError('Invalid reception capability') from exc
243+
text = await response.text()
244+
capabilities = set()
245+
for capability in text.split(','):
246+
try:
247+
capabilities.add(ReceptionCapability(capability.strip()))
248+
except ValueError:
249+
pass
250+
return capabilities
244251
else:
245252
await raise_server_error(response, ReceptionCapabilitiesServerError)
246253

threema/gateway/exception.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'IDServerError',
1212
'GatewayKeyError',
1313
'KeyServerError',
14-
'ReceptionCapabilitiesError',
1514
'ReceptionCapabilitiesServerError',
1615
'CreditsServerError',
1716
'DirectionError',
@@ -117,15 +116,7 @@ class KeyServerError(GatewayKeyError, GatewayServerError):
117116
}
118117

119118

120-
class ReceptionCapabilitiesError(GatewayError):
121-
"""
122-
An invalid reception capability has been returned.
123-
"""
124-
125-
126-
class ReceptionCapabilitiesServerError(
127-
ReceptionCapabilitiesError, GatewayServerError
128-
):
119+
class ReceptionCapabilitiesServerError(GatewayServerError):
129120
"""
130121
The server responded with an error code while fetching the reception
131122
capabilities of a Threema ID.

0 commit comments

Comments
 (0)