Post expiry period on edit profile screen

main
Bob Mottram 2022-08-10 17:13:52 +01:00
parent e128a89e9c
commit df25614b24
3 changed files with 49 additions and 0 deletions

View File

@ -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'):

View File

@ -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

View File

@ -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 += ' </div>\n'
return edit_profile_form