From a40126027e0b0485f4992aff8dfb6317ea2d35da Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 30 May 2022 13:27:41 +0100 Subject: [PATCH 1/4] Tidying --- announce.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/announce.py b/announce.py index 9dd01f6e0..626fb09ae 100644 --- a/announce.py +++ b/announce.py @@ -135,10 +135,10 @@ def announced_by_person(is_announced: bool, post_actor: str, def create_announce(session, base_dir: str, federation_list: [], nickname: str, domain: str, port: int, - to_url: str, ccUrl: str, http_prefix: str, - object_url: str, saveToFile: bool, + to_url: str, cc_url: str, http_prefix: str, + object_url: str, save_to_file: bool, client_to_server: bool, - send_threads: [], postLog: [], + send_threads: [], post_log: [], person_cache: {}, cached_webfingers: {}, debug: bool, project_version: str, signing_priv_key_pem: str, @@ -146,7 +146,7 @@ def create_announce(session, base_dir: str, federation_list: [], onion_domain: str, i2p_domain: str) -> {}: """Creates an announce message Typically to_url will be https://www.w3.org/ns/activitystreams#Public - and ccUrl might be a specific person favorited or repeated and the + and cc_url might be a specific person favorited or repeated and the followers url object_url is typically the url of the message, corresponding to url or atomUri in createPostBase """ @@ -172,10 +172,10 @@ def create_announce(session, base_dir: str, federation_list: [], 'to': [to_url], 'type': 'Announce' } - if ccUrl: - if len(ccUrl) > 0: - new_announce['cc'] = [ccUrl] - if saveToFile: + if cc_url: + if len(cc_url) > 0: + new_announce['cc'] = [cc_url] + if save_to_file: outbox_dir = create_outbox_dir(nickname, domain, base_dir) filename = \ outbox_dir + '/' + new_announce_id.replace('/', '#') + '.json' @@ -202,7 +202,7 @@ def create_announce(session, base_dir: str, federation_list: [], announce_nickname, announce_domain, announce_port, None, http_prefix, True, client_to_server, federation_list, - send_threads, postLog, cached_webfingers, + send_threads, post_log, cached_webfingers, person_cache, debug, project_version, None, group_account, signing_priv_key_pem, 639633, @@ -214,7 +214,7 @@ def create_announce(session, base_dir: str, federation_list: [], def announce_public(session, base_dir: str, federation_list: [], nickname: str, domain: str, port: int, http_prefix: str, object_url: str, client_to_server: bool, - send_threads: [], postLog: [], + send_threads: [], post_log: [], person_cache: {}, cached_webfingers: {}, debug: bool, project_version: str, signing_priv_key_pem: str, @@ -225,12 +225,12 @@ def announce_public(session, base_dir: str, federation_list: [], from_domain = get_full_domain(domain, port) to_url = 'https://www.w3.org/ns/activitystreams#Public' - ccUrl = local_actor_url(http_prefix, nickname, from_domain) + '/followers' + cc_url = local_actor_url(http_prefix, nickname, from_domain) + '/followers' return create_announce(session, base_dir, federation_list, nickname, domain, port, - to_url, ccUrl, http_prefix, + to_url, cc_url, http_prefix, object_url, True, client_to_server, - send_threads, postLog, + send_threads, post_log, person_cache, cached_webfingers, debug, project_version, signing_priv_key_pem, curr_domain, @@ -239,7 +239,7 @@ def announce_public(session, base_dir: str, federation_list: [], def send_announce_via_server(base_dir: str, session, from_nickname: str, password: str, - from_domain: str, fromPort: int, + from_domain: str, from_port: int, http_prefix: str, repeat_object_url: str, cached_webfingers: {}, person_cache: {}, debug: bool, project_version: str, @@ -250,7 +250,7 @@ def send_announce_via_server(base_dir: str, session, print('WARN: No session for send_announce_via_server') return 6 - from_domain_full = get_full_domain(from_domain, fromPort) + from_domain_full = get_full_domain(from_domain, from_port) to_url = 'https://www.w3.org/ns/activitystreams#Public' actor_str = local_actor_url(http_prefix, from_nickname, from_domain_full) From 611c6cab178c7dada835013361a7aaf4425425f7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 30 May 2022 13:45:47 +0100 Subject: [PATCH 2/4] Tidying --- acceptreject.py | 40 ++++++++++++++++++++-------------------- blocking.py | 4 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/acceptreject.py b/acceptreject.py index a21aa3866..2b7a7021f 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -25,54 +25,54 @@ from utils import has_object_string_type def _create_accept_reject(base_dir: str, federation_list: [], nickname: str, domain: str, port: int, - toUrl: str, ccUrl: str, http_prefix: str, - objectJson: {}, acceptType: str) -> {}: + to_url: str, cc_url: str, http_prefix: str, + object_json: {}, accept_type: str) -> {}: """Accepts or rejects something (eg. a follow request or offer) - Typically toUrl will be https://www.w3.org/ns/activitystreams#Public - and ccUrl might be a specific person favorited or repeated and + Typically to_url will be https://www.w3.org/ns/activitystreams#Public + and cc_url might be a specific person favorited or repeated and the followers url objectUrl is typically the url of the message, corresponding to url or atomUri in createPostBase """ - if not objectJson.get('actor'): + if not object_json.get('actor'): return None - if not url_permitted(objectJson['actor'], federation_list): + if not url_permitted(object_json['actor'], federation_list): return None domain = get_full_domain(domain, port) new_accept = { "@context": "https://www.w3.org/ns/activitystreams", - 'type': acceptType, + 'type': accept_type, 'actor': local_actor_url(http_prefix, nickname, domain), - 'to': [toUrl], + 'to': [to_url], 'cc': [], - 'object': objectJson + 'object': object_json } - if ccUrl: - if len(ccUrl) > 0: - new_accept['cc'] = [ccUrl] + if cc_url: + if len(cc_url) > 0: + new_accept['cc'] = [cc_url] return new_accept def create_accept(base_dir: str, federation_list: [], nickname: str, domain: str, port: int, - toUrl: str, ccUrl: str, http_prefix: str, - objectJson: {}) -> {}: + to_url: str, cc_url: str, http_prefix: str, + object_json: {}) -> {}: return _create_accept_reject(base_dir, federation_list, nickname, domain, port, - toUrl, ccUrl, http_prefix, - objectJson, 'Accept') + to_url, cc_url, http_prefix, + object_json, 'Accept') def create_reject(base_dir: str, federation_list: [], nickname: str, domain: str, port: int, - toUrl: str, ccUrl: str, http_prefix: str, - objectJson: {}) -> {}: + to_url: str, cc_url: str, http_prefix: str, + object_json: {}) -> {}: return _create_accept_reject(base_dir, federation_list, nickname, domain, port, - toUrl, ccUrl, - http_prefix, objectJson, 'Reject') + to_url, cc_url, + http_prefix, object_json, 'Reject') def _accept_follow(base_dir: str, domain: str, message_json: {}, diff --git a/blocking.py b/blocking.py index 4bce78539..3218bf60e 100644 --- a/blocking.py +++ b/blocking.py @@ -917,7 +917,7 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None: # generate instance allow list allowed_domains = [domain_full] follow_files = ('following.txt', 'followers.txt') - for subdir, dirs, files in os.walk(base_dir + '/accounts'): + for _, dirs, _ in os.walk(base_dir + '/accounts'): for acct in dirs: if not is_account_dir(acct): continue @@ -995,7 +995,7 @@ def load_cw_lists(base_dir: str, verbose: bool) -> {}: if not os.path.isdir(base_dir + '/cwlists'): return {} result = {} - for subdir, dirs, files in os.walk(base_dir + '/cwlists'): + for _, _, files in os.walk(base_dir + '/cwlists'): for fname in files: if not fname.endswith('.json'): continue From 937225acc75ab0205674ade65431e2471f658393 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 30 May 2022 14:11:33 +0100 Subject: [PATCH 3/4] dont_at_me emoji can appear within summary --- desktop_client.py | 5 ++++- webapp_post.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/desktop_client.py b/desktop_client.py index d14f0cb88..d57124023 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -1774,7 +1774,10 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, post_content = '' if post_json_object['object'].get('content'): post_content = post_json_object['object']['content'] - if not disallow_reply(post_content): + post_summary = '' + if post_json_object['object'].get('summary'): + post_summary = post_json_object['object']['summary'] + if not disallow_reply(post_summary + ' ' + post_content): if post_json_object.get('id'): post_id = post_json_object['id'] subject = None diff --git a/webapp_post.py b/webapp_post.py index cc46eaae6..6125562dc 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -2057,6 +2057,7 @@ def individual_post_as_html(signing_priv_key_pem: str, if not content_str: return '' + summary_str = '' if content_str: # does an emoji indicate a no boost preference? # if so then don't show the repeat/announce icon @@ -2064,7 +2065,10 @@ def individual_post_as_html(signing_priv_key_pem: str, announce_str = '' # does an emoji indicate a no replies preference? # if so then don't show the reply icon - if disallow_reply(content_str): + summary_str = get_summary_from_post(post_json_object, system_language, + languages_understood) + content_all_str = str(summary_str) + ' ' + content_str + if disallow_reply(content_all_str): reply_str = '' new_footer_str = \ @@ -2083,8 +2087,9 @@ def individual_post_as_html(signing_priv_key_pem: str, if post_is_sensitive: footer_str = '
' + footer_str - summary_str = get_summary_from_post(post_json_object, system_language, - languages_understood) + if not summary_str: + summary_str = get_summary_from_post(post_json_object, system_language, + languages_understood) is_patch = is_git_patch(base_dir, nickname, domain, post_json_object['object']['type'], summary_str, content_str) From 69efdba68ffa7923792e83664c28fdf29842d5d8 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 30 May 2022 14:43:06 +0100 Subject: [PATCH 4/4] no_announce also applies to summary --- desktop_client.py | 23 ++++++++++++----------- webapp_post.py | 12 ++++++------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/desktop_client.py b/desktop_client.py index d57124023..b7ae9979a 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -986,8 +986,8 @@ def _desktop_show_box(indent: str, translate: {}, screenreader: str, system_language: str, espeak, page_number: int, - newReplies: bool, - newDMs: bool) -> bool: + new_replies: bool, + new_dms: bool) -> bool: """Shows online timeline """ number_width = 2 @@ -1004,9 +1004,9 @@ def _desktop_show_box(indent: str, else: box_name_str = box_name title_str = _highlight_text(box_name_str.upper()) - # if newDMs: + # if new_dms: # notification_icons += ' 📩' - # if newReplies: + # if new_replies: # notification_icons += ' 📨' if notification_icons: @@ -1086,8 +1086,7 @@ def _desktop_show_box(indent: str, if i > 10: break likes_count = no_of_likes(post_json_object) - if likes_count > 10: - likes_count = 10 + likes_count = max(likes_count, 10) for _ in range(likes_count): if not space_added: space_added = True @@ -1654,8 +1653,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, refresh_timeline = True elif command_str.startswith('prev'): page_number -= 1 - if page_number < 1: - page_number = 1 + page_number = max(page_number, 1) prev_timeline_first_id = '' box_json = c2s_box_json(base_dir, session, nickname, password, @@ -1673,8 +1671,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, command_str.startswith('show ') or command_str == 'read' or command_str == 'show'): - if command_str == 'read' or \ - command_str == 'show': + if command_str in ('read', 'show'): post_index_str = '1' else: if 'read ' in command_str: @@ -2157,7 +2154,11 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, post_content = '' if post_json_object['object'].get('content'): post_content = post_json_object['object']['content'] - if not disallow_announce(post_content): + post_summary = '' + if post_json_object['object'].get('summary'): + post_summary = post_json_object['object']['summary'] + if not disallow_announce(post_summary + ' ' + + post_content): if post_json_object.get('id'): post_id = post_json_object['id'] announce_actor = \ diff --git a/webapp_post.py b/webapp_post.py index 6125562dc..92dd236b0 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -2059,15 +2059,15 @@ def individual_post_as_html(signing_priv_key_pem: str, summary_str = '' if content_str: - # does an emoji indicate a no boost preference? - # if so then don't show the repeat/announce icon - if disallow_announce(content_str): - announce_str = '' - # does an emoji indicate a no replies preference? - # if so then don't show the reply icon summary_str = get_summary_from_post(post_json_object, system_language, languages_understood) content_all_str = str(summary_str) + ' ' + content_str + # does an emoji indicate a no boost preference? + # if so then don't show the repeat/announce icon + if disallow_announce(content_all_str): + announce_str = '' + # does an emoji indicate a no replies preference? + # if so then don't show the reply icon if disallow_reply(content_all_str): reply_str = ''