diff --git a/daemon.py b/daemon.py index 820eaca92..b6380d60d 100644 --- a/daemon.py +++ b/daemon.py @@ -80,6 +80,8 @@ from person import remove_account from person import can_remove_post from person import person_snooze from person import person_unsnooze +from posts import get_post_expiry_days +from posts import set_post_expiry_days from posts import get_original_post_from_announce_url from posts import save_post_to_box from posts import get_instance_actor_key @@ -6135,6 +6137,22 @@ class PubServer(BaseHTTPRequestHandler): del self.server.account_timezone[nickname] actor_changed = True + # set post expiry period in days + post_expiry_period_days = \ + get_post_expiry_days(base_dir, nickname, domain) + if fields.get('postExpiryPeriod'): + if fields['postExpiryPeriod'] != \ + str(post_expiry_period_days): + post_expiry_period_days = \ + fields['postExpiryPeriod'] + set_post_expiry_days(base_dir, nickname, domain, + post_expiry_period_days) + actor_changed = True + else: + if post_expiry_period_days > 0: + set_post_expiry_days(base_dir, nickname, domain, 0) + actor_changed = True + # change tox address current_tox_address = get_tox_address(actor_json) if fields.get('toxAddress'): diff --git a/posts.py b/posts.py index 3ac7c1030..6ad30d244 100644 --- a/posts.py +++ b/posts.py @@ -4318,6 +4318,28 @@ def expire_posts(base_dir: str, http_prefix: str, return expired_post_count +def get_post_expiry_days(base_dir: str, nickname: str, domain: str) -> int: + """ + """ + handle = nickname + '@' + domain + expire_posts_filename = \ + base_dir + '/accounts/' + handle + '/.expire_posts_days' + if not os.path.isfile(expire_posts_filename): + return 0 + days_str = None + try: + with open(expire_posts_filename, 'r', encoding='utf-8') as fp_expire: + days_str = fp_expire.read() + except OSError: + print('EX: unable to write post expire days ' + + expire_posts_filename) + if not days_str: + return 0 + if not days_str.isdigit(): + return 0 + return int(days_str) + + def set_post_expiry_days(base_dir: str, nickname: str, domain: str, max_age_days: int) -> None: """Sets the number of days after which posts from an account will expire diff --git a/webapp_profile.py b/webapp_profile.py index 585a2741b..17ad8eaca 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -38,6 +38,7 @@ from theme import get_themes_list from person import person_box_json from person import get_actor_json from person import get_person_avatar_url +from posts import get_post_expiry_days from posts import get_person_box from posts import is_moderator from posts import parse_user_feed @@ -58,6 +59,7 @@ from filters import is_filtered from follow import is_follower_of_person from follow import get_follower_domains from webapp_frontscreen import html_front_screen +from webapp_utils import edit_number_field from webapp_utils import html_keyboard_navigation from webapp_utils import html_hide_from_screen_reader from webapp_utils import scheduled_posts_exist @@ -2183,6 +2185,13 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, bio_str: str, edit_text_field(translate['Time Zone'], 'timeZone', timezone, 'Europe/London') + post_expiry_period_days = \ + get_post_expiry_days(base_dir, nickname, domain) + edit_profile_form += \ + edit_number_field(translate['Post expiry period in days'], + 'postExpiryPeriod', post_expiry_period_days, + 0, 9999999999999999999999, 0) + edit_profile_form += ' \n' return edit_profile_form