Preparing for opt-in quote toots

main
Bob Mottram 2024-04-20 10:59:56 +01:00
parent 295983eea3
commit d7e79c7761
3 changed files with 39 additions and 6 deletions

View File

@ -18,6 +18,7 @@ from languages import understood_post_language
from like import update_likes_collection from like import update_likes_collection
from reaction import update_reaction_collection from reaction import update_reaction_collection
from reaction import valid_emoji_content from reaction import valid_emoji_content
from utils import quote_toots_allowed
from utils import get_post_attachments from utils import get_post_attachments
from utils import lines_in_file from utils import lines_in_file
from utils import resembles_url from utils import resembles_url
@ -751,10 +752,16 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
if obj_dict_exists: if obj_dict_exists:
if is_quote_toot(post_json_object, content_str): if is_quote_toot(post_json_object, content_str):
if post_json_object.get('id'): allow_quotes = False
print('REJECT: inbox quote toot ' + if sending_actor:
str(post_json_object['id'])) allow_quotes = \
return None quote_toots_allowed(base_dir, nickname, domain,
post_nickname, post_domain)
if not allow_quotes:
if post_json_object.get('id'):
print('REJECT: inbox quote toot ' +
str(post_json_object['id']))
return None
# is this a reply to a blocked domain or account? # is this a reply to a blocked domain or account?
reply_id = get_reply_to(post_json_object['object']) reply_id = get_reply_to(post_json_object['object'])

View File

@ -15,6 +15,7 @@ from posts import outbox_message_create_wrap
from posts import save_post_to_box from posts import save_post_to_box
from posts import send_to_followers_thread from posts import send_to_followers_thread
from posts import send_to_named_addresses_thread from posts import send_to_named_addresses_thread
from utils import quote_toots_allowed
from utils import get_post_attachments from utils import get_post_attachments
from utils import get_attributed_to from utils import get_attributed_to
from utils import contains_invalid_actor_url_chars from utils import contains_invalid_actor_url_chars
@ -311,8 +312,12 @@ def post_message_to_outbox(session, translate: {},
return False return False
if is_quote_toot(message_json, ''): if is_quote_toot(message_json, ''):
print('REJECT: POST quote toot ' + str(message_json)) allow_quotes = \
return False quote_toots_allowed(base_dir, post_to_nickname, domain,
None, None)
if not allow_quotes:
print('REJECT: POST quote toot ' + str(message_json))
return False
content_str = get_base_content_from_post(message_json, system_language) content_str = get_base_content_from_post(message_json, system_language)
if content_str: if content_str:

View File

@ -4801,6 +4801,27 @@ def is_quote_toot(post_json_object: str, content: str) -> bool:
return False return False
def quote_toots_allowed(base_dir: str, nickname: str, domain: str,
sender_nickname: str, sender_domain: str) -> bool:
""" Returns true if quote toots are allowed by the given account
for the given sender
"""
account_dir = acct_dir(base_dir, nickname, domain)
quotes_enabled_filename = account_dir + '/.allowQuotes'
if os.path.isfile(quotes_enabled_filename):
# check blocks on individual sending accounts
quotes_blocked_filename = account_dir + '/quotesblocked.txt'
if sender_nickname is None:
return True
if os.path.isfile(quotes_blocked_filename):
sender_handle = sender_nickname + '@' + sender_domain
if text_in_file(sender_handle, quotes_blocked_filename):
# quote toots not permitted from this sender
return False
return True
return False
def license_link_from_name(license_name: str) -> str: def license_link_from_name(license_name: str) -> str:
"""Returns the license link from its name """Returns the license link from its name
""" """