Merge branch 'krille/simplify-relates-to' into 'main'

refactor: Simplify relates to and make it more type safe

See merge request famedly/company/frontend/famedlysdk!981
This commit is contained in:
Krille Fear 2022-03-24 07:42:51 +00:00
commit 1411a3ceae
1 changed files with 5 additions and 11 deletions

View File

@ -673,17 +673,11 @@ class Event extends MatrixEvent {
/// Get the event ID that this relationship will reference. `null` if there is none /// Get the event ID that this relationship will reference. `null` if there is none
String? get relationshipEventId { String? get relationshipEventId {
if (!(content['m.relates_to'] is Map)) { final relatesToMap = content.tryGetMap<String, dynamic>('m.relates_to');
return null; return relatesToMap?.tryGet<String>('event_id') ??
} relatesToMap
if (content['m.relates_to'].containsKey('event_id')) { ?.tryGetMap<String, dynamic>('m.in_reply_to')
return content['m.relates_to']['event_id']; ?.tryGet<String>('event_id');
}
if (content['m.relates_to']['m.in_reply_to'] is Map &&
content['m.relates_to']['m.in_reply_to'].containsKey('event_id')) {
return content['m.relates_to']['m.in_reply_to']['event_id'];
}
return null;
} }
/// Get whether this event has aggregated events from a certain [type] /// Get whether this event has aggregated events from a certain [type]