Option to not show boosts/announces of replies

merge-requests/30/head
Bob Mottram 2024-03-27 14:23:30 +00:00
parent c4c167c0ed
commit 987181fa47
3 changed files with 69 additions and 3 deletions

View File

@ -805,6 +805,35 @@ def _profile_post_block_military(nickname: str, fields: {}, self) -> None:
self.server.block_military)
def _profile_post_no_reply_boosts(base_dir: str, nickname: str, domain: str,
fields: {}) -> bool:
""" HTTP POST disallow boosts of replies in inbox
"""
no_reply_boosts_filename = \
acct_dir(base_dir, nickname, domain) + '/.noReplyBoosts'
no_reply_boosts = False
if fields.get('noReplyBoosts'):
if fields['noReplyBoosts'] == 'on':
no_reply_boosts = True
if no_reply_boosts:
if not os.path.isfile(no_reply_boosts_filename):
try:
with open(no_reply_boosts_filename, 'w+',
encoding='utf-8') as rfile:
rfile.write('\n')
except OSError:
print('EX: unable to write noReplyBoosts ' +
no_reply_boosts_filename)
if not no_reply_boosts:
if os.path.isfile(no_reply_boosts_filename):
try:
os.remove(no_reply_boosts_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
no_reply_boosts_filename)
def _profile_post_hide_follows(base_dir: str, nickname: str, domain: str,
actor_json: {}, fields: {}, self,
actor_changed: bool,
@ -2923,6 +2952,8 @@ def profile_edit(self, calling_domain: str, cookie: str,
actor_json, fields, self,
actor_changed, premium)
_profile_post_block_military(nickname, fields, self)
_profile_post_no_reply_boosts(base_dir, nickname, domain,
fields)
notify_likes_filename = \
acct_dir(base_dir, nickname, domain) + '/.notifyLikes'

View File

@ -1585,6 +1585,7 @@ def _valid_post_content(base_dir: str, nickname: str, domain: str,
reply_id = get_reply_to(message_json['object'])
if reply_id:
if isinstance(reply_id, str):
# this is a reply
original_post_id = reply_id
post_post_filename = locate_post(base_dir, nickname, domain,
original_post_id)
@ -3372,8 +3373,23 @@ def _receive_announce(recent_posts_cache: {},
bold_reading,
show_vote_posts,
languages_understood)
# are annouced/boosted replies allowed?
announce_denied = False
if post_json_object:
if has_object_dict(post_json_object):
if post_json_object['object'].get('inReplyTo'):
account_dir = acct_dir(base_dir, nickname, domain)
no_reply_boosts_filename = account_dir + '/.noReplyBoosts'
if os.path.isfile(no_reply_boosts_filename):
post_json_object = None
announce_denied = True
if not post_json_object:
print('WARN: unable to download announce: ' + str(message_json))
if not announce_denied:
print('WARN: unable to download announce: ' + str(message_json))
else:
print('REJECT: Announce/Boost of reply denied ' +
message_json['object'])
not_in_onion = True
if onion_domain:
if onion_domain in message_json['object']:
@ -3391,6 +3407,7 @@ def _receive_announce(recent_posts_cache: {},
actor_url = get_actor_from_post(message_json)
print('DEBUG: Announce post downloaded for ' +
actor_url + ' -> ' + message_json['object'])
store_hash_tags(base_dir, nickname, domain,
http_prefix, domain_full,
post_json_object, translate)

View File

@ -2724,7 +2724,8 @@ def _html_edit_profile_options(is_admin: bool,
show_replies_followers: bool,
show_replies_mutuals: bool,
hide_follows: bool,
premium: bool) -> str:
premium: bool,
no_reply_boosts: bool) -> str:
"""option checkboxes section of edit profile screen
"""
edit_profile_form = ' <div class="container">\n'
@ -2764,9 +2765,11 @@ def _html_edit_profile_options(is_admin: bool,
edit_profile_form += \
edit_check_box(translate["Don't show the Reaction button"],
'hideReactionButton', hide_reaction_button)
bold_str = bold_reading_string(translate['Bold reading'])
edit_profile_form += \
edit_check_box(bold_str, 'boldReading', bold_reading)
minimize_all_images = False
if nickname in min_images_for_accounts:
minimize_all_images = True
@ -2774,31 +2777,40 @@ def _html_edit_profile_options(is_admin: bool,
edit_profile_form += \
edit_check_box(minimize_all_images_str, 'minimizeAllImages',
minimize_all_images)
reverse = False
if nickname in reverse_sequence:
reverse = True
reverse_str = translate['Reverse timelines']
edit_profile_form += \
edit_check_box(reverse_str, 'reverseTimelines', reverse)
show_vote_posts_str = translate['Show vote posts']
edit_profile_form += \
edit_check_box(show_vote_posts_str, 'showVotes', show_vote_posts)
show_replies_followers_str = translate['Only allow replies from followers']
if premium:
show_replies_followers_str = translate['Only allow replies from fans']
edit_profile_form += \
edit_check_box(show_replies_followers_str, 'repliesFromFollowersOnly',
show_replies_followers)
show_replies_mutuals_str = translate['Only allow replies from mutuals']
edit_profile_form += \
edit_check_box(show_replies_mutuals_str, 'repliesFromMutualsOnly',
show_replies_mutuals)
hide_follows_str = translate['Do not show follows on your profile']
if premium:
hide_follows_str = translate['Do not show fans on your profile']
edit_profile_form += \
edit_check_box(hide_follows_str, 'hideFollows', hide_follows)
no_reply_boosts_str = translate["Don't show boosted replies"]
edit_profile_form += \
edit_check_box(no_reply_boosts_str, 'noReplyBoosts', no_reply_boosts)
edit_profile_form += ' </div>\n'
return edit_profile_form
@ -3209,6 +3221,12 @@ def html_edit_profile(server, translate: {},
# is this a premium account?
premium = is_premium_account(base_dir, nickname, domain)
# are boosts of replies permitted in the inbox?
no_reply_boosts_filename = account_dir + '/.noReplyBoosts'
no_reply_boosts = False
if os.path.isfile(no_reply_boosts_filename):
no_reply_boosts = True
# Option checkboxes
edit_profile_form += \
_html_edit_profile_options(is_admin, manually_approves_followers,
@ -3222,7 +3240,7 @@ def html_edit_profile(server, translate: {},
reverse_sequence, show_vote_posts,
show_replies_followers,
show_replies_mutuals, hide_follows,
premium)
premium, no_reply_boosts)
# Contact information
edit_profile_form += \