diff --git a/daemon.py b/daemon.py index c3ed83122..0dcd6da04 100644 --- a/daemon.py +++ b/daemon.py @@ -242,6 +242,7 @@ from categories import set_hashtag_category from categories import update_hashtag_categories from languages import get_actor_languages from languages import set_actor_languages +from languages import get_understood_languages from like import update_likes_collection from reaction import update_reaction_collection from utils import undo_reaction_collection_entry @@ -499,6 +500,12 @@ class PubServer(BaseHTTPRequestHandler): city = get_spoofed_city(self.server.city, self.server.base_dir, nickname, self.server.domain) + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) message_json = \ create_public_post(self.server.base_dir, @@ -519,7 +526,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.system_language, conversation_id, self.server.low_bandwidth, - self.server.content_license_url) + self.server.content_license_url, + languages_understood) if message_json: # name field contains the answer message_json['object']['name'] = answer @@ -16811,6 +16819,14 @@ class PubServer(BaseHTTPRequestHandler): conversation_id = None if fields.get('conversationId'): conversation_id = fields['conversationId'] + + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) + message_json = \ create_public_post(self.server.base_dir, nickname, @@ -16831,7 +16847,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.system_language, conversation_id, self.server.low_bandwidth, - self.server.content_license_url) + self.server.content_license_url, + languages_understood) if message_json: if fields['schedulePost']: return 1 @@ -16898,6 +16915,12 @@ class PubServer(BaseHTTPRequestHandler): conversation_id = None if fields.get('conversationId'): conversation_id = fields['conversationId'] + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) message_json = \ create_blog_post(self.server.base_dir, nickname, self.server.domain, self.server.port, @@ -16917,7 +16940,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.system_language, conversation_id, self.server.low_bandwidth, - self.server.content_license_url) + self.server.content_license_url, + languages_understood) if message_json: if fields['schedulePost']: return 1 @@ -17049,6 +17073,13 @@ class PubServer(BaseHTTPRequestHandler): if fields.get('conversationId'): conversation_id = fields['conversationId'] + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) + message_json = \ create_unlisted_post(self.server.base_dir, nickname, @@ -17070,7 +17101,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.system_language, conversation_id, self.server.low_bandwidth, - self.server.content_license_url) + self.server.content_license_url, + languages_understood) if message_json: if fields['schedulePost']: return 1 @@ -17100,6 +17132,12 @@ class PubServer(BaseHTTPRequestHandler): conversation_id = fields['conversationId'] mentions_message = mentions_str + fields['message'] + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) message_json = \ create_followers_only_post(self.server.base_dir, nickname, @@ -17123,7 +17161,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.system_language, conversation_id, self.server.low_bandwidth, - self.server.content_license_url) + self.server.content_license_url, + languages_understood) if message_json: if fields['schedulePost']: return 1 @@ -17156,6 +17195,13 @@ class PubServer(BaseHTTPRequestHandler): conversation_id = fields['conversationId'] content_license_url = self.server.content_license_url + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) + message_json = \ create_direct_message_post(self.server.base_dir, nickname, @@ -17183,7 +17229,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.system_language, conversation_id, self.server.low_bandwidth, - content_license_url) + content_license_url, + languages_understood) if message_json: if fields['schedulePost']: return 1 @@ -17217,6 +17264,12 @@ class PubServer(BaseHTTPRequestHandler): comments_enabled = False conversation_id = None mentions_message = mentions_str + fields['message'] + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) message_json = \ create_direct_message_post(self.server.base_dir, nickname, @@ -17239,7 +17292,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.system_language, conversation_id, self.server.low_bandwidth, - self.server.content_license_url) + self.server.content_license_url, + languages_understood) if message_json: if fields['schedulePost']: return 1 @@ -17262,6 +17316,12 @@ class PubServer(BaseHTTPRequestHandler): self.server.base_dir, nickname, self.server.domain) + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) message_json = \ create_report_post(self.server.base_dir, nickname, @@ -17275,7 +17335,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.debug, fields['subject'], self.server.system_language, self.server.low_bandwidth, - self.server.content_license_url) + self.server.content_license_url, + languages_understood) if message_json: if self._post_to_outbox(message_json, self.server.project_version, @@ -17300,6 +17361,12 @@ class PubServer(BaseHTTPRequestHandler): nickname, self.server.domain) int_duration = int(fields['duration']) + languages_understood = \ + get_understood_languages(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain_full, + self.server.person_cache) message_json = \ create_question_post(self.server.base_dir, nickname, @@ -17316,7 +17383,8 @@ class PubServer(BaseHTTPRequestHandler): int_duration, self.server.system_language, self.server.low_bandwidth, - self.server.content_license_url) + self.server.content_license_url, + languages_understood) if message_json: if self.server.debug: print('DEBUG: new Question') diff --git a/desktop_client.py b/desktop_client.py index ca0fb9108..e502b71dd 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -418,6 +418,7 @@ def _desktop_reply_to_post(session, post_id: str, cached_webfingers: {}, person_cache: {}, debug: bool, subject: str, screenreader: str, system_language: str, + languages_understood: [], espeak, conversation_id: str, low_bandwidth: bool, content_license_url: str, @@ -474,8 +475,8 @@ def _desktop_reply_to_post(session, post_id: str, comments_enabled, attach, media_type, attached_image_description, city, cached_webfingers, person_cache, is_article, - system_language, low_bandwidth, - content_license_url, + system_language, languages_understood, + low_bandwidth, content_license_url, debug, post_id, post_id, conversation_id, subject) == 0: say_str = 'Reply sent' @@ -490,6 +491,7 @@ def _desktop_new_post(session, cached_webfingers: {}, person_cache: {}, debug: bool, screenreader: str, system_language: str, + languages_understood: [], espeak, low_bandwidth: bool, content_license_url: str, signing_priv_key_pem: str) -> None: @@ -542,8 +544,8 @@ def _desktop_new_post(session, comments_enabled, attach, media_type, attached_image_description, city, cached_webfingers, person_cache, is_article, - system_language, low_bandwidth, - content_license_url, + system_language, languages_understood, + low_bandwidth, content_license_url, debug, None, None, conversation_id, subject) == 0: say_str = 'Post sent' @@ -1137,6 +1139,7 @@ def _desktop_new_dm(session, to_handle: str, cached_webfingers: {}, person_cache: {}, debug: bool, screenreader: str, system_language: str, + languages_understood: [], espeak, low_bandwidth: bool, content_license_url: str, signing_priv_key_pem: str) -> None: @@ -1154,23 +1157,25 @@ def _desktop_new_dm(session, to_handle: str, for handle in handles_list: handle = handle.strip() - _desktop_new_d_mbase(session, handle, + _desktop_new_dm_base(session, handle, base_dir, nickname, password, domain, port, http_prefix, cached_webfingers, person_cache, debug, screenreader, system_language, + languages_understood, espeak, low_bandwidth, content_license_url, signing_priv_key_pem) -def _desktop_new_d_mbase(session, to_handle: str, +def _desktop_new_dm_base(session, to_handle: str, base_dir: str, nickname: str, password: str, domain: str, port: int, http_prefix: str, cached_webfingers: {}, person_cache: {}, debug: bool, screenreader: str, system_language: str, + languages_understood: [], espeak, low_bandwidth: bool, content_license_url: str, signing_priv_key_pem: str) -> None: @@ -1265,8 +1270,8 @@ def _desktop_new_d_mbase(session, to_handle: str, comments_enabled, attach, media_type, attached_image_description, city, cached_webfingers, person_cache, is_article, - system_language, low_bandwidth, - content_license_url, + system_language, languages_understood, + low_bandwidth, content_license_url, debug, None, None, conversation_id, subject) == 0: say_str = 'Direct message sent' @@ -1344,6 +1349,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, content_license_url = 'https://creativecommons.org/licenses/by/4.0' blocked_cache = {} + languages_understood = [system_language] indent = ' ' if show_new_posts: @@ -1748,6 +1754,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, cached_webfingers, person_cache, debug, subject, screenreader, system_language, + languages_understood, espeak, conversation_id, low_bandwidth, content_license_url, @@ -1785,6 +1792,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, cached_webfingers, person_cache, debug, screenreader, system_language, + languages_understood, espeak, low_bandwidth, content_license_url, signing_priv_key_pem) @@ -1797,6 +1805,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, cached_webfingers, person_cache, debug, screenreader, system_language, + languages_understood, espeak, low_bandwidth, content_license_url, signing_priv_key_pem) diff --git a/epicyon.py b/epicyon.py index 4cf35b9c9..4b2e57dbd 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1323,6 +1323,7 @@ if args.message: signing_priv_key_pem = None if args.secure_mode: signing_priv_key_pem = get_instance_actor_key(base_dir, domain) + languages_understood = [args.language] print('Sending post to ' + args.sendto) send_post_via_server(signing_priv_key_pem, __version__, @@ -1333,7 +1334,8 @@ if args.message: args.commentsEnabled, attach, media_type, attached_image_description, city, cached_webfingers, person_cache, is_article, - args.language, args.low_bandwidth, + args.language, languages_understood, + args.low_bandwidth, args.content_license_url, args.debug, reply_to, reply_to, args.conversationId, subject) for i in range(10): @@ -2886,6 +2888,7 @@ if args.testdata: test_is_article = False conversation_id = None low_bandwidth = False + languages_understood = [args.language] create_public_post(base_dir, nickname, domain, port, http_prefix, "like this is totally just a #test man", @@ -2899,7 +2902,8 @@ if args.testdata: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, args.language, conversation_id, - low_bandwidth, args.content_license_url) + low_bandwidth, args.content_license_url, + languages_understood) create_public_post(base_dir, nickname, domain, port, http_prefix, "Zoiks!!!", test_followers_only, @@ -2912,7 +2916,8 @@ if args.testdata: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, args.language, conversation_id, - low_bandwidth, args.content_license_url) + low_bandwidth, args.content_license_url, + languages_understood) create_public_post(base_dir, nickname, domain, port, http_prefix, "Hey scoob we need like a hundred more #milkshakes", test_followers_only, @@ -2925,7 +2930,8 @@ if args.testdata: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, args.language, conversation_id, - low_bandwidth, args.content_license_url) + low_bandwidth, args.content_license_url, + languages_understood) create_public_post(base_dir, nickname, domain, port, http_prefix, "Getting kinda spooky around here", test_followers_only, @@ -2938,7 +2944,8 @@ if args.testdata: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, args.language, conversation_id, - low_bandwidth, args.content_license_url) + low_bandwidth, args.content_license_url, + languages_understood) create_public_post(base_dir, nickname, domain, port, http_prefix, "And they would have gotten away with it too" + "if it wasn't for those pesky hackers", @@ -2952,7 +2959,8 @@ if args.testdata: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, args.language, conversation_id, - low_bandwidth, args.content_license_url) + low_bandwidth, args.content_license_url, + languages_understood) create_public_post(base_dir, nickname, domain, port, http_prefix, "man these centralized sites are like the worst!", test_followers_only, @@ -2965,7 +2973,8 @@ if args.testdata: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, args.language, conversation_id, - low_bandwidth, args.content_license_url) + low_bandwidth, args.content_license_url, + languages_understood) create_public_post(base_dir, nickname, domain, port, http_prefix, "another mystery solved #test", test_followers_only, @@ -2978,7 +2987,8 @@ if args.testdata: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, args.language, conversation_id, - low_bandwidth, args.content_license_url) + low_bandwidth, args.content_license_url, + languages_understood) create_public_post(base_dir, nickname, domain, port, http_prefix, "let's go bowling", test_followers_only, @@ -2991,7 +3001,8 @@ if args.testdata: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, args.language, conversation_id, - low_bandwidth, args.content_license_url) + low_bandwidth, args.content_license_url, + languages_understood) domain_full = domain + ':' + str(port) clear_follows(base_dir, nickname, domain) follow_person(base_dir, nickname, domain, 'maxboardroom', domain_full, diff --git a/inbox.py b/inbox.py index 51692f5e0..ba8daf129 100644 --- a/inbox.py +++ b/inbox.py @@ -2825,7 +2825,8 @@ def _bounce_dm(senderPostId: str, session, http_prefix: str, translate: {}, debug: bool, last_bounce_message: [], system_language: str, signing_priv_key_pem: str, - content_license_url: str) -> bool: + content_license_url: str, + languages_understood: []) -> bool: """Sends a bounce message back to the sending handle if a DM has been rejected """ @@ -2886,7 +2887,8 @@ def _bounce_dm(senderPostId: str, session, http_prefix: str, event_date, event_time, location, system_language, conversation_id, low_bandwidth, - content_license_url) + content_license_url, + languages_understood) if not post_json_object: print('WARN: unable to create bounce message to ' + sending_handle) return False @@ -2913,7 +2915,8 @@ def _is_valid_dm(base_dir: str, nickname: str, domain: str, port: int, last_bounce_message: [], handle: str, system_language: str, signing_priv_key_pem: str, - content_license_url: str) -> bool: + content_license_url: str, + languages_understood: []) -> bool: """Is the given message a valid DM? """ if nickname == 'inbox': @@ -2994,7 +2997,8 @@ def _is_valid_dm(base_dir: str, nickname: str, domain: str, port: int, last_bounce_message, system_language, signing_priv_key_pem, - content_license_url) + content_license_url, + languages_understood) return False # dm index will be updated @@ -3233,7 +3237,8 @@ def _inbox_after_initial(recent_posts_cache: {}, max_recent_posts: int, signing_priv_key_pem: str, default_reply_interval_hrs: int, cw_lists: {}, lists_enabled: str, - content_license_url: str) -> bool: + content_license_url: str, + languages_understood: []) -> bool: """ Anything which needs to be done after initial checks have passed """ actor = key_id @@ -3516,7 +3521,8 @@ def _inbox_after_initial(recent_posts_cache: {}, max_recent_posts: int, last_bounce_message, handle, system_language, signing_priv_key_pem, - content_license_url): + content_license_url, + languages_understood): return False # get the actor being replied to @@ -4530,6 +4536,7 @@ def run_inbox_queue(recent_posts_cache: {}, max_recent_posts: int, for handle, _ in recipients_dict.items(): destination = \ queue_json['destination'].replace(inbox_handle, handle) + languages_understood = [system_language] _inbox_after_initial(recent_posts_cache, max_recent_posts, session, key_id, handle, @@ -4558,7 +4565,8 @@ def run_inbox_queue(recent_posts_cache: {}, max_recent_posts: int, signing_priv_key_pem, default_reply_interval_hrs, cw_lists, lists_enabled, - content_license_url) + content_license_url, + languages_understood) if debug: pprint(queue_json['post']) print('Queue: Queue post accepted') diff --git a/languages.py b/languages.py index 52da5048a..0506b219c 100644 --- a/languages.py +++ b/languages.py @@ -33,6 +33,20 @@ def get_actor_languages(actor_json: {}) -> str: return languages_str +def get_understood_languages(base_dir: str, http_prefix: str, + nickname: str, domain_full: str, + person_cache: {}) -> []: + """Returns a list of understood languages for the given account + """ + person_url = local_actor_url(http_prefix, nickname, domain_full) + actor_json = \ + get_person_from_cache(base_dir, person_url, person_cache, False) + if not actor_json: + print('WARN: unable to load actor to obtain languages ' + person_url) + return [] + return get_actor_languages_list(actor_json) + + def set_actor_languages(base_dir: str, actor_json: {}, languages_str: str) -> None: """Sets the languages used by the given actor diff --git a/newsdaemon.py b/newsdaemon.py index 7233eab66..9397ff5de 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -641,6 +641,7 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str, image_description = None city = 'London, England' conversation_id = None + languages_understood = [system_language] blog = create_news_post(base_dir, domain, port, http_prefix, rss_description, @@ -649,7 +650,8 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str, image_description, city, rss_title, system_language, conversation_id, low_bandwidth, - content_license_url) + content_license_url, + languages_understood) if not blog: continue diff --git a/posts.py b/posts.py index fc0018ecb..781134d44 100644 --- a/posts.py +++ b/posts.py @@ -32,6 +32,7 @@ from webfinger import webfinger_handle from httpsig import create_signed_header from siteactive import site_is_active from languages import understood_post_language +from utils import get_summary_from_post from utils import get_user_paths from utils import invalid_ciphertext from utils import has_object_stringType @@ -637,7 +638,10 @@ def _get_posts(session, outbox_url: str, max_posts: int, print('max emojis reached') continue - if this_item.get('summary'): + if this_item.get('summaryMap'): + if this_item['summaryMap'].get(system_language): + summary = this_item['summaryMap'][system_language] + if not summary and this_item.get('summary'): if this_item['summary']: summary = this_item['summary'] @@ -1054,7 +1058,9 @@ def _add_auto_cw(base_dir: str, nickname: str, domain: str, def _create_post_cw_from_reply(base_dir: str, nickname: str, domain: str, in_reply_to: str, - sensitive: bool, summary: str) -> (bool, str): + sensitive: bool, summary: str, + system_language: str, + languages_understood: []) -> (bool, str): """If this is a reply and the original post has a CW then use the same CW """ @@ -1072,7 +1078,11 @@ def _create_post_cw_from_reply(base_dir: str, nickname: str, domain: str, if reply_to_json['object']['sensitive']: sensitive = True if reply_to_json['object'].get('summary'): - summary = reply_to_json['object']['summary'] + summary = \ + get_summary_from_post(reply_to_json, + system_language, + languages_understood) + return sensitive, summary @@ -1112,6 +1122,9 @@ def _create_post_s2s(base_dir: str, nickname: str, domain: str, port: int, 'conversation': conversation_id, 'type': post_object_type, 'summary': summary, + 'summaryMap': { + system_language: summary + }, 'inReplyTo': in_reply_to, 'published': published, 'url': new_post_url, @@ -1178,6 +1191,9 @@ def _create_post_c2s(base_dir: str, nickname: str, domain: str, port: int, 'conversation': conversation_id, 'type': post_object_type, 'summary': summary, + 'summaryMap': { + system_language: summary + }, 'inReplyTo': in_reply_to, 'published': published, 'url': new_post_url, @@ -1399,7 +1415,8 @@ def _create_post_base(base_dir: str, event_status: str, ticket_url: str, system_language: str, conversation_id: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: """Creates a message """ content = remove_invalid_chars(content) @@ -1486,7 +1503,8 @@ def _create_post_base(base_dir: str, sensitive, summary = \ _create_post_cw_from_reply(base_dir, nickname, domain, - in_reply_to, sensitive, summary) + in_reply_to, sensitive, summary, + system_language, languages_understood) event_date_str = \ _create_post_place_and_time(event_date, end_date, @@ -1710,6 +1728,9 @@ def get_pinned_post_as_json(base_dir: str, http_prefix: str, 'replies': {}, 'sensitive': False, 'summary': None, + 'summaryMap': { + system_language: None + }, 'tag': [], 'to': ['https://www.w3.org/ns/activitystreams#Public'], 'type': 'Note', @@ -1791,7 +1812,8 @@ def create_public_post(base_dir: str, is_article: bool, system_language: str, conversation_id: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: """Public post """ domain_full = get_full_domain(domain, port) @@ -1825,7 +1847,8 @@ def create_public_post(base_dir: str, anonymous_participation_enabled, event_status, ticket_url, system_language, conversation_id, low_bandwidth, - content_license_url) + content_license_url, + languages_understood) def _append_citations_to_blog_post(base_dir: str, @@ -1869,7 +1892,8 @@ def create_blog_post(base_dir: str, event_date: str, event_time: str, location: str, system_language: str, conversation_id: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: blog_json = \ create_public_post(base_dir, nickname, domain, port, http_prefix, @@ -1881,7 +1905,8 @@ def create_blog_post(base_dir: str, schedule_post, event_date, event_time, location, True, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) blog_json['object']['url'] = \ blog_json['object']['url'].replace('/@', '/users/') _append_citations_to_blog_post(base_dir, nickname, domain, blog_json) @@ -1896,7 +1921,8 @@ def create_news_post(base_dir: str, image_description: str, city: str, subject: str, system_language: str, conversation_id: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: client_to_server = False in_reply_to = None in_reply_to_atom_uri = None @@ -1915,7 +1941,8 @@ def create_news_post(base_dir: str, schedule_post, event_date, event_time, location, True, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) blog['object']['type'] = 'Article' return blog @@ -1930,7 +1957,8 @@ def create_question_post(base_dir: str, image_description: str, city: str, subject: str, durationDays: int, system_language: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: """Question post with multiple choice options """ domain_full = get_full_domain(domain, port) @@ -1947,7 +1975,8 @@ def create_question_post(base_dir: str, False, None, None, None, None, None, None, None, None, None, None, None, None, None, system_language, - None, low_bandwidth, content_license_url) + None, low_bandwidth, content_license_url, + languages_understood) message_json['object']['type'] = 'Question' message_json['object']['oneOf'] = [] message_json['object']['votersCount'] = 0 @@ -1982,7 +2011,8 @@ def create_unlisted_post(base_dir: str, event_date: str, event_time: str, location: str, system_language: str, conversation_id: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: """Unlisted post. This has the #Public and followers links inverted. """ domain_full = get_full_domain(domain, port) @@ -2001,7 +2031,7 @@ def create_unlisted_post(base_dir: str, None, None, None, None, None, None, None, None, None, None, system_language, conversation_id, low_bandwidth, - content_license_url) + content_license_url, languages_understood) def create_followers_only_post(base_dir: str, @@ -2018,7 +2048,8 @@ def create_followers_only_post(base_dir: str, event_date: str, event_time: str, location: str, system_language: str, conversation_id: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: """Followers only post """ domain_full = get_full_domain(domain, port) @@ -2036,7 +2067,7 @@ def create_followers_only_post(base_dir: str, None, None, None, None, None, None, None, None, None, None, system_language, conversation_id, low_bandwidth, - content_license_url) + content_license_url, languages_understood) def get_mentioned_people(base_dir: str, http_prefix: str, @@ -2090,7 +2121,8 @@ def create_direct_message_post(base_dir: str, event_date: str, event_time: str, location: str, system_language: str, conversation_id: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: """Direct Message post """ content = resolve_petnames(base_dir, nickname, domain, content) @@ -2115,7 +2147,7 @@ def create_direct_message_post(base_dir: str, None, None, None, None, None, None, None, None, None, None, system_language, conversation_id, low_bandwidth, - content_license_url) + content_license_url, languages_understood) # mentioned recipients go into To rather than Cc message_json['to'] = message_json['object']['cc'] message_json['object']['to'] = message_json['to'] @@ -2136,7 +2168,8 @@ def create_report_post(base_dir: str, image_description: str, city: str, debug: bool, subject: str, system_language: str, low_bandwidth: bool, - content_license_url: str) -> {}: + content_license_url: str, + languages_understood: []) -> {}: """Send a report to moderators """ domain_full = get_full_domain(domain, port) @@ -2212,7 +2245,8 @@ def create_report_post(base_dir: str, False, None, None, None, None, None, None, None, None, None, None, None, None, None, system_language, - None, low_bandwidth, content_license_url) + None, low_bandwidth, content_license_url, + languages_understood) if not post_json_object: continue @@ -2306,6 +2340,7 @@ def send_post(signing_priv_key_pem: str, project_version: str, federation_list: [], send_threads: [], post_log: [], cached_webfingers: {}, person_cache: {}, is_article: bool, system_language: str, + languages_understood: [], shared_items_federated_domains: [], shared_item_federation_tokens: {}, low_bandwidth: bool, content_license_url: str, @@ -2375,7 +2410,7 @@ def send_post(signing_priv_key_pem: str, project_version: str, None, None, None, None, None, None, None, None, system_language, conversation_id, low_bandwidth, - content_license_url) + content_license_url, languages_understood) # get the senders private key private_key_pem = _get_person_key(nickname, domain, base_dir, 'private') @@ -2457,6 +2492,7 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str, image_description: str, city: str, cached_webfingers: {}, person_cache: {}, is_article: bool, system_language: str, + languages_understood: [], low_bandwidth: bool, content_license_url: str, debug: bool = False, @@ -2547,7 +2583,7 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str, None, None, None, None, None, None, None, None, system_language, conversation_id, low_bandwidth, - content_license_url) + content_license_url, languages_understood) auth_header = create_basic_auth_header(from_nickname, password) diff --git a/scripts/commit_words b/scripts/commit_words new file mode 100755 index 000000000..c2c7533a4 --- /dev/null +++ b/scripts/commit_words @@ -0,0 +1,2 @@ +#!/bin/bash +git log --pretty=format:'%s' | tr ' ' '\n' | sed 's/.*/\L&/' | sort | uniq -c | sort -rg | head -n 100 \ No newline at end of file diff --git a/tests.py b/tests.py index 3df4f5c56..bfc89fbd5 100644 --- a/tests.py +++ b/tests.py @@ -703,6 +703,7 @@ def create_server_alice(path: str, domain: str, port: int, os.chdir(path) shared_items_federated_domains = [] system_language = 'en' + languages_understood = [system_language] nickname = 'alice' http_prefix = 'http' proxy_type = None @@ -760,7 +761,8 @@ def create_server_alice(path: str, domain: str, port: int, test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) create_public_post(path, nickname, domain, port, http_prefix, "Curiouser and curiouser!", test_followers_only, @@ -774,7 +776,8 @@ def create_server_alice(path: str, domain: str, port: int, test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) create_public_post(path, nickname, domain, port, http_prefix, "In the gardens of memory, in the palace " + "of dreams, that is where you and I shall meet", @@ -789,7 +792,8 @@ def create_server_alice(path: str, domain: str, port: int, test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) regenerate_index_for_box(path, nickname, domain, 'outbox') global TEST_SERVER_ALICE_RUNNING TEST_SERVER_ALICE_RUNNING = True @@ -853,6 +857,7 @@ def create_server_bob(path: str, domain: str, port: int, os.chdir(path) shared_items_federated_domains = [] system_language = 'en' + languages_understood = [system_language] nickname = 'bob' http_prefix = 'http' proxy_type = None @@ -909,7 +914,8 @@ def create_server_bob(path: str, domain: str, port: int, test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) create_public_post(path, nickname, domain, port, http_prefix, "One of the things I've realised is that " + "I am very simple", @@ -924,7 +930,8 @@ def create_server_bob(path: str, domain: str, port: int, test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) create_public_post(path, nickname, domain, port, http_prefix, "Quantum physics is a bit of a passion of mine", test_followers_only, @@ -938,7 +945,8 @@ def create_server_bob(path: str, domain: str, port: int, test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) regenerate_index_for_box(path, nickname, domain, 'outbox') global TEST_SERVER_BOB_RUNNING TEST_SERVER_BOB_RUNNING = True @@ -1154,6 +1162,7 @@ def test_post_message_between_servers(base_dir: str) -> None: TEST_SERVER_BOB_RUNNING = False system_language = 'en' + languages_understood = [system_language] http_prefix = 'http' proxy_type = None content_license_url = 'https://creativecommons.org/licenses/by/4.0' @@ -1258,6 +1267,7 @@ def test_post_message_between_servers(base_dir: str) -> None: attached_image_description, city, federation_list, alice_send_threads, alice_post_log, alice_cached_webfingers, alice_person_cache, is_article, system_language, + languages_understood, alice_shared_items_federated_domains, alice_shared_item_federation_tokens, low_bandwidth, content_license_url, @@ -1478,6 +1488,7 @@ def test_follow_between_servers(base_dir: str) -> None: TEST_SERVER_BOB_RUNNING = False system_language = 'en' + languages_understood = [system_language] http_prefix = 'http' proxy_type = None federation_list = [] @@ -1620,6 +1631,7 @@ def test_follow_between_servers(base_dir: str) -> None: None, None, None, city, federation_list, alice_send_threads, alice_post_log, alice_cached_webfingers, alice_person_cache, is_article, system_language, + languages_understood, alice_shared_items_federated_domains, alice_shared_item_federation_tokens, low_bandwidth, content_license_url, @@ -1668,6 +1680,7 @@ def test_shared_items_federation(base_dir: str) -> None: TEST_SERVER_BOB_RUNNING = False system_language = 'en' + languages_understood = [system_language] http_prefix = 'http' proxy_type = None federation_list = [] @@ -1980,6 +1993,7 @@ def test_shared_items_federation(base_dir: str) -> None: None, None, None, city, federation_list, alice_send_threads, alice_post_log, alice_cached_webfingers, alice_person_cache, is_article, system_language, + languages_understood, alice_shared_items_federated_domains, alice_shared_item_federation_tokens, low_bandwidth, content_license_url, True, @@ -2078,6 +2092,7 @@ def test_group_follow(base_dir: str) -> None: global TEST_SERVER_BOB_RUNNING global TEST_SERVER_GROUP_RUNNING system_language = 'en' + languages_understood = [system_language] TEST_SERVER_ALICE_RUNNING = False TEST_SERVER_BOB_RUNNING = False TEST_SERVER_GROUP_RUNNING = False @@ -2405,6 +2420,7 @@ def test_group_follow(base_dir: str) -> None: None, None, None, city, federation_list, alice_send_threads, alice_post_log, alice_cached_webfingers, alice_person_cache, is_article, system_language, + languages_understood, alice_shared_items_federated_domains, alice_shared_item_federation_tokens, low_bandwidth, content_license_url, @@ -2730,6 +2746,7 @@ def _test_follows(base_dir: str) -> None: def _test_create_person_account(base_dir: str): print('test_create_person_account') system_language = 'en' + languages_understood = [system_language] curr_dir = base_dir nickname = 'test382' domain = 'badgerdomain.com' @@ -2782,7 +2799,8 @@ def _test_create_person_account(base_dir: str): test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) os.chdir(curr_dir) shutil.rmtree(base_dir, ignore_errors=False, onerror=None) @@ -2850,6 +2868,7 @@ def test_client_to_server(base_dir: str): TEST_SERVER_BOB_RUNNING = False system_language = 'en' + languages_understood = [system_language] http_prefix = 'http' proxy_type = None federation_list = [] @@ -2962,8 +2981,8 @@ def test_client_to_server(base_dir: str): attached_image_filename, media_type, attached_image_description, city, cached_webfingers, person_cache, is_article, - system_language, low_bandwidth, - content_license_url, + system_language, languages_understood, + low_bandwidth, content_license_url, True, None, None, conversation_id, None) print('send_result: ' + str(send_result)) @@ -4303,6 +4322,7 @@ def _test_mentioned_people(base_dir: str) -> None: def _test_reply_to_public_post(base_dir: str) -> None: system_language = 'en' + languages_understood = [system_language] nickname = 'test7492362' domain = 'other.site' port = 443 @@ -4339,7 +4359,8 @@ def _test_reply_to_public_post(base_dir: str) -> None: test_subject, test_schedule_post, test_event_date, test_event_time, test_location, test_is_article, system_language, conversation_id, - low_bandwidth, content_license_url) + low_bandwidth, content_license_url, + languages_understood) # print(str(reply)) assert reply['object']['content'] == \ '
' + \
@@ -5106,6 +5127,7 @@ def _test_functions():
def _test_links_within_post(base_dir: str) -> None:
print('test_links_within_post')
system_language = 'en'
+ languages_understood = [system_language]
nickname = 'test27636'
domain = 'rando.site'
port = 443
@@ -5142,7 +5164,8 @@ def _test_links_within_post(base_dir: str) -> None:
test_subject, test_schedule_post,
test_event_date, test_event_time, test_location,
test_is_article, system_language, conversation_id,
- low_bandwidth, content_license_url)
+ low_bandwidth, content_license_url,
+ languages_understood)
assert post_json_object['object']['content'] == \
' This is a test post with links.
' + \
@@ -5179,7 +5202,8 @@ def _test_links_within_post(base_dir: str) -> None:
test_subject, test_schedule_post,
test_event_date, test_event_time, test_location,
test_is_article, system_language, conversation_id,
- low_bandwidth, content_license_url)
+ low_bandwidth, content_license_url,
+ languages_understood)
assert post_json_object['object']['content'] == content
assert post_json_object['object']['contentMap'][system_language] == content
@@ -6100,6 +6124,7 @@ def _translate_ontology(base_dir: str) -> None:
def _test_can_replyto(base_dir: str) -> None:
print('test_can_reply_to')
system_language = 'en'
+ languages_understood = [system_language]
nickname = 'test27637'
domain = 'rando.site'
port = 443
@@ -6136,7 +6161,8 @@ def _test_can_replyto(base_dir: str) -> None:
test_subject, test_schedule_post,
test_event_date, test_event_time, test_location,
test_is_article, system_language, conversation_id,
- low_bandwidth, content_license_url)
+ low_bandwidth, content_license_url,
+ languages_understood)
# set the date on the post
curr_date_str = "2021-09-08T20:45:00Z"
post_json_object['published'] = curr_date_str
diff --git a/utils.py b/utils.py
index 74e6d2b39..702a6e892 100644
--- a/utils.py
+++ b/utils.py
@@ -89,34 +89,45 @@ def get_actor_languages_list(actor_json: {}) -> []:
def get_content_from_post(post_json_object: {}, system_language: str,
- languages_understood: []) -> str:
+ languages_understood: [],
+ contentType: str = "content") -> str:
"""Returns the content from the post in the given language
including searching for a matching entry within contentMap
"""
this_post_json = post_json_object
if has_object_dict(post_json_object):
this_post_json = post_json_object['object']
- if not this_post_json.get('content'):
+ if not this_post_json.get(contentType):
return ''
content = ''
- if this_post_json.get('contentMap'):
- if isinstance(this_post_json['contentMap'], dict):
- if this_post_json['contentMap'].get(system_language):
- sys_lang = this_post_json['contentMap'][system_language]
+ mapDict = contentType + 'Map'
+ if this_post_json.get(mapDict):
+ if isinstance(this_post_json[mapDict], dict):
+ if this_post_json[mapDict].get(system_language):
+ sys_lang = this_post_json[mapDict][system_language]
if isinstance(sys_lang, str):
- return this_post_json['contentMap'][system_language]
+ return this_post_json[mapDict][system_language]
else:
- # is there a contentMap entry for one of
+ # is there a contentMap/summaryMap entry for one of
# the understood languages?
for lang in languages_understood:
- if this_post_json['contentMap'].get(lang):
- return this_post_json['contentMap'][lang]
+ if this_post_json[mapDict].get(lang):
+ return this_post_json[mapDict][lang]
else:
- if isinstance(this_post_json['content'], str):
- content = this_post_json['content']
+ if isinstance(this_post_json[contentType], str):
+ content = this_post_json[contentType]
return content
+def get_summary_from_post(post_json_object: {}, system_language: str,
+ languages_understood: []) -> str:
+ """Returns the summary from the post in the given language
+ including searching for a matching entry within summaryMap
+ """
+ return get_content_from_post(post_json_object, system_language,
+ languages_understood, "summary")
+
+
def get_base_content_from_post(post_json_object: {},
system_language: str) -> str:
"""Returns the content from the post in the given language
diff --git a/webapp_post.py b/webapp_post.py
index d07f1f81f..d31148636 100644
--- a/webapp_post.py
+++ b/webapp_post.py
@@ -28,6 +28,7 @@ from utils import remove_html
from utils import get_actor_languages_list
from utils import get_base_content_from_post
from utils import get_content_from_post
+from utils import get_summary_from_post
from utils import has_object_dict
from utils import update_announce_collection
from utils import is_pgp_encrypted
@@ -1852,6 +1853,9 @@ def individual_post_as_html(signing_priv_key_pem: str,
if translate.get(sensitive_str):
sensitive_str = translate[sensitive_str]
post_json_object['object']['summary'] = sensitive_str
+ post_json_object['object']['summaryMap'] = {
+ system_language: sensitive_str
+ }
# add an extra line if there is a content warning,
# for better vertical spacing on mobile
@@ -1860,6 +1864,9 @@ def individual_post_as_html(signing_priv_key_pem: str,
if not post_json_object['object'].get('summary'):
post_json_object['object']['summary'] = ''
+ post_json_object['object']['summaryMap'] = {
+ system_language: ''
+ }
if post_json_object['object'].get('cipherText'):
post_json_object['object']['content'] = \
@@ -1883,10 +1890,11 @@ def individual_post_as_html(signing_priv_key_pem: str,
if not content_str:
return ''
+ 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'],
- post_json_object['object']['summary'],
- content_str)
+ summary_str, content_str)
_log_post_timing(enable_timing_log, post_start_time, '16')
@@ -1921,12 +1929,11 @@ def individual_post_as_html(signing_priv_key_pem: str,
else:
post_id = 'post' + str(create_password(8))
content_str = ''
- if post_json_object['object'].get('summary'):
- cw_str = str(post_json_object['object']['summary'])
+ if summary_str:
cw_str = \
add_emoji_to_display_name(session, base_dir, http_prefix,
nickname, domain,
- cw_str, False)
+ summary_str, False)
content_str += \
'\n '
if is_moderation_post: