Merge branch 'client-feature-bad-encrypted' into 'master'
[Room] Return m.bad.encrypted See merge request famedly/famedlysdk!197
This commit is contained in:
commit
083dd8eb29
|
@ -248,6 +248,8 @@ class Event {
|
||||||
return MessageTypes.Sticker;
|
return MessageTypes.Sticker;
|
||||||
case "m.location":
|
case "m.location":
|
||||||
return MessageTypes.Location;
|
return MessageTypes.Location;
|
||||||
|
case "m.bad.encrypted":
|
||||||
|
return MessageTypes.BadEncrypted;
|
||||||
default:
|
default:
|
||||||
if (type == EventTypes.Message) {
|
if (type == EventTypes.Message) {
|
||||||
return MessageTypes.Text;
|
return MessageTypes.Text;
|
||||||
|
@ -378,7 +380,8 @@ class Event {
|
||||||
/// Searches for the reply event in the given timeline.
|
/// Searches for the reply event in the given timeline.
|
||||||
Future<Event> getReplyEvent(Timeline timeline) async {
|
Future<Event> getReplyEvent(Timeline timeline) async {
|
||||||
if (!isReply) return null;
|
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);
|
return await timeline.getEventById(replyEventId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -394,6 +397,7 @@ enum MessageTypes {
|
||||||
Location,
|
Location,
|
||||||
Reply,
|
Reply,
|
||||||
Sticker,
|
Sticker,
|
||||||
|
BadEncrypted,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1487,6 +1487,8 @@ class Room {
|
||||||
|
|
||||||
/// Decrypts the given [event] with one of the available ingoingGroupSessions.
|
/// Decrypts the given [event] with one of the available ingoingGroupSessions.
|
||||||
Event decryptGroupMessage(Event event) {
|
Event decryptGroupMessage(Event event) {
|
||||||
|
Map<String, dynamic> decryptedPayload;
|
||||||
|
try {
|
||||||
if (!client.encryptionEnabled) throw ("Encryption is not enabled");
|
if (!client.encryptionEnabled) throw ("Encryption is not enabled");
|
||||||
if (event.content["algorithm"] != "m.megolm.v1.aes-sha2") {
|
if (event.content["algorithm"] != "m.megolm.v1.aes-sha2") {
|
||||||
throw ("Unknown encryption algorithm");
|
throw ("Unknown encryption algorithm");
|
||||||
|
@ -1509,8 +1511,16 @@ class Room {
|
||||||
decryptResult.message_index;
|
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.
|
// 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 =
|
decryptedPayload = json.decode(decryptResult.plaintext);
|
||||||
json.decode(decryptResult.plaintext);
|
} catch (exception) {
|
||||||
|
decryptedPayload = {
|
||||||
|
"content": {
|
||||||
|
"msgtype": "m.bad.encrypted",
|
||||||
|
"body": exception.toString(),
|
||||||
|
},
|
||||||
|
"type": "m.room.message",
|
||||||
|
};
|
||||||
|
}
|
||||||
return Event(
|
return Event(
|
||||||
content: decryptedPayload["content"],
|
content: decryptedPayload["content"],
|
||||||
typeKey: decryptedPayload["type"],
|
typeKey: decryptedPayload["type"],
|
||||||
|
|
Loading…
Reference in a new issue