From c125d4dc694d7cb3fb275daca41164d555e17963 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 1 Dec 2019 14:34:10 +0000 Subject: [PATCH] Add muted parameter to recent posts cache --- posts.py | 19 ++++++++++++++++--- webinterface.py | 18 +++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/posts.py b/posts.py index 259271559..05da2c3b5 100644 --- a/posts.py +++ b/posts.py @@ -2660,8 +2660,15 @@ def mutePost(baseDir: str,nickname: str,domain: str,postId: str, \ getCachedPostFilename(baseDir,nickname,domain,postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) - removePostFromCache(postJsonObject,recentPostsCache) + os.remove(cachedPostFilename) + + # if the post is in the recent posts cache then mark it as muted + postId=postJsonObject['id'].replace('/activity','').replace('/','#') + if postId in recentPostsCache['index']: + print('MUTE: '+postId+' is in recent posts cache') + if recentPostsCache['json'].get(postId): + recentPostsCache['json'][postId]['muted']=True + print('MUTE: '+postId+' marked as muted in recent posts cache') def unmutePost(baseDir: str,nickname: str,domain: str,postId: str, \ recentPostsCache: {}) -> None: @@ -2685,4 +2692,10 @@ def unmutePost(baseDir: str,nickname: str,domain: str,postId: str, \ if cachedPostFilename: if os.path.isfile(cachedPostFilename): os.remove(cachedPostFilename) - removePostFromCache(postJsonObject,recentPostsCache) + # if the post is in the recent posts cache then mark it as not muted + postId=postJsonObject['id'].replace('/activity','').replace('/','#') + if postId in recentPostsCache['index']: + print('UNMUTE: '+postId+' is in recent posts cache') + if recentPostsCache['json'].get(postId): + recentPostsCache['json'][postId]['muted']=False + print('UNMUTE: '+postId+' marked as not muted in recent posts cache') diff --git a/webinterface.py b/webinterface.py index 0c1066791..5979f8c3e 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1995,20 +1995,19 @@ def preparePostFromHtmlCache(postHtml: str,boxName: str,pageNumber: int) -> str: postHtml=postHtml.replace('?tl=inbox','?tl=tlbookmarks') return postHtml.replace(';-999;',';'+str(pageNumber)+';').replace('?page=-999','?page='+str(pageNumber)) -def postIsMuted(baseDir: str,nickname: str,domain: str, messageId: str) -> bool: +def postIsMuted(baseDir: str,nickname: str,domain: str, postJsonObject: {},messageId: str) -> bool: """ Returns true if the given post is muted """ + if postJsonObject.get('muted'): + return True postDir=baseDir+'/accounts/'+nickname+'@'+domain muteFilename=postDir+'/inbox/'+messageId.replace('/','#')+'.json.muted' - print('TEST MUTE: '+muteFilename) if os.path.isfile(muteFilename): return True muteFilename=postDir+'/outbox/'+messageId.replace('/','#')+'.json.muted' - print('TEST MUTE: '+muteFilename) if os.path.isfile(muteFilename): return True muteFilename=baseDir+'/accounts/cache/announce/'+nickname+'/'+messageId.replace('/','#')+'.json.muted' - print('TEST MUTE: '+muteFilename) if os.path.isfile(muteFilename): return True return False @@ -2256,7 +2255,7 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \ '?tl='+boxName+'" title="'+bookmarkTitle+'">' bookmarkStr+=''+bookmarkTitle+' |' - isMuted=postIsMuted(baseDir,nickname,domain,messageId) + isMuted=postIsMuted(baseDir,nickname,domain,postJsonObject,messageId) deleteStr='' muteStr='' @@ -2804,10 +2803,11 @@ def htmlTimeline(defaultTimeline: str, \ if boxName!='tlmedia' and recentPostsCache.get('index'): postId=item['id'].replace('/activity','').replace('/','#') if postId in recentPostsCache['index']: - if recentPostsCache['html'].get(postId): - currTlStr=recentPostsCache['html'][postId] - currTlStr= \ - preparePostFromHtmlCache(currTlStr,boxName,pageNumber) + if not item.get('muted'): + if recentPostsCache['html'].get(postId): + currTlStr=recentPostsCache['html'][postId] + currTlStr= \ + preparePostFromHtmlCache(currTlStr,boxName,pageNumber) if not currTlStr: # read the post from disk currTlStr= \