Change the join API to allow joins using aliases.
This commit is contained in:
parent
8c23028c8b
commit
a4a8e448a7
3 changed files with 56 additions and 12 deletions
|
@ -183,7 +183,7 @@ class MatrixClient:
|
||||||
def room_join(self, room_id):
|
def room_join(self, room_id):
|
||||||
query_parameters = {"access_token": self.access_token}
|
query_parameters = {"access_token": self.access_token}
|
||||||
|
|
||||||
path = ("{api}/rooms/{room_id}/join?"
|
path = ("{api}/join/{room_id}?"
|
||||||
"{query_parameters}").format(
|
"{query_parameters}").format(
|
||||||
api=MATRIX_API_PATH,
|
api=MATRIX_API_PATH,
|
||||||
room_id=quote(room_id),
|
room_id=quote(room_id),
|
||||||
|
@ -458,6 +458,15 @@ class MatrixPartMessage(MatrixMessage):
|
||||||
data
|
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):
|
class MatrixInviteMessage(MatrixMessage):
|
||||||
def __init__(self, client, room_id, user_id):
|
def __init__(self, client, room_id, user_id):
|
||||||
|
|
|
@ -209,9 +209,9 @@ class MatrixRedactEvent(MatrixEvent):
|
||||||
|
|
||||||
|
|
||||||
class MatrixJoinEvent(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.room_id = room_id
|
||||||
self.event_id = event_id
|
|
||||||
MatrixEvent.__init__(self, server)
|
MatrixEvent.__init__(self, server)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -220,7 +220,7 @@ class MatrixJoinEvent(MatrixEvent):
|
||||||
return cls(
|
return cls(
|
||||||
server,
|
server,
|
||||||
room_id,
|
room_id,
|
||||||
sanitize_id(parsed_dict["event_id"]),
|
sanitize_id(parsed_dict["room_id"]),
|
||||||
)
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return MatrixErrorEvent.from_dict(
|
return MatrixErrorEvent.from_dict(
|
||||||
|
@ -229,3 +229,26 @@ class MatrixJoinEvent(MatrixEvent):
|
||||||
False,
|
False,
|
||||||
parsed_dict
|
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
|
||||||
|
)
|
||||||
|
|
|
@ -687,6 +687,22 @@ def matrix_handle_message(
|
||||||
event = message.event
|
event = message.event
|
||||||
event.execute()
|
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:
|
elif message_type is MessageType.SYNC:
|
||||||
next_batch = response['next_batch']
|
next_batch = response['next_batch']
|
||||||
|
|
||||||
|
@ -703,10 +719,6 @@ def matrix_handle_message(
|
||||||
# TODO add a delay to this
|
# TODO add a delay to this
|
||||||
server.sync()
|
server.sync()
|
||||||
|
|
||||||
elif message_type is MessageType.SEND:
|
|
||||||
event = message.event
|
|
||||||
event.execute()
|
|
||||||
|
|
||||||
elif message_type == MessageType.ROOM_MSG:
|
elif message_type == MessageType.ROOM_MSG:
|
||||||
# Response has no messages, that is we already got the oldest message
|
# Response has no messages, that is we already got the oldest message
|
||||||
# in a previous request, nothing to do
|
# in a previous request, nothing to do
|
||||||
|
@ -720,10 +732,6 @@ def matrix_handle_message(
|
||||||
|
|
||||||
room.prev_batch = response['end']
|
room.prev_batch = response['end']
|
||||||
|
|
||||||
elif message_type == MessageType.REDACT:
|
|
||||||
event = message.event
|
|
||||||
event.execute()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
server_buffer_prnt(
|
server_buffer_prnt(
|
||||||
server,
|
server,
|
||||||
|
@ -783,6 +791,10 @@ def handle_http_response(server, message):
|
||||||
event = message.event
|
event = message.event
|
||||||
event.execute()
|
event.execute()
|
||||||
|
|
||||||
|
elif message.type == MessageType.PART:
|
||||||
|
event = message.event
|
||||||
|
event.execute()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
error_message = ("{prefix}Unhandled 403 error, please inform the "
|
error_message = ("{prefix}Unhandled 403 error, please inform the "
|
||||||
"developers about this: {error}").format(
|
"developers about this: {error}").format(
|
||||||
|
|
Loading…
Add table
Reference in a new issue