diff --git a/lib/src/utils/commands_extension.dart b/lib/src/utils/commands_extension.dart index 2f6d2fc5..132be15f 100644 --- a/lib/src/utils/commands_extension.dart +++ b/lib/src/utils/commands_extension.dart @@ -156,6 +156,25 @@ extension CommandsClientExtension on Client { if (inReplyTo == null) { return null; } + final match = RegExp(r':(?:([-\w]+)~)?([-\w]+):').firstMatch(args.msg); + if (match != null) { + final emotePacks = args.room.getImagePacksFlat(ImagePackUsage.emoticon); + final pack = match[1]; + final emote = match[2]; + String? mxc; + if (pack != null) { + mxc = emotePacks[pack]?[emote]; + } else { + for (final emotePack in emotePacks.values) { + mxc = emotePack[emote]; + break; + } + } + if (mxc != null) { + args.msg = mxc; + } + } + return await args.room.sendReaction(inReplyTo.eventId, args.msg); }); addCommand('join', (CommandArgs args) async { diff --git a/test/commands_test.dart b/test/commands_test.dart index c78fa50d..e60b77f9 100644 --- a/test/commands_test.dart +++ b/test/commands_test.dart @@ -156,6 +156,45 @@ void main() { }); }); + test('react_custom_emote', () async { + FakeMatrixApi.calledEndpoints.clear(); + room.setState(Event( + type: 'im.ponies.room_emotes', + content: { + 'images': { + 'room_plain': {'url': 'mxc://room_plain'} + } + }, + room: room, + stateKey: '', + senderId: '@fakeuser:fakeServer.notExisting', + eventId: '\$fakeid5:fakeServer.notExisting', + originServerTs: DateTime.now(), + )); + await room.sendTextEvent('/react :room_plain:', + inReplyTo: Event( + eventId: '\$event', + type: 'm.room.message', + content: { + 'msgtype': 'm.text', + 'body': 'yay', + 'format': 'org.matrix.custom.html', + 'formatted_body': 'yay', + }, + originServerTs: DateTime.now(), + senderId: client.userID!, + room: room, + )); + final sent = getLastMessagePayload('m.reaction'); + expect(sent, { + 'm.relates_to': { + 'rel_type': 'm.annotation', + 'event_id': '\$event', + 'key': 'mxc://room_plain', + }, + }); + }); + test('thread', () async { FakeMatrixApi.calledEndpoints.clear(); await room.sendTextEvent(