From 60282b4eec1addc4125f5672fd1965786a30f689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Sun, 21 Oct 2018 18:56:39 +0200 Subject: [PATCH] buffer: Support encrypted attachments. Note, the printed url should be passed to a helper program that will download the file and decrypt it. --- matrix/buffer.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/matrix/buffer.py b/matrix/buffer.py index 3b588c5..57ff631 100644 --- a/matrix/buffer.py +++ b/matrix/buffer.py @@ -33,6 +33,7 @@ from nio import ( RoomMessage, RoomMessageEmote, RoomMessageMedia, + RoomEncryptedMedia, RoomMessageNotice, RoomMessageText, RoomMessageUnknown, @@ -1151,6 +1152,31 @@ class RoomBuffer(object): nick, data, date, self.get_event_tags(event), extra_prefix ) + elif isinstance(event, RoomEncryptedMedia): + nick = self.find_nick(event.sender) + date = server_ts_to_weechat(event.server_timestamp) + http_url = Api.encrypted_mxc_to_plumb( + event.url, + event.key["k"], + event.hashes["sha256"], + event.iv + ) + url = http_url if http_url else event.url + + description = "{}".format(event.body) if event.body else "file" + data = ("{del_color}<{ncolor}{desc}{del_color}>{ncolor} " + "{del_color}[{ncolor}{url}{del_color}]{ncolor}").format( + del_color=W.color("chat_delimiters"), + ncolor=W.color("reset"), + desc=description, url=url) + + extra_prefix = (self.warning_prefix if event.decrypted + and not event.verified else "") + + self.weechat_buffer.message( + nick, data, date, self.get_event_tags(event), extra_prefix + ) + elif isinstance(event, RoomMessageUnknown): nick = self.find_nick(event.sender) date = server_ts_to_weechat(event.server_timestamp)