From 2653902825407d5ce8da0ccf0dcc3e4cb286ef62 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 17 Nov 2022 19:08:21 +0000 Subject: [PATCH] Receiving edited posts --- daemon.py | 198 +++++++++++++++++++++++++++++++++++++++++++++++++++--- inbox.py | 74 ++++++++++---------- 2 files changed, 227 insertions(+), 45 deletions(-) diff --git a/daemon.py b/daemon.py index 61548d1bc..772e8c061 100644 --- a/daemon.py +++ b/daemon.py @@ -114,6 +114,7 @@ from inbox import run_inbox_queue from inbox import run_inbox_queue_watchdog from inbox import save_post_to_inbox_queue from inbox import populate_replies +from inbox import receive_edit_to_post from follow import follower_approval_active from follow import is_following_actor from follow import get_following_feed @@ -445,7 +446,23 @@ class PubServer(BaseHTTPRequestHandler): edited_published: str, edited_postid: str, recent_posts_cache: {}, - box_name: str) -> None: + box_name: str, + max_mentions: int, max_emoji: int, + allow_local_network_access: bool, + debug: bool, + system_language: str, http_prefix: str, + domain_full: str, person_cache: {}, + signing_priv_key_pem: str, + max_recent_posts: int, translate: {}, + session, cached_webfingers: {}, port: int, + allow_deletion: bool, + yt_replace_domain: str, + twitter_replacement_domain: str, + show_published_date_only: bool, + peertube_instances: [], + theme_name: str, max_like_count: int, + cw_lists: {}, dogwhistles: {}, + min_images_for_accounts: []) -> None: """When an edited post is created this assigns a published and updated date to it, and uses the previous id @@ -469,9 +486,30 @@ class PubServer(BaseHTTPRequestHandler): edited_updated message_json['type'] = 'Update' - # update memory cache - if recent_posts_cache['html'].get(edited_postid): - del recent_posts_cache['html'][edited_postid] + message_json2 = message_json.copy() + receive_edit_to_post(recent_posts_cache, + message_json2, + base_dir, + nickname, domain, + max_mentions, max_emoji, + allow_local_network_access, + debug, + system_language, http_prefix, + domain_full, person_cache, + signing_priv_key_pem, + max_recent_posts, + translate, + session, + cached_webfingers, + port, + allow_deletion, + yt_replace_domain, + twitter_replacement_domain, + show_published_date_only, + peertube_instances, + theme_name, max_like_count, + cw_lists, dogwhistles, + min_images_for_accounts) # update the index id_str = edited_postid.split('/')[-1] @@ -19499,13 +19537,49 @@ class PubServer(BaseHTTPRequestHandler): if message_json: if edited_postid: recent_posts_cache = self.server.recent_posts_cache + allow_local_network_access = \ + self.server.allow_local_network_access + signing_priv_key_pem = \ + self.server.signing_priv_key_pem + twitter_replacement_domain = \ + self.server.twitter_replacement_domain + show_published_date_only = \ + self.server.show_published_date_only + min_images_for_accounts = \ + self.server.min_images_for_accounts + peertube_instances = \ + self.server.peertube_instances self._update_edited_post(self.server.base_dir, nickname, self.server.domain, message_json, edited_published, edited_postid, recent_posts_cache, - 'outbox') + 'outbox', + self.server.max_mentions, + self.server.max_emoji, + allow_local_network_access, + self.server.debug, + self.server.system_language, + self.server.http_prefix, + self.server.domain_full, + self.server.person_cache, + signing_priv_key_pem, + self.server.max_recent_posts, + self.server.translate, + curr_session, + self.server.cached_webfingers, + self.server.port, + self.server.allow_deletion, + self.server.yt_replace_domain, + twitter_replacement_domain, + show_published_date_only, + peertube_instances, + self.server.theme_name, + self.server.max_like_count, + self.server.cw_lists, + self.server.dogwhistles, + min_images_for_accounts) print('DEBUG: sending edited public post ' + str(message_json)) if fields['schedulePost']: @@ -19766,13 +19840,49 @@ class PubServer(BaseHTTPRequestHandler): if message_json: if edited_postid: recent_posts_cache = self.server.recent_posts_cache + allow_local_network_access = \ + self.server.allow_local_network_access + signing_priv_key_pem = \ + self.server.signing_priv_key_pem + twitter_replacement_domain = \ + self.server.twitter_replacement_domain + show_published_date_only = \ + self.server.show_published_date_only + min_images_for_accounts = \ + self.server.min_images_for_accounts + peertube_instances = \ + self.server.peertube_instances self._update_edited_post(self.server.base_dir, nickname, self.server.domain, message_json, edited_published, edited_postid, recent_posts_cache, - 'outbox') + 'outbox', + self.server.max_mentions, + self.server.max_emoji, + allow_local_network_access, + self.server.debug, + self.server.system_language, + self.server.http_prefix, + self.server.domain_full, + self.server.person_cache, + signing_priv_key_pem, + self.server.max_recent_posts, + self.server.translate, + curr_session, + self.server.cached_webfingers, + self.server.port, + self.server.allow_deletion, + self.server.yt_replace_domain, + twitter_replacement_domain, + show_published_date_only, + peertube_instances, + self.server.theme_name, + self.server.max_like_count, + self.server.cw_lists, + self.server.dogwhistles, + min_images_for_accounts) print('DEBUG: sending edited unlisted post ' + str(message_json)) @@ -19839,13 +19949,49 @@ class PubServer(BaseHTTPRequestHandler): if message_json: if edited_postid: recent_posts_cache = self.server.recent_posts_cache + allow_local_network_access = \ + self.server.allow_local_network_access + signing_priv_key_pem = \ + self.server.signing_priv_key_pem + twitter_replacement_domain = \ + self.server.twitter_replacement_domain + show_published_date_only = \ + self.server.show_published_date_only + min_images_for_accounts = \ + self.server.min_images_for_accounts + peertube_instances = \ + self.server.peertube_instances self._update_edited_post(self.server.base_dir, nickname, self.server.domain, message_json, edited_published, edited_postid, recent_posts_cache, - 'outbox') + 'outbox', + self.server.max_mentions, + self.server.max_emoji, + allow_local_network_access, + self.server.debug, + self.server.system_language, + self.server.http_prefix, + self.server.domain_full, + self.server.person_cache, + signing_priv_key_pem, + self.server.max_recent_posts, + self.server.translate, + curr_session, + self.server.cached_webfingers, + self.server.port, + self.server.allow_deletion, + self.server.yt_replace_domain, + twitter_replacement_domain, + show_published_date_only, + peertube_instances, + self.server.theme_name, + self.server.max_like_count, + self.server.cw_lists, + self.server.dogwhistles, + min_images_for_accounts) print('DEBUG: sending edited followers post ' + str(message_json)) @@ -19926,13 +20072,49 @@ class PubServer(BaseHTTPRequestHandler): str(edited_postid)) if edited_postid: recent_posts_cache = self.server.recent_posts_cache + allow_local_network_access = \ + self.server.allow_local_network_access + signing_priv_key_pem = \ + self.server.signing_priv_key_pem + twitter_replacement_domain = \ + self.server.twitter_replacement_domain + show_published_date_only = \ + self.server.show_published_date_only + min_images_for_accounts = \ + self.server.min_images_for_accounts + peertube_instances = \ + self.server.peertube_instances self._update_edited_post(self.server.base_dir, nickname, self.server.domain, message_json, edited_published, edited_postid, recent_posts_cache, - 'outbox') + 'outbox', + self.server.max_mentions, + self.server.max_emoji, + allow_local_network_access, + self.server.debug, + self.server.system_language, + self.server.http_prefix, + self.server.domain_full, + self.server.person_cache, + signing_priv_key_pem, + self.server.max_recent_posts, + self.server.translate, + curr_session, + self.server.cached_webfingers, + self.server.port, + self.server.allow_deletion, + self.server.yt_replace_domain, + twitter_replacement_domain, + show_published_date_only, + peertube_instances, + self.server.theme_name, + self.server.max_like_count, + self.server.cw_lists, + self.server.dogwhistles, + min_images_for_accounts) print('DEBUG: sending edited dm post ' + str(message_json)) diff --git a/inbox.py b/inbox.py index 0862f269e..813b1b709 100644 --- a/inbox.py +++ b/inbox.py @@ -1137,25 +1137,25 @@ def _receive_update_to_question(recent_posts_cache: {}, message_json: {}, remove_post_from_cache(message_json, recent_posts_cache) -def _receive_edit_to_post(recent_posts_cache: {}, message_json: {}, - base_dir: str, - nickname: str, domain: str, - max_mentions: int, max_emoji: int, - allow_local_network_access: bool, - debug: bool, - system_language: str, http_prefix: str, - domain_full: str, person_cache: {}, - signing_priv_key_pem: str, - max_recent_posts: int, translate: {}, - session, cached_webfingers: {}, port: int, - allow_deletion: bool, - yt_replace_domain: str, - twitter_replacement_domain: str, - show_published_date_only: bool, - peertube_instances: [], - theme_name: str, max_like_count: int, - cw_lists: {}, dogwhistles: {}, - min_images_for_accounts: []) -> bool: +def receive_edit_to_post(recent_posts_cache: {}, message_json: {}, + base_dir: str, + nickname: str, domain: str, + max_mentions: int, max_emoji: int, + allow_local_network_access: bool, + debug: bool, + system_language: str, http_prefix: str, + domain_full: str, person_cache: {}, + signing_priv_key_pem: str, + max_recent_posts: int, translate: {}, + session, cached_webfingers: {}, port: int, + allow_deletion: bool, + yt_replace_domain: str, + twitter_replacement_domain: str, + show_published_date_only: bool, + peertube_instances: [], + theme_name: str, max_like_count: int, + cw_lists: {}, dogwhistles: {}, + min_images_for_accounts: []) -> bool: """A post was edited """ if not has_object_dict(message_json): @@ -1205,7 +1205,7 @@ def _receive_edit_to_post(recent_posts_cache: {}, message_json: {}, # has the content changed? if post_json_object['object']['content'] == \ message_json['object']['content']: - # same content + # same content. Has the summary changed? if 'summary' in post_json_object['object'] and \ 'summary' in message_json['object']: if post_json_object['object']['summary'] == \ @@ -1329,23 +1329,23 @@ def _receive_update_activity(recent_posts_cache: {}, session, base_dir: str, elif message_json['object']['type'] == 'Note': if message_json['object'].get('id'): domain_full = get_full_domain(domain, port) - if _receive_edit_to_post(recent_posts_cache, message_json, - base_dir, nickname, domain, - max_mentions, max_emoji, - allow_local_network_access, - debug, system_language, http_prefix, - domain_full, person_cache, - signing_priv_key_pem, - max_recent_posts, translate, - session, cached_webfingers, port, - allow_deletion, - yt_replace_domain, - twitter_replacement_domain, - show_published_date_only, - peertube_instances, - theme_name, max_like_count, - cw_lists, dogwhistles, - min_images_for_accounts): + if receive_edit_to_post(recent_posts_cache, message_json, + base_dir, nickname, domain, + max_mentions, max_emoji, + allow_local_network_access, + debug, system_language, http_prefix, + domain_full, person_cache, + signing_priv_key_pem, + max_recent_posts, translate, + session, cached_webfingers, port, + allow_deletion, + yt_replace_domain, + twitter_replacement_domain, + show_published_date_only, + peertube_instances, + theme_name, max_like_count, + cw_lists, dogwhistles, + min_images_for_accounts): print('EDITPOST: received ' + message_json['object']['id']) return True else: