forked from indymedia/epicyon
Undoing likes via the web interface
parent
f9d86cf762
commit
cfae58b92b
54
daemon.py
54
daemon.py
|
@ -641,6 +641,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.GETbusy=False
|
||||
return
|
||||
|
||||
# announce/repeat from the web interface
|
||||
if authorized and '?repeat=' in self.path:
|
||||
repeatUrl=self.path.split('?repeat=')[1]
|
||||
actor=self.path.split('?repeat=')[0]
|
||||
|
@ -667,7 +668,58 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
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]
|
||||
actor=self.path.split('?like=')[0]
|
||||
self.postToNickname=getNicknameFromActor(actor)
|
||||
if not self.server.session:
|
||||
self.server.session= \
|
||||
createSession(self.server.domain,self.server.port,self.server.useTor)
|
||||
likeActor=self.server.httpPrefix+'://'+self.server.fullDomain+'/users/'+self.postToNickname
|
||||
likeJson= {
|
||||
'type': 'Like',
|
||||
'actor': likeActor,
|
||||
'object': likeUrl,
|
||||
'to': [likeActor+'/followers'],
|
||||
'cc': []
|
||||
}
|
||||
if likeJson:
|
||||
self._postToOutbox(likeJson)
|
||||
self.server.GETbusy=False
|
||||
self._redirect_headers(actor+'/inbox',cookie)
|
||||
return
|
||||
|
||||
# undo a like from the web interface icon
|
||||
if authorized and '?unlike=' in self.path:
|
||||
likeUrl=self.path.split('?unlike=')[1]
|
||||
actor=self.path.split('?unlike=')[0]
|
||||
self.postToNickname=getNicknameFromActor(actor)
|
||||
if not self.server.session:
|
||||
self.server.session= \
|
||||
createSession(self.server.domain,self.server.port,self.server.useTor)
|
||||
undoActor=self.server.httpPrefix+'://'+self.server.fullDomain+'/users/'+self.postToNickname
|
||||
undoLikeJson= {
|
||||
'type': 'Undo',
|
||||
'actor': undoActor,
|
||||
'object': {
|
||||
'type': 'Like',
|
||||
'actor': undoActor,
|
||||
'object': likeUrl,
|
||||
'to': [undoActor+'/followers'],
|
||||
'cc': []
|
||||
},
|
||||
'to': [undoActor+'/followers'],
|
||||
'cc': []
|
||||
}
|
||||
if undoLikeJson:
|
||||
self._postToOutbox(undoLikeJson)
|
||||
self.server.GETbusy=False
|
||||
self._redirect_headers(actor+'/inbox',cookie)
|
||||
return
|
||||
|
||||
# reply from the web interface icon
|
||||
inReplyTo=None
|
||||
if authorized and '?replyto=' in self.path:
|
||||
inReplyTo=self.path.split('?replyto=')[1]
|
||||
|
|
15
like.py
15
like.py
|
@ -59,6 +59,21 @@ def undoLikesCollectionEntry(postFilename: str,objectUrl: str, actor: str,debug:
|
|||
with open(postFilename, 'w') as fp:
|
||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=True)
|
||||
|
||||
def likedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool:
|
||||
"""Returns True if the given post is liked by the given actor
|
||||
"""
|
||||
if not postJsonObject.get('object'):
|
||||
return False
|
||||
if not isinstance(postJsonObject['object'], dict):
|
||||
return False
|
||||
if not postJsonObject['object'].get('likes'):
|
||||
return False
|
||||
actorMatch=domain+'/users/'+nickname
|
||||
for item in postJsonObject['object']['likes']['items']:
|
||||
if item['actor'].endswith(actorMatch):
|
||||
return True
|
||||
return False
|
||||
|
||||
def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bool) -> None:
|
||||
"""Updates the likes collection within a post
|
||||
"""
|
||||
|
|
|
@ -22,6 +22,7 @@ from posts import getUserUrl
|
|||
from posts import parseUserFeed
|
||||
from session import getJson
|
||||
from auth import createPassword
|
||||
from like import likedByPerson
|
||||
|
||||
def htmlGetLoginCredentials(loginParams: str,lastLoginTime: int) -> (str,str):
|
||||
"""Receives login credentials via HTTPServer POST
|
||||
|
@ -563,10 +564,15 @@ def individualPostAsHtml(baseDir: str, \
|
|||
if fullDomain+'/users/'+nickname not in postJsonObject['actor']:
|
||||
announceStr= \
|
||||
'<a href="/users/'+nickname+'?repeat='+postJsonObject['object']['id']+'" title="Repeat this post">' \
|
||||
'<img src="/icons/repeat_inactive.png"/></a>'
|
||||
'<img src="/icons/repeat_inactive.png"/></a>'
|
||||
likeIcon='like_inactive.png'
|
||||
likeLink='like'
|
||||
if likedByPerson(postJsonObject,nickname,fullDomain):
|
||||
likeIcon='like.png'
|
||||
likeLink='unlike'
|
||||
likeStr= \
|
||||
'<a href="/users/'+nickname+'?like='+postJsonObject['object']['id']+'" title="Like this post">' \
|
||||
'<img src="/icons/like_inactive.png"/></a>'
|
||||
'<a href="/users/'+nickname+'?'+likeLink+'='+postJsonObject['object']['id']+'" title="Like this post">' \
|
||||
'<img src="/icons/'+likeIcon+'"/></a>'
|
||||
|
||||
if showIcons:
|
||||
footerStr='<div class="'+containerClassIcons+'">'
|
||||
|
|
Loading…
Reference in New Issue