Change the join API to allow joins using aliases.

This commit is contained in:
poljar (Damir Jelić) 2018-02-14 14:21:56 +01:00
parent 8c23028c8b
commit a4a8e448a7
3 changed files with 56 additions and 12 deletions

View file

@ -183,7 +183,7 @@ class MatrixClient:
def room_join(self, room_id):
query_parameters = {"access_token": self.access_token}
path = ("{api}/rooms/{room_id}/join?"
path = ("{api}/join/{room_id}?"
"{query_parameters}").format(
api=MATRIX_API_PATH,
room_id=quote(room_id),
@ -458,6 +458,15 @@ class MatrixPartMessage(MatrixMessage):
data
)
def decode_body(self, server):
object_hook = partial(
MatrixEvents.MatrixPartEvent.from_dict,
server,
self.room_id
)
return self._decode(server, object_hook)
class MatrixInviteMessage(MatrixMessage):
def __init__(self, client, room_id, user_id):

View file

@ -209,9 +209,9 @@ class MatrixRedactEvent(MatrixEvent):
class MatrixJoinEvent(MatrixEvent):
def __init__(self, server, room_id, event_id):
def __init__(self, server, room, room_id):
self.room = room
self.room_id = room_id
self.event_id = event_id
MatrixEvent.__init__(self, server)
@classmethod
@ -220,7 +220,7 @@ class MatrixJoinEvent(MatrixEvent):
return cls(
server,
room_id,
sanitize_id(parsed_dict["event_id"]),
sanitize_id(parsed_dict["room_id"]),
)
except KeyError:
return MatrixErrorEvent.from_dict(
@ -229,3 +229,26 @@ class MatrixJoinEvent(MatrixEvent):
False,
parsed_dict
)
class MatrixPartEvent(MatrixEvent):
def __init__(self, server, room_id):
self.room_id = room_id
MatrixEvent.__init__(self, server)
@classmethod
def from_dict(cls, server, room_id, parsed_dict):
try:
if parsed_dict is {}:
return cls(
server,
room_id)
raise KeyError
except KeyError:
return MatrixErrorEvent.from_dict(
server,
"Error leaving room",
False,
parsed_dict
)

View file

@ -687,6 +687,22 @@ def matrix_handle_message(
event = message.event
event.execute()
elif message_type is MessageType.JOIN:
event = message.event
event.execute()
elif message_type is MessageType.PART:
event = message.event
event.execute()
elif message_type is MessageType.SEND:
event = message.event
event.execute()
elif message_type == MessageType.REDACT:
event = message.event
event.execute()
elif message_type is MessageType.SYNC:
next_batch = response['next_batch']
@ -703,10 +719,6 @@ def matrix_handle_message(
# TODO add a delay to this
server.sync()
elif message_type is MessageType.SEND:
event = message.event
event.execute()
elif message_type == MessageType.ROOM_MSG:
# Response has no messages, that is we already got the oldest message
# in a previous request, nothing to do
@ -720,10 +732,6 @@ def matrix_handle_message(
room.prev_batch = response['end']
elif message_type == MessageType.REDACT:
event = message.event
event.execute()
else:
server_buffer_prnt(
server,
@ -783,6 +791,10 @@ def handle_http_response(server, message):
event = message.event
event.execute()
elif message.type == MessageType.PART:
event = message.event
event.execute()
else:
error_message = ("{prefix}Unhandled 403 error, please inform the "
"developers about this: {error}").format(