Function for reply icon html

main
Bob Mottram 2020-11-30 16:00:36 +00:00
parent eb6c220cec
commit 83e85a927c
1 changed files with 65 additions and 51 deletions

View File

@ -242,6 +242,63 @@ def getAvatarImageHtml(showAvatarOptions: bool,
return avatarLink.strip()
def getReplyIconHtml(nickname: str, isPublicRepeat: bool,
showIcons: bool, commentsEnabled: bool,
postJsonObject: {}, pageNumberParam: str,
iconsPath: str, translate: {}) -> str:
"""Returns html for the reply icon/button
"""
replyStr = ''
if showIcons and commentsEnabled:
# reply is permitted - create reply icon
replyToLink = postJsonObject['object']['id']
if postJsonObject['object'].get('attributedTo'):
if isinstance(postJsonObject['object']['attributedTo'], str):
replyToLink += \
'?mention=' + postJsonObject['object']['attributedTo']
if postJsonObject['object'].get('content'):
mentionedActors = \
getMentionsFromHtml(postJsonObject['object']['content'])
if mentionedActors:
for actorUrl in mentionedActors:
if '?mention=' + actorUrl not in replyToLink:
replyToLink += '?mention=' + actorUrl
if len(replyToLink) > 500:
break
replyToLink += pageNumberParam
replyStr = ''
if isPublicRepeat:
replyStr += \
' <a class="imageAnchor" href="/users/' + \
nickname + '?replyto=' + replyToLink + \
'?actor=' + postJsonObject['actor'] + \
'" title="' + translate['Reply to this post'] + '">\n'
else:
if isDM(postJsonObject):
replyStr += \
' ' + \
'<a class="imageAnchor" href="/users/' + nickname + \
'?replydm=' + replyToLink + \
'?actor=' + postJsonObject['actor'] + \
'" title="' + translate['Reply to this post'] + '">\n'
else:
replyStr += \
' ' + \
'<a class="imageAnchor" href="/users/' + nickname + \
'?replyfollowers=' + replyToLink + \
'?actor=' + postJsonObject['actor'] + \
'" title="' + translate['Reply to this post'] + '">\n'
replyStr += \
' ' + \
'<img loading="lazy" title="' + \
translate['Reply to this post'] + '" alt="' + \
translate['Reply to this post'] + \
' |" src="/' + iconsPath + '/reply.png"/></a>\n'
return replyStr
def individualPostAsHtml(allowDownloads: bool,
recentPostsCache: {}, maxRecentPosts: int,
iconsPath: str, translate: {},
@ -485,59 +542,16 @@ def individualPostAsHtml(allowDownloads: bool,
titleStr + ' <img loading="lazy" src="/' + \
iconsPath + '/dm.png" class="DMicon"/>\n'
replyStr = ''
# check if replying is permitted
commentsEnabled = True
if 'commentsEnabled' in postJsonObject['object']:
if postJsonObject['object']['commentsEnabled'] is False:
commentsEnabled = False
if showIcons and commentsEnabled:
# reply is permitted - create reply icon
replyToLink = postJsonObject['object']['id']
if postJsonObject['object'].get('attributedTo'):
if isinstance(postJsonObject['object']['attributedTo'], str):
replyToLink += \
'?mention=' + postJsonObject['object']['attributedTo']
if postJsonObject['object'].get('content'):
mentionedActors = \
getMentionsFromHtml(postJsonObject['object']['content'])
if mentionedActors:
for actorUrl in mentionedActors:
if '?mention=' + actorUrl not in replyToLink:
replyToLink += '?mention=' + actorUrl
if len(replyToLink) > 500:
break
replyToLink += pageNumberParam
replyStr = ''
if isPublicRepeat:
replyStr += \
' <a class="imageAnchor" href="/users/' + \
nickname + '?replyto=' + replyToLink + \
'?actor=' + postJsonObject['actor'] + \
'" title="' + translate['Reply to this post'] + '">\n'
else:
if isDM(postJsonObject):
replyStr += \
' ' + \
'<a class="imageAnchor" href="/users/' + nickname + \
'?replydm=' + replyToLink + \
'?actor=' + postJsonObject['actor'] + \
'" title="' + translate['Reply to this post'] + '">\n'
else:
replyStr += \
' ' + \
'<a class="imageAnchor" href="/users/' + nickname + \
'?replyfollowers=' + replyToLink + \
'?actor=' + postJsonObject['actor'] + \
'" title="' + translate['Reply to this post'] + '">\n'
replyStr += \
' ' + \
'<img loading="lazy" title="' + \
translate['Reply to this post'] + '" alt="' + \
translate['Reply to this post'] + \
' |" src="/' + iconsPath + '/reply.png"/></a>\n'
replyStr = getReplyIconHtml(nickname, isPublicRepeat,
showIcons, commentsEnabled,
postJsonObject, pageNumberParam,
iconsPath, translate)
# benchmark 10
if enableTimingLog: