From dbd6fb8290db9514c77c7cf5bc1f64dd470965bf Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Sep 2022 13:22:50 +0100 Subject: [PATCH 1/7] Banner on emoji search screen --- daemon.py | 7 +++++-- webapp_search.py | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/daemon.py b/daemon.py index ae1188933..bad4744b6 100644 --- a/daemon.py +++ b/daemon.py @@ -4355,10 +4355,13 @@ class PubServer(BaseHTTPRequestHandler): search_str = \ search_str.replace(' emoji', '') # emoji search + nickname = get_nickname_from_actor(actor_str) emoji_str = \ html_search_emoji(self.server.translate, - base_dir, - search_str) + base_dir, search_str, + nickname, domain, + self.server.theme_name, + self.server.access_keys) if emoji_str: msg = emoji_str.encode('utf-8') msglen = len(msg) diff --git a/webapp_search.py b/webapp_search.py index 5bdd79e38..31810397a 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -44,7 +44,9 @@ from webapp_hashtagswarm import html_hash_tag_swarm from maps import html_hashtag_maps -def html_search_emoji(translate: {}, base_dir: str, search_str: str) -> str: +def html_search_emoji(translate: {}, base_dir: str, search_str: str, + nickname: str, domain: str, theme: str, + access_keys: {}) -> str: """Search results for emoji """ # emoji.json is generated so that it can be customized and the changes @@ -66,6 +68,24 @@ def html_search_emoji(translate: {}, base_dir: str, search_str: str) -> str: get_config_param(base_dir, 'instanceTitle') emoji_form = \ html_header_with_external_style(css_filename, instance_title, None) + + # show top banner + if nickname and domain and theme: + banner_file, _ = \ + get_banner_file(base_dir, nickname, domain, theme) + emoji_form += \ + '
\n' + \ + '\n' + emoji_form += \ + '\n' + \ + '
\n' + emoji_form += '

' + \ translate['Emoji Search'] + \ '

' From a0f38af3f397071cc092c166b5e68fab6b2d865a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Sep 2022 13:50:08 +0100 Subject: [PATCH 2/7] Show banner on history search screen --- daemon.py | 6 ++++-- webapp_search.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/daemon.py b/daemon.py index bad4744b6..3b4d5e558 100644 --- a/daemon.py +++ b/daemon.py @@ -4081,7 +4081,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.cw_lists, self.server.lists_enabled, timezone, bold_reading, - self.server.dogwhistles) + self.server.dogwhistles, + self.server.access_keys) if history_str: msg = history_str.encode('utf-8') msglen = len(msg) @@ -4162,7 +4163,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.cw_lists, self.server.lists_enabled, timezone, bold_reading, - self.server.dogwhistles) + self.server.dogwhistles, + self.server.access_keys) if bookmarks_str: msg = bookmarks_str.encode('utf-8') msglen = len(msg) diff --git a/webapp_search.py b/webapp_search.py index 31810397a..ef886d4bc 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -655,7 +655,7 @@ def html_history_search(translate: {}, base_dir: str, cw_lists: {}, lists_enabled: str, timezone: str, bold_reading: bool, - dogwhistles: {}) -> str: + dogwhistles: {}, access_keys: {}) -> str: """Show a page containing search results for your post history """ if historysearch.startswith("'"): @@ -683,6 +683,22 @@ def html_history_search(translate: {}, base_dir: str, if box_name == 'bookmarks': history_search_title = '🔍 ' + translate['Bookmarks'] + if nickname and domain and theme_name: + banner_file, _ = \ + get_banner_file(base_dir, nickname, domain, theme_name) + history_search_form += \ + '
\n' + \ + '\n' + history_search_form += \ + '\n' + \ + '
\n' + history_search_form += \ '

' + \ history_search_title + '

' From e20954b75b9e14bf26449daac91b04b88bbb848b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Sep 2022 14:21:06 +0100 Subject: [PATCH 3/7] Banner on skills search screen --- daemon.py | 5 ++++- webapp_search.py | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/daemon.py b/daemon.py index 3b4d5e558..1719d6242 100644 --- a/daemon.py +++ b/daemon.py @@ -3995,13 +3995,16 @@ class PubServer(BaseHTTPRequestHandler): break # skill search search_str = search_str.replace('*', '').strip() + nickname = get_nickname_from_actor(actor_str) skill_str = \ html_skills_search(actor_str, self.server.translate, base_dir, search_str, self.server.instance_only_skills_search, - 64) + 64, nickname, domain, + self.server.theme_name, + self.server.access_keys) if skill_str: msg = skill_str.encode('utf-8') msglen = len(msg) diff --git a/webapp_search.py b/webapp_search.py index ef886d4bc..48cbee0ae 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -502,7 +502,9 @@ def html_search(translate: {}, base_dir: str, path: str, domain: str, def html_skills_search(actor: str, translate: {}, base_dir: str, skillsearch: str, instance_only: bool, - posts_per_page: int) -> str: + posts_per_page: int, + nickname: str, domain: str, theme_name: str, + access_keys: {}) -> str: """Show a page containing search results for a skill """ if skillsearch.startswith('*'): @@ -596,6 +598,24 @@ def html_skills_search(actor: str, translate: {}, base_dir: str, get_config_param(base_dir, 'instanceTitle') skill_search_form = \ html_header_with_external_style(css_filename, instance_title, None) + + # show top banner + if nickname and domain and theme_name: + banner_file, _ = \ + get_banner_file(base_dir, nickname, domain, theme_name) + skill_search_form += \ + '
\n' + \ + '\n' + skill_search_form += \ + '\n' + \ + '
\n' + skill_search_form += \ '

' + \ translate['Skills search'] + ': ' + \ From f585592d7c70f58577bb0e089c72728eeb4671a0 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Sep 2022 14:43:52 +0100 Subject: [PATCH 4/7] Banner on shared items search screen --- daemon.py | 10 ++++++++-- webapp_search.py | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/daemon.py b/daemon.py index 1719d6242..1647cd26b 100644 --- a/daemon.py +++ b/daemon.py @@ -4379,6 +4379,7 @@ class PubServer(BaseHTTPRequestHandler): # wanted items search shared_items_federated_domains = \ self.server.shared_items_federated_domains + nickname = get_nickname_from_actor(actor_str) wanted_items_str = \ html_search_shared_items(self.server.translate, base_dir, @@ -4388,7 +4389,9 @@ class PubServer(BaseHTTPRequestHandler): domain_full, actor_str, calling_domain, shared_items_federated_domains, - 'wanted') + 'wanted', nickname, domain, + self.server.theme_name, + self.server.access_keys) if wanted_items_str: msg = wanted_items_str.encode('utf-8') msglen = len(msg) @@ -4401,6 +4404,7 @@ class PubServer(BaseHTTPRequestHandler): # shared items search shared_items_federated_domains = \ self.server.shared_items_federated_domains + nickname = get_nickname_from_actor(actor_str) shared_items_str = \ html_search_shared_items(self.server.translate, base_dir, @@ -4410,7 +4414,9 @@ class PubServer(BaseHTTPRequestHandler): domain_full, actor_str, calling_domain, shared_items_federated_domains, - 'shares') + 'shares', nickname, domain, + self.server.theme_name, + self.server.access_keys) if shared_items_str: msg = shared_items_str.encode('utf-8') msglen = len(msg) diff --git a/webapp_search.py b/webapp_search.py index 48cbee0ae..e4fd17867 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -249,7 +249,9 @@ def html_search_shared_items(translate: {}, domain_full: str, actor: str, calling_domain: str, shared_items_federated_domains: [], - shares_file_type: str) -> str: + shares_file_type: str, + nickname: str, domain: str, theme_name: str, + access_keys: {}) -> str: """Search results for shared items """ curr_page = 1 @@ -270,6 +272,24 @@ def html_search_shared_items(translate: {}, title_str = translate['Shared Items Search'] else: title_str = translate['Wanted Items Search'] + + # show top banner + if nickname and domain and theme_name: + banner_file, _ = \ + get_banner_file(base_dir, nickname, domain, theme_name) + shared_items_form += \ + '
\n' + \ + '\n' + shared_items_form += \ + '\n' + \ + '
\n' + shared_items_form += \ '

' + \ '' + title_str + '

' From fb8b19aaef0958d8de8e29b9691690009d3eb9f0 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Sep 2022 17:19:09 +0100 Subject: [PATCH 5/7] Tidying --- content.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/content.py b/content.py index e184df2aa..3ceccc8be 100644 --- a/content.py +++ b/content.py @@ -742,8 +742,8 @@ def post_tag_exists(tagType: str, tagName: str, tags: {}) -> bool: return False -def _add_mention(word_str: str, http_prefix: str, following: str, - petnames: str, replace_mentions: {}, +def _add_mention(word_str: str, http_prefix: str, following: [], + petnames: [], replace_mentions: {}, recipients: [], tags: {}) -> bool: """Detects mentions and adds them to the replacements dict and recipients list @@ -771,8 +771,7 @@ def _add_mention(word_str: str, http_prefix: str, following: str, 'type': 'Mention' } replace_mentions[word_str] = \ - "@" + \ possible_nickname + "" return True @@ -798,9 +797,8 @@ def _add_mention(word_str: str, http_prefix: str, following: str, 'type': 'Mention' } replace_mentions[word_str] = \ - "@" + \ replace_nickname + "" return True From 2477618d697f6f2579d3e4b8538596f8d866e7f1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Sep 2022 17:22:56 +0100 Subject: [PATCH 6/7] Tidying --- content.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/content.py b/content.py index 3ceccc8be..5008d395b 100644 --- a/content.py +++ b/content.py @@ -829,8 +829,7 @@ def _add_mention(word_str: str, http_prefix: str, following: [], 'type': 'Mention' } replace_mentions[word_str] = \ - "@" + \ possible_nickname + "" return True @@ -847,8 +846,7 @@ def _add_mention(word_str: str, http_prefix: str, following: [], 'type': 'Mention' } replace_mentions[word_str] = \ - "@" + \ possible_nickname + "" return True From a8134f3243c5305d4b3370e9383167548cc9ac8f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Sep 2022 18:09:00 +0100 Subject: [PATCH 7/7] Full url for mentions --- content.py | 50 ++++++++++++++++++++++++++++++++++++++------------ tests.py | 5 +++-- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/content.py b/content.py index 5008d395b..b7e386de9 100644 --- a/content.py +++ b/content.py @@ -15,6 +15,7 @@ import email.parser import urllib.parse from shutil import copyfile from dateutil.parser import parse +from utils import get_user_paths from utils import convert_published_to_local_timezone from utils import has_object_dict from utils import valid_hash_tag @@ -742,8 +743,28 @@ def post_tag_exists(tagType: str, tagName: str, tags: {}) -> bool: return False -def _add_mention(word_str: str, http_prefix: str, following: [], - petnames: [], replace_mentions: {}, +def _mention_to_url(base_dir: str, http_prefix: str, + domain: str, nickname: str) -> str: + """Convert https://somedomain/@somenick to + https://somedomain/users/somenick + This uses the hack of trying the cache directory to see if + there is a matching actor + """ + possible_paths = get_user_paths() + cache_dir = base_dir + '/cache/actors' + cache_path_start = cache_dir + '/' + http_prefix + ':##' + domain + for users_path in possible_paths: + users_path = users_path.replace('/', '#') + possible_cache_entry = \ + cache_path_start + users_path + nickname + '.json' + if os.path.isfile(possible_cache_entry): + return http_prefix + '://' + \ + domain + users_path.replace('#', '/') + nickname + return http_prefix + '://' + domain + '/users/' + nickname + + +def _add_mention(base_dir: str, word_str: str, http_prefix: str, + following: [], petnames: [], replace_mentions: {}, recipients: [], tags: {}) -> bool: """Detects mentions and adds them to the replacements dict and recipients list @@ -761,8 +782,9 @@ def _add_mention(word_str: str, http_prefix: str, following: [], if possible_nickname == follow_nick: follow_str = remove_eol(follow) replace_domain = follow_str.split('@')[1] - recipient_actor = http_prefix + "://" + \ - replace_domain + "/@" + possible_nickname + recipient_actor = \ + _mention_to_url(base_dir, http_prefix, + replace_domain, possible_nickname) if recipient_actor not in recipients: recipients.append(recipient_actor) tags[word_str] = { @@ -787,8 +809,9 @@ def _add_mention(word_str: str, http_prefix: str, following: [], follow_str = remove_eol(follow) replace_nickname = follow_str.split('@')[0] replace_domain = follow_str.split('@')[1] - recipient_actor = http_prefix + "://" + \ - replace_domain + "/@" + replace_nickname + recipient_actor = \ + _mention_to_url(base_dir, http_prefix, + replace_domain, replace_nickname) if recipient_actor not in recipients: recipients.append(recipient_actor) tags[word_str] = { @@ -819,8 +842,9 @@ def _add_mention(word_str: str, http_prefix: str, following: [], for follow in following: if remove_eol(follow) != possible_handle: continue - recipient_actor = http_prefix + "://" + \ - possible_domain + "/@" + possible_nickname + recipient_actor = \ + _mention_to_url(base_dir, http_prefix, + possible_domain, possible_nickname) if recipient_actor not in recipients: recipients.append(recipient_actor) tags[word_str] = { @@ -836,8 +860,9 @@ def _add_mention(word_str: str, http_prefix: str, following: [], # @nick@domain if not (possible_domain == 'localhost' or '.' in possible_domain): return False - recipient_actor = http_prefix + "://" + \ - possible_domain + "/@" + possible_nickname + recipient_actor = \ + _mention_to_url(base_dir, http_prefix, + possible_domain, possible_nickname) if recipient_actor not in recipients: recipients.append(recipient_actor) tags[word_str] = { @@ -1221,8 +1246,9 @@ def add_html_tags(base_dir: str, http_prefix: str, long_words_list.append(word_str) first_char = word_str[0] if first_char == '@': - if _add_mention(word_str, http_prefix, following, petnames, - replace_mentions, recipients, hashtags): + if _add_mention(base_dir, word_str, http_prefix, following, + petnames, replace_mentions, recipients, + hashtags): prev_word_str = '' continue elif first_char == '#': diff --git a/tests.py b/tests.py index 8b9ba7068..188e3bc3f 100644 --- a/tests.py +++ b/tests.py @@ -4697,7 +4697,7 @@ def _test_reply_to_public_post(base_dir: str) -> None: # print(str(reply)) expected_str = \ '

' + \ - '@ninjarodent' + \ ' This is a test.

' if reply['object']['content'] != expected_str: @@ -4707,7 +4707,8 @@ def _test_reply_to_public_post(base_dir: str) -> None: reply['object']['contentMap'][system_language] = reply['object']['content'] assert reply['object']['tag'][0]['type'] == 'Mention' assert reply['object']['tag'][0]['name'] == '@ninjarodent@rat.site' - assert reply['object']['tag'][0]['href'] == 'https://rat.site/@ninjarodent' + assert reply['object']['tag'][0]['href'] == \ + 'https://rat.site/users/ninjarodent' assert len(reply['object']['to']) == 1 assert reply['object']['to'][0].endswith('#Public') assert len(reply['object']['cc']) >= 1