Limit the number of reaction types which can be shown on a post

merge-requests/30/head
Bob Mottram 2021-11-10 17:20:59 +00:00
parent bdd63be131
commit af69491fe9
2 changed files with 10 additions and 3 deletions

View File

@ -502,7 +502,7 @@ def updateReactionCollection(recentPostsCache: {},
def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
actor: str) -> str:
actor: str, maxReactionTypes: int) -> str:
"""html containing row of emoji reactions
"""
if not hasObjectDict(postJsonObject):
@ -515,7 +515,8 @@ def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
for item in postJsonObject['object']['reactions']['items']:
emojiContent = item['content']
if not reactions.get(emojiContent):
reactions[emojiContent] = 1
if len(reactions.items()) < maxReactionTypes:
reactions[emojiContent] = 1
else:
reactions[emojiContent] += 1
if len(reactions.items()) == 0:

View File

@ -1304,6 +1304,10 @@ def individualPostAsHtml(signingPrivateKeyPem: str,
if not postJsonObject:
return ''
# maximum number of different emoji reactions which can
# be added to a post
maxReactionTypes = 5
# benchmark
postStartTime = time.time()
@ -1882,7 +1886,9 @@ def individualPostAsHtml(signingPrivateKeyPem: str,
if boxName != 'tlmedia':
reactionStr = ''
if showIcons:
reactionStr = htmlEmojiReactions(postJsonObject, True, personUrl)
reactionStr = \
htmlEmojiReactions(postJsonObject, True, personUrl,
maxReactionTypes)
if postIsSensitive and reactionStr:
reactionStr = '<br>' + reactionStr
postHtml = ' <div id="' + timelinePostBookmark + \