Show handles for emoji reactions, same as matrix

main
Bob Mottram 2021-11-13 20:48:53 +00:00
parent d87cb69fd0
commit 0a5657fba4
1 changed files with 24 additions and 4 deletions

View File

@ -517,6 +517,7 @@ def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
actor: str, maxReactionTypes: int, actor: str, maxReactionTypes: int,
boxName: str, pageNumber: int) -> str: boxName: str, pageNumber: int) -> str:
"""html containing row of emoji reactions """html containing row of emoji reactions
displayed at the bottom of posts, above the icons
""" """
if not hasObjectDict(postJsonObject): if not hasObjectDict(postJsonObject):
return '' return ''
@ -531,19 +532,37 @@ def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
for item in postJsonObject['object']['reactions']['items']: for item in postJsonObject['object']['reactions']['items']:
emojiContent = item['content'] emojiContent = item['content']
emojiActor = item['actor'] emojiActor = item['actor']
emojiNickname = getNicknameFromActor(emojiActor)
emojiDomain, _ = getDomainFromActor(emojiActor)
emojiHandle = emojiNickname + '@' + emojiDomain
if emojiActor == actor: if emojiActor == actor:
if emojiContent not in reactedToByThisActor: if emojiContent not in reactedToByThisActor:
reactedToByThisActor.append(emojiContent) reactedToByThisActor.append(emojiContent)
if not reactions.get(emojiContent): if not reactions.get(emojiContent):
if len(reactions.items()) < maxReactionTypes: if len(reactions.items()) < maxReactionTypes:
reactions[emojiContent] = 1 reactions[emojiContent] = {
"handles": [emojiHandle],
"count": 1
}
else: else:
reactions[emojiContent] += 1 reactions[emojiContent]['count'] += 1
if len(reactions[emojiContent]['handles']) < 32:
reactions[emojiContent]['handles'].append(emojiHandle)
if len(reactions.items()) == 0: if len(reactions.items()) == 0:
return '' return ''
reactBy = removeIdEnding(postJsonObject['object']['id']) reactBy = removeIdEnding(postJsonObject['object']['id'])
htmlStr = '<div class="emojiReactionBar">\n' htmlStr = '<div class="emojiReactionBar">\n'
for emojiContent, count in reactions.items(): for emojiContent, item in reactions.items():
count = item['count']
# get the handles of actors who reacted
handlesStr = ''
item['handles'].sort()
for handle in item['handles']:
if handlesStr:
handlesStr += '&#10;'
handlesStr += handle
if emojiContent not in reactedToByThisActor: if emojiContent not in reactedToByThisActor:
baseUrl = actor + '?react=' + reactBy baseUrl = actor + '?react=' + reactBy
else: else:
@ -563,7 +582,8 @@ def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
# urlencode the emoji # urlencode the emoji
emojiContentEncoded = urllib.parse.quote_plus(emojiContent) emojiContentEncoded = urllib.parse.quote_plus(emojiContent)
emojiContentStr = \ emojiContentStr = \
' <a href="' + baseUrl + emojiContentEncoded + '">' + \ ' <a href="' + baseUrl + emojiContentEncoded + \
'" title="' + handlesStr + '">' + \
emojiContentStr + '</a>\n' emojiContentStr + '</a>\n'
htmlStr += emojiContentStr htmlStr += emojiContentStr
htmlStr += ' </div>\n' htmlStr += ' </div>\n'