Merge branch 'henri2h/dont-assume-redacts-is-valid' into 'main'
fix: don't assume redacts attribute from content to be valid See merge request famedly/company/frontend/famedlysdk!1131
This commit is contained in:
commit
d94bb1e480
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue