From aa6e483bd8b9a3a5279751868d2ee61672789baa Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 12 Oct 2024 13:31:49 +0100 Subject: [PATCH] Set default searchable_by --- daemon_post_receive.py | 17 +++++++++++++++-- utils.py | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/daemon_post_receive.py b/daemon_post_receive.py index efb35d47b..170618eab 100644 --- a/daemon_post_receive.py +++ b/daemon_post_receive.py @@ -30,6 +30,7 @@ from media import attach_media from city import get_spoofed_city from flags import is_image_file from flags import is_float +from utils import set_searchable_by from utils import get_instance_url from utils import save_json from utils import remove_post_from_cache @@ -151,6 +152,9 @@ def _receive_new_post_process_newpost(self, fields: {}, video_transcript = '' if fields.get('videoTranscript'): video_transcript = fields['videoTranscript'] + if fields.get('searchableByDropdown'): + set_searchable_by(base_dir, nickname, domain, + fields['searchableByDropdown']) message_json = \ create_public_post(base_dir, nickname, domain, port, @@ -310,6 +314,9 @@ def _receive_new_post_process_newblog(self, fields: {}, video_transcript = '' if fields.get('videoTranscript'): video_transcript = fields['videoTranscript'] + if fields.get('searchableByDropdown'): + set_searchable_by(base_dir, nickname, domain, + fields['searchableByDropdown']) message_json = \ create_blog_post(base_dir, nickname, domain, port, http_prefix, @@ -702,6 +709,9 @@ def _receive_new_post_process_newfollowers(self, fields: {}, video_transcript = '' if fields.get('videoTranscript'): video_transcript = fields['videoTranscript'] + if fields.get('searchableByDropdown'): + set_searchable_by(base_dir, nickname, domain, + fields['searchableByDropdown']) message_json = \ create_followers_only_post(base_dir, nickname, domain, port, http_prefix, @@ -1345,6 +1355,9 @@ def _receive_new_post_process_newreading(self, fields: {}, city = get_spoofed_city(city, base_dir, nickname, domain) msg_str = fields['readingupdatetype'] + if fields.get('searchableByDropdown'): + set_searchable_by(base_dir, nickname, domain, + fields['searchableByDropdown']) # reading status message_json = \ create_reading_post(base_dir, nickname, domain, @@ -1798,8 +1811,8 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, fields['languagesDropdown']) self.server.default_post_language[nickname] = \ fields['languagesDropdown'] - if not fields.get('searchableByDropdown'): - fields['searchableByDropdown'] = 'yourself' + if 'searchableByDropdown' not in fields: + fields['searchableByDropdown'] = [] if not citations_button_press: # Store a file which contains the time in seconds diff --git a/utils.py b/utils.py index db00a3315..24df3d670 100644 --- a/utils.py +++ b/utils.py @@ -5153,3 +5153,25 @@ def load_searchable_by_default(base_dir: str) -> {}: print('EX: unable to load searchableByDefault ' + filename) break return result + + +def set_searchable_by(base_dir: str, nickname: str, domain: str, + searchable_by: str) -> None: + """Sets the searchable_by state for an account from the dropdown on + new post screen + """ + if not searchable_by: + return + filename = acct_dir(base_dir, nickname, domain) + '/.searchableByDefault' + + # already the same state? + if os.path.isfile(filename): + if text_in_file(searchable_by, filename, True): + return + + # write the new state + try: + with open(filename, 'w+', encoding='utf-8') as fp_search: + fp_search.write(searchable_by) + except OSError: + print('EX: unable to write searchableByDropdown ' + filename)