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 reaction import update_reaction_collection
from reaction import valid_emoji_content
from utils import quote_toots_allowed
from utils import get_post_attachments
from utils import lines_in_file
from utils import resembles_url
@ -751,6 +752,12 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
if obj_dict_exists:
if is_quote_toot(post_json_object, content_str):
allow_quotes = False
if sending_actor:
allow_quotes = \
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']))

View File

@ -15,6 +15,7 @@ from posts import outbox_message_create_wrap
from posts import save_post_to_box
from posts import send_to_followers_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_attributed_to
from utils import contains_invalid_actor_url_chars
@ -311,6 +312,10 @@ def post_message_to_outbox(session, translate: {},
return False
if is_quote_toot(message_json, ''):
allow_quotes = \
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

View File

@ -4801,6 +4801,27 @@ def is_quote_toot(post_json_object: str, content: str) -> bool:
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:
"""Returns the license link from its name
"""