rooms: Return an error event instead of None upon decryption failure.
This commit is contained in:
parent
4323931309
commit
dec12a898e
2 changed files with 33 additions and 2 deletions
|
@ -46,7 +46,8 @@ from .rooms import (
|
||||||
RoomRedactionEvent,
|
RoomRedactionEvent,
|
||||||
RoomRedactedMessageEvent,
|
RoomRedactedMessageEvent,
|
||||||
RoomEncryptionEvent,
|
RoomEncryptionEvent,
|
||||||
RoomPowerLevels
|
RoomPowerLevels,
|
||||||
|
UndecryptedEvent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -953,6 +954,18 @@ class RoomBuffer(object):
|
||||||
elif isinstance(event, RoomPowerLevels):
|
elif isinstance(event, RoomPowerLevels):
|
||||||
self._handle_power_level(event)
|
self._handle_power_level(event)
|
||||||
|
|
||||||
|
elif isinstance(event, UndecryptedEvent):
|
||||||
|
nick = self.find_nick(event.sender)
|
||||||
|
date = server_ts_to_weechat(event.timestamp)
|
||||||
|
data = ("Error decrypting event session "
|
||||||
|
"id: {}".format(event.session_id))
|
||||||
|
self.weechat_buffer.message(
|
||||||
|
nick,
|
||||||
|
data,
|
||||||
|
date,
|
||||||
|
self.get_event_tags(event)
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
W.prnt("", "Unhandled event of type {}.".format(
|
W.prnt("", "Unhandled event of type {}.".format(
|
||||||
type(event).__name__))
|
type(event).__name__))
|
||||||
|
|
|
@ -262,7 +262,7 @@ class RoomInfo():
|
||||||
)
|
)
|
||||||
|
|
||||||
if not plaintext:
|
if not plaintext:
|
||||||
return None
|
return UndecryptedEvent.from_dict(event_dict)
|
||||||
|
|
||||||
parsed_plaintext = json.loads(plaintext, encoding="utf-8")
|
parsed_plaintext = json.loads(plaintext, encoding="utf-8")
|
||||||
|
|
||||||
|
@ -328,6 +328,24 @@ class RoomEvent(object):
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
|
|
||||||
|
|
||||||
|
class UndecryptedEvent(RoomEvent):
|
||||||
|
def __init__(self, event_id, sender, timestamp, session_id):
|
||||||
|
self.session_id = session_id
|
||||||
|
RoomEvent.__init__(self, event_id, sender, timestamp)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, event):
|
||||||
|
event_id = (sanitize_id(event["event_id"])
|
||||||
|
if "event_id" in event else None)
|
||||||
|
sender = (sanitize_id(event["sender"])
|
||||||
|
if "sender" in event else None)
|
||||||
|
timestamp = (sanitize_ts(event["origin_server_ts"])
|
||||||
|
if "origin_server_ts" in event else None)
|
||||||
|
session_id = event["content"]["session_id"]
|
||||||
|
|
||||||
|
return cls(event_id, sender, timestamp, session_id)
|
||||||
|
|
||||||
|
|
||||||
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)
|
RoomEvent.__init__(self, event_id, sender, timestamp)
|
||||||
|
|
Loading…
Reference in a new issue