fix: don't assume redacts attribute from content to be valid

This commit is contained in:
henri2h 2022-09-12 17:09:29 +02:00
parent 7a9e5cbb85
commit 7b61f8eb01
5 changed files with 23 additions and 14 deletions

View File

@ -2061,7 +2061,8 @@ class Client extends MatrixApi {
case EventUpdateType.inviteState: case EventUpdateType.inviteState:
final stateEvent = Event.fromJson(eventUpdate.content, room); final stateEvent = Event.fromJson(eventUpdate.content, room);
if (stateEvent.type == EventTypes.Redaction) { if (stateEvent.type == EventTypes.Redaction) {
final String redacts = eventUpdate.content['redacts']; final String? redacts = eventUpdate.content.tryGet<String>('redacts');
if (redacts != null) {
room.states.forEach( room.states.forEach(
(String key, Map<String, Event> states) => states.forEach( (String key, Map<String, Event> states) => states.forEach(
(String key, Event state) { (String key, Event state) {
@ -2071,6 +2072,7 @@ class Client extends MatrixApi {
}, },
), ),
); );
}
} else { } else {
// We want to set state the in-memory cache for the room with the new event. // We want to set state the in-memory cache for the room with the new event.
// To do this, we have to respect to not save edits, unless they edit the // To do this, we have to respect to not save edits, unless they edit the

View File

@ -937,7 +937,9 @@ class FluffyBoxDatabase extends DatabaseApi {
// In case of this is a redaction event // In case of this is a redaction event
if (eventUpdate.content['type'] == EventTypes.Redaction) { if (eventUpdate.content['type'] == EventTypes.Redaction) {
final event = await getEventById(eventUpdate.content['redacts'], tmpRoom); final eventId = eventUpdate.content.tryGet<String>('redacts');
final event =
eventId != null ? await getEventById(eventId, tmpRoom) : null;
if (event != null) { if (event != null) {
event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom)); event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom));
await _eventsBox.put( await _eventsBox.put(

View File

@ -963,7 +963,9 @@ class HiveCollectionsDatabase extends DatabaseApi {
// In case of this is a redaction event // In case of this is a redaction event
if (eventUpdate.content['type'] == EventTypes.Redaction) { if (eventUpdate.content['type'] == EventTypes.Redaction) {
final event = await getEventById(eventUpdate.content['redacts'], tmpRoom); final eventId = eventUpdate.content.tryGet<String>('redacts');
final event =
eventId != null ? await getEventById(eventId, tmpRoom) : null;
if (event != null) { if (event != null) {
event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom)); event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom));
await _eventsBox.put( await _eventsBox.put(

View File

@ -910,7 +910,9 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
// In case of this is a redaction event // In case of this is a redaction event
if (eventUpdate.content['type'] == EventTypes.Redaction) { if (eventUpdate.content['type'] == EventTypes.Redaction) {
final tmpRoom = Room(id: eventUpdate.roomID, client: client); final tmpRoom = Room(id: eventUpdate.roomID, client: client);
final event = await getEventById(eventUpdate.content['redacts'], tmpRoom); final eventId = eventUpdate.content.tryGet<String>('redacts');
final event =
eventId != null ? await getEventById(eventId, tmpRoom) : null;
if (event != null) { if (event != null) {
event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom)); event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom));
await _eventsBox.put( await _eventsBox.put(

View File

@ -504,7 +504,8 @@ class Timeline {
// Handle redaction events // Handle redaction events
if (eventUpdate.content['type'] == EventTypes.Redaction) { if (eventUpdate.content['type'] == EventTypes.Redaction) {
final index = _findEvent(event_id: eventUpdate.content['redacts']); final index =
_findEvent(event_id: eventUpdate.content.tryGet<String>('redacts'));
if (index < events.length) { if (index < events.length) {
removeAggregatedEvent(events[index]); removeAggregatedEvent(events[index]);