From 53bd98075ee4d87c9f91684fa4c9857b37c7ebda Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 22 Aug 2019 13:41:16 +0100 Subject: [PATCH] Use preferred names in posts --- utils.py | 9 +++++++++ webinterface.py | 20 +++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/utils.py b/utils.py index c4fd586a..891ddc60 100644 --- a/utils.py +++ b/utils.py @@ -61,6 +61,15 @@ def urlPermitted(url: str, federationList: [],capability: str): return True return False +def getPreferredName(actor: str,personCache: {}) -> str: + """Returns the preferred name for the given actor + """ + if not personCache.get(actor): + return None + if not personCache[actor].get('preferredUsername'): + return personCache[actor]['preferredUsername'] + return None + def getNicknameFromActor(actor: str) -> str: """Returns the nickname from an actor url """ diff --git a/webinterface.py b/webinterface.py index eef036fa..427c399a 100644 --- a/webinterface.py +++ b/webinterface.py @@ -20,6 +20,7 @@ from utils import getDomainFromActor from utils import locatePost from utils import noOfAccounts from utils import isPublicPost +from utils import getPreferredName from follow import isFollowingActor from webfinger import webfingerHandle from posts import getPersonBox @@ -1128,12 +1129,21 @@ def individualPostAsHtml(baseDir: str, \ if postJsonObject.get('id'): messageId=postJsonObject['id'].replace('/activity','') - titleStr+='@'+actorNickname+'@'+actorDomain+'' + preferredName=getPreferredName(postJsonObject['actor'],personCache) + if preferredName: + titleStr+=''+preferredName+'' + else: + titleStr+='@'+actorNickname+'@'+actorDomain+'' + if isAnnounced: if postJsonObject['object'].get('attributedTo'): announceNickname=getNicknameFromActor(postJsonObject['object']['attributedTo']) announceDomain,announcePort=getDomainFromActor(postJsonObject['object']['attributedTo']) - titleStr+=' @'+announceNickname+'@'+announceDomain+'' + announcePreferredName=getPreferredName(postJsonObject['object']['attributedTo'],personCache) + if announcePreferredName: + titleStr+=' '+announcePreferredName+'' + else: + titleStr+=' @'+announceNickname+'@'+announceDomain+'' else: titleStr+=' @unattributed' else: @@ -1145,7 +1155,11 @@ def individualPostAsHtml(baseDir: str, \ replyNickname=getNicknameFromActor(postJsonObject['object']['inReplyTo']) replyDomain,replyPort=getDomainFromActor(postJsonObject['object']['inReplyTo']) if replyNickname and replyDomain: - titleStr+=' @'+replyNickname+'@'+replyDomain+'' + replyPreferredName=getPreferredName(postJsonObject['object']['inReplyTo'],personCache) + if replyPreferredName: + titleStr+=' '+replyPreferredName+'' + else: + titleStr+=' @'+replyNickname+'@'+replyDomain+'' else: postDomain=postJsonObject['object']['inReplyTo'].replace('https://','').replace('http://','').replace('dat://','') if '/' in postDomain: