server: Enable Olm support.

This commit is contained in:
Damir Jelić 2018-09-19 11:40:08 +02:00
parent 76e0aba3aa
commit 97d3a59e33
2 changed files with 38 additions and 17 deletions

View file

@ -37,6 +37,7 @@ from nio import (
RoomMessageUnknown, RoomMessageUnknown,
RoomNameEvent, RoomNameEvent,
RoomTopicEvent, RoomTopicEvent,
MegolmEvent
) )
from . import globals as G from . import globals as G
@ -1098,17 +1099,25 @@ class RoomBuffer(object):
elif isinstance(event, PowerLevelsEvent): elif isinstance(event, PowerLevelsEvent):
self._handle_power_level(event) self._handle_power_level(event)
# elif isinstance(event, UndecryptedEvent): elif isinstance(event, MegolmEvent):
# nick = self.find_nick(event.sender) nick = self.find_nick(event.sender)
# date = server_ts_to_weechat(event.server_timestamp) date = server_ts_to_weechat(event.server_timestamp)
# data = ("Error decrypting event session " "{del_color}<{log_color}Message redacted by: "
# "id: {}".format(event.session_id)) "{censor}{log_color}{reason}{del_color}>"
# self.weechat_buffer.message( "{ncolor}"
# nick, data = ("{del_color}<{log_color}Unable to decrypt: "
# data, "The sender's device has not sent us "
# date, "the keys for this message{del_color}>{ncolor}").format(
# self.get_event_tags(event) del_color=W.color("chat_delimiters"),
# ) log_color=W.color("logger.color.backlog_line"),
ncolor=W.color("reset"))
session_id_tag = SCRIPT_NAME + "_sessionid_" + event.session_id
self.weechat_buffer.message(
nick,
data,
date,
self.get_event_tags(event) + [session_id_tag]
)
else: else:
W.prnt( W.prnt(
@ -1249,7 +1258,7 @@ class RoomBuffer(object):
break break
if leave_index: if leave_index:
timeline_events = info.timeline.events[leave_index + 1 :] timeline_events = info.timeline.events[leave_index + 1:]
# Handle our leave as a state event since we're not in the # Handle our leave as a state event since we're not in the
# nicklist anymore but we're already printed out our leave # nicklist anymore but we're already printed out our leave
self.handle_state_event(info.timeline.events[leave_index]) self.handle_state_event(info.timeline.events[leave_index])

View file

@ -259,7 +259,12 @@ class MatrixServer(object):
def _change_client(self): def _change_client(self):
host = ":".join([self.config.address, str(self.config.port)]) host = ":".join([self.config.address, str(self.config.port)])
self.client = HttpClient(host, self.config.username, self.device_id) self.client = HttpClient(
host,
self.config.username,
self.device_id,
self.get_session_path()
)
def update_option(self, option, option_name): def update_option(self, option, option_name):
if option_name == "address": if option_name == "address":
@ -633,6 +638,10 @@ 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)
def keys_upload(self):
_, request = self.client.keys_upload()
self.send_or_queue(request)
def _print_message_error(self, message): def _print_message_error(self, message):
server_buffer_prnt( server_buffer_prnt(
self, self,
@ -683,10 +692,8 @@ class MatrixServer(object):
W.prnt(self.server_buffer, message) W.prnt(self.server_buffer, message)
# if not self.olm: if not self.client.olm_account_shared:
# self.create_olm() self.keys_upload()
# self.store_olm()
# self.upload_keys(device_keys=True, one_time_keys=False)
sync_filter = { sync_filter = {
"room": { "room": {
@ -743,7 +750,12 @@ class MatrixServer(object):
return return
self._handle_room_info(response) self._handle_room_info(response)
self.next_batch = response.next_batch self.next_batch = response.next_batch
if self.client.should_upload_keys:
self.keys_upload()
self.schedule_sync() self.schedule_sync()
def handle_transport_response(self, response): def handle_transport_response(self, response):