Preferred name becomes display name - less ambiguous

master
Bob Mottram 2019-08-22 19:36:07 +01:00
parent 8a581ababd
commit f695039e5a
17 changed files with 63 additions and 63 deletions

View File

@ -445,7 +445,7 @@ def sendAnnounceViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)

View File

@ -111,7 +111,7 @@ def sendAvailabilityViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,postToBox)

View File

@ -180,7 +180,7 @@ def sendBlockViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
@ -258,7 +258,7 @@ def sendUndoBlockViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)

View File

@ -2168,9 +2168,9 @@ class PubServer(BaseHTTPRequestHandler):
if len(actorJson['skills'].items())!=len(newSkills.items()):
actorChanged=True
actorJson['skills']=newSkills
if fields.get('preferredNickname'):
if fields['preferredNickname']!=actorJson['preferredUsername']:
actorJson['preferredUsername']=fields['preferredNickname']
if fields.get('displayNickname'):
if fields['displayNickname']!=actorJson['name']:
actorJson['name']=fields['displayNickname']
actorChanged=True
if fields.get('bio'):
if fields['bio']!=actorJson['summary']:

View File

@ -125,7 +125,7 @@ def sendDeleteViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)

View File

@ -9,7 +9,7 @@ __status__ = "Production"
from person import createPerson
from person import createSharedInbox
from person import createCapabilitiesInbox
from person import setPreferredNickname
from person import setDisplayNickname
from person import setBio
from person import setProfileImage
from person import removeAccount

View File

@ -558,7 +558,7 @@ def sendFollowRequestViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
@ -642,7 +642,7 @@ def sendUnfollowRequestViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)

View File

@ -573,7 +573,7 @@ def personReceiveUpdate(baseDir: str, \
domain: str,port: int, \
updateNickname: str,updateDomain: str,updatePort: int, \
personJson: {},personCache: {},debug: bool) -> bool:
"""Changes an actor. eg: avatar or preferred name change
"""Changes an actor. eg: avatar or display name change
"""
if debug:
print('DEBUG: receiving actor update for '+personJson['url'])

View File

@ -357,7 +357,7 @@ def sendLikeViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
@ -435,7 +435,7 @@ def sendUndoLikeViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)

View File

@ -179,7 +179,7 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
'manuallyApprovesFollowers': False,
'name': nickname,
'outbox': httpPrefix+'://'+domain+'/users/'+nickname+'/outbox',
'preferredUsername': ''+nickname,
'preferredUsername': nickname,
'summary': '',
'publicKey': {
'id': httpPrefix+'://'+domain+'/users/'+nickname+'#main-key',
@ -443,9 +443,9 @@ def personInboxJson(baseDir: str,domain: str,port: int,path: str, \
return createInbox(baseDir,nickname,domain,port,httpPrefix, \
noOfItems,headerOnly,ocapAlways,pageNumber)
def setPreferredNickname(baseDir: str,nickname: str, domain: str, \
preferredName: str) -> bool:
if len(preferredName)>32:
def setDisplayNickname(baseDir: str,nickname: str, domain: str, \
displayName: str) -> bool:
if len(displayName)>32:
return False
handle=nickname.lower()+'@'+domain.lower()
filename=baseDir+'/accounts/'+handle.lower()+'.json'
@ -456,7 +456,7 @@ def setPreferredNickname(baseDir: str,nickname: str, domain: str, \
personJson=commentjson.load(fp)
if not personJson:
return False
personJson['preferredUsername']=preferredName
personJson['name']=displayName
with open(filename, 'w') as fp:
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
return True

View File

@ -188,13 +188,13 @@ def getPersonBox(baseDir: str,session,wfRequest: {},personCache: {}, \
if personJson.get('icon'):
if personJson['icon'].get('url'):
avatarUrl=personJson['icon']['url']
preferredName=None
if personJson.get('preferredUsername'):
preferredName=personJson['preferredUsername']
displayName=None
if personJson.get('name'):
displayName=personJson['name']
storePersonInCache(baseDir,personUrl,personJson,personCache)
return boxJson,pubKeyId,pubKey,personId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName
return boxJson,pubKeyId,pubKey,personId,sharedInbox,capabilityAcquisition,avatarUrl,displayName
def getPosts(session,outboxUrl: str,maxPosts: int, \
maxMentions: int, \
@ -964,7 +964,7 @@ def sendPost(projectVersion: str, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,postToBox)
@ -1060,7 +1060,7 @@ def sendPostViaServer(projectVersion: str, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
@ -1192,7 +1192,7 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
postToBox='outbox'
# get the actor inbox/outbox/capabilities for the To handle
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInboxUrl,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInboxUrl,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,postToBox)
@ -1820,7 +1820,7 @@ def getPublicPostsOfPerson(baseDir: str,nickname: str,domain: str, \
if not wfRequest:
sys.exit()
personUrl,pubKeyId,pubKey,personId,shaedInbox,capabilityAcquisition,avatarUrl,preferredName= \
personUrl,pubKeyId,pubKey,personId,shaedInbox,capabilityAcquisition,avatarUrl,displayName= \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,'outbox')
wfResult = json.dumps(wfRequest, indent=4, sort_keys=True)

View File

@ -257,7 +257,7 @@ def sendRoleViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,delegatorDomain,postToBox)

View File

@ -329,7 +329,7 @@ def sendShareViaServer(baseDir,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
@ -415,7 +415,7 @@ def sendUndoShareViaServer(baseDir: str,session, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)

View File

@ -131,7 +131,7 @@ def sendSkillViaServer(baseDir: str,session,nickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,postToBox)

View File

@ -46,7 +46,7 @@ from follow import unfollowerOfPerson
from follow import getFollowersOfPerson
from follow import sendFollowRequest
from person import createPerson
from person import setPreferredNickname
from person import setDisplayNickname
from person import setBio
from skills import setSkillLevel
from roles import setRole
@ -967,7 +967,7 @@ def testCreatePerson():
assert os.path.isfile(baseDir+'/accounts/passwords')
deleteAllPosts(baseDir,nickname,domain,'inbox')
deleteAllPosts(baseDir,nickname,domain,'outbox')
setPreferredNickname(baseDir,nickname,domain,'badger')
setDisplayNickname(baseDir,nickname,domain,'badger')
setBio(baseDir,nickname,domain,'Randomly roaming in your backyard')
archivePostsForPerson(nickname,domain,baseDir,'inbox',None,4)
archivePostsForPerson(nickname,domain,baseDir,'outbox',None,4)

View File

@ -61,16 +61,16 @@ 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
def getDisplayName(actor: str,personCache: {}) -> str:
"""Returns the display name for the given actor
"""
if '/statuses/' in actor:
actor=actor.split('/statuses/')[0]
if not personCache.get(actor):
return None
if personCache[actor].get('actor'):
if personCache[actor]['actor'].get('preferredUsername'):
return personCache[actor]['actor']['preferredUsername']
if personCache[actor]['actor'].get('name'):
return personCache[actor]['actor']['name']
return None
def getNicknameFromActor(actor: str) -> str:

View File

@ -20,7 +20,7 @@ from utils import getDomainFromActor
from utils import locatePost
from utils import noOfAccounts
from utils import isPublicPost
from utils import getPreferredName
from utils import getDisplayName
from follow import isFollowingActor
from webfinger import webfingerHandle
from posts import getPersonBox
@ -291,13 +291,13 @@ def htmlEditProfile(baseDir: str,path: str,domain: str,port: int) -> str:
return ''
isBot=''
preferredNickname=nickname
displayNickname=nickname
bioStr=''
manuallyApprovesFollowers=''
with open(actorFilename, 'r') as fp:
actorJson=commentjson.load(fp)
if actorJson.get('preferredUsername'):
preferredNickname=actorJson['preferredUsername']
if actorJson.get('name'):
displayNickname=actorJson['name']
if actorJson.get('summary'):
bioStr=actorJson['summary'].replace('<p>','').replace('</p>','')
if actorJson.get('manuallyApprovesFollowers'):
@ -367,7 +367,7 @@ def htmlEditProfile(baseDir: str,path: str,domain: str,port: int) -> str:
' <a href="'+pathOriginal+'"><button class="cancelbtn">Cancel</button></a>' \
' </div>'+ \
' <div class="container">' \
' <input type="text" placeholder="Preferred name" name="preferredNickname" value="'+preferredNickname+'">' \
' <input type="text" placeholder="name" name="displayNickname" value="'+displayNickname+'">' \
' <textarea id="message" name="bio" placeholder="Your bio..." style="height:200px">'+bioStr+'</textarea>' \
' </div>' \
' <div class="container">' \
@ -810,7 +810,7 @@ def htmlProfile(projectVersion: str, \
nickname=profileJson['name']
if not nickname:
return ""
preferredName=profileJson['preferredUsername']
displayName=profileJson['name']
domain,port=getDomainFromActor(profileJson['id'])
if not domain:
return ""
@ -886,7 +886,7 @@ def htmlProfile(projectVersion: str, \
' <div class="hero-image">' \
' <div class="hero-text">'+ \
' <img src="'+profileJson['icon']['url']+'" alt="'+nickname+'@'+domainFull+'">' \
' <h1>'+preferredName+'</h1>' \
' <h1>'+displayName+'</h1>' \
' <p><b>@'+nickname+'@'+domainFull+'</b></p>' \
' <p>'+profileDescription+'</p>'+ \
loginButton+ \
@ -959,13 +959,13 @@ def individualFollowAsHtml(baseDir: str,session,wfRequest: {}, \
if not avatarUrl:
avatarUrl=followUrl+'/avatar.png'
if domain not in followUrl:
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,'outbox')
if avatarUrl2:
avatarUrl=avatarUrl2
if preferredName:
titleStr=preferredName+' '+titleStr
if displayName:
titleStr=displayName+' '+titleStr
buttonsStr=''
if authorized:
@ -1129,9 +1129,9 @@ def individualPostAsHtml(baseDir: str, \
if postJsonObject.get('id'):
messageId=postJsonObject['id'].replace('/activity','')
preferredName=getPreferredName(postJsonObject['actor'],personCache)
if preferredName:
titleStr+='<a href="'+messageId+'">'+preferredName+'</a>'
displayName=getDisplayName(postJsonObject['actor'],personCache)
if displayName:
titleStr+='<a href="'+messageId+'">'+displayName+'</a>'
else:
titleStr+='<a href="'+messageId+'">@'+actorNickname+'@'+actorDomain+'</a>'
@ -1139,9 +1139,9 @@ def individualPostAsHtml(baseDir: str, \
if postJsonObject['object'].get('attributedTo'):
announceNickname=getNicknameFromActor(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>'
announceDisplayName=getDisplayName(postJsonObject['object']['attributedTo'],personCache)
if announceDisplayName:
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">'+announceDisplayName+'</a>'
else:
titleStr+=' <img src="/icons/repeat_inactive.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['id']+'">@'+announceNickname+'@'+announceDomain+'</a>'
else:
@ -1155,9 +1155,9 @@ def individualPostAsHtml(baseDir: str, \
replyNickname=getNicknameFromActor(postJsonObject['object']['inReplyTo'])
replyDomain,replyPort=getDomainFromActor(postJsonObject['object']['inReplyTo'])
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>'
replyDisplayName=getDisplayName(postJsonObject['object']['inReplyTo'],personCache)
if replyDisplayName:
titleStr+=' <img src="/icons/reply.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['inReplyTo']+'">'+replyDisplayName+'</a>'
else:
titleStr+=' <img src="/icons/reply.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['inReplyTo']+'">@'+replyNickname+'@'+replyDomain+'</a>'
else:
@ -1203,13 +1203,13 @@ def individualPostAsHtml(baseDir: str, \
fullDomain=domain+':'+str(port)
if fullDomain not in postJsonObject['actor']:
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,displayName = \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,'outbox')
if avatarUrl2:
avatarUrl=avatarUrl2
if preferredName:
titleStr=preferredName+' '+titleStr
if displayName:
titleStr=displayName+' '+titleStr
avatarDropdown= \
' <a href="'+postJsonObject['actor']+'">' \
@ -1778,9 +1778,9 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
avatarUrl=profileJson['icon']['url']
if not avatarUrl:
avatarUrl=getPersonAvatarUrl(baseDir,personUrl,personCache)
preferredName=searchNickname
if profileJson.get('preferredUsername'):
preferredName=profileJson['preferredUsername']
displayName=searchNickname
if profileJson.get('displayUsername'):
displayName=profileJson['name']
profileDescription=''
if profileJson.get('summary'):
profileDescription=profileJson['summary']
@ -1807,7 +1807,7 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
' <div class="hero-image">' \
' <div class="hero-text">' \
' <img src="'+avatarUrl+'" alt="'+searchNickname+'@'+searchDomainFull+'">' \
' <h1>'+preferredName+'</h1>' \
' <h1>'+displayName+'</h1>' \
' <p><b>@'+searchNickname+'@'+searchDomainFull+'</b></p>' \
' <p>'+profileDescription+'</p>'+ \
' </div>' \