From c400404e3dd9a1806516348360388813b1efe850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 26 Mar 2019 18:09:54 +0100 Subject: [PATCH] server: Unstuck the group session shared flag. The group session shared flag could be stuck in a permanent True state if we try to share a group session comming from a key claim response in the case that we have unverified devices. --- matrix/server.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/matrix/server.py b/matrix/server.py index 5e2b061..3299c84 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -48,6 +48,7 @@ from nio import ( SyncResponse, PartialSyncResponse, ShareGroupSessionResponse, + ShareGroupSessionError, KeysQueryResponse, KeysClaimResponse, DevicesResponse, @@ -838,6 +839,14 @@ class MatrixServer(object): return True + def share_group_session(self, room_id, ignore_missing_sessions=False): + _, request = self.client.share_group_session( + room_id, + ignore_missing_sessions + ) + self.send(request) + self.group_session_shared[room_id] = True + def room_send_event( self, room_id, # type: str @@ -856,9 +865,7 @@ class MatrixServer(object): except GroupEncryptionError: try: if not self.group_session_shared[room_id]: - _, request = self.client.share_group_session(room_id) - self.group_session_shared[room_id] = True - self.send(request) + self.share_group_session(room_id) raise except EncryptionError: @@ -1282,6 +1289,9 @@ class MatrixServer(object): self.get_joined_members(self.rooms_with_missing_members.pop()) elif isinstance(response, RoomSendResponse): self.handle_own_messages_error(response) + elif isinstance(response, ShareGroupSessionError): + self.group_session_shared[response.room_id] = False + self.share_group_session(response.room_id) def handle_response(self, response): # type: (Response) -> None @@ -1363,8 +1373,7 @@ class MatrixServer(object): elif isinstance(response, KeysClaimResponse): self.keys_claimed[response.room_id] = False try: - self.group_session_shared[response.room_id] = True - _, request = self.client.share_group_session( + self.share_group_session( response.room_id, ignore_missing_sessions=True ) @@ -1375,8 +1384,6 @@ class MatrixServer(object): self.encryption_queue[response.room_id].clear() return - self.send(request) - elif isinstance(response, ShareGroupSessionResponse): room_id = response.room_id self.group_session_shared[response.room_id] = False