From 5dc3e11374b3cba5643916d02bc1a37bf859fc6f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 28 Sep 2021 14:24:57 +0100 Subject: [PATCH] Setting recent posts json after mute --- blocking.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/blocking.py b/blocking.py index 96b1865d3..a56836342 100644 --- a/blocking.py +++ b/blocking.py @@ -512,8 +512,9 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int, igIt = len(itemsList) itemsList.append(newIgnore) postJsonObj['ignores']['totalItems'] = igIt - postJsonObject['muted'] = True - saveJson(postJsonObject, postFilename) + postJsonObj['muted'] = True + if saveJson(postJsonObject, postFilename): + print('mutePost: saved ' + postFilename) # remove cached post so that the muted version gets recreated # 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('/', '#') if postId in recentPostsCache['index']: print('MUTE: ' + postId + ' is in recent posts cache') - if recentPostsCache['json'].get(postId): - postJsonObject['muted'] = True - recentPostsCache['json'][postId] = json.dumps(postJsonObject) - print('MUTE: ' + postId + - ' marked as muted in recent posts memory cache') + if recentPostsCache.get('json'): + recentPostsCache['json'][postId] = json.dumps(postJsonObject) + print('MUTE: ' + postId + + ' marked as muted in recent posts memory cache') if recentPostsCache.get('html'): if recentPostsCache['html'].get(postId): del recentPostsCache['html'][postId] @@ -598,7 +598,7 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int, else: igItLen = len(postJsonObj['ignores']['items']) postJsonObj['ignores']['totalItems'] = igItLen - postJsonObject['muted'] = False + postJsonObj['muted'] = False saveJson(postJsonObject, postFilename) # 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('/', '#') if postId in recentPostsCache['index']: print('UNMUTE: ' + postId + ' is in recent posts cache') - if recentPostsCache['json'].get(postId): - postJsonObject['muted'] = False - recentPostsCache['json'][postId] = json.dumps(postJsonObject) - print('UNMUTE: ' + postId + - ' marked as unmuted in recent posts cache') + if recentPostsCache.get('json'): + recentPostsCache['json'][postId] = json.dumps(postJsonObject) + print('UNMUTE: ' + postId + + ' marked as unmuted in recent posts cache') if recentPostsCache.get('html'): if recentPostsCache['html'].get(postId): del recentPostsCache['html'][postId]