Add topic event class.
This commit is contained in:
parent
e4f042a6a7
commit
4537635db3
3 changed files with 37 additions and 9 deletions
|
@ -360,6 +360,16 @@ class MatrixTopicMessage(MatrixMessage):
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def decode_body(self, server):
|
||||||
|
object_hook = partial(
|
||||||
|
MatrixEvents.MatrixTopicEvent.from_dict,
|
||||||
|
server,
|
||||||
|
self.room_id,
|
||||||
|
self.topic,
|
||||||
|
)
|
||||||
|
|
||||||
|
return self._decode(server, object_hook)
|
||||||
|
|
||||||
|
|
||||||
class MatrixRedactMessage(MatrixMessage):
|
class MatrixRedactMessage(MatrixMessage):
|
||||||
def __init__(self, client, room_id, event_id, reason=None):
|
def __init__(self, client, room_id, event_id, reason=None):
|
||||||
|
|
|
@ -143,3 +143,23 @@ class MatrixSendEvent(MatrixEvent):
|
||||||
False,
|
False,
|
||||||
parsed_dict
|
parsed_dict
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MatrixTopicEvent(MatrixEvent):
|
||||||
|
def __init__(self, server, room_id, event_id, topic):
|
||||||
|
self.room_id = room_id
|
||||||
|
self.topic = topic
|
||||||
|
self.event_id = event_id
|
||||||
|
MatrixEvent.__init__(self, server)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, server, room_id, topic, parsed_dict):
|
||||||
|
try:
|
||||||
|
return cls(server, room_id, parsed_dict["event_id"], topic)
|
||||||
|
except KeyError:
|
||||||
|
return MatrixErrorEvent.from_dict(
|
||||||
|
server,
|
||||||
|
"Error setting topic",
|
||||||
|
False,
|
||||||
|
parsed_dict
|
||||||
|
)
|
||||||
|
|
|
@ -683,6 +683,10 @@ def matrix_handle_message(
|
||||||
event = message.event
|
event = message.event
|
||||||
event.execute()
|
event.execute()
|
||||||
|
|
||||||
|
elif message_type is MessageType.TOPIC:
|
||||||
|
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']
|
||||||
|
|
||||||
|
@ -717,8 +721,7 @@ def matrix_handle_message(
|
||||||
room.prev_batch = response['end']
|
room.prev_batch = response['end']
|
||||||
|
|
||||||
# Nothing to do here, we'll handle topic changes and redactions in the sync
|
# Nothing to do here, we'll handle topic changes and redactions in the sync
|
||||||
elif (message_type == MessageType.TOPIC or
|
elif message_type == MessageType.REDACT:
|
||||||
message_type == MessageType.REDACT):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -765,14 +768,9 @@ def handle_http_response(server, message):
|
||||||
event.execute()
|
event.execute()
|
||||||
|
|
||||||
elif message.type == MessageType.TOPIC:
|
elif message.type == MessageType.TOPIC:
|
||||||
response = message.decoded_response
|
event = message.event
|
||||||
reason = ("." if not response or not response["error"] else
|
event.execute()
|
||||||
": {r}.".format(r=response["error"]))
|
|
||||||
|
|
||||||
error_message = ("{prefix}Can't set topic{reason}").format(
|
|
||||||
prefix=W.prefix("network"),
|
|
||||||
reason=reason)
|
|
||||||
server_buffer_prnt(server, error_message)
|
|
||||||
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