Use like json if available when updating collections

merge-requests/26/head
Bob Mottram 2021-10-17 17:11:38 +01:00
parent aa11bb566f
commit 7ee48e6d20
4 changed files with 21 additions and 15 deletions

View File

@ -7401,7 +7401,7 @@ class PubServer(BaseHTTPRequestHandler):
updateLikesCollection(recentPostsCache,
baseDir, likedPostFilename,
likeUrl, likeActor, self.postToNickname,
domain, debug)
domain, debug, likedPostJson)
likeUrl = origPostUrl
likedPostFilename = origFilename
if debug:
@ -7409,7 +7409,7 @@ class PubServer(BaseHTTPRequestHandler):
updateLikesCollection(recentPostsCache,
baseDir, likedPostFilename, likeUrl,
likeActor, self.postToNickname, domain,
debug)
debug, None)
if debug:
print('Regenerating html post for changed likes collection')
# clear the icon from the cache so that it gets updated
@ -7570,7 +7570,8 @@ class PubServer(BaseHTTPRequestHandler):
if origFilename and origPostUrl:
undoLikesCollectionEntry(recentPostsCache,
baseDir, likedPostFilename,
likeUrl, undoActor, domain, debug)
likeUrl, undoActor, domain, debug,
likedPostJson)
likeUrl = origPostUrl
likedPostFilename = origFilename
if debug:
@ -7578,7 +7579,7 @@ class PubServer(BaseHTTPRequestHandler):
undoLikesCollectionEntry(recentPostsCache,
baseDir,
likedPostFilename, likeUrl,
undoActor, domain, debug)
undoActor, domain, debug, None)
if debug:
print('Regenerating html post for changed likes collection')
if likedPostJson:

View File

@ -940,7 +940,7 @@ def _receiveLike(recentPostsCache: {},
likeActor, postLikedId)
updateLikesCollection(recentPostsCache, baseDir, postFilename,
postLikedId, likeActor,
handleName, domain, debug)
handleName, domain, debug, None)
# regenerate the html
likedPostJson = loadJson(postFilename, 0, 1)
if likedPostJson:
@ -961,7 +961,7 @@ def _receiveLike(recentPostsCache: {},
postLikedId,
likeActor,
handleName,
domain, debug)
domain, debug, None)
if likedPostJson:
if debug:
cachedPostFilename = \
@ -1052,7 +1052,7 @@ def _receiveUndoLike(recentPostsCache: {},
likeActor = messageJson['actor']
postLikedId = messageJson['object']
undoLikesCollectionEntry(recentPostsCache, baseDir, postFilename,
postLikedId, likeActor, domain, debug)
postLikedId, likeActor, domain, debug, None)
# regenerate the html
likedPostJson = loadJson(postFilename, 0, 1)
if likedPostJson:
@ -1069,7 +1069,8 @@ def _receiveUndoLike(recentPostsCache: {},
postFilename = announceLikedFilename
undoLikesCollectionEntry(recentPostsCache, baseDir,
postFilename, postLikedId,
likeActor, domain, debug)
likeActor, domain, debug,
None)
if likedPostJson:
if debug:
cachedPostFilename = \

12
like.py
View File

@ -129,7 +129,7 @@ def _like(recentPostsCache: {},
updateLikesCollection(recentPostsCache,
baseDir, postFilename, objectUrl,
newLikeJson['actor'],
nickname, domain, debug)
nickname, domain, debug, None)
sendSignedJson(newLikeJson, session, baseDir,
nickname, domain, port,
@ -368,7 +368,7 @@ def outboxLike(recentPostsCache: {},
updateLikesCollection(recentPostsCache,
baseDir, postFilename, messageId,
messageJson['actor'],
nickname, domain, debug)
nickname, domain, debug, None)
if debug:
print('DEBUG: post liked via c2s - ' + postFilename)
@ -404,7 +404,7 @@ def outboxUndoLike(recentPostsCache: {},
return True
undoLikesCollectionEntry(recentPostsCache, baseDir, postFilename,
messageId, messageJson['actor'],
domain, debug)
domain, debug, None)
if debug:
print('DEBUG: post undo liked via c2s - ' + postFilename)
@ -412,10 +412,12 @@ def outboxUndoLike(recentPostsCache: {},
def updateLikesCollection(recentPostsCache: {},
baseDir: str, postFilename: str,
objectUrl: str, actor: str,
nickname: str, domain: str, debug: bool) -> None:
nickname: str, domain: str, debug: bool,
postJsonObject: {}) -> None:
"""Updates the likes collection within a post
"""
postJsonObject = loadJson(postFilename)
if not postJsonObject:
postJsonObject = loadJson(postFilename)
if not postJsonObject:
return

View File

@ -2161,10 +2161,12 @@ def getFileCaseInsensitive(path: str) -> str:
def undoLikesCollectionEntry(recentPostsCache: {},
baseDir: str, postFilename: str, objectUrl: str,
actor: str, domain: str, debug: bool) -> None:
actor: str, domain: str, debug: bool,
postJsonObject: {}) -> None:
"""Undoes a like for a particular actor
"""
postJsonObject = loadJson(postFilename)
if not postJsonObject:
postJsonObject = loadJson(postFilename)
if not postJsonObject:
return
# remove any cached version of this post so that the