From 7c7ace43f9e4122121d66fb6251ed988884c5c13 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 1 Aug 2019 13:18:22 +0100 Subject: [PATCH] Undo announces via the web interface --- announce.py | 10 +++++----- daemon.py | 27 +++++++++++++++++++++++++++ like.py | 2 +- webinterface.py | 36 ++++++++++++++++++++++-------------- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/announce.py b/announce.py index c91b1f9cd..b7566c2d5 100644 --- a/announce.py +++ b/announce.py @@ -82,19 +82,19 @@ def undoAnnounceCollectionEntry(postFilename: str,actor: str,debug: bool) -> Non if postJsonObject['object']['shares'].get('totalItems'): totalItems=postJsonObject['object']['shares']['totalItems'] itemFound=False - for likeItem in postJsonObject['object']['shares']['items']: - if likeItem.get('actor'): - if likeItem['actor']==actor: + for announceItem in postJsonObject['object']['shares']['items']: + if announceItem.get('actor'): + if announceItem['actor']==actor: if debug: print('DEBUG: Announce was removed for '+actor) - postJsonObject['object']['shares']['items'].remove(likeItem) + postJsonObject['object']['shares']['items'].remove(announceItem) itemFound=True break if itemFound: if totalItems==1: if debug: print('DEBUG: shares (announcements) was removed from post') - postJsonObject['object'].remove(postJsonObject['object']['shares']) + del postJsonObject['object']['shares'] else: postJsonObject['object']['shares']['totalItems']=len(postJsonObject['shares']['items']) with open(postFilename, 'w') as fp: diff --git a/daemon.py b/daemon.py index ad4e8a85c..d2ac34a86 100644 --- a/daemon.py +++ b/daemon.py @@ -673,6 +673,33 @@ class PubServer(BaseHTTPRequestHandler): self._redirect_headers(actor+'/inbox',cookie) return + # undo an announce/repeat from the web interface + if authorized and '?unrepeat=' in self.path: + repeatUrl=self.path.split('?unrepeat=')[1] + actor=self.path.split('?unrepeat=')[0] + self.postToNickname=getNicknameFromActor(actor) + if not self.server.session: + self.server.session= \ + createSession(self.server.domain,self.server.port,self.server.useTor) + undoAnnounceActor=self.server.httpPrefix+'://'+self.server.domainFull+'/users/'+self.postToNickname + newUndoAnnounce = { + 'actor': undoAnnounceActor, + 'type': 'Undo', + 'cc': [undoAnnounceActor+'/followers'], + 'to': ['https://www.w3.org/ns/activitystreams#Public'], + 'object': { + 'actor': undoAnnounceActor, + 'cc': [undoAnnounceActor+'/followers'], + 'object': repeatUrl, + 'to': ['https://www.w3.org/ns/activitystreams#Public'], + 'type': 'Announce' + } + } + self._postToOutbox(newUndoAnnounce) + self.server.GETbusy=False + self._redirect_headers(actor+'/inbox',cookie) + return + # like from the web interface icon if authorized and '?like=' in self.path: likeUrl=self.path.split('?like=')[1] diff --git a/like.py b/like.py index d2cdd6a12..8d7a738b1 100644 --- a/like.py +++ b/like.py @@ -55,7 +55,7 @@ def undoLikesCollectionEntry(postFilename: str,objectUrl: str, actor: str,debug: if totalItems==1: if debug: print('DEBUG: likes was removed from post') - postJsonObject['object'].remove(postJsonObject['object']['likes']) + del postJsonObject['object']['likes'] else: postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items']) with open(postFilename, 'w') as fp: diff --git a/webinterface.py b/webinterface.py index 9de9c2ca7..974455576 100644 --- a/webinterface.py +++ b/webinterface.py @@ -23,6 +23,7 @@ from posts import parseUserFeed from session import getJson from auth import createPassword from like import likedByPerson +from announce import announcedByPerson def htmlGetLoginCredentials(loginParams: str,lastLoginTime: int) -> (str,str): """Receives login credentials via HTTPServer POST @@ -559,20 +560,27 @@ def individualPostAsHtml(baseDir: str, \ footerStr=''+publishedStr+'\n' # don't allow announce/repeat of your own posts - announceStr='' - likeStr='' - if fullDomain+'/users/'+nickname not in postJsonObject['actor']: - announceStr= \ - '' \ - '' - likeIcon='like_inactive.png' - likeLink='like' - if likedByPerson(postJsonObject,nickname,fullDomain): - likeIcon='like.png' - likeLink='unlike' - likeStr= \ - '' \ - '' + announceIcon='repeat_inactive.png' + announceLink='repeat' + announceTitle='Repeat this post' + if announcedByPerson(postJsonObject,nickname,fullDomain): + announceIcon='repeat.png' + announceLink='unrepeat' + announceTitle='Undo the repeat this post' + announceStr= \ + '' \ + '' + + likeIcon='like_inactive.png' + likeLink='like' + likeTitle='Like this post' + if likedByPerson(postJsonObject,nickname,fullDomain): + likeIcon='like.png' + likeLink='unlike' + likeTitle='Undo the like of this post' + likeStr= \ + '' \ + '' if showIcons: footerStr='
'