diff --git a/webapp_post.py b/webapp_post.py
index 269995f4..92201716 100644
--- a/webapp_post.py
+++ b/webapp_post.py
@@ -632,6 +632,330 @@ def getBlogCitationsHtml(boxName: str,
return citationsStr
+def getPostTitleHtml(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):
+ """Returns the title of a post containing names of participants
+ x replies to y, x announces y, etc
+ """
+ titleStr = ''
+ replyAvatarImageInPost = ''
+ if showRepeatIcon:
+ if isAnnounced:
+ if postJsonObject['object'].get('attributedTo'):
+ attributedTo = ''
+ if isinstance(postJsonObject['object']['attributedTo'], str):
+ attributedTo = postJsonObject['object']['attributedTo']
+ if attributedTo.startswith(postActor):
+ titleStr += \
+ '
\n'
+ else:
+ # benchmark 13.2
+ if enableTimingLog:
+ timeDiff = int((time.time() - postStartTime) * 1000)
+ if timeDiff > 100:
+ print('TIMING INDIV ' + boxName +
+ ' 13.2 = ' + str(timeDiff))
+ announceNickname = None
+ if attributedTo:
+ announceNickname = getNicknameFromActor(attributedTo)
+ if announceNickname:
+ announceDomain, announcePort = \
+ getDomainFromActor(attributedTo)
+ getPersonFromCache(baseDir, attributedTo,
+ personCache, allowDownloads)
+ announceDisplayName = \
+ getDisplayName(baseDir, attributedTo, personCache)
+ if announceDisplayName:
+ # benchmark 13.3
+ if enableTimingLog:
+ timeDiff = \
+ int((time.time() - postStartTime) * 1000)
+ if timeDiff > 100:
+ print('TIMING INDIV ' + boxName +
+ ' 13.3 = ' + str(timeDiff))
+
+ if ':' in announceDisplayName:
+ announceDisplayName = \
+ addEmojiToDisplayName(baseDir, httpPrefix,
+ nickname, domain,
+ announceDisplayName,
+ False)
+ # benchmark 13.3.1
+ if enableTimingLog:
+ timeDiff = \
+ int((time.time() - postStartTime) * 1000)
+ if timeDiff > 100:
+ print('TIMING INDIV ' + boxName +
+ ' 13.3.1 = ' + str(timeDiff))
+
+ titleStr += \
+ ' ' + \
+ '
\n' + \
+ ' ' + \
+ announceDisplayName + '\n'
+ # show avatar of person replied to
+ announceActor = \
+ postJsonObject['object']['attributedTo']
+ announceAvatarUrl = \
+ getPersonAvatarUrl(baseDir, announceActor,
+ personCache, allowDownloads)
+
+ # benchmark 13.4
+ if enableTimingLog:
+ timeDiff = \
+ int((time.time() - postStartTime) * 1000)
+ if timeDiff > 100:
+ print('TIMING INDIV ' + boxName +
+ ' 13.4 = ' + str(timeDiff))
+
+ if announceAvatarUrl:
+ idx = 'Show options for this person'
+ if '/users/news/' not in announceAvatarUrl:
+ replyAvatarImageInPost = \
+ ' ' \
+ '
\n'
+ else:
+ titleStr += \
+ '
\n' + \
+ ' @' + \
+ announceNickname + '@' + \
+ announceDomain + '\n'
+ else:
+ titleStr += \
+ '
\n' + \
+ ' @unattributed\n'
+ else:
+ titleStr += \
+ ' ' + \
+ '
\n' + \
+ ' @unattributed\n'
+ else:
+ if postJsonObject['object'].get('inReplyTo'):
+ containerClassIcons = 'containericons darker'
+ containerClass = 'container darker'
+ if postJsonObject['object']['inReplyTo'].startswith(postActor):
+ titleStr += \
+ '
\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 += \
+ ' ' + \
+ '
\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'
+ else:
+ inReplyTo = \
+ postJsonObject['object']['inReplyTo']
+ titleStr += \
+ ' ' + \
+ '
\n' + \
+ ' @' + \
+ replyNickname + '@' + \
+ replyDomain + '\n'
+ else:
+ titleStr += \
+ '
\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 += \
+ '
\n' + \
+ ' ' + \
+ postDomain + '\n'
+ return (titleStr, replyAvatarImageInPost,
+ containerClassIcons, containerClass)
+
+
def individualPostAsHtml(allowDownloads: bool,
recentPostsCache: {}, maxRecentPosts: int,
iconsPath: str, translate: {},
@@ -997,303 +1321,30 @@ def individualPostAsHtml(allowDownloads: bool,
if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 13.1 = ' + str(timeDiff))
- replyAvatarImageInPost = ''
- if showRepeatIcon:
- if isAnnounced:
- if postJsonObject['object'].get('attributedTo'):
- attributedTo = ''
- if isinstance(postJsonObject['object']['attributedTo'], str):
- attributedTo = postJsonObject['object']['attributedTo']
- if attributedTo.startswith(postActor):
- titleStr += \
- '
\n'
- else:
- # benchmark 13.2
- if enableTimingLog:
- timeDiff = int((time.time() - postStartTime) * 1000)
- if timeDiff > 100:
- print('TIMING INDIV ' + boxName +
- ' 13.2 = ' + str(timeDiff))
- announceNickname = None
- if attributedTo:
- announceNickname = getNicknameFromActor(attributedTo)
- if announceNickname:
- announceDomain, announcePort = \
- getDomainFromActor(attributedTo)
- getPersonFromCache(baseDir, attributedTo,
- personCache, allowDownloads)
- announceDisplayName = \
- getDisplayName(baseDir, attributedTo, personCache)
- if announceDisplayName:
- # benchmark 13.3
- if enableTimingLog:
- timeDiff = \
- int((time.time() - postStartTime) * 1000)
- if timeDiff > 100:
- print('TIMING INDIV ' + boxName +
- ' 13.3 = ' + str(timeDiff))
-
- if ':' in announceDisplayName:
- announceDisplayName = \
- addEmojiToDisplayName(baseDir, httpPrefix,
- nickname, domain,
- announceDisplayName,
- False)
- # benchmark 13.3.1
- if enableTimingLog:
- timeDiff = \
- int((time.time() - postStartTime) * 1000)
- if timeDiff > 100:
- print('TIMING INDIV ' + boxName +
- ' 13.3.1 = ' + str(timeDiff))
-
- titleStr += \
- ' ' + \
- '
\n' + \
- ' ' + \
- announceDisplayName + '\n'
- # show avatar of person replied to
- announceActor = \
- postJsonObject['object']['attributedTo']
- announceAvatarUrl = \
- getPersonAvatarUrl(baseDir, announceActor,
- personCache, allowDownloads)
-
- # benchmark 13.4
- if enableTimingLog:
- timeDiff = \
- int((time.time() - postStartTime) * 1000)
- if timeDiff > 100:
- print('TIMING INDIV ' + boxName +
- ' 13.4 = ' + str(timeDiff))
-
- if announceAvatarUrl:
- idx = 'Show options for this person'
- if '/users/news/' not in announceAvatarUrl:
- replyAvatarImageInPost = \
- ' ' \
- '\n'
- else:
- titleStr += \
- '
\n' + \
- ' @' + \
- announceNickname + '@' + \
- announceDomain + '\n'
- else:
- titleStr += \
- '
\n' + \
- ' @unattributed\n'
- else:
- titleStr += \
- ' ' + \
- '
\n' + \
- ' @unattributed\n'
- else:
- if postJsonObject['object'].get('inReplyTo'):
- containerClassIcons = 'containericons darker'
- containerClass = 'container darker'
- if postJsonObject['object']['inReplyTo'].startswith(postActor):
- titleStr += \
- '
\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 += \
- ' ' + \
- '
\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'
- else:
- inReplyTo = \
- postJsonObject['object']['inReplyTo']
- titleStr += \
- ' ' + \
- '
\n' + \
- ' @' + \
- replyNickname + '@' + \
- replyDomain + '\n'
- else:
- titleStr += \
- '
\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 += \
- '
\n' + \
- ' ' + \
- postDomain + '\n'
+ # get the title: x replies to y, x announces y, etc
+ (titleStr2,
+ replyAvatarImageInPost,
+ containerClassIcons,
+ containerClass) = getPostTitleHtml(baseDir,
+ httpPrefix,
+ nickname, domain,
+ showRepeatIcon,
+ isAnnounced,
+ postJsonObject,
+ postActor,
+ translate,
+ iconsPath,
+ enableTimingLog,
+ postStartTime,
+ boxName,
+ personCache,
+ allowDownloads,
+ avatarPosition,
+ pageNumber,
+ messageIdStr,
+ containerClassIcons,
+ containerClass)
+ titleStr += titleStr2
# benchmark 14
if enableTimingLog: