diff --git a/lib/src/event.dart b/lib/src/event.dart index 608d3f1f..051093c5 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -626,16 +626,15 @@ class Event extends MatrixEvent { /// Get the relationship type of an event. `null` if there is none String get relationshipType { - if (content == null || !(content['m.relates_to'] is Map)) { + if (content?.tryGet>('m.relates_to') == null) { return null; } - if (content['m.relates_to'].containsKey('rel_type')) { - return content['m.relates_to']['rel_type']; - } if (content['m.relates_to'].containsKey('m.in_reply_to')) { return RelationshipTypes.Reply; } - return null; + return content + .tryGet>('m.relates_to') + .tryGet('rel_type'); } /// Get the event ID that this relationship will reference. `null` if there is none diff --git a/test/event_test.dart b/test/event_test.dart index 6bbcdeac..ccd98e41 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -174,7 +174,7 @@ void main() { jsonObj['type'] = 'm.room.message'; jsonObj['content']['msgtype'] = 'm.text'; - jsonObj['content']['m.relates_to'] = {}; + jsonObj['content']['m.relates_to'] = {}; jsonObj['content']['m.relates_to']['m.in_reply_to'] = { 'event_id': '1234', };