[Timeline] Try to decrypt but not block

This commit is contained in:
Christian Pauly 2020-02-15 08:58:08 +00:00
parent 4921c4c31b
commit 3c386391cf
4 changed files with 26 additions and 30 deletions

View file

@ -1178,20 +1178,7 @@ class Client {
); );
this.store?.storeEventUpdate(update); this.store?.storeEventUpdate(update);
if (event["type"] == "m.room.encrypted") { if (event["type"] == "m.room.encrypted") {
Room room = getRoomById(roomID); update = update.decrypt(this.getRoomById(update.roomID));
try {
Event decrpytedEvent =
room.decryptGroupMessage(Event.fromJson(event, room));
event = decrpytedEvent.toJson();
update = EventUpdate(
eventType: event["type"],
roomID: roomID,
type: type,
content: event,
);
} catch (e) {
print("[LibOlm] Could not decrypt megolm event: " + e.toString());
}
} }
_updateRoomsByEventUpdate(update); _updateRoomsByEventUpdate(update);
onEvent.add(update); onEvent.add(update);

View file

@ -698,7 +698,7 @@ class Room {
eventType: resp["state"][i]["type"], eventType: resp["state"][i]["type"],
content: resp["state"][i], content: resp["state"][i],
); );
client.onEvent.add(eventUpdate); client.onEvent.add(eventUpdate.decrypt(this));
client.store.storeEventUpdate(eventUpdate); client.store.storeEventUpdate(eventUpdate);
} }
return; return;
@ -711,7 +711,7 @@ class Room {
eventType: resp["state"][i]["type"], eventType: resp["state"][i]["type"],
content: resp["state"][i], content: resp["state"][i],
); );
client.onEvent.add(eventUpdate); client.onEvent.add(eventUpdate.decrypt(this));
} }
} }
} }
@ -725,7 +725,7 @@ class Room {
eventType: history[i]["type"], eventType: history[i]["type"],
content: history[i], content: history[i],
); );
client.onEvent.add(eventUpdate); client.onEvent.add(eventUpdate.decrypt(this));
client.store.storeEventUpdate(eventUpdate); client.store.storeEventUpdate(eventUpdate);
client.store.setRoomPrevBatch(id, resp["end"]); client.store.setRoomPrevBatch(id, resp["end"]);
} }
@ -739,7 +739,7 @@ class Room {
eventType: history[i]["type"], eventType: history[i]["type"],
content: history[i], content: history[i],
); );
client.onEvent.add(eventUpdate); client.onEvent.add(eventUpdate.decrypt(this));
} }
} }
client.onRoomUpdate.add( client.onRoomUpdate.add(

View file

@ -21,6 +21,8 @@
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>. * along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/ */
import '../../famedlysdk.dart';
/// Represents a new event (e.g. a message in a room) or an update for an /// Represents a new event (e.g. a message in a room) or an update for an
/// already known event. /// already known event.
class EventUpdate { class EventUpdate {
@ -39,4 +41,23 @@ class EventUpdate {
final Map<String, dynamic> content; final Map<String, dynamic> content;
EventUpdate({this.eventType, this.roomID, this.type, this.content}); EventUpdate({this.eventType, this.roomID, this.type, this.content});
EventUpdate decrypt(Room room) {
if (eventType != "m.room.encrypted") {
return this;
}
try {
Event decrpytedEvent =
room.decryptGroupMessage(Event.fromJson(content, room));
return EventUpdate(
eventType: eventType,
roomID: roomID,
type: type,
content: decrpytedEvent.toJson(),
);
} catch (e) {
print("[LibOlm] Could not decrypt megolm event: " + e.toString());
return this;
}
}
} }

View file

@ -92,18 +92,6 @@ class Timeline {
try { try {
if (eventUpdate.roomID != room.id) return; if (eventUpdate.roomID != room.id) return;
if (eventUpdate.eventType == "m.room.encrypted") {
Event decrypted =
room.decryptGroupMessage(Event.fromJson(eventUpdate.content, room));
eventUpdate = EventUpdate(
eventType: decrypted.typeKey,
content: eventUpdate.content,
type: eventUpdate.type,
roomID: eventUpdate.roomID,
);
eventUpdate.content["content"] = decrypted.content;
}
if (eventUpdate.type == "timeline" || eventUpdate.type == "history") { if (eventUpdate.type == "timeline" || eventUpdate.type == "history") {
// Redaction events are handled as modification for existing events. // Redaction events are handled as modification for existing events.
if (eventUpdate.eventType == "m.room.redaction") { if (eventUpdate.eventType == "m.room.redaction") {