Function for getting avatar html

merge-requests/30/head
Bob Mottram 2020-11-30 15:20:10 +00:00
parent cfd5b6393e
commit 92e5576207
1 changed files with 54 additions and 35 deletions

View File

@ -207,6 +207,41 @@ def getAvatarImageUrl(session,
return avatarUrl return avatarUrl
def getAvatarLink(showAvatarOptions: bool,
nickname: str, domainFull: str,
avatarUrl: str, postActor: str,
translate: {}, avatarPosition: str,
pageNumber: int, messageIdStr: str) -> str:
"""Get html for the avatar image
"""
avatarLink = ''
if '/users/news/' not in avatarUrl:
avatarLink = ' <a class="imageAnchor" href="' + postActor + '">'
avatarLink += \
' <img loading="lazy" src="' + avatarUrl + '" title="' + \
translate['Show profile'] + '" alt=" "' + avatarPosition + \
'/></a>\n'
if showAvatarOptions and \
domainFull + '/users/' + nickname not in postActor:
if '/users/news/' not in avatarUrl:
avatarLink = \
' <a class="imageAnchor" href="/users/' + \
nickname + '?options=' + postActor + \
';' + str(pageNumber) + ';' + avatarUrl + messageIdStr + '">\n'
avatarLink += \
' <img loading="lazy" title="' + \
translate['Show options for this person'] + \
'" src="' + avatarUrl + '" ' + avatarPosition + '/></a>\n'
else:
# don't link to the person options for the news account
avatarLink += \
' <img loading="lazy" title="' + \
translate['Show options for this person'] + \
'" src="' + avatarUrl + '" ' + avatarPosition + '/>\n'
return avatarLink.strip()
def individualPostAsHtml(allowDownloads: bool, def individualPostAsHtml(allowDownloads: bool,
recentPostsCache: {}, maxRecentPosts: int, recentPostsCache: {}, maxRecentPosts: int,
iconsPath: str, translate: {}, iconsPath: str, translate: {},
@ -261,11 +296,11 @@ def individualPostAsHtml(allowDownloads: bool,
if messageId: if messageId:
messageIdStr = ';' + messageId messageIdStr = ';' + messageId
fullDomain = domain domainFull = domain
if port: if port:
if port != 80 and port != 443: if port != 80 and port != 443:
if ':' not in domain: if ':' not in domain:
fullDomain = domain + ':' + str(port) domainFull = domain + ':' + str(port)
pageNumberParam = '' pageNumberParam = ''
if pageNumber: if pageNumber:
@ -309,7 +344,8 @@ def individualPostAsHtml(allowDownloads: bool,
if timeDiff > 100: if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 5 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName + ' 5 = ' + str(timeDiff))
if fullDomain not in postActor: # get the display name
if domainFull not in postActor:
(inboxUrl, pubKeyId, pubKey, (inboxUrl, pubKeyId, pubKey,
fromPersonId, sharedInbox, fromPersonId, sharedInbox,
avatarUrl2, displayName) = getPersonBox(baseDir, session, wfRequest, avatarUrl2, displayName) = getPersonBox(baseDir, session, wfRequest,
@ -325,6 +361,7 @@ def individualPostAsHtml(allowDownloads: bool,
if avatarUrl2: if avatarUrl2:
avatarUrl = avatarUrl2 avatarUrl = avatarUrl2
if displayName: if displayName:
# add any emoji to the display name
if ':' in displayName: if ':' in displayName:
displayName = \ displayName = \
addEmojiToDisplayName(baseDir, httpPrefix, addEmojiToDisplayName(baseDir, httpPrefix,
@ -337,33 +374,15 @@ def individualPostAsHtml(allowDownloads: bool,
if timeDiff > 100: if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 7 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName + ' 7 = ' + str(timeDiff))
avatarLink = '' avatarLink = \
if '/users/news/' not in avatarUrl: getAvatarLink(showAvatarOptions,
avatarLink = ' <a class="imageAnchor" href="' + postActor + '">' nickname, domainFull,
avatarLink += \ avatarUrl, postActor,
' <img loading="lazy" src="' + avatarUrl + '" title="' + \ translate, avatarPosition,
translate['Show profile'] + '" alt=" "' + avatarPosition + \ pageNumber, messageIdStr)
'/></a>\n'
if showAvatarOptions and \
fullDomain + '/users/' + nickname not in postActor:
if '/users/news/' not in avatarUrl:
avatarLink = \
' <a class="imageAnchor" href="/users/' + \
nickname + '?options=' + postActor + \
';' + str(pageNumber) + ';' + avatarUrl + messageIdStr + '">\n'
avatarLink += \
' <img loading="lazy" title="' + \
translate['Show options for this person'] + \
'" src="' + avatarUrl + '" ' + avatarPosition + '/></a>\n'
else:
# don't link to the person options for the news account
avatarLink += \
' <img loading="lazy" title="' + \
translate['Show options for this person'] + \
'" src="' + avatarUrl + '" ' + avatarPosition + '/>\n'
avatarImageInPost = \ avatarImageInPost = \
' <div class="timeline-avatar">' + avatarLink.strip() + '</div>\n' ' <div class="timeline-avatar">' + avatarLink + '</div>\n'
# don't create new html within the bookmarks timeline # don't create new html within the bookmarks timeline
# it should already have been created for the inbox # it should already have been created for the inbox
@ -535,9 +554,9 @@ def individualPostAsHtml(allowDownloads: bool,
print('TIMING INDIV ' + boxName + ' 11 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName + ' 11 = ' + str(timeDiff))
editStr = '' editStr = ''
if (postJsonObject['actor'].endswith(fullDomain + '/users/' + nickname) or if (postJsonObject['actor'].endswith(domainFull + '/users/' + nickname) or
(isEditor(baseDir, nickname) and (isEditor(baseDir, nickname) and
postJsonObject['actor'].endswith(fullDomain + '/users/news'))): postJsonObject['actor'].endswith(domainFull + '/users/news'))):
if '/statuses/' in postJsonObject['object']['id']: if '/statuses/' in postJsonObject['object']['id']:
if isBlogPost(postJsonObject): if isBlogPost(postJsonObject):
blogPostId = postJsonObject['object']['id'] blogPostId = postJsonObject['object']['id']
@ -588,7 +607,7 @@ def individualPostAsHtml(allowDownloads: bool,
if not isPublicRepeat: if not isPublicRepeat:
announceLink = 'repeatprivate' announceLink = 'repeatprivate'
announceTitle = translate['Repeat this post'] announceTitle = translate['Repeat this post']
if announcedByPerson(postJsonObject, nickname, fullDomain): if announcedByPerson(postJsonObject, nickname, domainFull):
announceIcon = 'repeat.png' announceIcon = 'repeat.png'
if not isPublicRepeat: if not isPublicRepeat:
announceLink = 'unrepeatprivate' announceLink = 'unrepeatprivate'
@ -638,7 +657,7 @@ def individualPostAsHtml(allowDownloads: bool,
likeCountStr = ' (' + str(likeCount) + ')' likeCountStr = ' (' + str(likeCount) + ')'
else: else:
likeCountStr = ' (10+)' likeCountStr = ' (10+)'
if likedByPerson(postJsonObject, nickname, fullDomain): if likedByPerson(postJsonObject, nickname, domainFull):
if likeCount == 1: if likeCount == 1:
# liked by the reader only # liked by the reader only
likeCountStr = '' likeCountStr = ''
@ -683,7 +702,7 @@ def individualPostAsHtml(allowDownloads: bool,
bookmarkIcon = 'bookmark_inactive.png' bookmarkIcon = 'bookmark_inactive.png'
bookmarkLink = 'bookmark' bookmarkLink = 'bookmark'
bookmarkTitle = translate['Bookmark this post'] bookmarkTitle = translate['Bookmark this post']
if bookmarkedByPerson(postJsonObject, nickname, fullDomain): if bookmarkedByPerson(postJsonObject, nickname, domainFull):
bookmarkIcon = 'bookmark.png' bookmarkIcon = 'bookmark.png'
bookmarkLink = 'unbookmark' bookmarkLink = 'unbookmark'
bookmarkTitle = translate['Undo the bookmark'] bookmarkTitle = translate['Undo the bookmark']
@ -722,7 +741,7 @@ def individualPostAsHtml(allowDownloads: bool,
deleteStr = '' deleteStr = ''
muteStr = '' muteStr = ''
if (allowDeletion or if (allowDeletion or
('/' + fullDomain + '/' in postActor and ('/' + domainFull + '/' in postActor and
messageId.startswith(postActor))): messageId.startswith(postActor))):
if '/users/' + nickname + '/' in messageId: if '/users/' + nickname + '/' in messageId:
if not isNewsPost(postJsonObject): if not isNewsPost(postJsonObject):
@ -1075,7 +1094,7 @@ def individualPostAsHtml(allowDownloads: bool,
attachmentStr, galleryStr = \ attachmentStr, galleryStr = \
getPostAttachmentsAsHtml(postJsonObject, boxName, translate, getPostAttachmentsAsHtml(postJsonObject, boxName, translate,
isMuted, avatarLink.strip(), isMuted, avatarLink,
replyStr, announceStr, likeStr, replyStr, announceStr, likeStr,
bookmarkStr, deleteStr, muteStr) bookmarkStr, deleteStr, muteStr)