forked from indymedia/epicyon
Fix display of likes
parent
05b4827cfb
commit
ab9b42c211
23
like.py
23
like.py
|
@ -64,21 +64,28 @@ def undoLikesCollectionEntry(postFilename: str,objectUrl: str,actor: str,debug:
|
|||
def likedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool:
|
||||
"""Returns True if the given post is liked by the given person
|
||||
"""
|
||||
if not postJsonObject.get('object'):
|
||||
if noOfLikes(postJsonObject)==0:
|
||||
return False
|
||||
if not isinstance(postJsonObject['object'], dict):
|
||||
return False
|
||||
if not postJsonObject['object'].get('likes'):
|
||||
return False
|
||||
if not postJsonObject['object']['likes'].get('items'):
|
||||
postJsonObject['object']['likes']['items']=[]
|
||||
postJsonObject['object']['likes']['totalItems']=0
|
||||
actorMatch=domain+'/users/'+nickname
|
||||
for item in postJsonObject['object']['likes']['items']:
|
||||
if item['actor'].endswith(actorMatch):
|
||||
return True
|
||||
return False
|
||||
|
||||
def noOfLikes(postJsonObject: {}) -> int:
|
||||
"""Returns the number of likes ona given post
|
||||
"""
|
||||
if not postJsonObject.get('object'):
|
||||
return 0
|
||||
if not isinstance(postJsonObject['object'], dict):
|
||||
return 0
|
||||
if not postJsonObject['object'].get('likes'):
|
||||
return 0
|
||||
if not postJsonObject['object']['likes'].get('items'):
|
||||
postJsonObject['object']['likes']['items']=[]
|
||||
postJsonObject['object']['likes']['totalItems']=0
|
||||
return len(postJsonObject['object']['likes']['items'])
|
||||
|
||||
def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bool) -> None:
|
||||
"""Updates the likes collection within a post
|
||||
"""
|
||||
|
|
|
@ -33,6 +33,7 @@ from posts import outboxMessageCreateWrap
|
|||
from session import getJson
|
||||
from auth import createPassword
|
||||
from like import likedByPerson
|
||||
from like import noOfLikes
|
||||
from announce import announcedByPerson
|
||||
from blocking import isBlocked
|
||||
from content import getMentionsFromHtml
|
||||
|
@ -1549,7 +1550,7 @@ def individualPostAsHtml(baseDir: str, \
|
|||
likeIcon='like_inactive.png'
|
||||
likeLink='like'
|
||||
likeTitle='Like this post'
|
||||
if likedByPerson(postJsonObject,nickname,fullDomain):
|
||||
if noOfLikes(postJsonObject)>0:
|
||||
likeIcon='like.png'
|
||||
likeLink='unlike'
|
||||
likeTitle='Undo the like of this post'
|
||||
|
|
Loading…
Reference in New Issue