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, def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
actor: str) -> str: actor: str, maxReactionTypes: int) -> str:
"""html containing row of emoji reactions """html containing row of emoji reactions
""" """
if not hasObjectDict(postJsonObject): if not hasObjectDict(postJsonObject):
@ -515,7 +515,8 @@ 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']
if not reactions.get(emojiContent): if not reactions.get(emojiContent):
reactions[emojiContent] = 1 if len(reactions.items()) < maxReactionTypes:
reactions[emojiContent] = 1
else: else:
reactions[emojiContent] += 1 reactions[emojiContent] += 1
if len(reactions.items()) == 0: if len(reactions.items()) == 0:

View File

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