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,
RoomNameEvent,
RoomTopicEvent,
MegolmEvent
)
from . import globals as G
@ -1098,17 +1099,25 @@ class RoomBuffer(object):
elif isinstance(event, PowerLevelsEvent):
self._handle_power_level(event)
# elif isinstance(event, UndecryptedEvent):
# nick = self.find_nick(event.sender)
# date = server_ts_to_weechat(event.server_timestamp)
# data = ("Error decrypting event session "
# "id: {}".format(event.session_id))
# self.weechat_buffer.message(
# nick,
# data,
# date,
# self.get_event_tags(event)
# )
elif isinstance(event, MegolmEvent):
nick = self.find_nick(event.sender)
date = server_ts_to_weechat(event.server_timestamp)
"{del_color}<{log_color}Message redacted by: "
"{censor}{log_color}{reason}{del_color}>"
"{ncolor}"
data = ("{del_color}<{log_color}Unable to decrypt: "
"The sender's device has not sent us "
"the keys for this message{del_color}>{ncolor}").format(
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:
W.prnt(
@ -1249,7 +1258,7 @@ class RoomBuffer(object):
break
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
# nicklist anymore but we're already printed out our leave
self.handle_state_event(info.timeline.events[leave_index])

View file

@ -259,7 +259,12 @@ class MatrixServer(object):
def _change_client(self):
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):
if option_name == "address":
@ -633,6 +638,10 @@ class MatrixServer(object):
self.own_message_queue[uuid] = own_message
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):
server_buffer_prnt(
self,
@ -683,10 +692,8 @@ class MatrixServer(object):
W.prnt(self.server_buffer, message)
# if not self.olm:
# self.create_olm()
# self.store_olm()
# self.upload_keys(device_keys=True, one_time_keys=False)
if not self.client.olm_account_shared:
self.keys_upload()
sync_filter = {
"room": {
@ -743,7 +750,12 @@ class MatrixServer(object):
return
self._handle_room_info(response)
self.next_batch = response.next_batch
if self.client.should_upload_keys:
self.keys_upload()
self.schedule_sync()
def handle_transport_response(self, response):