Update @nickname in actors cache

main
Bob Mottram 2020-01-19 20:58:50 +00:00
parent 6d0d9bf148
commit e3c05562fd
2 changed files with 22 additions and 4 deletions

View File

@ -3922,7 +3922,7 @@ class PubServer(BaseHTTPRequestHandler):
except Exception as e:
print('WARN: Unable to save token for '+loginNickname+' '+str(e))
personUpgradeActor(None,loginHandle, \
personUpgradeActor(self.server.baseDir,None,loginHandle, \
self.server.baseDir+'/accounts/'+loginHandle+'.json')
self.server.tokensLookup[self.server.tokens[loginNickname]]=loginNickname

View File

@ -373,9 +373,10 @@ def createCapabilitiesInbox(baseDir: str,nickname: str,domain: str,port: int, \
"""
return createPersonBase(baseDir,nickname,domain,port,httpPrefix,True,None)
def personUpgradeActor(personJson: {},handle: str,filename: str) -> None:
def personUpgradeActor(baseDir: str,personJson: {},handle: str,filename: str) -> None:
"""Alter the actor to add any new properties
"""
updateActor=False
if not os.path.isfile(filename):
print('WARN: actor file not found '+filename)
return
@ -389,8 +390,25 @@ def personUpgradeActor(personJson: {},handle: str,filename: str) -> None:
'locationPrimary':True,
'locationDeleted':False
}]
saveJson(personJson,filename)
print('Nomadic locations added to to actor '+handle)
updateActor=True
if updateActor:
saveJson(personJson,filename)
# also update the actor within the cache
actorCacheFilename= \
baseDir+'/accounts/cache/actors/'+ \
personJson['id'].replace('/','#')+'.json'
if os.path.isfile(actorCacheFilename):
saveJson(personJson,actorCacheFilename)
# update domain/@nickname in actors cache
actorCacheFilename= \
baseDir+'/accounts/cache/actors/'+ \
personJson['id'].replace('/users/','/@').replace('/','#')+'.json'
if os.path.isfile(actorCacheFilename):
saveJson(personJson,actorCacheFilename)
def personLookup(domain: str,path: str,baseDir: str) -> {}:
"""Lookup the person for an given nickname
@ -426,7 +444,7 @@ def personLookup(domain: str,path: str,baseDir: str) -> {}:
if not os.path.isfile(filename):
return None
personJson=loadJson(filename)
personUpgradeActor(personJson,handle,filename)
personUpgradeActor(baseDir,personJson,handle,filename)
#if not personJson:
# personJson={"user": "unknown"}
return personJson