From f05d2f0a2b87c94f584bc2d547e5b84b388f9998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 27 Jun 2019 17:32:39 +0200 Subject: [PATCH 1/7] server: Enable sending state events to encrypted rooms. State events are not encrypted so sending them is done as usually. --- matrix/server.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/matrix/server.py b/matrix/server.py index 16fd9c5..7c4a7c3 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -803,9 +803,6 @@ class MatrixServer(object): self.send_or_queue(request) def room_send_state(self, room_buffer, body, event_type): - if room_buffer.room.encrypted: - return - _, request = self.client.room_put_state( room_buffer.room.room_id, event_type, body ) From e82d7013eca0c978776b36a8b2f6bb4c38fd0a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 27 Jun 2019 19:53:59 +0200 Subject: [PATCH 2/7] README: Mention the minimal supported python2 version. This closes #94. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b222dcc..3914720 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ support is still experimental. either Python2 or Python3, but when you install dependencies you will have to take into account which version of Python your Weechat was built to use. + The minimal supported python2 version is 2.7.10. + To check the python version that weechat is using, run: /python version From 4c8ee2848bd7b7949756ec5d2773073b5db96e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 2 Jul 2019 18:09:36 +0200 Subject: [PATCH 3/7] server: Change the way the homeserver url is passed to nio. --- matrix/server.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/matrix/server.py b/matrix/server.py index 7c4a7c3..568fc5c 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -270,6 +270,7 @@ class MatrixServer(object): pass self.address = None + self.homeserver = None self.client = None self.access_token = None # type: Optional[str] self.next_batch = None # type: Optional[str] @@ -349,29 +350,31 @@ class MatrixServer(object): device_file.write(self.device_id) @staticmethod - def _parse_url(address): + def _parse_url(address, port): + if not address.startswith("http"): + address = "https://{}".format(address) + parsed_url = urlparse(address) - if parsed_url.netloc: - netloc, path = (parsed_url.netloc, parsed_url.path) - else: - try: - netloc, path = address.split("/", 1) - except ValueError: - netloc, path = (address, "") + homeserver = parsed_url._replace( + netloc=parsed_url.hostname + ":{}".format(port) + ) - return netloc, path.strip("/") + return homeserver def _change_client(self): - netloc, extra_path = MatrixServer._parse_url(self.config.address) - host = "{}:{}".format(netloc, self.config.port) - self.address = netloc + homeserver = MatrixServer._parse_url( + self.config.address, + self.config.port + ) + self.address = homeserver.hostname + self.homeserver = homeserver + self.client = HttpClient( - host, + homeserver.geturl(), self.config.username, self.device_id, self.get_session_path(), - extra_path=extra_path ) self.client.add_to_device_callback( self.key_verification_cb, From 4c04f6319b9e665e168417be92b5e9657b581c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 2 Jul 2019 18:10:12 +0200 Subject: [PATCH 4/7] buffer: Store the homeserver inside room buffers. --- matrix/buffer.py | 3 ++- matrix/server.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/matrix/buffer.py b/matrix/buffer.py index 68a39d5..188326a 100644 --- a/matrix/buffer.py +++ b/matrix/buffer.py @@ -849,8 +849,9 @@ class WeechatChannelBuffer(object): class RoomBuffer(object): - def __init__(self, room, server_name, prev_batch): + def __init__(self, room, server_name, homeserver, prev_batch): self.room = room + self.homeserver = homeserver self._backlog_pending = False self.prev_batch = prev_batch self.joined = True diff --git a/matrix/server.py b/matrix/server.py index 568fc5c..93b1568 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -1628,7 +1628,7 @@ class MatrixServer(object): def create_room_buffer(self, room_id, prev_batch): room = self.client.rooms[room_id] - buf = RoomBuffer(room, self.name, prev_batch) + buf = RoomBuffer(room, self.name, self.homeserver, prev_batch) if room.members_synced: buf.members_fetched = True From e9214862fe37191d956188ff64aef89330ebbf77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 2 Jul 2019 18:10:35 +0200 Subject: [PATCH 5/7] buffer: Pass the homeserver to the mxc -> http api function. This fixes #57. --- matrix/buffer.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/matrix/buffer.py b/matrix/buffer.py index 188326a..279c12d 100644 --- a/matrix/buffer.py +++ b/matrix/buffer.py @@ -1376,7 +1376,7 @@ class RoomBuffer(object): elif isinstance(event, RoomMessageMedia): nick = self.find_nick(event.sender) date = server_ts_to_weechat(event.server_timestamp) - http_url = Api.mxc_to_http(event.url) + http_url = Api.mxc_to_http(event.url, self.homeserver.geturl()) url = http_url if http_url else event.url description = "/{}".format(event.body) if event.body else "" @@ -1396,7 +1396,8 @@ class RoomBuffer(object): event.url, event.key["k"], event.hashes["sha256"], - event.iv + event.iv, + self.homeserver.geturl() ) url = http_url if http_url else event.url From 934863e209145db7638cce95140a88c38ec8eff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 2 Jul 2019 18:11:28 +0200 Subject: [PATCH 6/7] buffer: Change the way the domain localvar is set. Room ids in newer room versions will become opaque strings and won't contain the domain of the homeserver. Get the domain from the homeserver url instead. --- matrix/buffer.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/matrix/buffer.py b/matrix/buffer.py index 279c12d..3bb9acb 100644 --- a/matrix/buffer.py +++ b/matrix/buffer.py @@ -885,15 +885,11 @@ class RoomBuffer(object): buffer_name, server_name, user ) - try: - _, room_domain = room.room_id.split(":", 1) - W.buffer_set( - self.weechat_buffer._ptr, - "localvar_set_domain", - room_domain - ) - except ValueError: - pass + W.buffer_set( + self.weechat_buffer._ptr, + "localvar_set_domain", + self.homeserver.hostname + ) W.buffer_set( self.weechat_buffer._ptr, From 2758ece4a91a59e7390cc00faf9e965a2ec16405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 3 Jul 2019 21:20:07 +0200 Subject: [PATCH 7/7] tests: Fix server tests. --- tests/server_test.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/server_test.py b/tests/server_test.py index 764c19a..ceb94fb 100644 --- a/tests/server_test.py +++ b/tests/server_test.py @@ -6,20 +6,16 @@ G.CONFIG = MockConfig() class TestClass(object): def test_address_parsing(self): - host, extra_path = MatrixServer._parse_url("example.org") - assert host == "example.org" - assert extra_path == "" + homeserver = MatrixServer._parse_url("example.org", 8080) + assert homeserver.hostname == "example.org" + assert homeserver.geturl() == "https://example.org:8080" - host, extra_path = MatrixServer._parse_url("example.org/_matrix") - assert host == "example.org" - assert extra_path == "_matrix" + homeserver = MatrixServer._parse_url("example.org/_matrix", 80) + assert homeserver.hostname == "example.org" + assert homeserver.geturl() == "https://example.org:80/_matrix" - host, extra_path = MatrixServer._parse_url( - "https://example.org/_matrix" + homeserver = MatrixServer._parse_url( + "https://example.org/_matrix", 80 ) - assert host == "example.org" - assert extra_path == "_matrix" - - host, extra_path = MatrixServer._parse_url("https://example.org") - assert host == "example.org" - assert extra_path == "" + assert homeserver.hostname == "example.org" + assert homeserver.geturl() == "https://example.org:80/_matrix"