From d6e9131b12e95f1d7805fb7f576920b2303f42c9 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Fri, 15 May 2020 21:05:28 +0200 Subject: [PATCH] change emote packs slightly --- lib/src/room.dart | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 2d76ee2..3457b92 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -497,9 +497,31 @@ class Room { return resp['event_id']; } + /// return all current emote packs for this room + Map> get emotePacks { + final packs = >{}; + final addEmotePack = (String packName, Map content) { + packs[packName] = {}; + content.forEach((key, value) { + if (key is String && value is String && value.startsWith('mxc://')) { + packs[packName][key] = value; + } + }); + }; + final roomEmotes = getState('im.ponies.room_emotes'); + final userEmotes = client.accountData['im.ponies.user_emotes']; + if (roomEmotes != null && roomEmotes.content['short'] is Map) { + addEmotePack('room', roomEmotes.content['short']); + } + if (userEmotes != null && userEmotes.content['short'] is Map) { + addEmotePack('user', userEmotes.content['short']); + } + return packs; + } + /// Sends a normal text message to this room. Returns the event ID generated /// by the server for this message. - Future sendTextEvent(String message, {String txid, Event inReplyTo, bool parseMarkdown = true}) { + Future sendTextEvent(String message, {String txid, Event inReplyTo, bool parseMarkdown = true, Map> emotePacks}) { final event = { 'msgtype': 'm.text', 'body': message, @@ -509,25 +531,7 @@ class Room { event['body'] = message.substring(4); } if (parseMarkdown) { - // load the emote packs - final emotePacks = >{}; - final addEmotePack = (String packName, Map content) { - emotePacks[packName] = {}; - content.forEach((key, value) { - if (key is String && value is String && value.startsWith('mxc://')) { - emotePacks[packName][key] = value; - } - }); - }; - final roomEmotes = getState('im.ponies.room_emotes'); - final userEmotes = client.accountData['im.ponies.user_emotes']; - if (roomEmotes != null && roomEmotes.content['short'] is Map) { - addEmotePack('room', roomEmotes.content['short']); - } - if (userEmotes != null && userEmotes.content['short'] is Map) { - addEmotePack('user', userEmotes.content['short']); - } - final html = markdown(event['body'], emotePacks); + final html = markdown(event['body'], emotePacks ?? this.emotePacks); // if the decoded html is the same as the body, there is no need in sending a formatted message if (HtmlUnescape().convert(html) != event['body']) { event['format'] = 'org.matrix.custom.html';