From 6a459089148dc04c77891c3f51800c00007a9b1f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 17 Oct 2023 10:27:58 +0100 Subject: [PATCH] Tidying --- posts.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/posts.py b/posts.py index b877335c8..f7aeff3dc 100644 --- a/posts.py +++ b/posts.py @@ -2741,6 +2741,23 @@ def thread_send_post(session, post_json_str: str, federation_list: [], tries += 1 +def _get_inbox_domain(inbox_url: str, to_domain: str) -> str: + """ the inbox domain being sent to isn't always the same + as the destination instance domain. eg public-api.wordpress.com + rather than the wordpress instance domain + """ + inbox_url_domain, inbox_url_port = get_domain_from_actor(inbox_url) + if not inbox_url_domain: + return inbox_url + inbox_domain = get_full_domain(inbox_url_domain, inbox_url_port) + if inbox_domain != to_domain: + print('_get_inbox_domain ' + + 'inbox domain is not the same as instance domain ' + + inbox_domain + ' != ' + to_domain) + return inbox_domain + return to_domain + + def send_post(signing_priv_key_pem: str, project_version: str, session, base_dir: str, nickname: str, domain: str, port: int, to_nickname: str, to_domain: str, to_port: int, cc_str: str, @@ -2837,14 +2854,7 @@ def send_post(signing_priv_key_pem: str, project_version: str, # NOTE: the inbox domain being sent to isn't always the same # as the destination instance domain. eg public-api.wordpress.com # rather than the wordpress instance domain - inbox_url_domain, inbox_url_port = get_domain_from_actor(inbox_url) - if inbox_url_domain: - inbox_domain = get_full_domain(inbox_url_domain, inbox_url_port) - if inbox_domain != to_domain: - print('send_post ' + - 'inbox domain is not the same as instance domain ' + - inbox_domain + ' != ' + to_domain) - to_domain = inbox_domain + to_domain = _get_inbox_domain(inbox_url, to_domain) if to_domain not in inbox_url: return 7 @@ -3272,14 +3282,7 @@ def send_signed_json(post_json_object: {}, session, base_dir: str, # NOTE: the inbox domain being sent to isn't always the same # as the destination instance domain. eg public-api.wordpress.com # rather than the wordpress instance domain - inbox_url_domain, inbox_url_port = get_domain_from_actor(inbox_url) - if inbox_url_domain: - inbox_domain = get_full_domain(inbox_url_domain, inbox_url_port) - if inbox_domain != to_domain: - print('send_signed_json ' + - 'inbox domain is not the same as instance domain ' + - inbox_domain + ' != ' + to_domain) - to_domain = inbox_domain + to_domain = _get_inbox_domain(inbox_url, to_domain) if to_domain not in inbox_url: if debug: