diff --git a/desktop_client.py b/desktop_client.py index d415d3b84..37805df4a 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -16,6 +16,7 @@ import webbrowser import urllib.parse from pathlib import Path from random import randint +from utils import get_actor_languages_list from utils import get_attributed_to from utils import remove_html from utils import safe_system_string @@ -64,6 +65,7 @@ from bookmarks import send_bookmark_via_server from bookmarks import send_undo_bookmark_via_server from delete import send_delete_via_server from person import get_actor_json +from cache import get_person_from_cache def _desktop_help() -> None: @@ -803,6 +805,12 @@ def _read_local_box_post(session, nickname: str, domain: str, yt_replace_domain = None twitter_replacement_domain = None show_vote_posts = False + languages_understood = [] + person_url = local_actor_url(http_prefix, nickname, domain_full) + actor_json = \ + get_person_from_cache(base_dir, person_url, person_cache) + if actor_json: + languages_understood = get_actor_languages_list(actor_json) post_json_object2 = \ download_announce(session, base_dir, http_prefix, @@ -817,7 +825,8 @@ def _read_local_box_post(session, nickname: str, domain: str, domain_full, person_cache, signing_priv_key_pem, blocked_cache, bold_reading, - show_vote_posts) + show_vote_posts, + languages_understood) if post_json_object2: if has_object_dict(post_json_object2): if post_json_object2['object'].get('attributedTo') and \ @@ -2661,7 +2670,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, signing_priv_key_pem, blocked_cache, bold_reading, - show_vote_posts) + show_vote_posts, + languages_understood) if post_json_object2: post_json_object = post_json_object2 if post_json_object: diff --git a/inbox.py b/inbox.py index d8ee8ad3a..e1fcdfdac 100644 --- a/inbox.py +++ b/inbox.py @@ -3001,7 +3001,8 @@ def _receive_announce(recent_posts_cache: {}, lists_enabled: str, bold_reading: bool, dogwhistles: {}, mitm: bool, min_images_for_accounts: [], - buy_sites: {}) -> bool: + buy_sites: {}, + languages_understood: []) -> bool: """Receives an announce activity within the POST section of HTTPServer """ if message_json['type'] != 'Announce': @@ -3183,7 +3184,8 @@ def _receive_announce(recent_posts_cache: {}, domain_full, person_cache, signing_priv_key_pem, blocked_cache, bold_reading, - show_vote_posts) + show_vote_posts, + languages_understood) if not post_json_object: print('WARN: unable to download announce: ' + str(message_json)) not_in_onion = True @@ -4757,7 +4759,8 @@ def _inbox_after_initial(server, inbox_start_time, max_like_count, cw_lists, lists_enabled, bold_reading, dogwhistles, mitm, server.min_images_for_accounts, - server.buy_sites): + server.buy_sites, + languages_understood): if debug: print('DEBUG: Announce accepted from ' + actor) fitness_performance(inbox_start_time, server.fitness, @@ -4973,7 +4976,8 @@ def _inbox_after_initial(server, inbox_start_time, allow_local_network_access, recent_posts_cache, debug, system_language, domain_full, person_cache, signing_priv_key_pem, - bold_reading, show_vote_posts): + bold_reading, show_vote_posts, + languages_understood): # media index will be updated update_index_list.append('tlmedia') fitness_performance(inbox_start_time, server.fitness, diff --git a/outbox.py b/outbox.py index ce2bc8951..f798e8b2c 100644 --- a/outbox.py +++ b/outbox.py @@ -543,7 +543,7 @@ def post_message_to_outbox(session, translate: {}, acct_dir(base_dir, post_to_nickname, domain) + '/.noVotes' if os.path.isfile(show_vote_file): show_vote_posts = False - + languages_understood = [] if is_image_media(session, base_dir, http_prefix, post_to_nickname, domain, message_json, @@ -555,7 +555,8 @@ def post_message_to_outbox(session, translate: {}, domain_full, person_cache, signing_priv_key_pem, bold_reading, - show_vote_posts): + show_vote_posts, + languages_understood): inbox_update_index('tlmedia', base_dir, post_to_nickname + '@' + domain, saved_filename, debug) diff --git a/posts.py b/posts.py index a057c55b6..16f09ec16 100644 --- a/posts.py +++ b/posts.py @@ -4212,7 +4212,8 @@ def is_image_media(session, base_dir: str, http_prefix: str, domain_full: str, person_cache: {}, signing_priv_key_pem: str, bold_reading: bool, - show_vote_posts: bool) -> bool: + show_vote_posts: bool, + languages_understood: []) -> bool: """Returns true if the given post has attached image media """ if post_json_object['type'] == 'Announce': @@ -4229,7 +4230,8 @@ def is_image_media(session, base_dir: str, http_prefix: str, domain_full, person_cache, signing_priv_key_pem, blocked_cache, bold_reading, - show_vote_posts) + show_vote_posts, + languages_understood) if post_json_announce: post_json_object = post_json_announce if post_json_object['type'] != 'Create': @@ -5597,7 +5599,8 @@ def download_announce(session, base_dir: str, http_prefix: str, domain_full: str, person_cache: {}, signing_priv_key_pem: str, blocked_cache: {}, bold_reading: bool, - show_vote_posts: bool) -> {}: + show_vote_posts: bool, + languages_understood: []) -> {}: """Download the post referenced by an announce """ if not post_json_object.get('object'): @@ -5726,7 +5729,8 @@ def download_announce(session, base_dir: str, http_prefix: str, converted_json = \ convert_video_to_note(base_dir, nickname, domain, system_language, - announced_json, blocked_cache) + announced_json, blocked_cache, + languages_understood) if converted_json: announced_json = converted_json if not contains_statuses(announced_json['id']): diff --git a/video.py b/video.py index 1deb07896..0a91e6b67 100644 --- a/video.py +++ b/video.py @@ -13,13 +13,15 @@ from utils import get_nickname_from_actor from utils import get_domain_from_actor from utils import remove_id_ending from utils import get_attributed_to +from utils import get_content_from_post from blocking import is_blocked from filters import is_filtered def convert_video_to_note(base_dir: str, nickname: str, domain: str, system_language: str, - post_json_object: {}, blocked_cache: {}) -> {}: + post_json_object: {}, blocked_cache: {}, + languages_understood: []) -> {}: """Converts a PeerTube Video ActivityPub(ish) object into a Note, so that it can then be displayed in a timeline """ @@ -92,10 +94,9 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str, system_language): return None content += '
' + post_json_object['license']['name'] + '
' - post_content = post_json_object['content'] - if 'contentMap' in post_json_object: - if post_json_object['contentMap'].get(system_language): - post_content = post_json_object['contentMap'][system_language] + post_content = \ + get_content_from_post(post_json_object, system_language, + languages_understood, "content") content += post_content conversation_id = remove_id_ending(post_json_object['id']) diff --git a/webapp_post.py b/webapp_post.py index fe79f43f6..275a09e55 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -2162,6 +2162,13 @@ def individual_post_as_html(signing_priv_key_pem: str, if is_public_post(post_json_object): is_public_repeat = True + person_url = local_actor_url(http_prefix, nickname, domain_full) + actor_json = \ + get_person_from_cache(base_dir, person_url, person_cache) + languages_understood = [] + if actor_json: + languages_understood = get_actor_languages_list(actor_json) + title_str = '' gallery_str = '' is_announced = False @@ -2185,7 +2192,8 @@ def individual_post_as_html(signing_priv_key_pem: str, domain_full, person_cache, signing_priv_key_pem, blocked_cache, bold_reading, - show_vote_posts) + show_vote_posts, + languages_understood) if not post_json_announce: # if the announce could not be downloaded then mark it as rejected announced_post_id = remove_id_ending(post_json_object['id']) @@ -2515,13 +2523,6 @@ def individual_post_as_html(signing_priv_key_pem: str, _log_post_timing(enable_timing_log, post_start_time, '14') - person_url = local_actor_url(http_prefix, nickname, domain_full) - actor_json = \ - get_person_from_cache(base_dir, person_url, person_cache) - languages_understood = [] - if actor_json: - languages_understood = get_actor_languages_list(actor_json) - edits_filename = account_dir + box_name + '/' + edits_post_url edits_str = '' if os.path.isfile(edits_filename):