From bc7f1ef8ddcd3c30e7c1ca27676989bb2b296f0f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 19 Aug 2019 13:59:57 +0100 Subject: [PATCH] Emoji image replacement --- content.py | 6 +++--- webinterface.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/content.py b/content.py index 053522830..0a513a969 100644 --- a/content.py +++ b/content.py @@ -89,12 +89,12 @@ def addEmoji(baseDir: str,wordStr: str,httpPrefix: str,domain: str,replaceEmoji: return False emojiUrl=httpPrefix+"://"+domain+"/emoji/"+emojiDict[emoji]+'.png' postTags[emoji]= { - 'href': emojiUrl, + 'id': emojiUrl, 'name': ':'+emoji+':', 'type': 'Emoji' } - replaceEmoji[wordStr]= \ - "\""+emoji+"\"" + #replaceEmoji[wordStr]= \ + # "\""+emoji+"\"" return True def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},recipients: [],tags: {}) -> bool: diff --git a/webinterface.py b/webinterface.py index a5e35cc19..e8f4605d0 100644 --- a/webinterface.py +++ b/webinterface.py @@ -940,6 +940,24 @@ def contentWarningScript() -> str: '}' return script +def htmlRemplaceEmojiFromTags(content: str,tag: {}) -> str: + """Uses the tags to replace :emoji: with html image markup + """ + for tagItem in tag: + if not tagItem.get('id'): + continue + if not tagItem.get('type'): + continue + if not tagItem.get('name'): + continue + if tagItem['type']!='Emoji': + continue + if tagItem['name'] not in content: + continue + emojiHtml="\""+tagItem['name'].replace(':','')+"\"" + content=content.replace(tagItem['name'],emojiHtml) + return content + def individualPostAsHtml(baseDir: str, \ session,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int, \ @@ -1158,6 +1176,9 @@ def individualPostAsHtml(baseDir: str, \ contentStr+=postJsonObject['object']['content']+attachmentStr contentStr+='' + if postJsonObject['object'].get('tag'): + contentStr=htmlRemplaceEmojiFromTags(contentStr,postJsonObject['object']['tag']) + return \ '
\n'+ \ avatarDropdown+ \