Look up avatars for profile screen

master
Bob Mottram 2019-07-22 15:09:21 +01:00
parent ed6a98af07
commit e4503b7143
11 changed files with 118 additions and 43 deletions

View File

@ -280,7 +280,7 @@ def sendAnnounceViaServer(session,fromNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:

View File

@ -107,7 +107,7 @@ def sendAvailabilityViaServer(session,nickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:

View File

@ -95,7 +95,7 @@ def sendBlockViaServer(session,fromNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:
@ -167,7 +167,7 @@ def sendUndoBlockViaServer(session,fromNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:

View File

@ -651,12 +651,26 @@ class PubServer(BaseHTTPRequestHandler):
getPerson = personLookup(self.server.domain,self.path.replace('/following',''), \
self.server.baseDir)
if getPerson:
if not self.server.session:
if self.server.debug:
print('DEBUG: creating new session for c2s')
self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor)
if not self.server.session:
if self.server.debug:
print('DEBUG: creating new session')
self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html')
self.wfile.write(htmlProfile(self.server.baseDir, \
self.server.httpPrefix, \
authorized, \
self.server.ocapAlways, \
getPerson,'following', \
self.server.session, \
self.server.cachedWebfingers, \
self.server.personCache, \
following).encode('utf-8'))
self.server.GETbusy=False
return
@ -680,12 +694,20 @@ class PubServer(BaseHTTPRequestHandler):
getPerson = personLookup(self.server.domain,self.path.replace('/followers',''), \
self.server.baseDir)
if getPerson:
if not self.server.session:
if self.server.debug:
print('DEBUG: creating new session')
self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html')
self.wfile.write(htmlProfile(self.server.baseDir, \
self.server.httpPrefix, \
authorized, \
self.server.ocapAlways, \
getPerson,'followers', \
self.server.session, \
self.server.cachedWebfingers, \
self.server.personCache, \
followers).encode('utf-8'))
self.server.GETbusy=False
return
@ -699,12 +721,20 @@ class PubServer(BaseHTTPRequestHandler):
self.server.baseDir)
if getPerson:
if 'text/html' in self.headers['Accept']:
if not self.server.session:
if self.server.debug:
print('DEBUG: creating new session')
self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html')
self.wfile.write(htmlProfile(self.server.baseDir, \
self.server.httpPrefix, \
authorized, \
self.server.ocapAlways, \
getPerson,'posts').encode('utf-8'))
getPerson,'posts',
self.server.session, \
self.server.cachedWebfingers, \
self.server.personCache).encode('utf-8'))
else:
self._set_headers('application/json')
self.wfile.write(json.dumps(getPerson).encode('utf-8'))

View File

@ -116,7 +116,7 @@ def sendDeleteViaServer(session,fromNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:

View File

@ -513,7 +513,7 @@ def sendFollowRequestViaServer(session,fromNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:
@ -588,7 +588,7 @@ def sendUnfollowRequestViaServer(session,fromNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:

View File

@ -312,7 +312,7 @@ def sendLikeViaServer(session,fromNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:
@ -383,7 +383,7 @@ def sendUndoLikeViaServer(session,fromNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:

View File

@ -114,16 +114,16 @@ def parseUserFeed(session,feedUrl: str,asHeader: {}) -> None:
yield item
def getPersonBox(session,wfRequest: {},personCache: {}, \
boxName='inbox') -> (str,str,str,str,str):
boxName='inbox') -> (str,str,str,str,str,str):
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
personUrl = getUserUrl(wfRequest)
if not personUrl:
return None,None,None,None,None
return None,None,None,None,None,None
personJson = getPersonFromCache(personUrl,personCache)
if not personJson:
personJson = getJson(session,personUrl,asHeader,None)
if not personJson:
return None,None,None,None,None
return None,None,None,None,None,None
boxJson=None
if not personJson.get(boxName):
if personJson.get('endpoints'):
@ -133,7 +133,7 @@ def getPersonBox(session,wfRequest: {},personCache: {}, \
boxJson=personJson[boxName]
if not boxJson:
return None,None,None,None,None
return None,None,None,None,None,None
personId=None
if personJson.get('id'):
@ -155,10 +155,14 @@ def getPersonBox(session,wfRequest: {},personCache: {}, \
capabilityAcquisition=None
if personJson.get('capabilityAcquisitionEndpoint'):
capabilityAcquisition=personJson['capabilityAcquisitionEndpoint']
avaratUrl=None
if personJson.get('icon'):
if personJson['icon'].get('url'):
avaratUrl=personJson['icon']['url']
storePersonInCache(personUrl,personJson,personCache)
return boxJson,pubKeyId,pubKey,personId,sharedInbox,capabilityAcquisition
return boxJson,pubKeyId,pubKey,personId,sharedInbox,capabilityAcquisition,avatarUrl
def getPosts(session,outboxUrl: str,maxPosts: int, \
maxMentions: int, \
@ -656,7 +660,7 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
# If there are more than one followers on the target domain
@ -743,7 +747,7 @@ def sendPostViaServer(session,fromNickname: str,password: str, \
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:
@ -869,7 +873,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 = \
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInboxUrl,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if nickname=='capabilities':
@ -1319,7 +1323,7 @@ def getPublicPostsOfPerson(nickname: str,domain: str, \
if not wfRequest:
sys.exit()
personUrl,pubKeyId,pubKey,personId,shaedInbox,capabilityAcquisition= \
personUrl,pubKeyId,pubKey,personId,shaedInbox,capabilityAcquisition,avatarUrl= \
getPersonBox(session,wfRequest,personCache,'outbox')
wfResult = json.dumps(wfRequest, indent=4, sort_keys=True)

View File

@ -187,7 +187,7 @@ def sendRoleViaServer(session,delegatorNickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:

View File

@ -118,7 +118,7 @@ def sendSkillViaServer(session,nickname: str,password: str,
postToBox='outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl = \
getPersonBox(session,wfRequest,personCache,postToBox)
if not inboxUrl:

View File

@ -11,6 +11,7 @@ from pprint import pprint
from person import personBoxJson
from utils import getNicknameFromActor
from utils import getDomainFromActor
from posts import getPersonBox
def htmlHeader(css=None,lang='en') -> str:
if not css:
@ -37,30 +38,43 @@ def htmlFooter() -> str:
'</html>\n'
return htmlStr
def htmlProfilePosts(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,nickname: str,domain: str,port: int) -> str:
def htmlProfilePosts(baseDir: str,httpPrefix: str, \
authorized: bool,ocapAlways: bool, \
nickname: str,domain: str,port: int, \
session,wfRequest: {},personCache: {}) -> str:
"""Shows posts on the profile screen
"""
profileStr=''
outboxFeed=personBoxJson(baseDir,domain, \
port,'/users/'+nickname+'/outbox?page=1', \
httpPrefix, \
4, 'outbox', \
authorized, \
ocapAlways)
outboxFeed= \
personBoxJson(baseDir,domain, \
port,'/users/'+nickname+'/outbox?page=1', \
httpPrefix, \
4, 'outbox', \
authorized, \
ocapAlways)
for item in outboxFeed['orderedItems']:
if item['type']=='Create':
profileStr+=individualPostAsHtml(item)
profileStr+= \
individualPostAsHtml(session,wfRequest,personCache, \
domain,item)
return profileStr
def htmlProfileFollowing(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,nickname: str,domain: str,port: int,followingJson: {}) -> str:
def htmlProfileFollowing(baseDir: str,httpPrefix: str, \
authorized: bool,ocapAlways: bool, \
nickname: str,domain: str,port: int, \
session,wfRequest: {},personCache: {}, \
followingJson: {}) -> str:
"""Shows following on the profile screen
"""
profileStr=''
for item in followingJson['orderedItems']:
profileStr+=individualFollowAsHtml(item)
profileStr+=individualFollowAsHtml(session,wfRequest,personCache,domain,item)
return profileStr
def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,profileJson: {},selected: str,extraJson=None) -> str:
def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
ocapAlways: bool,profileJson: {},selected: str, \
session,wfRequest: {},personCache: {}, \
extraJson=None) -> str:
"""Show the profile page as html
"""
nickname=profileJson['name']
@ -303,24 +317,40 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,p
'}'
if selected=='posts':
profileStr+=htmlProfilePosts(baseDir,httpPrefix,authorized,ocapAlways,nickname,domain,port)
profileStr+= \
htmlProfilePosts(baseDir,httpPrefix,authorized, \
ocapAlways,nickname,domain,port, \
session,wfRequest,personCache)
if selected=='following' or selected=='followers':
profileStr+=htmlProfileFollowing(baseDir,httpPrefix,authorized,ocapAlways,nickname,domain,port,extraJson)
profileStr+= \
htmlProfileFollowing(baseDir,httpPrefix, \
authorized,ocapAlways,nickname, \
domain,port,session, \
wfRequest,personCache,extraJson)
profileStr=htmlHeader(profileStyle)+profileStr+htmlFooter()
return profileStr
def individualFollowAsHtml(followUrl: str) -> str:
def individualFollowAsHtml(session,wfRequest: {}, \
personCache: {},domain: str, \
followUrl: str) -> str:
nickname=getNicknameFromActor(followUrl)
domain,port=getDomainFromActor(followUrl)
titleStr='@'+nickname+'@'+domain
avatarUrl=followUrl+'/avatar.png'
if domain not in followUrl:
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2 = \
getPersonBox(session,wfRequest,personCache,'outbox')
if avatarUrl2:
avatarUrl=avatarUrl2
return \
'<div class="container">\n' \
'<a href="'+followUrl+'">' \
'<img src="'+followUrl+'/avatar.png" alt="Avatar">\n'+ \
'<img src="'+avatarUrl+'" alt="Avatar">\n'+ \
'<p>'+titleStr+'</p></a>'+ \
'</div>\n'
def individualPostAsHtml(postJsonObject: {}) -> str:
def individualPostAsHtml(session,wfRequest: {},personCache: {}, \
domain: str,postJsonObject: {}) -> str:
avatarPosition=''
containerClass='container'
timeClass='time-right'
@ -361,18 +391,26 @@ def individualPostAsHtml(postJsonObject: {}) -> str:
'<a href="'+attach['url']+'">' \
'<img src="'+attach['url']+'" alt="'+imageDescription+'" title="'+imageDescription+'" class="attachment"></a>\n'
attachmentCtr+=1
avatarUrl=postJsonObject['actor']+'/avatar.png'
if domain not in postJsonObject['actor']:
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2 = \
getPersonBox(session,wfRequest,personCache,'outbox')
if avatarUrl2:
avatarUrl=avatarUrl2
return \
'<div class="'+containerClass+'">\n' \
'<a href="'+postJsonObject['actor']+'">' \
'<img src="'+postJsonObject['actor']+'/avatar.png" alt="Avatar"'+avatarPosition+'></a>\n'+ \
'<img src="'+avatarUrl+'" alt="Avatar"'+avatarPosition+'></a>\n'+ \
'<p class="post-title">'+titleStr+'</p>'+ \
postJsonObject['object']['content']+'\n'+ \
attachmentStr+ \
'<span class="'+timeClass+'">'+postJsonObject['object']['published']+'</span>\n'+ \
'</div>\n'
def htmlTimeline(timelineJson: {}) -> str:
def htmlTimeline(session,wfRequest: {},personCache: {}, \
domain: str,timelineJson: {}) -> str:
"""Show the timeline as html
"""
if not timelineJson.get('orderedItems'):
@ -380,7 +418,8 @@ def htmlTimeline(timelineJson: {}) -> str:
tlStr=htmlHeader()
for item in timelineJson['orderedItems']:
if item['type']=='Create':
tlStr+=individualPostAsHtml(item)
tlStr+=individualPostAsHtml(session,wfRequest,personCache, \
domain,item)
tlStr+=htmlFooter()
return tlStr
@ -394,11 +433,13 @@ def htmlOutbox(outboxJson: {}) -> str:
"""
return htmlTimeline(outboxJson)
def htmlIndividualPost(postJsonObject: {}) -> str:
def htmlIndividualPost(session,wfRequest: {},personCache: {}, \
domain: str,postJsonObject: {}) -> str:
"""Show an individual post as html
"""
return htmlHeader()+ \
individualPostAsHtml(postJsonObject)+ \
individualPostAsHtml(session,wfRequest,personCache, \
domain,postJsonObject)+ \
htmlFooter()
def htmlPostReplies(postJsonObject: {}) -> str: