Merge branch 'dev'

This commit is contained in:
Damir Jelić 2019-07-12 17:00:47 +02:00
commit 8bc4c7114c
4 changed files with 40 additions and 44 deletions

View file

@ -41,6 +41,8 @@ support is still experimental.
either Python2 or Python3, but when you install dependencies you will have to 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. 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: To check the python version that weechat is using, run:
/python version /python version

View file

@ -849,8 +849,9 @@ class WeechatChannelBuffer(object):
class RoomBuffer(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.room = room
self.homeserver = homeserver
self._backlog_pending = False self._backlog_pending = False
self.prev_batch = prev_batch self.prev_batch = prev_batch
self.joined = True self.joined = True
@ -884,15 +885,11 @@ class RoomBuffer(object):
buffer_name, server_name, user buffer_name, server_name, user
) )
try: W.buffer_set(
_, room_domain = room.room_id.split(":", 1) self.weechat_buffer._ptr,
W.buffer_set( "localvar_set_domain",
self.weechat_buffer._ptr, self.homeserver.hostname
"localvar_set_domain", )
room_domain
)
except ValueError:
pass
W.buffer_set( W.buffer_set(
self.weechat_buffer._ptr, self.weechat_buffer._ptr,
@ -1375,7 +1372,7 @@ class RoomBuffer(object):
elif isinstance(event, RoomMessageMedia): elif isinstance(event, RoomMessageMedia):
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)
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 url = http_url if http_url else event.url
description = "/{}".format(event.body) if event.body else "" description = "/{}".format(event.body) if event.body else ""
@ -1395,7 +1392,8 @@ class RoomBuffer(object):
event.url, event.url,
event.key["k"], event.key["k"],
event.hashes["sha256"], event.hashes["sha256"],
event.iv event.iv,
self.homeserver.geturl()
) )
url = http_url if http_url else event.url url = http_url if http_url else event.url

View file

@ -270,6 +270,7 @@ class MatrixServer(object):
pass pass
self.address = None self.address = None
self.homeserver = None
self.client = None self.client = None
self.access_token = None # type: Optional[str] self.access_token = None # type: Optional[str]
self.next_batch = None # type: Optional[str] self.next_batch = None # type: Optional[str]
@ -349,29 +350,31 @@ class MatrixServer(object):
device_file.write(self.device_id) device_file.write(self.device_id)
@staticmethod @staticmethod
def _parse_url(address): def _parse_url(address, port):
if not address.startswith("http"):
address = "https://{}".format(address)
parsed_url = urlparse(address) parsed_url = urlparse(address)
if parsed_url.netloc: homeserver = parsed_url._replace(
netloc, path = (parsed_url.netloc, parsed_url.path) netloc=parsed_url.hostname + ":{}".format(port)
else: )
try:
netloc, path = address.split("/", 1)
except ValueError:
netloc, path = (address, "")
return netloc, path.strip("/") return homeserver
def _change_client(self): def _change_client(self):
netloc, extra_path = MatrixServer._parse_url(self.config.address) homeserver = MatrixServer._parse_url(
host = "{}:{}".format(netloc, self.config.port) self.config.address,
self.address = netloc self.config.port
)
self.address = homeserver.hostname
self.homeserver = homeserver
self.client = HttpClient( self.client = HttpClient(
host, homeserver.geturl(),
self.config.username, self.config.username,
self.device_id, self.device_id,
self.get_session_path(), self.get_session_path(),
extra_path=extra_path
) )
self.client.add_to_device_callback( self.client.add_to_device_callback(
self.key_verification_cb, self.key_verification_cb,
@ -803,9 +806,6 @@ class MatrixServer(object):
self.send_or_queue(request) self.send_or_queue(request)
def room_send_state(self, room_buffer, body, event_type): def room_send_state(self, room_buffer, body, event_type):
if room_buffer.room.encrypted:
return
_, request = self.client.room_put_state( _, request = self.client.room_put_state(
room_buffer.room.room_id, event_type, body room_buffer.room.room_id, event_type, body
) )
@ -1628,7 +1628,7 @@ class MatrixServer(object):
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, self.homeserver, prev_batch)
if room.members_synced: if room.members_synced:
buf.members_fetched = True buf.members_fetched = True

View file

@ -6,20 +6,16 @@ G.CONFIG = MockConfig()
class TestClass(object): class TestClass(object):
def test_address_parsing(self): def test_address_parsing(self):
host, extra_path = MatrixServer._parse_url("example.org") homeserver = MatrixServer._parse_url("example.org", 8080)
assert host == "example.org" assert homeserver.hostname == "example.org"
assert extra_path == "" assert homeserver.geturl() == "https://example.org:8080"
host, extra_path = MatrixServer._parse_url("example.org/_matrix") homeserver = MatrixServer._parse_url("example.org/_matrix", 80)
assert host == "example.org" assert homeserver.hostname == "example.org"
assert extra_path == "_matrix" assert homeserver.geturl() == "https://example.org:80/_matrix"
host, extra_path = MatrixServer._parse_url( homeserver = MatrixServer._parse_url(
"https://example.org/_matrix" "https://example.org/_matrix", 80
) )
assert host == "example.org" assert homeserver.hostname == "example.org"
assert extra_path == "_matrix" assert homeserver.geturl() == "https://example.org:80/_matrix"
host, extra_path = MatrixServer._parse_url("https://example.org")
assert host == "example.org"
assert extra_path == ""