Checking for self-announces using a function

merge-requests/30/head
Bob Mottram 2021-06-03 14:21:57 +01:00
parent ea6571da4e
commit efe1b54b38
3 changed files with 24 additions and 2 deletions

View File

@ -41,7 +41,7 @@ def outboxAnnounce(recentPostsCache: {},
if messageJson['type'] == 'Announce': if messageJson['type'] == 'Announce':
if not isinstance(messageJson['object'], str): if not isinstance(messageJson['object'], str):
return False return False
if messageJson['actor'] in messageJson['object']: if isSelfAnnounce(messageJson):
return False return False
nickname = getNicknameFromActor(messageJson['actor']) nickname = getNicknameFromActor(messageJson['actor'])
if not nickname: if not nickname:
@ -390,3 +390,21 @@ def outboxUndoAnnounce(recentPostsCache: {},
messageJson['actor'], domain, debug) messageJson['actor'], domain, debug)
if debug: if debug:
print('DEBUG: post undo announce via c2s - ' + postFilename) 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']

View File

@ -80,6 +80,7 @@ from delete import removeOldHashtags
from categories import guessHashtagCategory from categories import guessHashtagCategory
from context import hasValidContext from context import hasValidContext
from speaker import updateSpeaker from speaker import updateSpeaker
from announce import isSelfAnnounce
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None: def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
@ -1359,7 +1360,7 @@ def _receiveAnnounce(recentPostsCache: {},
'"users" or "profile" missing from actor in ' + '"users" or "profile" missing from actor in ' +
messageJson['type']) messageJson['type'])
return False return False
if messageJson['actor'] in messageJson['object']: if isSelfAnnounce(messageJson):
if debug: if debug:
print('DEBUG: self-boost rejected') print('DEBUG: self-boost rejected')
return False return False

View File

@ -31,6 +31,7 @@ from webapp_column_left import getLeftColumnContent
from webapp_column_right import getRightColumnContent from webapp_column_right import getRightColumnContent
from webapp_headerbuttons import headerButtonsTimeline from webapp_headerbuttons import headerButtonsTimeline
from posts import isModerator from posts import isModerator
from announce import isSelfAnnounce
def _logTimelineTiming(enableTimingLog: bool, timelineStartTime, def _logTimelineTiming(enableTimingLog: bool, timelineStartTime,
@ -684,6 +685,8 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
# is the actor who sent this post snoozed? # is the actor who sent this post snoozed?
if isPersonSnoozed(baseDir, nickname, domain, item['actor']): if isPersonSnoozed(baseDir, nickname, domain, item['actor']):
continue continue
if isSelfAnnounce(item):
continue
# is the post in the memory cache of recent ones? # is the post in the memory cache of recent ones?
currTlStr = None currTlStr = None