Use preferred names in posts

master
Bob Mottram 2019-08-22 13:41:16 +01:00
parent 156c81c7ef
commit 53bd98075e
2 changed files with 26 additions and 3 deletions

View File

@ -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
"""

View File

@ -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+='<a href="'+messageId+'">@'+actorNickname+'@'+actorDomain+'</a>'
preferredName=getPreferredName(postJsonObject['actor'],personCache)
if preferredName:
titleStr+='<a href="'+messageId+'">'+preferredName+'</a>'
else:
titleStr+='<a href="'+messageId+'">@'+actorNickname+'@'+actorDomain+'</a>'
if isAnnounced:
if postJsonObject['object'].get('attributedTo'):
announceNickname=getNicknameFromActor(postJsonObject['object']['attributedTo'])
announceDomain,announcePort=getDomainFromActor(postJsonObject['object']['attributedTo'])
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">@'+announceNickname+'@'+announceDomain+'</a>'
announcePreferredName=getPreferredName(postJsonObject['object']['attributedTo'],personCache)
if announcePreferredName:
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">'+announcePreferredName+'</a>'
else:
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">@'+announceNickname+'@'+announceDomain+'</a>'
else:
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">@unattributed</a>'
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+=' <img src="/icons/reply.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['inReplyTo']+'">@'+replyNickname+'@'+replyDomain+'</a>'
replyPreferredName=getPreferredName(postJsonObject['object']['inReplyTo'],personCache)
if replyPreferredName:
titleStr+=' <img src="/icons/reply.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['inReplyTo']+'">'+replyPreferredName+'</a>'
else:
titleStr+=' <img src="/icons/reply.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['inReplyTo']+'">@'+replyNickname+'@'+replyDomain+'</a>'
else:
postDomain=postJsonObject['object']['inReplyTo'].replace('https://','').replace('http://','').replace('dat://','')
if '/' in postDomain: