[Room] Return m.bad.encrypted

This commit is contained in:
Christian Pauly 2020-02-18 08:02:17 +01:00
parent bf23664ccd
commit e2c34b101e
2 changed files with 38 additions and 24 deletions

View file

@ -248,6 +248,8 @@ class Event {
return MessageTypes.Sticker;
case "m.location":
return MessageTypes.Location;
case "m.bad.encrypted":
return MessageTypes.BadEncrypted;
default:
if (type == EventTypes.Message) {
return MessageTypes.Text;
@ -378,7 +380,8 @@ class Event {
/// Searches for the reply event in the given timeline.
Future<Event> getReplyEvent(Timeline timeline) async {
if (!isReply) return null;
final String replyEventId = content['m.relates_to']['m.in_reply_to']['event_id'];
final String replyEventId =
content['m.relates_to']['m.in_reply_to']['event_id'];
return await timeline.getEventById(replyEventId);
}
}
@ -394,6 +397,7 @@ enum MessageTypes {
Location,
Reply,
Sticker,
BadEncrypted,
None,
}

View file

@ -1487,6 +1487,8 @@ class Room {
/// Decrypts the given [event] with one of the available ingoingGroupSessions.
Event decryptGroupMessage(Event event) {
Map<String, dynamic> decryptedPayload;
try {
if (!client.encryptionEnabled) throw ("Encryption is not enabled");
if (event.content["algorithm"] != "m.megolm.v1.aes-sha2") {
throw ("Unknown encryption algorithm");
@ -1509,8 +1511,16 @@ class Room {
decryptResult.message_index;
// TODO: The client should check that the sender's fingerprint key matches the keys.ed25519 property of the event which established the Megolm session when marking the event as verified.
final Map<String, dynamic> decryptedPayload =
json.decode(decryptResult.plaintext);
decryptedPayload = json.decode(decryptResult.plaintext);
} catch (exception) {
decryptedPayload = {
"content": {
"msgtype": "m.bad.encrypted",
"body": exception.toString(),
},
"type": "m.room.message",
};
}
return Event(
content: decryptedPayload["content"],
typeKey: decryptedPayload["type"],