From fd8b2e67acbcddfa96997952a5cff905a8b74145 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 31 Jul 2019 11:09:02 +0100 Subject: [PATCH] Display announcements --- webinterface.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/webinterface.py b/webinterface.py index 7c00c33ee..c97cbb6a8 100644 --- a/webinterface.py +++ b/webinterface.py @@ -199,7 +199,7 @@ def htmlProfilePosts(baseDir: str,httpPrefix: str, \ authorized, \ ocapAlways) for item in outboxFeed['orderedItems']: - if item['type']=='Create': + if item['type']=='Create' or item['type']=='Announce': profileStr+= \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \ nickname,domain,port,item,None,True,False) @@ -419,13 +419,37 @@ def individualPostAsHtml(baseDir: str, \ postJsonObject: {}, \ avatarUrl: str, showAvatarDropdown: bool, showIcons=False) -> str: + """ Shows a single post as html + """ + titleStr='' + if postJsonObject['type']=='Announce': + if postJsonObject.get('object'): + if isinstance(postJsonObject['object'], str): + # get the announced post + asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} + announcedJson = getJson(session,postJsonObject['object'],asHeader,None) + if announcedJson: + if not postJsonObject.get('type'): + return '' + if postJsonObject['type']!='Create': + return '' + actorNickname=getNicknameFromActor(postJsonObject['actor']) + actorDomain,actorPort=getDomainFromActor(postJsonObject['actor']) + titleStr+='@'+actorNickname+'@'+actorDomain+' announced:\n' + postJsonObject=announcedJson + else: + return '' + else: + return '' + if not isinstance(postJsonObject['object'], dict): + return '' avatarPosition='' containerClass='container' containerClassIcons='containericons' timeClass='time-right' actorNickname=getNicknameFromActor(postJsonObject['actor']) actorDomain,actorPort=getDomainFromActor(postJsonObject['actor']) - titleStr='@'+actorNickname+'@'+actorDomain + titleStr+='@'+actorNickname+'@'+actorDomain if postJsonObject['object']['inReplyTo']: containerClassIcons='containericons darker' containerClass='container darker' @@ -564,7 +588,7 @@ def htmlTimeline(session,baseDir: str,wfRequest: {},personCache: {}, \ followApprovals+ \ '' for item in timelineJson['orderedItems']: - if item['type']=='Create': + if item['type']=='Create' or item['type']=='Announce': tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \ nickname,domain,port,item,None,True,showIndividualPostIcons) tlStr+=htmlFooter() @@ -773,7 +797,6 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \ if not backUrl.endswith('/inbox'): backUrl+='/inbox' - print('************************
') profileStr= \ '
' \ '
' \ @@ -798,7 +821,7 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \ for item in parseUserFeed(session,outboxUrl,asHeader): if not item.get('type'): continue - if item['type']!='Create': + if item['type']!='Create' and item['type']!='Announce': continue if not item.get('object'): continue