diff --git a/lib/src/room.dart b/lib/src/room.dart index fd9999c..8f528e5 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -437,6 +437,7 @@ class Room { name = name.replaceAll(RegExp(r'[^\w-]'), ''); return name.toLowerCase(); }; + final allMxcs = {}; // for easy dedupint final addEmotePack = (String packName, Map content, [String packNameOverride]) { if (!(content['short'] is Map)) { @@ -454,25 +455,18 @@ class Room { } content['short'].forEach((key, value) { if (key is String && value is String && value.startsWith('mxc://')) { - packs[packName][key] = value; + if (allMxcs.add(value)) { + packs[packName][key] = value; + } } }); }; - // first add all the room emotes - final allRoomEmotes = states.states['im.ponies.room_emotes']; - if (allRoomEmotes != null) { - for (final entry in allRoomEmotes.entries) { - final stateKey = entry.key; - final event = entry.value; - addEmotePack(stateKey.isEmpty ? 'room' : stateKey, event.content); - } - } - // next add all the user emotes + // first add all the user emotes final userEmotes = client.accountData['im.ponies.user_emotes']; if (userEmotes != null) { addEmotePack('user', userEmotes.content); } - // finally add all the external emote rooms + // next add all the external emote rooms final emoteRooms = client.accountData['im.ponies.emote_rooms']; if (emoteRooms != null && emoteRooms.content['rooms'] is Map) { for (final roomEntry in emoteRooms.content['rooms'].entries) { @@ -497,6 +491,15 @@ class Room { } } } + // finally add all the room emotes + final allRoomEmotes = states.states['im.ponies.room_emotes']; + if (allRoomEmotes != null) { + for (final entry in allRoomEmotes.entries) { + final stateKey = entry.key; + final event = entry.value; + addEmotePack(stateKey.isEmpty ? 'room' : stateKey, event.content); + } + } return packs; } diff --git a/lib/src/utils/markdown.dart b/lib/src/utils/markdown.dart index 082513b..745601b 100644 --- a/lib/src/utils/markdown.dart +++ b/lib/src/utils/markdown.dart @@ -65,7 +65,7 @@ class EmoteSyntax extends InlineSyntax { return true; } final element = Element.empty('img'); - element.attributes['data-mx-emote'] = ''; + element.attributes['data-mx-emoticon'] = ''; element.attributes['src'] = htmlEscape.convert(mxc); element.attributes['alt'] = htmlEscape.convert(emote); element.attributes['title'] = htmlEscape.convert(emote); diff --git a/test/markdown_test.dart b/test/markdown_test.dart index 9a4b999..7690d4b 100644 --- a/test/markdown_test.dart +++ b/test/markdown_test.dart @@ -54,11 +54,11 @@ void main() { }); test('emotes', () { expect(markdown(':fox:', emotePacks), - ':fox:'); + ':fox:'); expect(markdown(':user~fox:', emotePacks), - ':fox:'); + ':fox:'); expect(markdown(':raccoon:', emotePacks), - ':raccoon:'); + ':raccoon:'); expect(markdown(':invalid:', emotePacks), ':invalid:'); expect(markdown(':room~invalid:', emotePacks), ':room~invalid:'); });