server: Handle group session sharing responses.

This commit is contained in:
Damir Jelić 2018-10-01 17:11:09 +02:00
parent 595db64a55
commit 4860ffee11
2 changed files with 34 additions and 12 deletions

View file

@ -39,7 +39,8 @@ from nio import (
RoomNameEvent, RoomNameEvent,
RoomTopicEvent, RoomTopicEvent,
MegolmEvent, MegolmEvent,
Event Event,
OlmTrustError
) )
from . import globals as G from . import globals as G
@ -89,7 +90,12 @@ def room_buffer_input_cb(server_name, buffer, input_data):
formatted_data = Formatted.from_input_line(data) formatted_data = Formatted.from_input_line(data)
try:
server.room_send_message(room_buffer, formatted_data, "m.text") server.room_send_message(room_buffer, formatted_data, "m.text")
except OlmTrustError as e:
m = ("Untrusted devices found in room: {}".format(e))
server.error(m)
pass
return W.WEECHAT_RC_OK return W.WEECHAT_RC_OK

View file

@ -32,6 +32,7 @@ from nio import (
Rooms, Rooms,
RoomSendResponse, RoomSendResponse,
SyncResponse, SyncResponse,
ShareGroupSessionResponse,
TransportResponse, TransportResponse,
TransportType, TransportType,
RoomMessagesResponse, RoomMessagesResponse,
@ -624,11 +625,11 @@ class MatrixServer(object):
self.send_or_queue(request) self.send_or_queue(request)
def room_send_message(self, room_buffer, formatted, msgtype="m.text"): def room_send_message(self, room_buffer, formatted, msgtype="m.text"):
# type: (RoomBuffer, Formatted, str) -> None # type: (RoomBuffer, Formatted, str) -> bool
room = room_buffer.room room = room_buffer.room
if not self.client: if not self.client:
return return False
body = {"msgtype": msgtype, "body": formatted.to_plain()} body = {"msgtype": msgtype, "body": formatted.to_plain()}
@ -641,14 +642,11 @@ class MatrixServer(object):
room.room_id, "m.room.message", body room.room_id, "m.room.message", body
) )
except EncryptionError: except EncryptionError:
try: _, request = self.client.share_group_session(room.room_id)
uuid, request = self.client.share_group_session(room.room_id)
message = EncrytpionQueueItem(msgtype, formatted) message = EncrytpionQueueItem(msgtype, formatted)
self.encryption_queue[room.room_id].append(message) self.encryption_queue[room.room_id].append(message)
except OlmTrustError as e: self.send_or_queue(request)
m = ("Untrusted devices found in room: {}".format(e)) return False
self.error(m)
return
if msgtype == "m.emote": if msgtype == "m.emote":
message_class = OwnAction message_class = OwnAction
@ -661,6 +659,7 @@ class MatrixServer(object):
self.own_message_queue[uuid] = own_message self.own_message_queue[uuid] = own_message
self.send_or_queue(request) self.send_or_queue(request)
return True
def keys_upload(self): def keys_upload(self):
_, request = self.client.keys_upload() _, request = self.client.keys_upload()
@ -863,9 +862,26 @@ class MatrixServer(object):
elif isinstance(response, RoomSendResponse): elif isinstance(response, RoomSendResponse):
self.handle_own_messages(response) self.handle_own_messages(response)
elif isinstance(response, RoomMessagesResponse): elif isinstance(response, RoomMessagesResponse):
self.handle_backlog_response(response) self.handle_backlog_response(response)
elif isinstance(response, ShareGroupSessionResponse):
room_id = response.room_id
room_buffer = self.room_buffers[room_id]
while self.encryption_queue[room_id]:
message = self.encryption_queue[room_id].popleft()
try:
if not self.room_send_message(room_buffer,
message.formatted_message,
message.message_type):
self.encryption_queue.pop()
self.encryption_queue[room_id].appendleft(message)
break
except OlmTrustError:
break
def create_room_buffer(self, room_id, prev_batch): def create_room_buffer(self, room_id, prev_batch):
room = self.client.rooms[room_id] room = self.client.rooms[room_id]
buf = RoomBuffer(room, self.name, prev_batch) buf = RoomBuffer(room, self.name, prev_batch)