From b208ec623d20d0b139aed53195bb7c9571e53ef3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 28 May 2025 18:40:26 +0100 Subject: [PATCH] Move announce function --- announce.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++ desktop_client.py | 2 +- utils.py | 61 ----------------------------------------------- webapp_post.py | 2 +- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/announce.py b/announce.py index 7fba3be29..cfa16b777 100644 --- a/announce.py +++ b/announce.py @@ -711,3 +711,64 @@ def update_announce_collection(recent_posts_cache: {}, print('DEBUG: saving post with shares (announcements) added') pprint(post_json_object) save_json(post_json_object, post_filename) + + +def disallow_announce(content: str, attachment: [], capabilities: {}) -> bool: + """Are announces/boosts not allowed for the given post? + """ + # pixelfed style capabilities + if capabilities: + if 'announce' in capabilities: + if isinstance(capabilities['announce'], str): + if not capabilities['announce'].endswith('#Public'): + # TODO handle non-public announce permissions + print('CAPABILITIES: announce ' + capabilities['announce']) + return True + else: + # capabilities exist but with no announce defined + return True + + # emojis + disallow_strings = ( + ':boost_no:', + ':noboost:', + ':noboosts:', + ':no_boost:', + ':no_boosts:', + ':boosts_no:', + 'dont_repeat', + 'dont_announce', + 'dont_boost', + 'do not boost', + "don't boost", + 'boost_denied', + 'boosts_denied', + 'boostdenied', + 'boostsdenied' + ) + content_lower = content.lower() + for diss in disallow_strings: + if diss in content_lower: + return True + + # check for attached images without descriptions + if isinstance(attachment, list): + for item in attachment: + if not isinstance(item, dict): + continue + if not item.get('mediaType'): + continue + if not item.get('url'): + continue + if not item['mediaType'].startswith('image/'): + continue + if not item.get('name'): + # no image description + return True + image_description = item['name'] + if not isinstance(image_description, str): + continue + if len(image_description) < 5: + # not enough description + return True + return False diff --git a/desktop_client.py b/desktop_client.py index 91f3fcb91..df89b1907 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -25,7 +25,6 @@ from utils import get_attributed_to from utils import remove_html from utils import safe_system_string from utils import text_in_file -from utils import disallow_announce from utils import disallow_reply from utils import get_base_content_from_post from utils import has_object_dict @@ -60,6 +59,7 @@ from posts import c2s_box_json from posts import download_announce from announce import send_announce_via_server from announce import send_undo_announce_via_server +from announce import disallow_announce from pgp import pgp_local_public_key from pgp import pgp_decrypt from pgp import has_local_pg_pkey diff --git a/utils.py b/utils.py index 2ddabc5db..683c6069e 100644 --- a/utils.py +++ b/utils.py @@ -3348,67 +3348,6 @@ def _is_i2p_request(calling_domain: str, referer_domain: str, return False -def disallow_announce(content: str, attachment: [], capabilities: {}) -> bool: - """Are announces/boosts not allowed for the given post? - """ - # pixelfed style capabilities - if capabilities: - if 'announce' in capabilities: - if isinstance(capabilities['announce'], str): - if not capabilities['announce'].endswith('#Public'): - # TODO handle non-public announce permissions - print('CAPABILITIES: announce ' + capabilities['announce']) - return True - else: - # capabilities exist but with no announce defined - return True - - # emojis - disallow_strings = ( - ':boost_no:', - ':noboost:', - ':noboosts:', - ':no_boost:', - ':no_boosts:', - ':boosts_no:', - 'dont_repeat', - 'dont_announce', - 'dont_boost', - 'do not boost', - "don't boost", - 'boost_denied', - 'boosts_denied', - 'boostdenied', - 'boostsdenied' - ) - content_lower = content.lower() - for diss in disallow_strings: - if diss in content_lower: - return True - - # check for attached images without descriptions - if isinstance(attachment, list): - for item in attachment: - if not isinstance(item, dict): - continue - if not item.get('mediaType'): - continue - if not item.get('url'): - continue - if not item['mediaType'].startswith('image/'): - continue - if not item.get('name'): - # no image description - return True - image_description = item['name'] - if not isinstance(image_description, str): - continue - if len(image_description) < 5: - # not enough description - return True - return False - - def disallow_reply(content: str) -> bool: """Are replies not allowed for the given post? """ diff --git a/webapp_post.py b/webapp_post.py index 31e5c54b1..ef8cc87e9 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -20,6 +20,7 @@ from bookmarks import bookmarked_by_person from announce import update_announce_collection from announce import announced_by_person from announce import no_of_announces +from announce import disallow_announce from like import liked_by_person from like import no_of_likes from follow import is_following_actor @@ -54,7 +55,6 @@ from utils import remove_style_within_html from utils import license_link_from_name from utils import dont_speak_hashtags from utils import remove_eol -from utils import disallow_announce from utils import disallow_reply from utils import remove_hash_from_post_id from utils import remove_html