forked from indymedia/epicyon
Use preferred names in posts
parent
156c81c7ef
commit
53bd98075e
9
utils.py
9
utils.py
|
@ -61,6 +61,15 @@ def urlPermitted(url: str, federationList: [],capability: str):
|
||||||
return True
|
return True
|
||||||
return False
|
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:
|
def getNicknameFromActor(actor: str) -> str:
|
||||||
"""Returns the nickname from an actor url
|
"""Returns the nickname from an actor url
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -20,6 +20,7 @@ from utils import getDomainFromActor
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
from utils import noOfAccounts
|
from utils import noOfAccounts
|
||||||
from utils import isPublicPost
|
from utils import isPublicPost
|
||||||
|
from utils import getPreferredName
|
||||||
from follow import isFollowingActor
|
from follow import isFollowingActor
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
|
@ -1128,11 +1129,20 @@ def individualPostAsHtml(baseDir: str, \
|
||||||
if postJsonObject.get('id'):
|
if postJsonObject.get('id'):
|
||||||
messageId=postJsonObject['id'].replace('/activity','')
|
messageId=postJsonObject['id'].replace('/activity','')
|
||||||
|
|
||||||
|
preferredName=getPreferredName(postJsonObject['actor'],personCache)
|
||||||
|
if preferredName:
|
||||||
|
titleStr+='<a href="'+messageId+'">'+preferredName+'</a>'
|
||||||
|
else:
|
||||||
titleStr+='<a href="'+messageId+'">@'+actorNickname+'@'+actorDomain+'</a>'
|
titleStr+='<a href="'+messageId+'">@'+actorNickname+'@'+actorDomain+'</a>'
|
||||||
|
|
||||||
if isAnnounced:
|
if isAnnounced:
|
||||||
if postJsonObject['object'].get('attributedTo'):
|
if postJsonObject['object'].get('attributedTo'):
|
||||||
announceNickname=getNicknameFromActor(postJsonObject['object']['attributedTo'])
|
announceNickname=getNicknameFromActor(postJsonObject['object']['attributedTo'])
|
||||||
announceDomain,announcePort=getDomainFromActor(postJsonObject['object']['attributedTo'])
|
announceDomain,announcePort=getDomainFromActor(postJsonObject['object']['attributedTo'])
|
||||||
|
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>'
|
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">@'+announceNickname+'@'+announceDomain+'</a>'
|
||||||
else:
|
else:
|
||||||
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">@unattributed</a>'
|
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">@unattributed</a>'
|
||||||
|
@ -1145,6 +1155,10 @@ def individualPostAsHtml(baseDir: str, \
|
||||||
replyNickname=getNicknameFromActor(postJsonObject['object']['inReplyTo'])
|
replyNickname=getNicknameFromActor(postJsonObject['object']['inReplyTo'])
|
||||||
replyDomain,replyPort=getDomainFromActor(postJsonObject['object']['inReplyTo'])
|
replyDomain,replyPort=getDomainFromActor(postJsonObject['object']['inReplyTo'])
|
||||||
if replyNickname and replyDomain:
|
if replyNickname and replyDomain:
|
||||||
|
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>'
|
titleStr+=' <img src="/icons/reply.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['inReplyTo']+'">@'+replyNickname+'@'+replyDomain+'</a>'
|
||||||
else:
|
else:
|
||||||
postDomain=postJsonObject['object']['inReplyTo'].replace('https://','').replace('http://','').replace('dat://','')
|
postDomain=postJsonObject['object']['inReplyTo'].replace('https://','').replace('http://','').replace('dat://','')
|
||||||
|
|
Loading…
Reference in New Issue