From efe1b54b38280dff15c2e190d796cee3a04964aa Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 3 Jun 2021 14:21:57 +0100 Subject: [PATCH] Checking for self-announces using a function --- announce.py | 20 +++++++++++++++++++- inbox.py | 3 ++- webapp_timeline.py | 3 +++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/announce.py b/announce.py index 4e254f7f8..dccfb20ea 100644 --- a/announce.py +++ b/announce.py @@ -41,7 +41,7 @@ def outboxAnnounce(recentPostsCache: {}, if messageJson['type'] == 'Announce': if not isinstance(messageJson['object'], str): return False - if messageJson['actor'] in messageJson['object']: + if isSelfAnnounce(messageJson): return False nickname = getNicknameFromActor(messageJson['actor']) if not nickname: @@ -390,3 +390,21 @@ def outboxUndoAnnounce(recentPostsCache: {}, messageJson['actor'], domain, debug) if debug: print('DEBUG: post undo announce via c2s - ' + postFilename) + + +def isSelfAnnounce(postJsonObject: {}) -> bool: + """Is the given post a self announce? + """ + if not postJsonObject.get('actor'): + return False + if not postJsonObject.get('type'): + return False + if postJsonObject['type'] != 'Announce': + return False + if not postJsonObject.get('object'): + return False + if not isinstance(postJsonObject['actor'], str): + return False + if not isinstance(postJsonObject['object'], str): + return False + return postJsonObject['actor'] in postJsonObject['object'] diff --git a/inbox.py b/inbox.py index 2ccb07316..05ba550e9 100644 --- a/inbox.py +++ b/inbox.py @@ -80,6 +80,7 @@ from delete import removeOldHashtags from categories import guessHashtagCategory from context import hasValidContext from speaker import updateSpeaker +from announce import isSelfAnnounce def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None: @@ -1359,7 +1360,7 @@ def _receiveAnnounce(recentPostsCache: {}, '"users" or "profile" missing from actor in ' + messageJson['type']) return False - if messageJson['actor'] in messageJson['object']: + if isSelfAnnounce(messageJson): if debug: print('DEBUG: self-boost rejected') return False diff --git a/webapp_timeline.py b/webapp_timeline.py index 9500ffb6e..50ec00fbc 100644 --- a/webapp_timeline.py +++ b/webapp_timeline.py @@ -31,6 +31,7 @@ from webapp_column_left import getLeftColumnContent from webapp_column_right import getRightColumnContent from webapp_headerbuttons import headerButtonsTimeline from posts import isModerator +from announce import isSelfAnnounce def _logTimelineTiming(enableTimingLog: bool, timelineStartTime, @@ -684,6 +685,8 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, # is the actor who sent this post snoozed? if isPersonSnoozed(baseDir, nickname, domain, item['actor']): continue + if isSelfAnnounce(item): + continue # is the post in the memory cache of recent ones? currTlStr = None