When quote toots are enabled individual senders can have them blocked

main
Bob Mottram 2024-04-20 14:27:06 +01:00
parent f2550d0c67
commit d0b42d374b
4 changed files with 124 additions and 6 deletions

View File

@ -958,7 +958,7 @@ def allowed_announce_add(base_dir: str, nickname: str, domain: str,
encoding='utf-8') as fp_noannounce:
file_text = fp_noannounce.read()
except OSError:
print('EX: unable to read noannounce: ' +
print('EX: unable to read noannounce add: ' +
blocking_filename + ' ' + handle)
new_file_text = ''
@ -974,7 +974,7 @@ def allowed_announce_add(base_dir: str, nickname: str, domain: str,
encoding='utf-8') as fp_noannounce:
fp_noannounce.write(file_text)
except OSError:
print('EX: unable to write noannounce: ' +
print('EX: unable to write noannounce add: ' +
blocking_filename + ' ' + handle)
@ -995,7 +995,7 @@ def allowed_announce_remove(base_dir: str, nickname: str, domain: str,
encoding='utf-8') as fp_noannounce:
fp_noannounce.write(file_text)
except OSError:
print('EX: unable to write initial noannounce: ' +
print('EX: unable to write initial noannounce remove: ' +
blocking_filename + ' ' + handle)
return
@ -1006,7 +1006,7 @@ def allowed_announce_remove(base_dir: str, nickname: str, domain: str,
encoding='utf-8') as fp_noannounce:
file_text = fp_noannounce.read()
except OSError:
print('EX: unable to read noannounce: ' +
print('EX: unable to read noannounce remove: ' +
blocking_filename + ' ' + handle)
file_text += handle + '\n'
try:
@ -1018,6 +1018,71 @@ def allowed_announce_remove(base_dir: str, nickname: str, domain: str,
blocking_filename + ' ' + handle)
def blocked_quote_toots_add(base_dir: str, nickname: str, domain: str,
following_nickname: str,
following_domain: str) -> None:
"""Block quote toots for a handle
"""
account_dir = acct_dir(base_dir, nickname, domain)
blocking_filename = account_dir + '/quotesblocked.txt'
# if the quotesblocked.txt file doesn't yet exist
if os.path.isfile(blocking_filename):
return
handle = following_nickname + '@' + following_domain
if not text_in_file(handle + '\n', blocking_filename, False):
file_text = ''
try:
with open(blocking_filename, 'r',
encoding='utf-8') as fp_quotes:
file_text = fp_quotes.read()
except OSError:
print('EX: unable to read quotesblocked add: ' +
blocking_filename + ' ' + handle)
file_text += handle + '\n'
try:
with open(blocking_filename, 'w+',
encoding='utf-8') as fp_quotes:
fp_quotes.write(file_text)
except OSError:
print('EX: unable to write quotesblocked add: ' +
blocking_filename + ' ' + handle)
def blocked_quote_toots_remove(base_dir: str, nickname: str, domain: str,
following_nickname: str,
following_domain: str) -> None:
"""allow quote toots from a handle
"""
account_dir = acct_dir(base_dir, nickname, domain)
blocking_filename = account_dir + '/quotesblocked.txt'
handle = following_nickname + '@' + following_domain
# if the quotesblocked.txt file doesn't yet exist
if not os.path.isfile(blocking_filename):
return
file_text = ''
if text_in_file(handle + '\n', blocking_filename, False):
try:
with open(blocking_filename, 'r',
encoding='utf-8') as fp_quotes:
file_text = fp_quotes.read()
except OSError:
print('EX: unable to read quotesblocked remove: ' +
blocking_filename + ' ' + handle)
file_text = file_text.replace(handle + '\n', '')
try:
with open(blocking_filename, 'w+',
encoding='utf-8') as fp_quotes:
fp_quotes.write(file_text)
except OSError:
print('EX: unable to write quotesblocked remove: ' +
blocking_filename + ' ' + handle)
def outbox_block(base_dir: str, nickname: str, domain: str,
message_json: {}, debug: bool) -> bool:
""" When a block request is received by the outbox from c2s

View File

@ -42,6 +42,8 @@ from webapp_moderation import html_account_info
from languages import get_understood_languages
from blocking import allowed_announce_add
from blocking import allowed_announce_remove
from blocking import blocked_quote_toots_add
from blocking import blocked_quote_toots_remove
from notifyOnPost import add_notify_on_post
from notifyOnPost import remove_notify_on_post
from posts import is_moderator
@ -430,6 +432,35 @@ def person_options2(self, path: str,
self.server.postreq_busy = False
return
# person options screen, allow quote toots checkbox
# See html_person_options
if '&submitAllowQuotes=' in options_confirm_params:
allow_quote_toots = None
if 'allowQuotes=' in options_confirm_params:
allow_quote_toots = \
options_confirm_params.split('allowQuotes=')[1]
if '&' in allow_quote_toots:
allow_quote_toots = allow_quote_toots.split('&')[0]
if allow_quote_toots != 'on':
blocked_quote_toots_add(base_dir,
chooser_nickname,
domain,
options_nickname,
options_domain_full)
else:
blocked_quote_toots_remove(base_dir,
chooser_nickname,
domain,
options_nickname,
options_domain_full)
users_path_str = \
users_path + '/' + default_timeline + \
'?page=' + str(page_number)
redirect_headers(self, users_path_str, cookie,
calling_domain, 303)
self.server.postreq_busy = False
return
# person options screen, on notify checkbox
# See html_person_options
if '&submitNotifyOnPost=' in options_confirm_params:

View File

@ -4756,7 +4756,7 @@ def save_reverse_timeline(base_dir: str, reverse_sequence: []) -> []:
def get_quote_toot_url(post_json_object: str) -> str:
"""
""" Returns the url for a quote toot
"""
# adhoc quote toot implementations
object_quote_url_fields = ('quoteUri', 'quoteUrl', 'quoteReply',
@ -4835,7 +4835,7 @@ def quote_toots_allowed(base_dir: str, nickname: str, domain: str,
return True
if os.path.isfile(quotes_blocked_filename):
sender_handle = sender_nickname + '@' + sender_domain
if text_in_file(sender_handle, quotes_blocked_filename):
if text_in_file(sender_handle, quotes_blocked_filename, False):
# quote toots not permitted from this sender
return False
return True

View File

@ -12,6 +12,7 @@ from shutil import copyfile
from petnames import get_pet_name
from person import is_person_snoozed
from posts import is_moderator
from utils import quote_toots_allowed
from utils import get_full_domain
from utils import get_config_param
from utils import is_dormant
@ -477,6 +478,7 @@ def html_person_options(default_timeline: str,
# Notify when a post arrives from this person
if is_following_actor(base_dir, nickname, domain, options_actor):
# allow announces
checkbox_str = \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="allowAnnounce" checked> 🔁' + \
@ -489,6 +491,24 @@ def html_person_options(default_timeline: str,
checkbox_str = checkbox_str.replace(' checked>', '>')
options_str += checkbox_str
# allow quote toots
if quote_toots_allowed(base_dir, nickname, domain,
None, None):
checkbox_str = \
' <input type="checkbox" ' + \
'class="profilecheckbox" ' + \
'name="allowQuotes" checked> ' + \
translate['Show quote posts'] + \
'\n <button type="submit" class="buttonsmall" ' + \
'name="submitAllowQuotes">' + \
translate['Save'] + '</button><br>\n'
if quote_toots_allowed(base_dir, nickname, domain,
options_nickname,
options_domain_full):
checkbox_str = checkbox_str.replace(' checked>', '>')
options_str += checkbox_str
# notify about new posts
checkbox_str = \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="notifyOnPost" checked> 🔔' + \
@ -502,6 +522,7 @@ def html_person_options(default_timeline: str,
checkbox_str = checkbox_str.replace(' checked>', '>')
options_str += checkbox_str
# receive calendar events
checkbox_str = \
' <input type="checkbox" ' + \
'class="profilecheckbox" name="onCalendar" checked> ' + \
@ -515,6 +536,7 @@ def html_person_options(default_timeline: str,
checkbox_str = checkbox_str.replace(' checked>', '>')
options_str += checkbox_str
# minimise images for this handle
checkbox_str = \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="minimizeImages" checked> ' + \