Use reply and announce inhibitors in desktop client

main
Bob Mottram 2022-05-08 18:15:48 +01:00
parent 365c0626a1
commit 3a1dcc22cf
3 changed files with 96 additions and 56 deletions

View File

@ -16,6 +16,8 @@ import webbrowser
import urllib.parse import urllib.parse
from pathlib import Path from pathlib import Path
from random import randint from random import randint
from utils import disallow_announce
from utils import disallow_reply
from utils import get_base_content_from_post from utils import get_base_content_from_post
from utils import has_object_dict from utils import has_object_dict
from utils import get_full_domain from utils import get_full_domain
@ -1757,27 +1759,34 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
print('') print('')
elif command_str in ('reply', 'r'): elif command_str in ('reply', 'r'):
if post_json_object: if post_json_object:
if post_json_object.get('id'): post_content = ''
post_id = post_json_object['id'] if post_json_object['object'].get('content'):
subject = None post_content = post_json_object['object']['content']
if post_json_object['object'].get('summary'): if not disallow_reply(post_content):
subject = post_json_object['object']['summary'] if post_json_object.get('id'):
conversation_id = None post_id = post_json_object['id']
if post_json_object['object'].get('conversation'): subject = None
conversation_id = \ if post_json_object['object'].get('summary'):
post_json_object['object']['conversation'] subject = post_json_object['object']['summary']
session_reply = create_session(proxy_type) conversation_id = None
_desktop_reply_to_post(session_reply, post_id, if post_json_object['object'].get('conversation'):
base_dir, nickname, password, conversation_id = \
domain, port, http_prefix, post_json_object['object']['conversation']
cached_webfingers, person_cache, session_reply = create_session(proxy_type)
debug, subject, _desktop_reply_to_post(session_reply, post_id,
screenreader, system_language, base_dir, nickname,
languages_understood, password,
espeak, conversation_id, domain, port, http_prefix,
low_bandwidth, cached_webfingers,
content_license_url, person_cache,
signing_priv_key_pem) debug, subject,
screenreader,
system_language,
languages_understood,
espeak, conversation_id,
low_bandwidth,
content_license_url,
signing_priv_key_pem)
refresh_timeline = True refresh_timeline = True
print('') print('')
elif (command_str == 'post' or command_str == 'p' or elif (command_str == 'post' or command_str == 'p' or
@ -2130,25 +2139,30 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
post_json_object = \ post_json_object = \
_desktop_get_box_post_object(box_json, curr_index) _desktop_get_box_post_object(box_json, curr_index)
if post_json_object: if post_json_object:
if post_json_object.get('id'): post_content = ''
post_id = post_json_object['id'] if post_json_object['object'].get('content'):
announce_actor = \ post_content = post_json_object['object']['content']
post_json_object['object']['attributedTo'] if not disallow_announce(post_content):
say_str = 'Announcing post by ' + \ if post_json_object.get('id'):
get_nickname_from_actor(announce_actor) post_id = post_json_object['id']
_say_command(say_str, say_str, announce_actor = \
screenreader, post_json_object['object']['attributedTo']
system_language, espeak) say_str = 'Announcing post by ' + \
session_announce = create_session(proxy_type) get_nickname_from_actor(announce_actor)
send_announce_via_server(base_dir, session_announce, _say_command(say_str, say_str,
nickname, password, screenreader,
domain, port, system_language, espeak)
http_prefix, post_id, session_announce = create_session(proxy_type)
cached_webfingers, send_announce_via_server(base_dir,
person_cache, session_announce,
True, __version__, nickname, password,
signing_priv_key_pem) domain, port,
refresh_timeline = True http_prefix, post_id,
cached_webfingers,
person_cache,
True, __version__,
signing_priv_key_pem)
refresh_timeline = True
print('') print('')
elif (command_str.startswith('unannounce') or elif (command_str.startswith('unannounce') or
command_str.startswith('undo announce') or command_str.startswith('undo announce') or

View File

@ -3614,3 +3614,41 @@ def is_i2p_request(calling_domain: str, referer_domain: str,
if referer_domain.endswith('.i2p'): if referer_domain.endswith('.i2p'):
return True return True
return False return False
def disallow_announce(content: str) -> bool:
"""Are announces/boosts not allowed for the given post?
"""
disallow_strings = (
':boost_no:',
':noboost:',
':noboosts:',
':no_boost:',
':no_boosts:',
':boosts_no:',
'dont_repeat',
'dont_announce',
'dont_boost'
)
for diss in disallow_strings:
if diss in content:
return True
return False
def disallow_reply(content: str) -> bool:
"""Are replies not allowed for the given post?
"""
disallow_strings = (
':reply_no:',
':noreply:',
':noreplies:',
':no_reply:',
':no_replies:',
':replies_no:',
'dont_at_me'
)
for diss in disallow_strings:
if diss in content:
return True
return False

View File

@ -25,6 +25,8 @@ from posts import post_is_muted
from posts import get_person_box from posts import get_person_box
from posts import download_announce from posts import download_announce
from posts import populate_replies_json from posts import populate_replies_json
from utils import disallow_announce
from utils import disallow_reply
from utils import convert_published_to_local_timezone from utils import convert_published_to_local_timezone
from utils import remove_hash_from_post_id from utils import remove_hash_from_post_id
from utils import remove_html from utils import remove_html
@ -2020,25 +2022,11 @@ def individual_post_as_html(signing_priv_key_pem: str,
if content_str: if content_str:
# does an emoji indicate a no boost preference? # does an emoji indicate a no boost preference?
# if so then don't show the repeat/announce icon # if so then don't show the repeat/announce icon
if ':boost_no:' in content_str or \ if disallow_announce(content_str):
':noboost:' in content_str or \
':noboosts:' in content_str or \
':no_boost:' in content_str or \
':no_boosts:' in content_str or \
':boosts_no:' in content_str or \
'dont_repeat' in content_str or \
'dont_announce' in content_str or \
'dont_boost' in content_str:
announce_str = '' announce_str = ''
# does an emoji indicate a no replies preference? # does an emoji indicate a no replies preference?
# if so then don't show the reply icon # if so then don't show the reply icon
if ':reply_no:' in content_str or \ if disallow_reply(content_str):
':noreply:' in content_str or \
':noreplies:' in content_str or \
':no_reply:' in content_str or \
':no_replies:' in content_str or \
':replies_no:' in content_str or \
'dont_at_me' in content_str:
reply_str = '' reply_str = ''
new_footer_str = \ new_footer_str = \