Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/src/utils/commands_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions test/commands_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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': '<b>yay</b>',
'format': 'org.matrix.custom.html',
'formatted_body': '<b>yay</b>',
},
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(
Expand Down