Less indentation

main
Bob Mottram 2020-06-28 12:09:38 +01:00
parent 67c6c16ef4
commit 01338dd85d
1 changed files with 49 additions and 48 deletions

View File

@ -898,58 +898,59 @@ def updateLikesCollection(recentPostsCache: {},
"""Updates the likes collection within a post """Updates the likes collection within a post
""" """
postJsonObject = loadJson(postFilename) postJsonObject = loadJson(postFilename)
if postJsonObject: if not postJsonObject:
# remove any cached version of this post so that the return
# like icon is changed # remove any cached version of this post so that the
nickname = getNicknameFromActor(actor) # like icon is changed
cachedPostFilename = getCachedPostFilename(baseDir, nickname, nickname = getNicknameFromActor(actor)
domain, postJsonObject) cachedPostFilename = getCachedPostFilename(baseDir, nickname,
if cachedPostFilename: domain, postJsonObject)
if os.path.isfile(cachedPostFilename): if cachedPostFilename:
os.remove(cachedPostFilename) if os.path.isfile(cachedPostFilename):
removePostFromCache(postJsonObject, recentPostsCache) os.remove(cachedPostFilename)
removePostFromCache(postJsonObject, recentPostsCache)
if not postJsonObject.get('object'): if not postJsonObject.get('object'):
if debug: if debug:
pprint(postJsonObject) pprint(postJsonObject)
print('DEBUG: post ' + objectUrl + ' has no object') print('DEBUG: post ' + objectUrl + ' has no object')
return return
if not isinstance(postJsonObject['object'], dict): if not isinstance(postJsonObject['object'], dict):
return 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 postJsonObject['object'].get('likes'):
if debug: if debug:
print('DEBUG: Adding initial like to ' + objectUrl) print('DEBUG: Adding initial like to ' + objectUrl)
likesJson = { likesJson = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
'id': objectUrl, 'id': objectUrl,
'type': 'Collection', 'type': 'Collection',
"totalItems": 1, "totalItems": 1,
'items': [{ 'items': [{
'type': 'Like',
'actor': actor
}]
}
postJsonObject['object']['likes'] = likesJson
else:
if not postJsonObject['object']['likes'].get('items'):
postJsonObject['object']['likes']['items'] = []
for likeItem in postJsonObject['object']['likes']['items']:
if likeItem.get('actor'):
if likeItem['actor'] == actor:
return
newLike = {
'type': 'Like', 'type': 'Like',
'actor': actor 'actor': actor
} }]
postJsonObject['object']['likes']['items'].append(newLike) }
itlen = len(postJsonObject['object']['likes']['items']) postJsonObject['object']['likes'] = likesJson
postJsonObject['object']['likes']['totalItems'] = itlen else:
if not postJsonObject['object']['likes'].get('items'):
postJsonObject['object']['likes']['items'] = []
for likeItem in postJsonObject['object']['likes']['items']:
if likeItem.get('actor'):
if likeItem['actor'] == actor:
return
newLike = {
'type': 'Like',
'actor': actor
}
postJsonObject['object']['likes']['items'].append(newLike)
itlen = len(postJsonObject['object']['likes']['items'])
postJsonObject['object']['likes']['totalItems'] = itlen
if debug: if debug:
print('DEBUG: saving post with likes added') print('DEBUG: saving post with likes added')
pprint(postJsonObject) pprint(postJsonObject)
saveJson(postJsonObject, postFilename) saveJson(postJsonObject, postFilename)