From 19426791728802a7635b28920e17434e7dc02732 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 1 Dec 2020 12:30:17 +0000 Subject: [PATCH] Function for showing title on reply posts --- webapp_post.py | 385 ++++++++++++++++++++++++++++--------------------- 1 file changed, 221 insertions(+), 164 deletions(-) diff --git a/webapp_post.py b/webapp_post.py index 93d0e8b5..9d6349a7 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -840,6 +840,208 @@ def getPostTitleAnnounceHtml(baseDir: str, containerClassIcons, containerClass) +def replyToYourselfHtml(translate: {}, iconsPath: str) -> str: + """Returns html for a title which is a reply to yourself + """ + return ' ' + translate['replying to themselves'] + \
+        '\n' + + +def getPostTitleReplyHtml(baseDir: str, + httpPrefix: str, + nickname: str, domain: str, + showRepeatIcon: bool, + isAnnounced: bool, + postJsonObject: {}, + postActor: str, + translate: {}, + iconsPath: str, + enableTimingLog: bool, + postStartTime, + boxName: str, + personCache: {}, + allowDownloads: bool, + avatarPosition: str, + pageNumber: int, + messageIdStr: str, + containerClassIcons: str, + containerClass: str) -> (str, str, str, str): + """Returns the reply title of a post containing names of participants + x replies to y + """ + titleStr = '' + replyAvatarImageInPost = '' + + if not postJsonObject['object'].get('inReplyTo'): + return (titleStr, replyAvatarImageInPost, + containerClassIcons, containerClass) + + containerClassIcons = 'containericons darker' + containerClass = 'container darker' + if postJsonObject['object']['inReplyTo'].startswith(postActor): + titleStr += replyToYourselfHtml(translate, iconsPath) + return (titleStr, replyAvatarImageInPost, + containerClassIcons, containerClass) + + if '/statuses/' in postJsonObject['object']['inReplyTo']: + inReplyTo = postJsonObject['object']['inReplyTo'] + replyActor = inReplyTo.split('/statuses/')[0] + replyNickname = getNicknameFromActor(replyActor) + if replyNickname: + replyDomain, replyPort = \ + getDomainFromActor(replyActor) + if replyNickname and replyDomain: + getPersonFromCache(baseDir, replyActor, + personCache, + allowDownloads) + replyDisplayName = \ + getDisplayName(baseDir, replyActor, + personCache) + if replyDisplayName: + if ':' in replyDisplayName: + # benchmark 13.5 + if enableTimingLog: + timeDiff = \ + int((time.time() - + postStartTime) * 1000) + if timeDiff > 100: + print('TIMING INDIV ' + + boxName + ' 13.5 = ' + + str(timeDiff)) + repDisp = replyDisplayName + replyDisplayName = \ + addEmojiToDisplayName(baseDir, + httpPrefix, + nickname, + domain, + repDisp, + False) + # benchmark 13.6 + if enableTimingLog: + timeDiff = \ + int((time.time() - + postStartTime) * 1000) + if timeDiff > 100: + print('TIMING INDIV ' + + boxName + ' 13.6 = ' + + str(timeDiff)) + titleStr += \ + ' ' + \ + '' + \
+                        translate['replying to'] + \
+                        '\n' + \ + ' ' + \ + '' + \ + replyDisplayName + '\n' + + # benchmark 13.7 + if enableTimingLog: + timeDiff = int((time.time() - + postStartTime) * 1000) + if timeDiff > 100: + print('TIMING INDIV ' + boxName + + ' 13.7 = ' + str(timeDiff)) + + # show avatar of person replied to + replyAvatarUrl = \ + getPersonAvatarUrl(baseDir, + replyActor, + personCache, + allowDownloads) + + # benchmark 13.8 + if enableTimingLog: + timeDiff = int((time.time() - + postStartTime) * 1000) + if timeDiff > 100: + print('TIMING INDIV ' + boxName + + ' 13.8 = ' + str(timeDiff)) + + if replyAvatarUrl: + replyAvatarImageInPost = \ + '
\n' + replyAvatarImageInPost += \ + ' ' + \ + '\n' + replyAvatarImageInPost += \ + ' ' + \ + ' \n' + \ + '
\n' + else: + inReplyTo = \ + postJsonObject['object']['inReplyTo'] + titleStr += \ + ' ' + \ + '' + \
+                        translate['replying to'] + \
+                        '\n' + \ + ' @' + \ + replyNickname + '@' + \ + replyDomain + '\n' + else: + titleStr += \ + ' ' + \
+                translate['replying to'] + \
+                '\n' + \ + ' @unknown\n' + else: + postDomain = \ + postJsonObject['object']['inReplyTo'] + prefixes = getProtocolPrefixes() + for prefix in prefixes: + postDomain = postDomain.replace(prefix, '') + if '/' in postDomain: + postDomain = postDomain.split('/', 1)[0] + if postDomain: + titleStr += \ + ' ' + translate['replying to'] + \
+                '\n' + \ + ' ' + \ + postDomain + '\n' + + return (titleStr, replyAvatarImageInPost, + containerClassIcons, containerClass) + + def getPostTitleHtml(baseDir: str, httpPrefix: str, nickname: str, domain: str, @@ -888,171 +1090,26 @@ def getPostTitleHtml(baseDir: str, messageIdStr, containerClassIcons, containerClass) - else: - if postJsonObject['object'].get('inReplyTo'): - containerClassIcons = 'containericons darker' - containerClass = 'container darker' - if postJsonObject['object']['inReplyTo'].startswith(postActor): - titleStr += \ - ' ' + translate['replying to themselves'] + \
-                    '\n' - else: - if '/statuses/' in postJsonObject['object']['inReplyTo']: - inReplyTo = postJsonObject['object']['inReplyTo'] - replyActor = inReplyTo.split('/statuses/')[0] - replyNickname = getNicknameFromActor(replyActor) - if replyNickname: - replyDomain, replyPort = \ - getDomainFromActor(replyActor) - if replyNickname and replyDomain: - getPersonFromCache(baseDir, replyActor, - personCache, - allowDownloads) - replyDisplayName = \ - getDisplayName(baseDir, replyActor, - personCache) - if replyDisplayName: - if ':' in replyDisplayName: - # benchmark 13.5 - if enableTimingLog: - timeDiff = \ - int((time.time() - - postStartTime) * 1000) - if timeDiff > 100: - print('TIMING INDIV ' + - boxName + ' 13.5 = ' + - str(timeDiff)) - repDisp = replyDisplayName - replyDisplayName = \ - addEmojiToDisplayName(baseDir, - httpPrefix, - nickname, - domain, - repDisp, - False) - # benchmark 13.6 - if enableTimingLog: - timeDiff = \ - int((time.time() - - postStartTime) * 1000) - if timeDiff > 100: - print('TIMING INDIV ' + - boxName + ' 13.6 = ' + - str(timeDiff)) - titleStr += \ - ' ' + \ - '' + \
-                                    translate['replying to'] + \
-                                    '\n' + \ - ' ' + \ - '' + \ - replyDisplayName + '\n' - # benchmark 13.7 - if enableTimingLog: - timeDiff = int((time.time() - - postStartTime) * 1000) - if timeDiff > 100: - print('TIMING INDIV ' + boxName + - ' 13.7 = ' + str(timeDiff)) - - # show avatar of person replied to - replyAvatarUrl = \ - getPersonAvatarUrl(baseDir, - replyActor, - personCache, - allowDownloads) - - # benchmark 13.8 - if enableTimingLog: - timeDiff = int((time.time() - - postStartTime) * 1000) - if timeDiff > 100: - print('TIMING INDIV ' + boxName + - ' 13.8 = ' + str(timeDiff)) - - if replyAvatarUrl: - replyAvatarImageInPost = \ - '
\n' - replyAvatarImageInPost += \ - ' ' + \ - '\n' - replyAvatarImageInPost += \ - ' ' + \ - ' \n' + \ - '
\n' - else: - inReplyTo = \ - postJsonObject['object']['inReplyTo'] - titleStr += \ - ' ' + \ - '' + \
-                                    translate['replying to'] + \
-                                    '\n' + \ - ' @' + \ - replyNickname + '@' + \ - replyDomain + '\n' - else: - titleStr += \ - ' ' + \
-                            translate['replying to'] + \
-                            '\n' + \ - ' @unknown\n' - else: - postDomain = \ - postJsonObject['object']['inReplyTo'] - prefixes = getProtocolPrefixes() - for prefix in prefixes: - postDomain = postDomain.replace(prefix, '') - if '/' in postDomain: - postDomain = postDomain.split('/', 1)[0] - if postDomain: - titleStr += \ - ' ' + translate['replying to'] + \
-                            '\n' + \ - ' ' + \ - postDomain + '\n' - return (titleStr, replyAvatarImageInPost, - containerClassIcons, containerClass) + return getPostTitleReplyHtml(baseDir, + httpPrefix, + nickname, domain, + showRepeatIcon, + isAnnounced, + postJsonObject, + postActor, + translate, + iconsPath, + enableTimingLog, + postStartTime, + boxName, + personCache, + allowDownloads, + avatarPosition, + pageNumber, + messageIdStr, + containerClassIcons, + containerClass) def individualPostAsHtml(allowDownloads: bool,