chore: Update emotes to match MSC

This commit is contained in:
Sorunome 2020-09-04 13:52:59 +02:00 committed by Christian Pauly
parent 8a0cc70cfe
commit f7e63097b4
3 changed files with 19 additions and 16 deletions

View File

@ -437,6 +437,7 @@ class Room {
name = name.replaceAll(RegExp(r'[^\w-]'), '');
return name.toLowerCase();
};
final allMxcs = <String>{}; // for easy dedupint
final addEmotePack = (String packName, Map<String, dynamic> 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;
}

View File

@ -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);

View File

@ -54,11 +54,11 @@ void main() {
});
test('emotes', () {
expect(markdown(':fox:', emotePacks),
'<img data-mx-emote="" src="mxc:&#47;&#47;roomfox" alt=":fox:" title=":fox:" height="32" vertical-align="middle" />');
'<img data-mx-emoticon="" src="mxc:&#47;&#47;roomfox" alt=":fox:" title=":fox:" height="32" vertical-align="middle" />');
expect(markdown(':user~fox:', emotePacks),
'<img data-mx-emote="" src="mxc:&#47;&#47;userfox" alt=":fox:" title=":fox:" height="32" vertical-align="middle" />');
'<img data-mx-emoticon="" src="mxc:&#47;&#47;userfox" alt=":fox:" title=":fox:" height="32" vertical-align="middle" />');
expect(markdown(':raccoon:', emotePacks),
'<img data-mx-emote="" src="mxc:&#47;&#47;raccoon" alt=":raccoon:" title=":raccoon:" height="32" vertical-align="middle" />');
'<img data-mx-emoticon="" src="mxc:&#47;&#47;raccoon" alt=":raccoon:" title=":raccoon:" height="32" vertical-align="middle" />');
expect(markdown(':invalid:', emotePacks), ':invalid:');
expect(markdown(':room~invalid:', emotePacks), ':room~invalid:');
});