mirror of https://gitlab.com/bashrc2/epicyon
				
				
				
			Merge
						commit
						604ae60c95
					
				|  | @ -25,54 +25,54 @@ from utils import has_object_string_type | ||||||
| 
 | 
 | ||||||
| def _create_accept_reject(base_dir: str, federation_list: [], | def _create_accept_reject(base_dir: str, federation_list: [], | ||||||
|                           nickname: str, domain: str, port: int, |                           nickname: str, domain: str, port: int, | ||||||
|                           toUrl: str, ccUrl: str, http_prefix: str, |                           to_url: str, cc_url: str, http_prefix: str, | ||||||
|                           objectJson: {}, acceptType: str) -> {}: |                           object_json: {}, accept_type: str) -> {}: | ||||||
|     """Accepts or rejects something (eg. a follow request or offer) |     """Accepts or rejects something (eg. a follow request or offer) | ||||||
|     Typically toUrl will be https://www.w3.org/ns/activitystreams#Public |     Typically to_url will be https://www.w3.org/ns/activitystreams#Public | ||||||
|     and ccUrl might be a specific person favorited or repeated and |     and cc_url might be a specific person favorited or repeated and | ||||||
|     the followers url objectUrl is typically the url of the message, |     the followers url objectUrl is typically the url of the message, | ||||||
|     corresponding to url or atomUri in createPostBase |     corresponding to url or atomUri in createPostBase | ||||||
|     """ |     """ | ||||||
|     if not objectJson.get('actor'): |     if not object_json.get('actor'): | ||||||
|         return None |         return None | ||||||
| 
 | 
 | ||||||
|     if not url_permitted(objectJson['actor'], federation_list): |     if not url_permitted(object_json['actor'], federation_list): | ||||||
|         return None |         return None | ||||||
| 
 | 
 | ||||||
|     domain = get_full_domain(domain, port) |     domain = get_full_domain(domain, port) | ||||||
| 
 | 
 | ||||||
|     new_accept = { |     new_accept = { | ||||||
|         "@context": "https://www.w3.org/ns/activitystreams", |         "@context": "https://www.w3.org/ns/activitystreams", | ||||||
|         'type': acceptType, |         'type': accept_type, | ||||||
|         'actor': local_actor_url(http_prefix, nickname, domain), |         'actor': local_actor_url(http_prefix, nickname, domain), | ||||||
|         'to': [toUrl], |         'to': [to_url], | ||||||
|         'cc': [], |         'cc': [], | ||||||
|         'object': objectJson |         'object': object_json | ||||||
|     } |     } | ||||||
|     if ccUrl: |     if cc_url: | ||||||
|         if len(ccUrl) > 0: |         if len(cc_url) > 0: | ||||||
|             new_accept['cc'] = [ccUrl] |             new_accept['cc'] = [cc_url] | ||||||
|     return new_accept |     return new_accept | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def create_accept(base_dir: str, federation_list: [], | def create_accept(base_dir: str, federation_list: [], | ||||||
|                   nickname: str, domain: str, port: int, |                   nickname: str, domain: str, port: int, | ||||||
|                   toUrl: str, ccUrl: str, http_prefix: str, |                   to_url: str, cc_url: str, http_prefix: str, | ||||||
|                   objectJson: {}) -> {}: |                   object_json: {}) -> {}: | ||||||
|     return _create_accept_reject(base_dir, federation_list, |     return _create_accept_reject(base_dir, federation_list, | ||||||
|                                  nickname, domain, port, |                                  nickname, domain, port, | ||||||
|                                  toUrl, ccUrl, http_prefix, |                                  to_url, cc_url, http_prefix, | ||||||
|                                  objectJson, 'Accept') |                                  object_json, 'Accept') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def create_reject(base_dir: str, federation_list: [], | def create_reject(base_dir: str, federation_list: [], | ||||||
|                   nickname: str, domain: str, port: int, |                   nickname: str, domain: str, port: int, | ||||||
|                   toUrl: str, ccUrl: str, http_prefix: str, |                   to_url: str, cc_url: str, http_prefix: str, | ||||||
|                   objectJson: {}) -> {}: |                   object_json: {}) -> {}: | ||||||
|     return _create_accept_reject(base_dir, federation_list, |     return _create_accept_reject(base_dir, federation_list, | ||||||
|                                  nickname, domain, port, |                                  nickname, domain, port, | ||||||
|                                  toUrl, ccUrl, |                                  to_url, cc_url, | ||||||
|                                  http_prefix, objectJson, 'Reject') |                                  http_prefix, object_json, 'Reject') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _accept_follow(base_dir: str, domain: str, message_json: {}, | def _accept_follow(base_dir: str, domain: str, message_json: {}, | ||||||
|  |  | ||||||
							
								
								
									
										30
									
								
								announce.py
								
								
								
								
							
							
						
						
									
										30
									
								
								announce.py
								
								
								
								
							|  | @ -135,10 +135,10 @@ def announced_by_person(is_announced: bool, post_actor: str, | ||||||
| 
 | 
 | ||||||
| def create_announce(session, base_dir: str, federation_list: [], | def create_announce(session, base_dir: str, federation_list: [], | ||||||
|                     nickname: str, domain: str, port: int, |                     nickname: str, domain: str, port: int, | ||||||
|                     to_url: str, ccUrl: str, http_prefix: str, |                     to_url: str, cc_url: str, http_prefix: str, | ||||||
|                     object_url: str, saveToFile: bool, |                     object_url: str, save_to_file: bool, | ||||||
|                     client_to_server: bool, |                     client_to_server: bool, | ||||||
|                     send_threads: [], postLog: [], |                     send_threads: [], post_log: [], | ||||||
|                     person_cache: {}, cached_webfingers: {}, |                     person_cache: {}, cached_webfingers: {}, | ||||||
|                     debug: bool, project_version: str, |                     debug: bool, project_version: str, | ||||||
|                     signing_priv_key_pem: str, |                     signing_priv_key_pem: str, | ||||||
|  | @ -146,7 +146,7 @@ def create_announce(session, base_dir: str, federation_list: [], | ||||||
|                     onion_domain: str, i2p_domain: str) -> {}: |                     onion_domain: str, i2p_domain: str) -> {}: | ||||||
|     """Creates an announce message |     """Creates an announce message | ||||||
|     Typically to_url will be https://www.w3.org/ns/activitystreams#Public |     Typically to_url will be https://www.w3.org/ns/activitystreams#Public | ||||||
|     and ccUrl might be a specific person favorited or repeated and the |     and cc_url might be a specific person favorited or repeated and the | ||||||
|     followers url object_url is typically the url of the message, |     followers url object_url is typically the url of the message, | ||||||
|     corresponding to url or atomUri in createPostBase |     corresponding to url or atomUri in createPostBase | ||||||
|     """ |     """ | ||||||
|  | @ -172,10 +172,10 @@ def create_announce(session, base_dir: str, federation_list: [], | ||||||
|         'to': [to_url], |         'to': [to_url], | ||||||
|         'type': 'Announce' |         'type': 'Announce' | ||||||
|     } |     } | ||||||
|     if ccUrl: |     if cc_url: | ||||||
|         if len(ccUrl) > 0: |         if len(cc_url) > 0: | ||||||
|             new_announce['cc'] = [ccUrl] |             new_announce['cc'] = [cc_url] | ||||||
|     if saveToFile: |     if save_to_file: | ||||||
|         outbox_dir = create_outbox_dir(nickname, domain, base_dir) |         outbox_dir = create_outbox_dir(nickname, domain, base_dir) | ||||||
|         filename = \ |         filename = \ | ||||||
|             outbox_dir + '/' + new_announce_id.replace('/', '#') + '.json' |             outbox_dir + '/' + new_announce_id.replace('/', '#') + '.json' | ||||||
|  | @ -202,7 +202,7 @@ def create_announce(session, base_dir: str, federation_list: [], | ||||||
|                          announce_nickname, announce_domain, |                          announce_nickname, announce_domain, | ||||||
|                          announce_port, None, |                          announce_port, None, | ||||||
|                          http_prefix, True, client_to_server, federation_list, |                          http_prefix, True, client_to_server, federation_list, | ||||||
|                          send_threads, postLog, cached_webfingers, |                          send_threads, post_log, cached_webfingers, | ||||||
|                          person_cache, |                          person_cache, | ||||||
|                          debug, project_version, None, group_account, |                          debug, project_version, None, group_account, | ||||||
|                          signing_priv_key_pem, 639633, |                          signing_priv_key_pem, 639633, | ||||||
|  | @ -214,7 +214,7 @@ def create_announce(session, base_dir: str, federation_list: [], | ||||||
| def announce_public(session, base_dir: str, federation_list: [], | def announce_public(session, base_dir: str, federation_list: [], | ||||||
|                     nickname: str, domain: str, port: int, http_prefix: str, |                     nickname: str, domain: str, port: int, http_prefix: str, | ||||||
|                     object_url: str, client_to_server: bool, |                     object_url: str, client_to_server: bool, | ||||||
|                     send_threads: [], postLog: [], |                     send_threads: [], post_log: [], | ||||||
|                     person_cache: {}, cached_webfingers: {}, |                     person_cache: {}, cached_webfingers: {}, | ||||||
|                     debug: bool, project_version: str, |                     debug: bool, project_version: str, | ||||||
|                     signing_priv_key_pem: str, |                     signing_priv_key_pem: str, | ||||||
|  | @ -225,12 +225,12 @@ def announce_public(session, base_dir: str, federation_list: [], | ||||||
|     from_domain = get_full_domain(domain, port) |     from_domain = get_full_domain(domain, port) | ||||||
| 
 | 
 | ||||||
|     to_url = 'https://www.w3.org/ns/activitystreams#Public' |     to_url = 'https://www.w3.org/ns/activitystreams#Public' | ||||||
|     ccUrl = local_actor_url(http_prefix, nickname, from_domain) + '/followers' |     cc_url = local_actor_url(http_prefix, nickname, from_domain) + '/followers' | ||||||
|     return create_announce(session, base_dir, federation_list, |     return create_announce(session, base_dir, federation_list, | ||||||
|                            nickname, domain, port, |                            nickname, domain, port, | ||||||
|                            to_url, ccUrl, http_prefix, |                            to_url, cc_url, http_prefix, | ||||||
|                            object_url, True, client_to_server, |                            object_url, True, client_to_server, | ||||||
|                            send_threads, postLog, |                            send_threads, post_log, | ||||||
|                            person_cache, cached_webfingers, |                            person_cache, cached_webfingers, | ||||||
|                            debug, project_version, |                            debug, project_version, | ||||||
|                            signing_priv_key_pem, curr_domain, |                            signing_priv_key_pem, curr_domain, | ||||||
|  | @ -239,7 +239,7 @@ def announce_public(session, base_dir: str, federation_list: [], | ||||||
| 
 | 
 | ||||||
| def send_announce_via_server(base_dir: str, session, | def send_announce_via_server(base_dir: str, session, | ||||||
|                              from_nickname: str, password: str, |                              from_nickname: str, password: str, | ||||||
|                              from_domain: str, fromPort: int, |                              from_domain: str, from_port: int, | ||||||
|                              http_prefix: str, repeat_object_url: str, |                              http_prefix: str, repeat_object_url: str, | ||||||
|                              cached_webfingers: {}, person_cache: {}, |                              cached_webfingers: {}, person_cache: {}, | ||||||
|                              debug: bool, project_version: str, |                              debug: bool, project_version: str, | ||||||
|  | @ -250,7 +250,7 @@ def send_announce_via_server(base_dir: str, session, | ||||||
|         print('WARN: No session for send_announce_via_server') |         print('WARN: No session for send_announce_via_server') | ||||||
|         return 6 |         return 6 | ||||||
| 
 | 
 | ||||||
|     from_domain_full = get_full_domain(from_domain, fromPort) |     from_domain_full = get_full_domain(from_domain, from_port) | ||||||
| 
 | 
 | ||||||
|     to_url = 'https://www.w3.org/ns/activitystreams#Public' |     to_url = 'https://www.w3.org/ns/activitystreams#Public' | ||||||
|     actor_str = local_actor_url(http_prefix, from_nickname, from_domain_full) |     actor_str = local_actor_url(http_prefix, from_nickname, from_domain_full) | ||||||
|  |  | ||||||
|  | @ -917,7 +917,7 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None: | ||||||
|         # generate instance allow list |         # generate instance allow list | ||||||
|         allowed_domains = [domain_full] |         allowed_domains = [domain_full] | ||||||
|         follow_files = ('following.txt', 'followers.txt') |         follow_files = ('following.txt', 'followers.txt') | ||||||
|         for subdir, dirs, files in os.walk(base_dir + '/accounts'): |         for _, dirs, _ in os.walk(base_dir + '/accounts'): | ||||||
|             for acct in dirs: |             for acct in dirs: | ||||||
|                 if not is_account_dir(acct): |                 if not is_account_dir(acct): | ||||||
|                     continue |                     continue | ||||||
|  | @ -995,7 +995,7 @@ def load_cw_lists(base_dir: str, verbose: bool) -> {}: | ||||||
|     if not os.path.isdir(base_dir + '/cwlists'): |     if not os.path.isdir(base_dir + '/cwlists'): | ||||||
|         return {} |         return {} | ||||||
|     result = {} |     result = {} | ||||||
|     for subdir, dirs, files in os.walk(base_dir + '/cwlists'): |     for _, _, files in os.walk(base_dir + '/cwlists'): | ||||||
|         for fname in files: |         for fname in files: | ||||||
|             if not fname.endswith('.json'): |             if not fname.endswith('.json'): | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|  | @ -986,8 +986,8 @@ def _desktop_show_box(indent: str, | ||||||
|                       translate: {}, |                       translate: {}, | ||||||
|                       screenreader: str, system_language: str, espeak, |                       screenreader: str, system_language: str, espeak, | ||||||
|                       page_number: int, |                       page_number: int, | ||||||
|                       newReplies: bool, |                       new_replies: bool, | ||||||
|                       newDMs: bool) -> bool: |                       new_dms: bool) -> bool: | ||||||
|     """Shows online timeline |     """Shows online timeline | ||||||
|     """ |     """ | ||||||
|     number_width = 2 |     number_width = 2 | ||||||
|  | @ -1004,9 +1004,9 @@ def _desktop_show_box(indent: str, | ||||||
|     else: |     else: | ||||||
|         box_name_str = box_name |         box_name_str = box_name | ||||||
|     title_str = _highlight_text(box_name_str.upper()) |     title_str = _highlight_text(box_name_str.upper()) | ||||||
|     # if newDMs: |     # if new_dms: | ||||||
|     #     notification_icons += ' 📩' |     #     notification_icons += ' 📩' | ||||||
|     # if newReplies: |     # if new_replies: | ||||||
|     #     notification_icons += ' 📨' |     #     notification_icons += ' 📨' | ||||||
| 
 | 
 | ||||||
|     if notification_icons: |     if notification_icons: | ||||||
|  | @ -1086,8 +1086,7 @@ def _desktop_show_box(indent: str, | ||||||
|                         if i > 10: |                         if i > 10: | ||||||
|                             break |                             break | ||||||
|         likes_count = no_of_likes(post_json_object) |         likes_count = no_of_likes(post_json_object) | ||||||
|         if likes_count > 10: |         likes_count = max(likes_count, 10) | ||||||
|             likes_count = 10 |  | ||||||
|         for _ in range(likes_count): |         for _ in range(likes_count): | ||||||
|             if not space_added: |             if not space_added: | ||||||
|                 space_added = True |                 space_added = True | ||||||
|  | @ -1654,8 +1653,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, | ||||||
|                 refresh_timeline = True |                 refresh_timeline = True | ||||||
|             elif command_str.startswith('prev'): |             elif command_str.startswith('prev'): | ||||||
|                 page_number -= 1 |                 page_number -= 1 | ||||||
|                 if page_number < 1: |                 page_number = max(page_number, 1) | ||||||
|                     page_number = 1 |  | ||||||
|                 prev_timeline_first_id = '' |                 prev_timeline_first_id = '' | ||||||
|                 box_json = c2s_box_json(base_dir, session, |                 box_json = c2s_box_json(base_dir, session, | ||||||
|                                         nickname, password, |                                         nickname, password, | ||||||
|  | @ -1673,8 +1671,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, | ||||||
|                   command_str.startswith('show ') or |                   command_str.startswith('show ') or | ||||||
|                   command_str == 'read' or |                   command_str == 'read' or | ||||||
|                   command_str == 'show'): |                   command_str == 'show'): | ||||||
|                 if command_str == 'read' or \ |                 if command_str in ('read', 'show'): | ||||||
|                    command_str == 'show': |  | ||||||
|                     post_index_str = '1' |                     post_index_str = '1' | ||||||
|                 else: |                 else: | ||||||
|                     if 'read ' in command_str: |                     if 'read ' in command_str: | ||||||
|  | @ -1774,7 +1771,10 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, | ||||||
|                     post_content = '' |                     post_content = '' | ||||||
|                     if post_json_object['object'].get('content'): |                     if post_json_object['object'].get('content'): | ||||||
|                         post_content = post_json_object['object']['content'] |                         post_content = post_json_object['object']['content'] | ||||||
|                     if not disallow_reply(post_content): |                     post_summary = '' | ||||||
|  |                     if post_json_object['object'].get('summary'): | ||||||
|  |                         post_summary = post_json_object['object']['summary'] | ||||||
|  |                     if not disallow_reply(post_summary + ' ' + post_content): | ||||||
|                         if post_json_object.get('id'): |                         if post_json_object.get('id'): | ||||||
|                             post_id = post_json_object['id'] |                             post_id = post_json_object['id'] | ||||||
|                             subject = None |                             subject = None | ||||||
|  | @ -2154,7 +2154,11 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, | ||||||
|                     post_content = '' |                     post_content = '' | ||||||
|                     if post_json_object['object'].get('content'): |                     if post_json_object['object'].get('content'): | ||||||
|                         post_content = post_json_object['object']['content'] |                         post_content = post_json_object['object']['content'] | ||||||
|                     if not disallow_announce(post_content): |                     post_summary = '' | ||||||
|  |                     if post_json_object['object'].get('summary'): | ||||||
|  |                         post_summary = post_json_object['object']['summary'] | ||||||
|  |                     if not disallow_announce(post_summary + ' ' + | ||||||
|  |                                              post_content): | ||||||
|                         if post_json_object.get('id'): |                         if post_json_object.get('id'): | ||||||
|                             post_id = post_json_object['id'] |                             post_id = post_json_object['id'] | ||||||
|                             announce_actor = \ |                             announce_actor = \ | ||||||
|  |  | ||||||
|  | @ -2057,14 +2057,18 @@ def individual_post_as_html(signing_priv_key_pem: str, | ||||||
|         if not content_str: |         if not content_str: | ||||||
|             return '' |             return '' | ||||||
| 
 | 
 | ||||||
|  |     summary_str = '' | ||||||
|     if content_str: |     if content_str: | ||||||
|  |         summary_str = get_summary_from_post(post_json_object, system_language, | ||||||
|  |                                             languages_understood) | ||||||
|  |         content_all_str = str(summary_str) + ' ' + content_str | ||||||
|         # does an emoji indicate a no boost preference? |         # does an emoji indicate a no boost preference? | ||||||
|         # if so then don't show the repeat/announce icon |         # if so then don't show the repeat/announce icon | ||||||
|         if disallow_announce(content_str): |         if disallow_announce(content_all_str): | ||||||
|             announce_str = '' |             announce_str = '' | ||||||
|         # does an emoji indicate a no replies preference? |         # does an emoji indicate a no replies preference? | ||||||
|         # if so then don't show the reply icon |         # if so then don't show the reply icon | ||||||
|         if disallow_reply(content_str): |         if disallow_reply(content_all_str): | ||||||
|             reply_str = '' |             reply_str = '' | ||||||
| 
 | 
 | ||||||
|     new_footer_str = \ |     new_footer_str = \ | ||||||
|  | @ -2083,6 +2087,7 @@ def individual_post_as_html(signing_priv_key_pem: str, | ||||||
|     if post_is_sensitive: |     if post_is_sensitive: | ||||||
|         footer_str = '<br>' + footer_str |         footer_str = '<br>' + footer_str | ||||||
| 
 | 
 | ||||||
|  |     if not summary_str: | ||||||
|         summary_str = get_summary_from_post(post_json_object, system_language, |         summary_str = get_summary_from_post(post_json_object, system_language, | ||||||
|                                             languages_understood) |                                             languages_understood) | ||||||
|     is_patch = is_git_patch(base_dir, nickname, domain, |     is_patch = is_git_patch(base_dir, nickname, domain, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue