fix: Dont encrypt reactions

This fixes that server
sends notifications for reactions.
This commit is contained in:
Christian Pauly 2022-03-15 08:42:53 +01:00
parent d047678971
commit f1d422b89a
4 changed files with 14 additions and 5 deletions

View File

@ -336,6 +336,12 @@ class Encryption {
Future<Map<String, dynamic>> encryptGroupMessagePayload( Future<Map<String, dynamic>> encryptGroupMessagePayload(
String roomId, Map<String, dynamic> payload, String roomId, Map<String, dynamic> payload,
{String type = EventTypes.Message}) async { {String type = EventTypes.Message}) async {
final Map<String, dynamic>? mRelatesTo = payload.remove('m.relates_to');
// Events which only contain a m.relates_to like reactions don't need to
// be encrypted.
if (payload.isEmpty && mRelatesTo != null) {
return {'m.relates_to': mRelatesTo};
}
final room = client.getRoomById(roomId); final room = client.getRoomById(roomId);
if (room == null || !room.encrypted || !enabled) { if (room == null || !room.encrypted || !enabled) {
return payload; return payload;
@ -357,7 +363,6 @@ class Encryption {
// we clone the payload as we do not want to remove 'm.relates_to' from the // we clone the payload as we do not want to remove 'm.relates_to' from the
// original payload passed into this function // original payload passed into this function
payload = payload.copy(); payload = payload.copy();
final Map<String, dynamic>? mRelatesTo = payload.remove('m.relates_to');
final payloadContent = { final payloadContent = {
'content': payload, 'content': payload,
'type': type, 'type': type,

View File

@ -190,7 +190,6 @@ class Client extends MatrixApi {
EventTypes.Message, EventTypes.Message,
EventTypes.Encrypted, EventTypes.Encrypted,
EventTypes.Sticker, EventTypes.Sticker,
EventTypes.Reaction,
]); ]);
// register all the default commands // register all the default commands

View File

@ -769,14 +769,18 @@ class Room {
String? txid, String? txid,
}) async { }) async {
txid ??= client.generateUniqueTransactionId(); txid ??= client.generateUniqueTransactionId();
final mustEncrypt = encrypted && client.encryptionEnabled; final mustEncrypt = encrypted && client.encryptionEnabled;
final sendMessageContent = mustEncrypt final sendMessageContent = mustEncrypt
? await client.encryption! ? await client.encryption!
.encryptGroupMessagePayload(id, content, type: type) .encryptGroupMessagePayload(id, content, type: type)
: content; : content;
return await client.sendMessage( return await client.sendMessage(
id, id,
mustEncrypt ? EventTypes.Encrypted : type, sendMessageContent.containsKey('ciphertext')
? EventTypes.Encrypted
: type,
txid, txid,
sendMessageContent, sendMessageContent,
); );

View File

@ -277,8 +277,9 @@ void main() {
stateKey: '', stateKey: '',
), ),
); );
expect(room.lastEvent?.eventId, '123456'); expect(room.lastEvent?.eventId, '5');
expect(room.lastEvent?.type, EventTypes.Reaction); expect(room.lastEvent?.body, 'edited cdc');
expect(room.lastEvent?.status, EventStatus.sent);
}); });
test('lastEvent when reply parent edited', () async { test('lastEvent when reply parent edited', () async {
room.setState( room.setState(