mirror of https://gitlab.com/bashrc2/epicyon
Announces can have likes collections
parent
9e1cdfe8da
commit
b490c0b791
24
like.py
24
like.py
|
@ -425,14 +425,12 @@ def updateLikesCollection(recentPostsCache: {},
|
||||||
except BaseException:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not hasObjectDict(postJsonObject):
|
obj = postJsonObject
|
||||||
if debug:
|
if hasObjectDict(postJsonObject):
|
||||||
pprint(postJsonObject)
|
obj = postJsonObject['object']
|
||||||
print('DEBUG: post ' + objectUrl + ' has no object')
|
|
||||||
return
|
|
||||||
if not objectUrl.endswith('/likes'):
|
if not objectUrl.endswith('/likes'):
|
||||||
objectUrl = objectUrl + '/likes'
|
objectUrl = objectUrl + '/likes'
|
||||||
if not postJsonObject['object'].get('likes'):
|
if not obj.get('likes'):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Adding initial like to ' + objectUrl)
|
print('DEBUG: Adding initial like to ' + objectUrl)
|
||||||
likesJson = {
|
likesJson = {
|
||||||
|
@ -445,11 +443,11 @@ def updateLikesCollection(recentPostsCache: {},
|
||||||
'actor': actor
|
'actor': actor
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
postJsonObject['object']['likes'] = likesJson
|
obj['likes'] = likesJson
|
||||||
else:
|
else:
|
||||||
if not postJsonObject['object']['likes'].get('items'):
|
if not obj['likes'].get('items'):
|
||||||
postJsonObject['object']['likes']['items'] = []
|
obj['likes']['items'] = []
|
||||||
for likeItem in postJsonObject['object']['likes']['items']:
|
for likeItem in obj['likes']['items']:
|
||||||
if likeItem.get('actor'):
|
if likeItem.get('actor'):
|
||||||
if likeItem['actor'] == actor:
|
if likeItem['actor'] == actor:
|
||||||
# already liked
|
# already liked
|
||||||
|
@ -458,9 +456,9 @@ def updateLikesCollection(recentPostsCache: {},
|
||||||
'type': 'Like',
|
'type': 'Like',
|
||||||
'actor': actor
|
'actor': actor
|
||||||
}
|
}
|
||||||
postJsonObject['object']['likes']['items'].append(newLike)
|
obj['likes']['items'].append(newLike)
|
||||||
itlen = len(postJsonObject['object']['likes']['items'])
|
itlen = len(obj['likes']['items'])
|
||||||
postJsonObject['object']['likes']['totalItems'] = itlen
|
obj['likes']['totalItems'] = itlen
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: saving post with likes added')
|
print('DEBUG: saving post with likes added')
|
||||||
|
|
28
utils.py
28
utils.py
|
@ -2184,27 +2184,25 @@ def undoLikesCollectionEntry(recentPostsCache: {},
|
||||||
return
|
return
|
||||||
if postJsonObject['type'] != 'Create':
|
if postJsonObject['type'] != 'Create':
|
||||||
return
|
return
|
||||||
if not hasObjectDict(postJsonObject):
|
obj = postJsonObject
|
||||||
if debug:
|
if hasObjectDict(postJsonObject):
|
||||||
pprint(postJsonObject)
|
obj = postJsonObject['object']
|
||||||
print('DEBUG: post ' + objectUrl + ' has no object')
|
if not obj.get('likes'):
|
||||||
return
|
return
|
||||||
if not postJsonObject['object'].get('likes'):
|
if not isinstance(obj['likes'], dict):
|
||||||
return
|
return
|
||||||
if not isinstance(postJsonObject['object']['likes'], dict):
|
if not obj['likes'].get('items'):
|
||||||
return
|
|
||||||
if not postJsonObject['object']['likes'].get('items'):
|
|
||||||
return
|
return
|
||||||
totalItems = 0
|
totalItems = 0
|
||||||
if postJsonObject['object']['likes'].get('totalItems'):
|
if obj['likes'].get('totalItems'):
|
||||||
totalItems = postJsonObject['object']['likes']['totalItems']
|
totalItems = obj['likes']['totalItems']
|
||||||
itemFound = False
|
itemFound = False
|
||||||
for likeItem in postJsonObject['object']['likes']['items']:
|
for likeItem in obj['likes']['items']:
|
||||||
if likeItem.get('actor'):
|
if likeItem.get('actor'):
|
||||||
if likeItem['actor'] == actor:
|
if likeItem['actor'] == actor:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: like was removed for ' + actor)
|
print('DEBUG: like was removed for ' + actor)
|
||||||
postJsonObject['object']['likes']['items'].remove(likeItem)
|
obj['likes']['items'].remove(likeItem)
|
||||||
itemFound = True
|
itemFound = True
|
||||||
break
|
break
|
||||||
if not itemFound:
|
if not itemFound:
|
||||||
|
@ -2212,10 +2210,10 @@ def undoLikesCollectionEntry(recentPostsCache: {},
|
||||||
if totalItems == 1:
|
if totalItems == 1:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: likes was removed from post')
|
print('DEBUG: likes was removed from post')
|
||||||
del postJsonObject['object']['likes']
|
del obj['likes']
|
||||||
else:
|
else:
|
||||||
itlen = len(postJsonObject['object']['likes']['items'])
|
itlen = len(obj['likes']['items'])
|
||||||
postJsonObject['object']['likes']['totalItems'] = itlen
|
obj['likes']['totalItems'] = itlen
|
||||||
|
|
||||||
saveJson(postJsonObject, postFilename)
|
saveJson(postJsonObject, postFilename)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue