mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
448b0e3120
commit
5ece8e80b5
104
inbox.py
104
inbox.py
|
@ -884,9 +884,7 @@ def _inbox_post_recipients(base_dir: str, post_json_object: {},
|
||||||
return recipients_dict, recipients_dict_followers
|
return recipients_dict, recipients_dict_followers
|
||||||
|
|
||||||
|
|
||||||
def _receive_undo_follow(session, base_dir: str, http_prefix: str,
|
def _receive_undo_follow(base_dir: str, message_json: {},
|
||||||
port: int, message_json: {},
|
|
||||||
federation_list: [],
|
|
||||||
debug: bool, domain: str,
|
debug: bool, domain: str,
|
||||||
onion_domain: str, i2p_domain: str) -> bool:
|
onion_domain: str, i2p_domain: str) -> bool:
|
||||||
if not message_json['object'].get('actor'):
|
if not message_json['object'].get('actor'):
|
||||||
|
@ -947,12 +945,8 @@ def _receive_undo_follow(session, base_dir: str, http_prefix: str,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _receive_undo(session, base_dir: str, http_prefix: str,
|
def _receive_undo(base_dir: str, message_json: {}, debug: bool,
|
||||||
port: int, send_threads: [], post_log: [],
|
domain: str, onion_domain: str, i2p_domain: str) -> bool:
|
||||||
cached_webfingers: {}, person_cache: {},
|
|
||||||
message_json: {}, federation_list: [],
|
|
||||||
debug: bool, domain: str,
|
|
||||||
onion_domain: str, i2p_domain: str) -> bool:
|
|
||||||
"""Receives an undo request within the POST section of HTTPServer
|
"""Receives an undo request within the POST section of HTTPServer
|
||||||
"""
|
"""
|
||||||
if not message_json['type'].startswith('Undo'):
|
if not message_json['type'].startswith('Undo'):
|
||||||
|
@ -971,10 +965,8 @@ def _receive_undo(session, base_dir: str, http_prefix: str,
|
||||||
return False
|
return False
|
||||||
if message_json['object']['type'] == 'Follow' or \
|
if message_json['object']['type'] == 'Follow' or \
|
||||||
message_json['object']['type'] == 'Join':
|
message_json['object']['type'] == 'Join':
|
||||||
return _receive_undo_follow(session, base_dir, http_prefix,
|
return _receive_undo_follow(base_dir, message_json,
|
||||||
port, message_json,
|
debug, domain, onion_domain, i2p_domain)
|
||||||
federation_list, debug,
|
|
||||||
domain, onion_domain, i2p_domain)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -1242,10 +1234,8 @@ def _receive_edit_to_post(recent_posts_cache: {}, message_json: {},
|
||||||
|
|
||||||
def _receive_update_activity(recent_posts_cache: {}, session, base_dir: str,
|
def _receive_update_activity(recent_posts_cache: {}, session, base_dir: str,
|
||||||
http_prefix: str, domain: str, port: int,
|
http_prefix: str, domain: str, port: int,
|
||||||
send_threads: [], post_log: [],
|
|
||||||
cached_webfingers: {},
|
cached_webfingers: {},
|
||||||
person_cache: {}, message_json: {},
|
person_cache: {}, message_json: {},
|
||||||
federation_list: [],
|
|
||||||
nickname: str, debug: bool,
|
nickname: str, debug: bool,
|
||||||
max_mentions: int, max_emoji: int,
|
max_mentions: int, max_emoji: int,
|
||||||
allow_local_network_access: bool,
|
allow_local_network_access: bool,
|
||||||
|
@ -1332,11 +1322,11 @@ def _receive_update_activity(recent_posts_cache: {}, session, base_dir: str,
|
||||||
|
|
||||||
|
|
||||||
def _receive_like(recent_posts_cache: {},
|
def _receive_like(recent_posts_cache: {},
|
||||||
session, handle: str, is_group: bool, base_dir: str,
|
session, handle: str, base_dir: str,
|
||||||
http_prefix: str, domain: str, port: int,
|
http_prefix: str, domain: str, port: int,
|
||||||
onion_domain: str, i2p_domain: str,
|
onion_domain: str, i2p_domain: str,
|
||||||
send_threads: [], post_log: [], cached_webfingers: {},
|
cached_webfingers: {},
|
||||||
person_cache: {}, message_json: {}, federation_list: [],
|
person_cache: {}, message_json: {},
|
||||||
debug: bool,
|
debug: bool,
|
||||||
signing_priv_key_pem: str,
|
signing_priv_key_pem: str,
|
||||||
max_recent_posts: int, translate: {},
|
max_recent_posts: int, translate: {},
|
||||||
|
@ -1394,7 +1384,7 @@ def _receive_like(recent_posts_cache: {},
|
||||||
handle_name, handle_dom,
|
handle_name, handle_dom,
|
||||||
post_liked_id,
|
post_liked_id,
|
||||||
like_actor):
|
like_actor):
|
||||||
_like_notify(base_dir, domain, onion_domain, handle,
|
_like_notify(base_dir, domain, onion_domain, i2p_domain, handle,
|
||||||
like_actor, post_liked_id)
|
like_actor, post_liked_id)
|
||||||
update_likes_collection(recent_posts_cache, base_dir, post_filename,
|
update_likes_collection(recent_posts_cache, base_dir, post_filename,
|
||||||
post_liked_id, like_actor,
|
post_liked_id, like_actor,
|
||||||
|
@ -1462,10 +1452,10 @@ def _receive_like(recent_posts_cache: {},
|
||||||
|
|
||||||
|
|
||||||
def _receive_undo_like(recent_posts_cache: {},
|
def _receive_undo_like(recent_posts_cache: {},
|
||||||
session, handle: str, is_group: bool, base_dir: str,
|
session, handle: str, base_dir: str,
|
||||||
http_prefix: str, domain: str, port: int,
|
http_prefix: str, domain: str, port: int,
|
||||||
send_threads: [], post_log: [], cached_webfingers: {},
|
cached_webfingers: {},
|
||||||
person_cache: {}, message_json: {}, federation_list: [],
|
person_cache: {}, message_json: {},
|
||||||
debug: bool,
|
debug: bool,
|
||||||
signing_priv_key_pem: str,
|
signing_priv_key_pem: str,
|
||||||
max_recent_posts: int, translate: {},
|
max_recent_posts: int, translate: {},
|
||||||
|
@ -1581,11 +1571,11 @@ def _receive_undo_like(recent_posts_cache: {},
|
||||||
|
|
||||||
|
|
||||||
def _receive_reaction(recent_posts_cache: {},
|
def _receive_reaction(recent_posts_cache: {},
|
||||||
session, handle: str, is_group: bool, base_dir: str,
|
session, handle: str, base_dir: str,
|
||||||
http_prefix: str, domain: str, port: int,
|
http_prefix: str, domain: str, port: int,
|
||||||
onion_domain: str,
|
onion_domain: str,
|
||||||
send_threads: [], post_log: [], cached_webfingers: {},
|
cached_webfingers: {},
|
||||||
person_cache: {}, message_json: {}, federation_list: [],
|
person_cache: {}, message_json: {},
|
||||||
debug: bool,
|
debug: bool,
|
||||||
signing_priv_key_pem: str,
|
signing_priv_key_pem: str,
|
||||||
max_recent_posts: int, translate: {},
|
max_recent_posts: int, translate: {},
|
||||||
|
@ -2850,7 +2840,8 @@ def _already_reacted(base_dir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _like_notify(base_dir: str, domain: str, onion_domain: str,
|
def _like_notify(base_dir: str, domain: str,
|
||||||
|
onion_domain: str, i2p_domain: str,
|
||||||
handle: str, actor: str, url: str) -> None:
|
handle: str, actor: str, url: str) -> None:
|
||||||
"""Creates a notification that a like has arrived
|
"""Creates a notification that a like has arrived
|
||||||
"""
|
"""
|
||||||
|
@ -2861,10 +2852,14 @@ def _like_notify(base_dir: str, domain: str, onion_domain: str,
|
||||||
# check that the liked post was by this handle
|
# check that the liked post was by this handle
|
||||||
nickname = handle.split('@')[0]
|
nickname = handle.split('@')[0]
|
||||||
if '/' + domain + '/users/' + nickname not in url:
|
if '/' + domain + '/users/' + nickname not in url:
|
||||||
if not onion_domain:
|
if onion_domain:
|
||||||
return
|
|
||||||
if '/' + onion_domain + '/users/' + nickname not in url:
|
if '/' + onion_domain + '/users/' + nickname not in url:
|
||||||
return
|
return
|
||||||
|
if i2p_domain:
|
||||||
|
if '/' + i2p_domain + '/users/' + nickname not in url:
|
||||||
|
return
|
||||||
|
if not i2p_domain and not onion_domain:
|
||||||
|
return
|
||||||
|
|
||||||
account_dir = base_dir + '/accounts/' + handle
|
account_dir = base_dir + '/accounts/' + handle
|
||||||
|
|
||||||
|
@ -3012,8 +3007,7 @@ def _reply_notify(base_dir: str, handle: str, url: str) -> None:
|
||||||
print('EX: unable to write ' + reply_file)
|
print('EX: unable to write ' + reply_file)
|
||||||
|
|
||||||
|
|
||||||
def _git_patch_notify(base_dir: str, handle: str,
|
def _git_patch_notify(base_dir: str, handle: str, subject: str,
|
||||||
subject: str, content: str,
|
|
||||||
from_nickname: str, from_domain: str) -> None:
|
from_nickname: str, from_domain: str) -> None:
|
||||||
"""Creates a notification that a new git patch has arrived
|
"""Creates a notification that a new git patch has arrived
|
||||||
"""
|
"""
|
||||||
|
@ -3051,7 +3045,6 @@ def _send_to_group_members(server, session, session_onion, session_i2p,
|
||||||
send_threads: [], post_log: [],
|
send_threads: [], post_log: [],
|
||||||
cached_webfingers: {},
|
cached_webfingers: {},
|
||||||
person_cache: {}, debug: bool,
|
person_cache: {}, debug: bool,
|
||||||
system_language: str,
|
|
||||||
curr_domain: str,
|
curr_domain: str,
|
||||||
onion_domain: str, i2p_domain: str,
|
onion_domain: str, i2p_domain: str,
|
||||||
signing_priv_key_pem: str) -> None:
|
signing_priv_key_pem: str) -> None:
|
||||||
|
@ -3238,7 +3231,7 @@ def _update_last_seen(base_dir: str, handle: str, actor: str) -> None:
|
||||||
print('EX: unable to write ' + last_seen_filename)
|
print('EX: unable to write ' + last_seen_filename)
|
||||||
|
|
||||||
|
|
||||||
def _bounce_dm(senderPostId: str, session, http_prefix: str,
|
def _bounce_dm(sender_post_id: str, session, http_prefix: str,
|
||||||
base_dir: str, nickname: str, domain: str, port: int,
|
base_dir: str, nickname: str, domain: str, port: int,
|
||||||
sending_handle: str, federation_list: [],
|
sending_handle: str, federation_list: [],
|
||||||
send_threads: [], post_log: [],
|
send_threads: [], post_log: [],
|
||||||
|
@ -3288,7 +3281,7 @@ def _bounce_dm(senderPostId: str, session, http_prefix: str,
|
||||||
media_type = None
|
media_type = None
|
||||||
image_description = ''
|
image_description = ''
|
||||||
city = 'London, England'
|
city = 'London, England'
|
||||||
in_reply_to = remove_id_ending(senderPostId)
|
in_reply_to = remove_id_ending(sender_post_id)
|
||||||
in_reply_to_atom_uri = None
|
in_reply_to_atom_uri = None
|
||||||
schedule_post = False
|
schedule_post = False
|
||||||
event_date = None
|
event_date = None
|
||||||
|
@ -3646,8 +3639,7 @@ def _check_for_git_patches(base_dir: str, nickname: str, domain: str,
|
||||||
json_obj['type'], json_obj['summary'],
|
json_obj['type'], json_obj['summary'],
|
||||||
json_obj['content'],
|
json_obj['content'],
|
||||||
from_nickname, from_domain_full):
|
from_nickname, from_domain_full):
|
||||||
_git_patch_notify(base_dir, handle,
|
_git_patch_notify(base_dir, handle, json_obj['summary'],
|
||||||
json_obj['summary'], json_obj['content'],
|
|
||||||
from_nickname, from_domain_full)
|
from_nickname, from_domain_full)
|
||||||
return 1
|
return 1
|
||||||
if '[PATCH]' in json_obj['content']:
|
if '[PATCH]' in json_obj['content']:
|
||||||
|
@ -3662,10 +3654,8 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||||
key_id: str, handle: str, message_json: {},
|
key_id: str, handle: str, message_json: {},
|
||||||
base_dir: str, http_prefix: str, send_threads: [],
|
base_dir: str, http_prefix: str, send_threads: [],
|
||||||
post_log: [], cached_webfingers: {}, person_cache: {},
|
post_log: [], cached_webfingers: {}, person_cache: {},
|
||||||
queue: [], domain: str,
|
domain: str, onion_domain: str, i2p_domain: str,
|
||||||
onion_domain: str, i2p_domain: str,
|
port: int, federation_list: [], debug: bool,
|
||||||
port: int, proxy_type: str,
|
|
||||||
federation_list: [], debug: bool,
|
|
||||||
queue_filename: str, destination_filename: str,
|
queue_filename: str, destination_filename: str,
|
||||||
max_replies: int, allow_deletion: bool,
|
max_replies: int, allow_deletion: bool,
|
||||||
max_mentions: int, max_emoji: int, translate: {},
|
max_mentions: int, max_emoji: int, translate: {},
|
||||||
|
@ -3715,15 +3705,13 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||||
handle_name = handle.split('@')[0]
|
handle_name = handle.split('@')[0]
|
||||||
|
|
||||||
if _receive_like(recent_posts_cache,
|
if _receive_like(recent_posts_cache,
|
||||||
session, handle, is_group,
|
session, handle,
|
||||||
base_dir, http_prefix,
|
base_dir, http_prefix,
|
||||||
domain, port,
|
domain, port,
|
||||||
onion_domain, i2p_domain,
|
onion_domain, i2p_domain,
|
||||||
send_threads, post_log,
|
|
||||||
cached_webfingers,
|
cached_webfingers,
|
||||||
person_cache,
|
person_cache,
|
||||||
message_json,
|
message_json,
|
||||||
federation_list,
|
|
||||||
debug, signing_priv_key_pem,
|
debug, signing_priv_key_pem,
|
||||||
max_recent_posts, translate,
|
max_recent_posts, translate,
|
||||||
allow_deletion,
|
allow_deletion,
|
||||||
|
@ -3743,14 +3731,12 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if _receive_undo_like(recent_posts_cache,
|
if _receive_undo_like(recent_posts_cache,
|
||||||
session, handle, is_group,
|
session, handle,
|
||||||
base_dir, http_prefix,
|
base_dir, http_prefix,
|
||||||
domain, port,
|
domain, port,
|
||||||
send_threads, post_log,
|
|
||||||
cached_webfingers,
|
cached_webfingers,
|
||||||
person_cache,
|
person_cache,
|
||||||
message_json,
|
message_json,
|
||||||
federation_list,
|
|
||||||
debug, signing_priv_key_pem,
|
debug, signing_priv_key_pem,
|
||||||
max_recent_posts, translate,
|
max_recent_posts, translate,
|
||||||
allow_deletion,
|
allow_deletion,
|
||||||
|
@ -3770,15 +3756,13 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if _receive_reaction(recent_posts_cache,
|
if _receive_reaction(recent_posts_cache,
|
||||||
session, handle, is_group,
|
session, handle,
|
||||||
base_dir, http_prefix,
|
base_dir, http_prefix,
|
||||||
domain, port,
|
domain, port,
|
||||||
onion_domain,
|
onion_domain,
|
||||||
send_threads, post_log,
|
|
||||||
cached_webfingers,
|
cached_webfingers,
|
||||||
person_cache,
|
person_cache,
|
||||||
message_json,
|
message_json,
|
||||||
federation_list,
|
|
||||||
debug, signing_priv_key_pem,
|
debug, signing_priv_key_pem,
|
||||||
max_recent_posts, translate,
|
max_recent_posts, translate,
|
||||||
allow_deletion,
|
allow_deletion,
|
||||||
|
@ -4346,8 +4330,7 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||||
http_prefix, federation_list,
|
http_prefix, federation_list,
|
||||||
send_threads,
|
send_threads,
|
||||||
post_log, cached_webfingers,
|
post_log, cached_webfingers,
|
||||||
person_cache,
|
person_cache, debug,
|
||||||
debug, system_language,
|
|
||||||
domain, onion_domain, i2p_domain,
|
domain, onion_domain, i2p_domain,
|
||||||
signing_priv_key_pem)
|
signing_priv_key_pem)
|
||||||
fitness_performance(inbox_start_time,
|
fitness_performance(inbox_start_time,
|
||||||
|
@ -4422,7 +4405,7 @@ def _restore_queue_items(base_dir: str, queue: []) -> None:
|
||||||
def run_inbox_queue_watchdog(project_version: str, httpd) -> None:
|
def run_inbox_queue_watchdog(project_version: str, httpd) -> None:
|
||||||
"""This tries to keep the inbox thread running even if it dies
|
"""This tries to keep the inbox thread running even if it dies
|
||||||
"""
|
"""
|
||||||
print('THREAD: Starting inbox queue watchdog')
|
print('THREAD: Starting inbox queue watchdog ' + project_version)
|
||||||
inbox_queue_original = httpd.thrInboxQueue.clone(run_inbox_queue)
|
inbox_queue_original = httpd.thrInboxQueue.clone(run_inbox_queue)
|
||||||
httpd.thrInboxQueue.start()
|
httpd.thrInboxQueue.start()
|
||||||
while True:
|
while True:
|
||||||
|
@ -5089,17 +5072,14 @@ def run_inbox_queue(server,
|
||||||
inbox_start_time = time.time()
|
inbox_start_time = time.time()
|
||||||
|
|
||||||
curr_session = session
|
curr_session = session
|
||||||
curr_proxy_type = proxy_type
|
|
||||||
if queue_json.get('actor'):
|
if queue_json.get('actor'):
|
||||||
if isinstance(queue_json['actor'], str):
|
if isinstance(queue_json['actor'], str):
|
||||||
sender_domain, _ = get_domain_from_actor(queue_json['actor'])
|
sender_domain, _ = get_domain_from_actor(queue_json['actor'])
|
||||||
if sender_domain.endswith('.onion') and \
|
if sender_domain.endswith('.onion') and \
|
||||||
session_onion and proxy_type != 'tor':
|
session_onion and proxy_type != 'tor':
|
||||||
curr_proxy_type = 'tor'
|
|
||||||
curr_session = session_onion
|
curr_session = session_onion
|
||||||
elif (sender_domain.endswith('.i2p') and
|
elif (sender_domain.endswith('.i2p') and
|
||||||
session_i2p and proxy_type != 'i2p'):
|
session_i2p and proxy_type != 'i2p'):
|
||||||
curr_proxy_type = 'i2p'
|
|
||||||
curr_session = session_i2p
|
curr_session = session_i2p
|
||||||
|
|
||||||
if debug and queue_json.get('actor'):
|
if debug and queue_json.get('actor'):
|
||||||
|
@ -5259,13 +5239,7 @@ def run_inbox_queue(server,
|
||||||
# if queue_json['post'].get('id'):
|
# if queue_json['post'].get('id'):
|
||||||
# queue_json['post']['id'] = queue_json['id']
|
# queue_json['post']['id'] = queue_json['id']
|
||||||
|
|
||||||
if _receive_undo(curr_session,
|
if _receive_undo(base_dir, queue_json['post'],
|
||||||
base_dir, http_prefix, port,
|
|
||||||
send_threads, post_log,
|
|
||||||
cached_webfingers,
|
|
||||||
person_cache,
|
|
||||||
queue_json['post'],
|
|
||||||
federation_list,
|
|
||||||
debug, domain, onion_domain, i2p_domain):
|
debug, domain, onion_domain, i2p_domain):
|
||||||
print('Queue: Undo accepted from ' + key_id)
|
print('Queue: Undo accepted from ' + key_id)
|
||||||
if os.path.isfile(queue_filename):
|
if os.path.isfile(queue_filename):
|
||||||
|
@ -5335,11 +5309,9 @@ def run_inbox_queue(server,
|
||||||
if _receive_update_activity(recent_posts_cache, curr_session,
|
if _receive_update_activity(recent_posts_cache, curr_session,
|
||||||
base_dir, http_prefix,
|
base_dir, http_prefix,
|
||||||
domain, port,
|
domain, port,
|
||||||
send_threads, post_log,
|
|
||||||
cached_webfingers,
|
cached_webfingers,
|
||||||
person_cache,
|
person_cache,
|
||||||
queue_json['post'],
|
queue_json['post'],
|
||||||
federation_list,
|
|
||||||
queue_json['postNickname'],
|
queue_json['postNickname'],
|
||||||
debug,
|
debug,
|
||||||
max_mentions, max_emoji,
|
max_mentions, max_emoji,
|
||||||
|
@ -5460,11 +5432,9 @@ def run_inbox_queue(server,
|
||||||
base_dir, http_prefix,
|
base_dir, http_prefix,
|
||||||
send_threads, post_log,
|
send_threads, post_log,
|
||||||
cached_webfingers,
|
cached_webfingers,
|
||||||
person_cache, queue,
|
person_cache, domain,
|
||||||
domain,
|
|
||||||
onion_domain, i2p_domain,
|
onion_domain, i2p_domain,
|
||||||
port, curr_proxy_type,
|
port, federation_list,
|
||||||
federation_list,
|
|
||||||
debug,
|
debug,
|
||||||
queue_filename, destination,
|
queue_filename, destination,
|
||||||
max_replies, allow_deletion,
|
max_replies, allow_deletion,
|
||||||
|
|
2
tests.py
2
tests.py
|
@ -3208,7 +3208,7 @@ def test_client_to_server(base_dir: str):
|
||||||
http_prefix,
|
http_prefix,
|
||||||
cached_webfingers, person_cache,
|
cached_webfingers, person_cache,
|
||||||
True, __version__, signing_priv_key_pem)
|
True, __version__, signing_priv_key_pem)
|
||||||
for _ in range(10):
|
for _ in range(20):
|
||||||
if os.path.isfile(alice_dir + '/accounts/alice@' + alice_domain +
|
if os.path.isfile(alice_dir + '/accounts/alice@' + alice_domain +
|
||||||
'/followers.txt'):
|
'/followers.txt'):
|
||||||
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
||||||
|
|
Loading…
Reference in New Issue