Add topic event class.

This commit is contained in:
poljar (Damir Jelić) 2018-02-14 11:51:57 +01:00
parent e4f042a6a7
commit 4537635db3
3 changed files with 37 additions and 9 deletions

View file

@ -360,6 +360,16 @@ class MatrixTopicMessage(MatrixMessage):
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):
def __init__(self, client, room_id, event_id, reason=None):

View file

@ -143,3 +143,23 @@ class MatrixSendEvent(MatrixEvent):
False,
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
)

View file

@ -683,6 +683,10 @@ def matrix_handle_message(
event = message.event
event.execute()
elif message_type is MessageType.TOPIC:
event = message.event
event.execute()
elif message_type is MessageType.SYNC:
next_batch = response['next_batch']
@ -717,8 +721,7 @@ def matrix_handle_message(
room.prev_batch = response['end']
# Nothing to do here, we'll handle topic changes and redactions in the sync
elif (message_type == MessageType.TOPIC or
message_type == MessageType.REDACT):
elif message_type == MessageType.REDACT:
pass
else:
@ -765,14 +768,9 @@ def handle_http_response(server, message):
event.execute()
elif message.type == MessageType.TOPIC:
response = message.decoded_response
reason = ("." if not response or not response["error"] else
": {r}.".format(r=response["error"]))
event = message.event
event.execute()
error_message = ("{prefix}Can't set topic{reason}").format(
prefix=W.prefix("network"),
reason=reason)
server_buffer_prnt(server, error_message)
else:
error_message = ("{prefix}Unhandled 403 error, please inform the "
"developers about this: {error}").format(