From cabdc9c3c5fa6210edf2ac560f1ed8bef383993d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 27 Aug 2020 18:40:09 +0100 Subject: [PATCH] Replies to muted posts are also muted --- inbox.py | 22 +++++++++++++++++++--- posts.py | 11 +++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/inbox.py b/inbox.py index 808858d4..ced05e1f 100644 --- a/inbox.py +++ b/inbox.py @@ -55,6 +55,7 @@ from posts import validContentWarning from posts import downloadAnnounce from posts import isDM from posts import isReply +from posts import isMuted from posts import isImageMedia from posts import sendSignedJson from posts import sendToFollowersThread @@ -2302,6 +2303,8 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int, postJsonObject, debug, __version__) + isReplyToMutedPost = False + if not isGroup: # create a DM notification file if needed postIsDM = isDM(postJsonObject) @@ -2352,9 +2355,13 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int, if nickname != 'inbox': # replies index will be updated updateIndexList.append('tlreplies') - replyNotify(baseDir, handle, - httpPrefix + '://' + domain + - '/users/' + nickname + '/tlreplies') + if not isMuted(baseDir, nickname, domain, + postJsonObject['object']['inReplyTo']): + replyNotify(baseDir, handle, + httpPrefix + '://' + domain + + '/users/' + nickname + '/tlreplies') + else: + isReplyToMutedPost = True if isImageMedia(session, baseDir, httpPrefix, nickname, domain, postJsonObject, @@ -2375,6 +2382,15 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int, # save the post to file if saveJson(postJsonObject, destinationFilename): + # If this is a reply to a muted post then also mute it. + # This enables you to ignore a threat that's getting boring + if isReplyToMutedPost: + print('MUTE REPLY: ' + destinationFilename) + muteFile = open(destinationFilename + '.muted', "w") + if muteFile: + muteFile.write('\n') + muteFile.close() + # update the indexes for different timelines for boxname in updateIndexList: if not inboxUpdateIndex(boxname, baseDir, handle, diff --git a/posts.py b/posts.py index 3a07d867..1517fea4 100644 --- a/posts.py +++ b/posts.py @@ -3509,6 +3509,17 @@ def downloadAnnounce(session, baseDir: str, httpPrefix: str, return None +def isMuted(baseDir: str, nickname: str, domain: str, postId: str) -> bool: + """Returns true if the given post is muted + """ + postFilename = locatePost(baseDir, nickname, domain, postId) + if not postFilename: + return False + if os.path.isfile(postFilename + '.muted'): + return True + return False + + def mutePost(baseDir: str, nickname: str, domain: str, postId: str, recentPostsCache: {}) -> None: """ Mutes the given post