diff --git a/lib/src/event.dart b/lib/src/event.dart index 43f4d27c..3cb2da50 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -1180,6 +1180,17 @@ class Event extends MatrixEvent { (fileSendingStatus) => fileSendingStatus.name == status, ); } + + /// Returns the mentioned userIds and wether the event includes an @room + /// mention. This is only determined by the `m.mention` object in the event + /// content. + ({List userIds, bool room}) get mentions { + final mentionsMap = content.tryGetMap('m.mentions'); + return ( + userIds: mentionsMap?.tryGetList('user_ids') ?? [], + room: mentionsMap?.tryGet('room') ?? false, + ); + } } enum FileSendingStatus { diff --git a/test/event_test.dart b/test/event_test.dart index 7f244095..a5166ce9 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -2951,5 +2951,28 @@ void main() async { Timeline(room: room, chunk: TimelineChunk(events: [targetEvent])); expect(await event.getReplyEvent(timeline), targetEvent); }); + test('getMentions', () { + final event = Event.fromJson( + { + 'content': { + 'msgtype': 'text', + 'body': 'Hello world @alice:matrix.org', + 'm.mentions': { + 'user_ids': ['@alice:matrix.org'], + 'room': false, + } + }, + 'event_id': '\$143273582443PhrSn:example.org', + 'origin_server_ts': 1432735824653, + 'room_id': room.id, + 'sender': '@example:example.org', + 'type': 'm.room.message', + 'unsigned': {'age': 1234}, + }, + room, + ); + expect(event.mentions.userIds, ['@alice:matrix.org']); + expect(event.mentions.room, false); + }); }); }