Merge branch 'dev'
This commit is contained in:
commit
8bc4c7114c
4 changed files with 40 additions and 44 deletions
|
@ -41,6 +41,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
|
||||
|
|
|
@ -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
|
||||
|
@ -884,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
|
||||
self.homeserver.hostname
|
||||
)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
W.buffer_set(
|
||||
self.weechat_buffer._ptr,
|
||||
|
@ -1375,7 +1372,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 ""
|
||||
|
@ -1395,7 +1392,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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
@ -803,9 +806,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
|
||||
)
|
||||
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue