From 262647575d30067a86ecddfada4feccb41f13131 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 24 Nov 2025 16:04:28 +0000 Subject: [PATCH] Add mutuals icon --- searchable.py | 19 ++----------------- utils.py | 16 ++++++++++++++++ webapp_post.py | 32 +++++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/searchable.py b/searchable.py index cbb68000e..4cd12fe6b 100644 --- a/searchable.py +++ b/searchable.py @@ -19,6 +19,7 @@ from utils import get_nickname_from_actor from utils import get_domain_from_actor from utils import get_full_domain from utils import get_followers_list +from utils import get_mutuals_of_person def load_searchable_by_default(base_dir: str) -> {}: @@ -140,22 +141,6 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str, return res -def _get_mutuals_of_person(base_dir: str, - nickname: str, domain: str) -> []: - """Returns the mutuals of a person - i.e. accounts which they follow and which also follow back - """ - followers = \ - get_followers_list(base_dir, nickname, domain, 'followers.txt') - following = \ - get_followers_list(base_dir, nickname, domain, 'following.txt') - mutuals: list[str] = [] - for handle in following: - if handle in followers: - mutuals.append(handle) - return mutuals - - def search_box_posts(base_dir: str, nickname: str, domain: str, search_str: str, max_results: int, box_name: str = 'outbox') -> []: @@ -190,7 +175,7 @@ def search_box_posts(base_dir: str, nickname: str, domain: str, following_list = get_followers_list(base_dir, nickname, domain, 'following.txt') # create a list containing all of the mutuals - mutuals_list = _get_mutuals_of_person(base_dir, nickname, domain) + mutuals_list = get_mutuals_of_person(base_dir, nickname, domain) res: list[str] = [] for root, _, fnames in os.walk(path): diff --git a/utils.py b/utils.py index db4947a21..069869419 100644 --- a/utils.py +++ b/utils.py @@ -814,6 +814,22 @@ def get_followers_list(base_dir: str, return [] +def get_mutuals_of_person(base_dir: str, + nickname: str, domain: str) -> []: + """Returns the mutuals of a person + i.e. accounts which they follow and which also follow back + """ + followers = \ + get_followers_list(base_dir, nickname, domain, 'followers.txt') + following = \ + get_followers_list(base_dir, nickname, domain, 'following.txt') + mutuals: list[str] = [] + for handle in following: + if handle in followers: + mutuals.append(handle) + return mutuals + + def get_followers_of_person(base_dir: str, nickname: str, domain: str, follow_file: str = 'following.txt') -> []: diff --git a/webapp_post.py b/webapp_post.py index bc624a221..2a2a3bf4b 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -42,6 +42,7 @@ from textmode import text_mode_removals from quote import get_quote_toot_url from timeFunctions import date_from_string_format from timeFunctions import convert_published_to_local_timezone +from utils import get_mutuals_of_person from utils import save_json from utils import remove_header_tags from utils import get_actor_from_post_id @@ -1501,7 +1502,8 @@ def _get_post_title_announce_html(base_dir: str, container_class: str, mitm: bool, mitm_servers: [], - software_name: str) -> (str, str, str, str): + software_name: str, + mutuals_list: []) -> (str, str, str, str): """Returns the announce title of a post containing names of participants x announces y """ @@ -1564,10 +1566,15 @@ def _get_post_title_announce_html(base_dir: str, nickname, domain, announce_display_name, False, translate) + # add mutual icon to the display name + mutuals_icon = '' + if announce_handle in mutuals_list: + mutuals_icon = ' ⇆' + _log_post_timing(enable_timing_log, post_start_time, '13.3.1') title_str += \ _announce_with_display_name_html(translate, post_json_object, - announce_display_name, + announce_display_name + mutuals_icon, nickname, announce_handle) if mitm or announce_domain in mitm_servers: @@ -1926,7 +1933,8 @@ def _get_post_title_html(base_dir: str, session, debug: bool, mitm_servers: [], - software_name: str) -> (str, str, str, str): + software_name: str, + mutuals_list: []) -> (str, str, str, str): """Returns the title of a post containing names of participants x replies to y, x announces y, etc """ @@ -1954,7 +1962,8 @@ def _get_post_title_html(base_dir: str, container_class_icons, container_class, mitm, mitm_servers, - software_name) + software_name, + mutuals_list) return _get_post_title_reply_html(base_dir, http_prefix, @@ -2638,6 +2647,14 @@ def individual_post_as_html(signing_priv_key_pem: str, if mitm or actor_domain in mitm_servers: mitm_str = ' ' + mitm_warning_html(translate) + # get the list of mutuals for the current account + mutuals_list = get_mutuals_of_person(base_dir, nickname, domain) + + # add mutual icon to the display name + mutuals_icon = '' + if actor_handle in mutuals_list: + mutuals_icon = ' ⇆' + if display_name: display_name = _enforce_max_display_name_length(display_name) # add emojis @@ -2651,7 +2668,7 @@ def individual_post_as_html(signing_priv_key_pem: str, nickname + '?options=' + post_actor + \ ';' + str(page_number) + ';' + avatar_url + message_id_str + \ '" tabindex="10" title="' + actor_handle + '">' + \ - '