From d863eb25e41ddb3237c05ef77ef5065615fec452 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 9 Feb 2023 20:40:42 +0000 Subject: [PATCH] Three representations of public post --- inbox.py | 4 +++- posts.py | 38 +++++++++++++++++++++++++++++--------- utils.py | 12 +++++++++--- webapp_utils.py | 8 ++++++-- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/inbox.py b/inbox.py index 68e821ea6..b6ff35ec0 100644 --- a/inbox.py +++ b/inbox.py @@ -822,7 +822,9 @@ def _inbox_post_recipients_add(base_dir: str, http_prefix: str, to_list: [], handle + ' does not exist') else: if debug: - if recipient.endswith('#Public'): + if recipient.endswith('#Public') or \ + recipient == 'as:Public' or \ + recipient == 'Public': print('DEBUG: #Public recipient is too non-specific. ' + recipient + ' ' + domain_match) else: diff --git a/posts.py b/posts.py index d2ab8977a..0bfee861c 100644 --- a/posts.py +++ b/posts.py @@ -456,7 +456,9 @@ def _is_public_feed_post(item: {}, person_posts: {}, debug: bool) -> bool: if this_item.get('to'): is_public = False for recipient in this_item['to']: - if recipient.endswith('#Public'): + if recipient.endswith('#Public') or \ + recipient == 'as:Public' or \ + recipient == 'Public': is_public = True break if not is_public: @@ -465,7 +467,9 @@ def _is_public_feed_post(item: {}, person_posts: {}, debug: bool) -> bool: if item.get('to'): is_public = False for recipient in item['to']: - if recipient.endswith('#Public'): + if recipient.endswith('#Public') or \ + recipient == 'as:Public' or \ + recipient == 'Public': is_public = True break if not is_public: @@ -1402,7 +1406,12 @@ def _create_post_mentions(cc_url: str, new_post: {}, to_cc = new_post['object']['cc'] if len(to_recipients) != 1: return - if to_recipients[0].endswith('#Public') and \ + to_public_recipient = False + if to_recipients[0].endswith('#Public') or \ + to_recipients[0] == 'as:Public' or \ + to_recipients[0] == 'Public': + to_public_recipient = True + if to_public_recipient and \ cc_url.endswith('/followers'): for tag in tags: if tag['type'] != 'Mention': @@ -1582,7 +1591,9 @@ def _create_post_base(base_dir: str, is_public = False for recipient in to_recipients: - if recipient.endswith('#Public'): + if recipient.endswith('#Public') or \ + recipient == 'as:Public' or \ + recipient == 'Public': is_public = True break @@ -2834,7 +2845,9 @@ def _add_followers_to_public_post(post_json_object: {}) -> None: if len(post_json_object['to']) == 0: return if not post_json_object['to'][0].endswith('#Public'): - return + if not post_json_object['to'][0] == 'as:Public': + if not post_json_object['to'][0] == 'Public': + return if post_json_object.get('cc'): return post_json_object['cc'] = post_json_object['actor'] + '/followers' @@ -2846,7 +2859,9 @@ def _add_followers_to_public_post(post_json_object: {}) -> None: if len(post_json_object['object']['to']) == 0: return if not post_json_object['object']['to'][0].endswith('#Public'): - return + if not post_json_object['object']['to'][0] == 'as:Public': + if not post_json_object['object']['to'][0] == 'Public': + return if post_json_object['object'].get('cc'): return post_json_object['object']['cc'] = \ @@ -3222,7 +3237,9 @@ def _send_to_named_addresses(server, session, session_onion, session_i2p, continue if '/' not in address: continue - if address.endswith('#Public'): + if address.endswith('#Public') or \ + address == 'as:Public' or \ + address == 'Public': continue if address.endswith('/followers'): continue @@ -3231,7 +3248,9 @@ def _send_to_named_addresses(server, session, session_onion, session_i2p, address = recipients_object[rtype] if address: if '/' in address: - if address.endswith('#Public'): + if address.endswith('#Public') or \ + address == 'as:Public' or \ + address == 'Public': continue if address.endswith('/followers'): continue @@ -3900,7 +3919,8 @@ def _add_post_string_to_timeline(post_str: str, boxname: str, ('"Create"' in post_str or '"Update"' in post_str))): if boxname == 'dm': - if '#Public' in post_str or '/followers' in post_str: + if '#Public' in post_str or \ + '/followers' in post_str: return False elif boxname == 'tlreplies': if box_actor not in post_str: diff --git a/utils.py b/utils.py index 6a0f9d751..652ca496b 100644 --- a/utils.py +++ b/utils.py @@ -2096,7 +2096,9 @@ def is_dm(post_json_object: {}) -> bool: if not post_json_object['object'].get(field_name): continue for to_address in post_json_object['object'][field_name]: - if to_address.endswith('#Public'): + if to_address.endswith('#Public') or \ + to_address == 'as:Public' or \ + to_address == 'Public': return False if to_address.endswith('followers'): return False @@ -2428,7 +2430,9 @@ def is_public_post(post_json_object: {}) -> bool: if not post_json_object['object'].get('to'): return False for recipient in post_json_object['object']['to']: - if recipient.endswith('#Public'): + if recipient.endswith('#Public') or \ + recipient == 'as:Public' or \ + recipient == 'Public': return True return False @@ -2471,7 +2475,9 @@ def is_unlisted_post(post_json_object: {}) -> bool: if not has_followers: return False for recipient in post_json_object['object']['cc']: - if recipient.endswith('#Public'): + if recipient.endswith('#Public') or \ + recipient == 'as:Public' or \ + recipient == 'Public': return True return False diff --git a/webapp_utils.py b/webapp_utils.py index 22465ec7d..43348c65f 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -564,13 +564,17 @@ def post_contains_public(post_json_object: {}) -> bool: return contains_public for to_address in post_json_object['object']['to']: - if to_address.endswith('#Public'): + if to_address.endswith('#Public') or \ + to_address == 'as:Public' or \ + to_address == 'Public': contains_public = True break if not contains_public: if post_json_object['object'].get('cc'): for to_address2 in post_json_object['object']['cc']: - if to_address2.endswith('#Public'): + if to_address2.endswith('#Public') or \ + to_address2 == 'as:Public' or \ + to_address2 == 'Public': contains_public = True break return contains_public