rooms: Fix BadEvent creation.
This commit is contained in:
parent
783f2d59e8
commit
901b18ac06
2 changed files with 20 additions and 15 deletions
|
@ -954,7 +954,8 @@ class RoomBuffer(object):
|
||||||
self._handle_power_level(event)
|
self._handle_power_level(event)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
W.prnt("", "Unhandled event of type {}.".format(type(event)))
|
W.prnt("", "Unhandled event of type {}.".format(
|
||||||
|
type(event).__name__))
|
||||||
|
|
||||||
def self_message(self, message):
|
def self_message(self, message):
|
||||||
nick = self.find_nick(self.room.own_user_id)
|
nick = self.find_nick(self.room.own_user_id)
|
||||||
|
|
|
@ -275,19 +275,21 @@ class RoomInfo():
|
||||||
def _parse_events(olm, room_id, parsed_dict):
|
def _parse_events(olm, room_id, parsed_dict):
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
try:
|
|
||||||
for event in parsed_dict:
|
for event in parsed_dict:
|
||||||
|
try:
|
||||||
e = RoomInfo.parse_event(olm, room_id, event)
|
e = RoomInfo.parse_event(olm, room_id, event)
|
||||||
events.append(e)
|
|
||||||
except (ValueError, TypeError, KeyError) as error:
|
except (ValueError, TypeError, KeyError) as error:
|
||||||
message = ("{prefix}matrix: Error parsing "
|
message = ("{prefix}matrix: Error parsing "
|
||||||
"room event of type {type}: {error}\n{event}").format(
|
"room event of type {type}: "
|
||||||
|
"{error}\n{event}").format(
|
||||||
prefix=W.prefix("error"),
|
prefix=W.prefix("error"),
|
||||||
type=event["type"],
|
type=event["type"],
|
||||||
error=pformat(error),
|
error=pformat(error),
|
||||||
event=pformat(event))
|
event=pformat(event))
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
e = BadEvent.from_dict(event)
|
e = BadEvent.from_dict(event)
|
||||||
|
|
||||||
|
finally:
|
||||||
events.append(e)
|
events.append(e)
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
@ -318,7 +320,7 @@ class RoomInfo():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class RoomEvent():
|
class RoomEvent(object):
|
||||||
|
|
||||||
def __init__(self, event_id, sender, timestamp):
|
def __init__(self, event_id, sender, timestamp):
|
||||||
self.event_id = event_id
|
self.event_id = event_id
|
||||||
|
@ -328,14 +330,16 @@ class RoomEvent():
|
||||||
|
|
||||||
class BadEvent(RoomEvent):
|
class BadEvent(RoomEvent):
|
||||||
def __init__(self, event_id, sender, timestamp, source):
|
def __init__(self, event_id, sender, timestamp, source):
|
||||||
|
RoomEvent.__init__(self, event_id, sender, timestamp)
|
||||||
self.source = source
|
self.source = source
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def from_dict(cls, event):
|
def from_dict(cls, event):
|
||||||
event_id = (sanitize_id(event["event_id"])
|
event_id = (sanitize_id(event["event_id"])
|
||||||
if "event_id" in event else None)
|
if "event_id" in event else None)
|
||||||
sender = (sanitize_id(event["sender"])
|
sender = (sanitize_id(event["sender"])
|
||||||
if "sender" in event else None)
|
if "sender" in event else None)
|
||||||
timestamp = (sanitize_id(event["origin_server_ts"])
|
timestamp = (sanitize_ts(event["origin_server_ts"])
|
||||||
if "origin_server_ts" in event else None)
|
if "origin_server_ts" in event else None)
|
||||||
source = json.dumps(event)
|
source = json.dumps(event)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue