diff --git a/announce.py b/announce.py index deae59b59..5538b72be 100644 --- a/announce.py +++ b/announce.py @@ -9,6 +9,7 @@ __module_group__ = "ActivityPub" from utils import has_object_string_object from utils import has_group_type +from utils import has_object_dict from utils import remove_domain_port from utils import remove_id_ending from utils import has_users_path @@ -33,6 +34,22 @@ from webfinger import webfinger_handle from auth import create_basic_auth_header +def no_of_announces(post_json_object: {}) -> int: + """Returns the number of announces on a given post + """ + obj = post_json_object + if has_object_dict(post_json_object): + obj = post_json_object['object'] + if not obj.get('shares'): + return 0 + if not isinstance(obj['shares'], dict): + return 0 + if not obj['shares'].get('items'): + obj['shares']['items'] = [] + obj['shares']['totalItems'] = 0 + return len(obj['shares']['items']) + + def is_self_announce(post_json_object: {}) -> bool: """Is the given post a self announce? """ diff --git a/cache.py b/cache.py index c0ba795ce..10deff344 100644 --- a/cache.py +++ b/cache.py @@ -34,18 +34,18 @@ def _remove_person_from_cache(base_dir: str, person_url: str, def check_for_changed_actor(session, base_dir: str, http_prefix: str, domain_full: str, - person_url: str, avatarUrl: str, person_cache: {}, + person_url: str, avatar_url: str, person_cache: {}, timeout_sec: int): """Checks if the avatar url exists and if not then the actor has probably changed without receiving an actor/Person Update. So clear the actor from the cache and it will be refreshed when the next post from them is sent """ - if not session or not avatarUrl: + if not session or not avatar_url: return - if domain_full in avatarUrl: + if domain_full in avatar_url: return - if url_exists(session, avatarUrl, timeout_sec, http_prefix, domain_full): + if url_exists(session, avatar_url, timeout_sec, http_prefix, domain_full): return _remove_person_from_cache(base_dir, person_url, person_cache) diff --git a/daemon.py b/daemon.py index bf805dccb..c218f511a 100644 --- a/daemon.py +++ b/daemon.py @@ -7427,8 +7427,12 @@ class PubServer(BaseHTTPRequestHandler): page_number = 1 options_list = options_str.split(';') options_actor = options_list[0] - options_page_number = options_list[1] - options_profile_url = options_list[2] + options_page_number = 1 + if len(options_list) > 1: + options_page_number = options_list[1] + options_profile_url = '' + if len(options_list) > 2: + options_profile_url = options_list[2] if '.' in options_profile_url and \ options_profile_url.startswith('/members/'): ext = options_profile_url.split('.')[-1] @@ -10482,6 +10486,68 @@ class PubServer(BaseHTTPRequestHandler): self.server.debug) return True + def _show_announcers_of_post(self, authorized: bool, + calling_domain: str, path: str, + base_dir: str, http_prefix: str, + domain: str, domain_full: str, port: int, + onion_domain: str, i2p_domain: str, + getreq_start_time, + proxy_type: str, cookie: str, + debug: str) -> bool: + """Show the announcers of a post + """ + if not authorized: + return False + if '?announcers=' not in path: + return False + if '/users/' not in path: + return False + nickname = path.split('/users/')[1] + if '?' in nickname: + nickname = nickname.split('?')[0] + post_url = path.split('?announcers=')[1] + if '?' in post_url: + post_url = post_url.split('?')[0] + post_url = post_url.replace('--', '/') + + # note that the likers function is reused, but with 'shares' + msg = \ + html_likers_of_post(base_dir, nickname, domain, port, + post_url, self.server.translate, + http_prefix, + self.server.theme_name, + self.server.access_keys, + self.server.recent_posts_cache, + self.server.max_recent_posts, + self.server.session, + self.server.cached_webfingers, + self.server.person_cache, + self.server.project_version, + self.server.yt_replace_domain, + self.server.twitter_replacement_domain, + self.server.show_published_date_only, + self.server.peertube_instances, + self.server.allow_local_network_access, + self.server.system_language, + self.server.max_like_count, + self.server.signing_priv_key_pem, + self.server.cw_lists, + self.server.lists_enabled, + 'inbox', self.server.default_timeline, + 'shares') + if not msg: + self._404() + return True + msg = msg.encode('utf-8') + msglen = len(msg) + self._set_headers('text/html', msglen, + cookie, calling_domain, False) + self._write(msg) + fitness_performance(getreq_start_time, self.server.fitness, + '_GET', '_show_announcers_of_post', + self.server.debug) + return True + def _show_post_from_file(self, post_filename: str, liked_by: str, react_by: str, react_emoji: str, authorized: bool, @@ -16564,6 +16630,22 @@ class PubServer(BaseHTTPRequestHandler): self.server.getreq_busy = False return + # show the announcers/repeaters of a post + if self._show_announcers_of_post(authorized, + calling_domain, self.path, + self.server.base_dir, + self.server.http_prefix, + self.server.domain, + self.server.domain_full, + self.server.port, + self.server.onion_domain, + self.server.i2p_domain, + getreq_start_time, + self.server.proxy_type, + cookie, self.server.debug): + self.server.getreq_busy = False + return + fitness_performance(getreq_start_time, self.server.fitness, '_GET', 'individual post done', self.server.debug) diff --git a/translations/ar.json b/translations/ar.json index c957dc507..0cf00963a 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -512,5 +512,7 @@ "Created": "مخلوق", "It is done": "تم", "Time Zone": "وحدة زمنية", - "Show who liked this post": "أظهر من أحب هذا المنشور" + "Show who liked this post": "أظهر من أحب هذا المنشور", + "Show who repeated this post": "أظهر من كرر هذا المنصب", + "Repeated by": "يتكرر بواسطة" } diff --git a/translations/ca.json b/translations/ca.json index dacb28c4b..28ee0a579 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -512,5 +512,7 @@ "Created": "Creat", "It is done": "Esta fet", "Time Zone": "Fus horari", - "Show who liked this post": "Mostra a qui li agrada aquesta publicació" + "Show who liked this post": "Mostra a qui li agrada aquesta publicació", + "Show who repeated this post": "Mostra qui ha repetit aquesta publicació", + "Repeated by": "Repetit per" } diff --git a/translations/cy.json b/translations/cy.json index 9748400f2..3fc651630 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -512,5 +512,7 @@ "Created": "Wedi creu", "It is done": "Mae'n cael ei wneud", "Time Zone": "Parth Amser", - "Show who liked this post": "Dangoswch pwy oedd yn hoffi'r post hwn" + "Show who liked this post": "Dangoswch pwy oedd yn hoffi'r post hwn", + "Show who repeated this post": "Dangoswch pwy ailadroddodd y post hwn", + "Repeated by": "Ailadrodd gan" } diff --git a/translations/de.json b/translations/de.json index 6affc0714..a1c18d712 100644 --- a/translations/de.json +++ b/translations/de.json @@ -512,5 +512,7 @@ "Created": "Erstellt", "It is done": "Es ist vollbracht", "Time Zone": "Zeitzone", - "Show who liked this post": "Zeigen, wem dieser Beitrag gefallen hat" + "Show who liked this post": "Zeigen, wem dieser Beitrag gefallen hat", + "Show who repeated this post": "Zeigen Sie, wer diesen Beitrag wiederholt hat", + "Repeated by": "Wiederholt von" } diff --git a/translations/en.json b/translations/en.json index 6d63e9362..798823909 100644 --- a/translations/en.json +++ b/translations/en.json @@ -512,5 +512,7 @@ "Created": "Created", "It is done": "It is done", "Time Zone": "Time Zone", - "Show who liked this post": "Show who liked this post" + "Show who liked this post": "Show who liked this post", + "Show who repeated this post": "Show who repeated this post", + "Repeated by": "Repeated by" } diff --git a/translations/es.json b/translations/es.json index 85622b5ec..1a2d74369 100644 --- a/translations/es.json +++ b/translations/es.json @@ -512,5 +512,7 @@ "Created": "Creada", "It is done": "Se hace", "Time Zone": "Zona horaria", - "Show who liked this post": "Mostrar a quién le gustó esta publicación" + "Show who liked this post": "Mostrar a quién le gustó esta publicación", + "Show who repeated this post": "Mostrar quién repitió esta publicación", + "Repeated by": "Repetido por" } diff --git a/translations/fr.json b/translations/fr.json index d2e81c3cf..b1e5267c3 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -512,5 +512,7 @@ "Created": "Créé", "It is done": "C'est fait", "Time Zone": "Fuseau horaire", - "Show who liked this post": "Montrer qui a aimé ce post" + "Show who liked this post": "Montrer qui a aimé ce post", + "Show who repeated this post": "Montrer qui a répété ce post", + "Repeated by": "Répété par" } diff --git a/translations/ga.json b/translations/ga.json index 094738e3f..f2481b3f4 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -512,5 +512,7 @@ "Created": "Cruthaithe", "It is done": "Déantar é", "Time Zone": "Crios Ama", - "Show who liked this post": "Taispeáin cé a thaitin an postáil seo" + "Show who liked this post": "Taispeáin cé a thaitin an postáil seo", + "Show who repeated this post": "Taispeáin cé a rinne an postáil seo arís", + "Repeated by": "Arís agus arís eile ag" } diff --git a/translations/hi.json b/translations/hi.json index ad4c7e2a2..34b8a4e7f 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -512,5 +512,7 @@ "Created": "बनाया था", "It is done": "हो गया है", "Time Zone": "समय क्षेत्र", - "Show who liked this post": "दिखाएँ कि इस पोस्ट को किसने पसंद किया" + "Show who liked this post": "दिखाएँ कि इस पोस्ट को किसने पसंद किया", + "Show who repeated this post": "दिखाएं कि इस पोस्ट को किसने दोहराया", + "Repeated by": "द्वारा दोहराया गया" } diff --git a/translations/it.json b/translations/it.json index d9219f0a5..0dab816ca 100644 --- a/translations/it.json +++ b/translations/it.json @@ -512,5 +512,7 @@ "Created": "Creata", "It is done": "È fatta", "Time Zone": "Fuso orario", - "Show who liked this post": "Mostra a chi è piaciuto questo post" + "Show who liked this post": "Mostra a chi è piaciuto questo post", + "Show who repeated this post": "Mostra chi ha ripetuto questo post", + "Repeated by": "Ripetuto da" } diff --git a/translations/ja.json b/translations/ja.json index 5c8c77d71..a12e4ab57 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -512,5 +512,7 @@ "Created": "作成した", "It is done": "されております", "Time Zone": "タイムゾーン", - "Show who liked this post": "この投稿を高く評価した人を表示する" + "Show who liked this post": "この投稿を高く評価した人を表示する", + "Show who repeated this post": "この投稿を繰り返した人を表示する", + "Repeated by": "によって繰り返される" } diff --git a/translations/ku.json b/translations/ku.json index f8ea5c51c..0b7fa9d3d 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -512,5 +512,7 @@ "Created": "Afirandin", "It is done": "Tê kirin", "Time Zone": "Qada demê", - "Show who liked this post": "Nîşan bide kê ev post eciband" + "Show who liked this post": "Nîşan bide kê ev post eciband", + "Show who repeated this post": "Nîşan bide kê ev post dubare kiriye", + "Repeated by": "Ji hêla dubare kirin" } diff --git a/translations/oc.json b/translations/oc.json index 95ebeb902..bc717207f 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -508,5 +508,7 @@ "Created": "Created", "It is done": "It is done", "Time Zone": "Time Zone", - "Show who liked this post": "Show who liked this post" + "Show who liked this post": "Show who liked this post", + "Show who repeated this post": "Show who repeated this post", + "Repeated by": "Repeated by" } diff --git a/translations/pt.json b/translations/pt.json index 84c1a68f2..43d8080ef 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -512,5 +512,7 @@ "Created": "Criada", "It is done": "Está feito", "Time Zone": "Fuso horário", - "Show who liked this post": "Mostrar quem gostou deste post" + "Show who liked this post": "Mostrar quem gostou deste post", + "Show who repeated this post": "Mostrar quem repetiu esta postagem", + "Repeated by": "Repetido por" } diff --git a/translations/ru.json b/translations/ru.json index 34e0bce98..9ce09948a 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -512,5 +512,7 @@ "Created": "Созданный", "It is done": "Сделано", "Time Zone": "Часовой пояс", - "Show who liked this post": "Показать, кому понравился этот пост" + "Show who liked this post": "Показать, кому понравился этот пост", + "Show who repeated this post": "Показать, кто повторил этот пост", + "Repeated by": "Повторено" } diff --git a/translations/sw.json b/translations/sw.json index ab7e8f5f8..7d5069316 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -512,5 +512,7 @@ "Created": "Imeundwa", "It is done": "Imefanyika", "Time Zone": "Eneo la Saa", - "Show who liked this post": "Onyesha ni nani aliyependa chapisho hili" + "Show who liked this post": "Onyesha ni nani aliyependa chapisho hili", + "Show who repeated this post": "Onyesha ni nani aliyerudia chapisho hili", + "Repeated by": "Imerudiwa na" } diff --git a/translations/zh.json b/translations/zh.json index 56b2b45ca..9a64482e6 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -512,5 +512,7 @@ "Created": "已创建", "It is done": "完成了", "Time Zone": "时区", - "Show who liked this post": "显示谁喜欢这篇文章" + "Show who liked this post": "显示谁喜欢这篇文章", + "Show who repeated this post": "显示谁重复了这篇文章", + "Repeated by": "重复" } diff --git a/webapp_likers.py b/webapp_likers.py index 088f69104..7cfe6e8b0 100644 --- a/webapp_likers.py +++ b/webapp_likers.py @@ -15,9 +15,11 @@ from utils import get_display_name from utils import get_nickname_from_actor from utils import has_object_dict from utils import load_json +from person import get_person_avatar_url from webapp_utils import html_header_with_external_style from webapp_utils import html_footer from webapp_utils import get_banner_file +from webapp_utils import add_emoji_to_display_name from webapp_post import individual_post_as_html @@ -38,7 +40,8 @@ def html_likers_of_post(base_dir: str, nickname: str, system_language: str, max_like_count: int, signing_priv_key_pem: str, cw_lists: {}, lists_enabled: str, - boxName: str, default_timeline: str) -> str: + boxName: str, default_timeline: str, + dict_name: str = 'likes') -> str: """Returns html for a screen showing who liked a post """ css_filename = base_dir + '/epicyon-profile.css' @@ -105,17 +108,22 @@ def html_likers_of_post(base_dir: str, nickname: str, obj = post_json_object if has_object_dict(post_json_object): obj = post_json_object['object'] - if not obj.get('likes'): + if not obj.get(dict_name): return None - if not isinstance(obj['likes'], dict): + if not isinstance(obj[dict_name], dict): return None - if not obj['likes'].get('items'): + if not obj[dict_name].get('items'): return None - html_str += '