Get avatar url from cache

master
Bob Mottram 2019-08-18 14:30:40 +01:00
parent a1cbc6e9c3
commit ecf978b48d
1 changed files with 19 additions and 2 deletions

View File

@ -35,6 +35,16 @@ from content import getMentionsFromHtml
from config import getConfigParam from config import getConfigParam
from skills import getSkills from skills import getSkills
def getPersonAvatarUrl(personUrl: str,personCache: {}) -> str:
"""Returns the avatar url for the person
"""
personJson = getPersonFromCache(personUrl,personCache)
if personJson:
if personJson.get('icon'):
if personJson['icon'].get('url'):
return prersonJson['icon']['url']
return None
def htmlSearchSharedItems(baseDir: str,searchStr: str,pageNumber: int,resultsPerPage: int,actor: str) -> str: def htmlSearchSharedItems(baseDir: str,searchStr: str,pageNumber: int,resultsPerPage: int,actor: str) -> str:
"""Search results for shared items """Search results for shared items
""" """
@ -888,7 +898,9 @@ def individualFollowAsHtml(session,wfRequest: {}, \
nickname=getNicknameFromActor(followUrl) nickname=getNicknameFromActor(followUrl)
domain,port=getDomainFromActor(followUrl) domain,port=getDomainFromActor(followUrl)
titleStr='@'+nickname+'@'+domain titleStr='@'+nickname+'@'+domain
avatarUrl=followUrl+'/avatar.png' avatarUrl=getPersonAvatarUrl(followUrl,personCache)
if not avatarUrl:
avatarUrl=followUrl+'/avatar.png'
if domain not in followUrl: if domain not in followUrl:
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \
getPersonBox(session,wfRequest,personCache, \ getPersonBox(session,wfRequest,personCache, \
@ -1008,6 +1020,8 @@ def individualPostAsHtml(baseDir: str, \
'<img src="'+attach['url']+'" alt="'+imageDescription+'" title="'+imageDescription+'" class="attachment"></a>\n' '<img src="'+attach['url']+'" alt="'+imageDescription+'" title="'+imageDescription+'" class="attachment"></a>\n'
attachmentCtr+=1 attachmentCtr+=1
if not avatarUrl:
avatarUrl=getPersonAvatarUrl(postJsonObject['actor'],personCache)
if not avatarUrl: if not avatarUrl:
avatarUrl=postJsonObject['actor']+'/avatar.png' avatarUrl=postJsonObject['actor']+'/avatar.png'
@ -1232,8 +1246,9 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
for item in timelineJson['orderedItems']: for item in timelineJson['orderedItems']:
if item['type']=='Create' or item['type']=='Announce': if item['type']=='Create' or item['type']=='Announce':
itemCtr+=1 itemCtr+=1
avatarUrl=getPersonAvatarUrl(item['actor'],personCache)
tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \ tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True, \ nickname,domain,port,item,avatarUrl,True, \
allowDeletion, \ allowDeletion, \
httpPrefix,projectVersion, httpPrefix,projectVersion,
showIndividualPostIcons) showIndividualPostIcons)
@ -1545,6 +1560,8 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
if profileJson.get('icon'): if profileJson.get('icon'):
if profileJson['icon'].get('url'): if profileJson['icon'].get('url'):
avatarUrl=profileJson['icon']['url'] avatarUrl=profileJson['icon']['url']
if not avatarUrl:
avatarUrl=getPersonAvatarUrl(personUrl,personCache)
preferredName=searchNickname preferredName=searchNickname
if profileJson.get('preferredUsername'): if profileJson.get('preferredUsername'):
preferredName=profileJson['preferredUsername'] preferredName=profileJson['preferredUsername']