Undo announces via the web interface

master
Bob Mottram 2019-08-01 13:18:22 +01:00
parent c7ecd001a9
commit 7c7ace43f9
4 changed files with 55 additions and 20 deletions

View File

@ -82,19 +82,19 @@ def undoAnnounceCollectionEntry(postFilename: str,actor: str,debug: bool) -> Non
if postJsonObject['object']['shares'].get('totalItems'): if postJsonObject['object']['shares'].get('totalItems'):
totalItems=postJsonObject['object']['shares']['totalItems'] totalItems=postJsonObject['object']['shares']['totalItems']
itemFound=False itemFound=False
for likeItem in postJsonObject['object']['shares']['items']: for announceItem in postJsonObject['object']['shares']['items']:
if likeItem.get('actor'): if announceItem.get('actor'):
if likeItem['actor']==actor: if announceItem['actor']==actor:
if debug: if debug:
print('DEBUG: Announce was removed for '+actor) print('DEBUG: Announce was removed for '+actor)
postJsonObject['object']['shares']['items'].remove(likeItem) postJsonObject['object']['shares']['items'].remove(announceItem)
itemFound=True itemFound=True
break break
if itemFound: if itemFound:
if totalItems==1: if totalItems==1:
if debug: if debug:
print('DEBUG: shares (announcements) was removed from post') print('DEBUG: shares (announcements) was removed from post')
postJsonObject['object'].remove(postJsonObject['object']['shares']) del postJsonObject['object']['shares']
else: else:
postJsonObject['object']['shares']['totalItems']=len(postJsonObject['shares']['items']) postJsonObject['object']['shares']['totalItems']=len(postJsonObject['shares']['items'])
with open(postFilename, 'w') as fp: with open(postFilename, 'w') as fp:

View File

@ -673,6 +673,33 @@ class PubServer(BaseHTTPRequestHandler):
self._redirect_headers(actor+'/inbox',cookie) self._redirect_headers(actor+'/inbox',cookie)
return 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 # like from the web interface icon
if authorized and '?like=' in self.path: if authorized and '?like=' in self.path:
likeUrl=self.path.split('?like=')[1] likeUrl=self.path.split('?like=')[1]

View File

@ -55,7 +55,7 @@ def undoLikesCollectionEntry(postFilename: str,objectUrl: str, actor: str,debug:
if totalItems==1: if totalItems==1:
if debug: if debug:
print('DEBUG: likes was removed from post') print('DEBUG: likes was removed from post')
postJsonObject['object'].remove(postJsonObject['object']['likes']) del postJsonObject['object']['likes']
else: else:
postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items']) postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items'])
with open(postFilename, 'w') as fp: with open(postFilename, 'w') as fp:

View File

@ -23,6 +23,7 @@ from posts import parseUserFeed
from session import getJson from session import getJson
from auth import createPassword from auth import createPassword
from like import likedByPerson from like import likedByPerson
from announce import announcedByPerson
def htmlGetLoginCredentials(loginParams: str,lastLoginTime: int) -> (str,str): def htmlGetLoginCredentials(loginParams: str,lastLoginTime: int) -> (str,str):
"""Receives login credentials via HTTPServer POST """Receives login credentials via HTTPServer POST
@ -559,19 +560,26 @@ def individualPostAsHtml(baseDir: str, \
footerStr='<span class="'+timeClass+'">'+publishedStr+'</span>\n' footerStr='<span class="'+timeClass+'">'+publishedStr+'</span>\n'
# don't allow announce/repeat of your own posts # don't allow announce/repeat of your own posts
announceStr='' announceIcon='repeat_inactive.png'
likeStr='' announceLink='repeat'
if fullDomain+'/users/'+nickname not in postJsonObject['actor']: announceTitle='Repeat this post'
if announcedByPerson(postJsonObject,nickname,fullDomain):
announceIcon='repeat.png'
announceLink='unrepeat'
announceTitle='Undo the repeat this post'
announceStr= \ announceStr= \
'<a href="/users/'+nickname+'?repeat='+postJsonObject['object']['id']+'" title="Repeat this post">' \ '<a href="/users/'+nickname+'?'+announceLink+'='+postJsonObject['object']['id']+'" title="'+announceTitle+'">' \
'<img src="/icons/repeat_inactive.png"/></a>' '<img src="/icons/'+announceIcon+'"/></a>'
likeIcon='like_inactive.png' likeIcon='like_inactive.png'
likeLink='like' likeLink='like'
likeTitle='Like this post'
if likedByPerson(postJsonObject,nickname,fullDomain): if likedByPerson(postJsonObject,nickname,fullDomain):
likeIcon='like.png' likeIcon='like.png'
likeLink='unlike' likeLink='unlike'
likeTitle='Undo the like of this post'
likeStr= \ likeStr= \
'<a href="/users/'+nickname+'?'+likeLink+'='+postJsonObject['object']['id']+'" title="Like this post">' \ '<a href="/users/'+nickname+'?'+likeLink+'='+postJsonObject['object']['id']+'" title="'+likeTitle+'">' \
'<img src="/icons/'+likeIcon+'"/></a>' '<img src="/icons/'+likeIcon+'"/></a>'
if showIcons: if showIcons: