Setting recent posts json after mute

merge-requests/30/head
Bob Mottram 2021-09-28 14:24:57 +01:00
parent 31a3aeb2dc
commit 5dc3e11374
1 changed files with 12 additions and 13 deletions

View File

@ -512,8 +512,9 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
igIt = len(itemsList) igIt = len(itemsList)
itemsList.append(newIgnore) itemsList.append(newIgnore)
postJsonObj['ignores']['totalItems'] = igIt postJsonObj['ignores']['totalItems'] = igIt
postJsonObject['muted'] = True postJsonObj['muted'] = True
saveJson(postJsonObject, postFilename) if saveJson(postJsonObject, postFilename):
print('mutePost: saved ' + postFilename)
# remove cached post so that the muted version gets recreated # remove cached post so that the muted version gets recreated
# without its content text and/or image # without its content text and/or image
@ -539,11 +540,10 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
removeIdEnding(postJsonObject['id']).replace('/', '#') removeIdEnding(postJsonObject['id']).replace('/', '#')
if postId in recentPostsCache['index']: if postId in recentPostsCache['index']:
print('MUTE: ' + postId + ' is in recent posts cache') print('MUTE: ' + postId + ' is in recent posts cache')
if recentPostsCache['json'].get(postId): if recentPostsCache.get('json'):
postJsonObject['muted'] = True recentPostsCache['json'][postId] = json.dumps(postJsonObject)
recentPostsCache['json'][postId] = json.dumps(postJsonObject) print('MUTE: ' + postId +
print('MUTE: ' + postId + ' marked as muted in recent posts memory cache')
' marked as muted in recent posts memory cache')
if recentPostsCache.get('html'): if recentPostsCache.get('html'):
if recentPostsCache['html'].get(postId): if recentPostsCache['html'].get(postId):
del recentPostsCache['html'][postId] del recentPostsCache['html'][postId]
@ -598,7 +598,7 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
else: else:
igItLen = len(postJsonObj['ignores']['items']) igItLen = len(postJsonObj['ignores']['items'])
postJsonObj['ignores']['totalItems'] = igItLen postJsonObj['ignores']['totalItems'] = igItLen
postJsonObject['muted'] = False postJsonObj['muted'] = False
saveJson(postJsonObject, postFilename) saveJson(postJsonObject, postFilename)
# remove cached post so that the muted version gets recreated # remove cached post so that the muted version gets recreated
@ -618,11 +618,10 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
removeIdEnding(postJsonObject['id']).replace('/', '#') removeIdEnding(postJsonObject['id']).replace('/', '#')
if postId in recentPostsCache['index']: if postId in recentPostsCache['index']:
print('UNMUTE: ' + postId + ' is in recent posts cache') print('UNMUTE: ' + postId + ' is in recent posts cache')
if recentPostsCache['json'].get(postId): if recentPostsCache.get('json'):
postJsonObject['muted'] = False recentPostsCache['json'][postId] = json.dumps(postJsonObject)
recentPostsCache['json'][postId] = json.dumps(postJsonObject) print('UNMUTE: ' + postId +
print('UNMUTE: ' + postId + ' marked as unmuted in recent posts cache')
' marked as unmuted in recent posts cache')
if recentPostsCache.get('html'): if recentPostsCache.get('html'):
if recentPostsCache['html'].get(postId): if recentPostsCache['html'].get(postId):
del recentPostsCache['html'][postId] del recentPostsCache['html'][postId]