Snake case

merge-requests/30/head
Bob Mottram 2021-12-31 23:07:23 +00:00
parent 2099cad0ac
commit 0a3d10b2ca
8 changed files with 986 additions and 978 deletions

1560
daemon.py

File diff suppressed because it is too large Load Diff

View File

@ -674,7 +674,7 @@ def _read_local_box_post(session, nickname: str, domain: str,
translate: {}, yourActor: str, translate: {}, yourActor: str,
domain_full: str, person_cache: {}, domain_full: str, person_cache: {},
signing_priv_key_pem: str, signing_priv_key_pem: str,
blockedCache: {}) -> {}: blocked_cache: {}) -> {}:
"""Reads a post from the given timeline """Reads a post from the given timeline
Returns the post json Returns the post json
""" """
@ -715,7 +715,7 @@ def _read_local_box_post(session, nickname: str, domain: str,
system_language, system_language,
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blockedCache) blocked_cache)
if post_json_object2: if post_json_object2:
if has_object_dict(post_json_object2): if has_object_dict(post_json_object2):
if post_json_object2['object'].get('attributedTo') and \ if post_json_object2['object'].get('attributedTo') and \
@ -1339,7 +1339,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
content_license_url = 'https://creativecommons.org/licenses/by/4.0' content_license_url = 'https://creativecommons.org/licenses/by/4.0'
blockedCache = {} blocked_cache = {}
indent = ' ' indent = ' '
if showNewPosts: if showNewPosts:
@ -1653,7 +1653,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
espeak, translate, yourActor, espeak, translate, yourActor,
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blockedCache) blocked_cache)
print('') print('')
sayStr = 'Press Enter to continue...' sayStr = 'Press Enter to continue...'
sayStr2 = _highlight_text(sayStr) sayStr2 = _highlight_text(sayStr)
@ -2439,7 +2439,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
system_language, system_language,
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blockedCache) blocked_cache)
if post_json_object2: if post_json_object2:
post_json_object = post_json_object2 post_json_object = post_json_object2
if post_json_object: if post_json_object:

View File

@ -457,7 +457,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
messageBytes: str, messageBytes: str,
httpHeaders: {}, httpHeaders: {},
postPath: str, debug: bool, postPath: str, debug: bool,
blockedCache: [], system_language: str) -> str: blocked_cache: [], system_language: str) -> str:
"""Saves the given json to the inbox queue for the person """Saves the given json to the inbox queue for the person
keyId specifies the actor sending the post keyId specifies the actor sending the post
""" """
@ -488,7 +488,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
print('No post Domain in actor') print('No post Domain in actor')
return None return None
if is_blocked(base_dir, nickname, domain, if is_blocked(base_dir, nickname, domain,
postNickname, postDomain, blockedCache): postNickname, postDomain, blocked_cache):
if debug: if debug:
print('DEBUG: post from ' + postNickname + ' blocked') print('DEBUG: post from ' + postNickname + ' blocked')
return None return None
@ -501,7 +501,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
post_json_object['object']['inReplyTo'] post_json_object['object']['inReplyTo']
replyDomain, replyPort = \ replyDomain, replyPort = \
get_domain_from_actor(inReplyTo) get_domain_from_actor(inReplyTo)
if is_blocked_domain(base_dir, replyDomain, blockedCache): if is_blocked_domain(base_dir, replyDomain, blocked_cache):
if debug: if debug:
print('WARN: post contains reply from ' + print('WARN: post contains reply from ' +
str(actor) + str(actor) +
@ -513,7 +513,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
if replyNickname and replyDomain: if replyNickname and replyDomain:
if is_blocked(base_dir, nickname, domain, if is_blocked(base_dir, nickname, domain,
replyNickname, replyDomain, replyNickname, replyDomain,
blockedCache): blocked_cache):
if debug: if debug:
print('WARN: post contains reply from ' + print('WARN: post contains reply from ' +
str(actor) + str(actor) +
@ -1864,7 +1864,7 @@ def _receive_announce(recent_posts_cache: {},
message_json['type']) message_json['type'])
return False return False
blockedCache = {} blocked_cache = {}
prefixes = get_protocol_prefixes() prefixes = get_protocol_prefixes()
# is the domain of the announce actor blocked? # is the domain of the announce actor blocked?
objectDomain = message_json['object'] objectDomain = message_json['object']
@ -1961,7 +1961,7 @@ def _receive_announce(recent_posts_cache: {},
system_language, system_language,
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blockedCache) blocked_cache)
if not post_json_object: if not post_json_object:
print('WARN: unable to download announce: ' + str(message_json)) print('WARN: unable to download announce: ' + str(message_json))
notInOnion = True notInOnion = True

View File

@ -178,7 +178,7 @@ def _person_receive_update_outbox(recent_posts_cache: {},
def post_message_to_outbox(session, translate: {}, def post_message_to_outbox(session, translate: {},
message_json: {}, postToNickname: str, message_json: {}, post_to_nickname: str,
server, base_dir: str, http_prefix: str, server, base_dir: str, http_prefix: str,
domain: str, domain_full: str, domain: str, domain_full: str,
onion_domain: str, i2p_domain: str, port: int, onion_domain: str, i2p_domain: str, port: int,
@ -216,7 +216,7 @@ def post_message_to_outbox(session, translate: {},
print('DEBUG: POST to outbox - adding Create wrapper') print('DEBUG: POST to outbox - adding Create wrapper')
message_json = \ message_json = \
outbox_message_create_wrap(http_prefix, outbox_message_create_wrap(http_prefix,
postToNickname, post_to_nickname,
domain, port, domain, port,
message_json) message_json)
@ -320,7 +320,7 @@ def post_message_to_outbox(session, translate: {},
mediaDir = \ mediaDir = \
base_dir + '/accounts/' + \ base_dir + '/accounts/' + \
postToNickname + '@' + domain post_to_nickname + '@' + domain
uploadMediaFilename = mediaDir + '/upload.' + fileExtension uploadMediaFilename = mediaDir + '/upload.' + fileExtension
if not os.path.isfile(uploadMediaFilename): if not os.path.isfile(uploadMediaFilename):
del message_json['object']['attachment'] del message_json['object']['attachment']
@ -374,16 +374,16 @@ def post_message_to_outbox(session, translate: {},
save_post_to_box(base_dir, save_post_to_box(base_dir,
http_prefix, http_prefix,
post_id, post_id,
postToNickname, domain_full, post_to_nickname, domain_full,
message_json, outboxName) message_json, outboxName)
if not savedFilename: if not savedFilename:
print('WARN: post not saved to outbox ' + outboxName) print('WARN: post not saved to outbox ' + outboxName)
return False return False
# save all instance blogs to the news actor # save all instance blogs to the news actor
if postToNickname != 'news' and outboxName == 'tlblogs': if post_to_nickname != 'news' and outboxName == 'tlblogs':
if '/' in savedFilename: if '/' in savedFilename:
if is_featured_writer(base_dir, postToNickname, domain): if is_featured_writer(base_dir, post_to_nickname, domain):
savedPostId = savedFilename.split('/')[-1] savedPostId = savedFilename.split('/')[-1]
blogsDir = \ blogsDir = \
base_dir + '/accounts/news@' + domain + '/tlblogs' base_dir + '/accounts/news@' + domain + '/tlblogs'
@ -397,7 +397,7 @@ def post_message_to_outbox(session, translate: {},
# clear the citations file if it exists # clear the citations file if it exists
citationsFilename = \ citationsFilename = \
base_dir + '/accounts/' + \ base_dir + '/accounts/' + \
postToNickname + '@' + domain + '/.citations.txt' post_to_nickname + '@' + domain + '/.citations.txt'
if os.path.isfile(citationsFilename): if os.path.isfile(citationsFilename):
try: try:
os.remove(citationsFilename) os.remove(citationsFilename)
@ -413,7 +413,7 @@ def post_message_to_outbox(session, translate: {},
if message_json['type'] in indexedActivities: if message_json['type'] in indexedActivities:
indexes = [outboxName, "inbox"] indexes = [outboxName, "inbox"]
selfActor = \ selfActor = \
local_actor_url(http_prefix, postToNickname, domain_full) local_actor_url(http_prefix, post_to_nickname, domain_full)
for boxNameIndex in indexes: for boxNameIndex in indexes:
if not boxNameIndex: if not boxNameIndex:
continue continue
@ -421,7 +421,7 @@ def post_message_to_outbox(session, translate: {},
# should this also go to the media timeline? # should this also go to the media timeline?
if boxNameIndex == 'inbox': if boxNameIndex == 'inbox':
if is_image_media(session, base_dir, http_prefix, if is_image_media(session, base_dir, http_prefix,
postToNickname, domain, post_to_nickname, domain,
message_json, message_json,
translate, translate,
yt_replace_domain, yt_replace_domain,
@ -432,7 +432,7 @@ def post_message_to_outbox(session, translate: {},
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem): signing_priv_key_pem):
inbox_update_index('tlmedia', base_dir, inbox_update_index('tlmedia', base_dir,
postToNickname + '@' + domain, post_to_nickname + '@' + domain,
savedFilename, debug) savedFilename, debug)
if boxNameIndex == 'inbox' and outboxName == 'tlblogs': if boxNameIndex == 'inbox' and outboxName == 'tlblogs':
@ -444,7 +444,7 @@ def post_message_to_outbox(session, translate: {},
# show sent post within the inbox, # show sent post within the inbox,
# as is the typical convention # as is the typical convention
inbox_update_index(boxNameIndex, base_dir, inbox_update_index(boxNameIndex, base_dir,
postToNickname + '@' + domain, post_to_nickname + '@' + domain,
savedFilename, debug) savedFilename, debug)
# regenerate the html # regenerate the html
@ -453,7 +453,7 @@ def post_message_to_outbox(session, translate: {},
showIndividualPostIcons = True showIndividualPostIcons = True
manuallyApproveFollowers = \ manuallyApproveFollowers = \
follower_approval_active(base_dir, follower_approval_active(base_dir,
postToNickname, domain) post_to_nickname, domain)
individual_post_as_html(signing_priv_key_pem, individual_post_as_html(signing_priv_key_pem,
False, recent_posts_cache, False, recent_posts_cache,
max_recent_posts, max_recent_posts,
@ -461,7 +461,7 @@ def post_message_to_outbox(session, translate: {},
base_dir, session, base_dir, session,
cached_webfingers, cached_webfingers,
person_cache, person_cache,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, None, True, message_json, None, True,
allow_deletion, allow_deletion,
http_prefix, __version__, http_prefix, __version__,
@ -513,7 +513,7 @@ def post_message_to_outbox(session, translate: {},
followersThread = \ followersThread = \
send_to_followers_thread(server.session, send_to_followers_thread(server.session,
base_dir, base_dir,
postToNickname, post_to_nickname,
domain, onion_domain, i2p_domain, domain, onion_domain, i2p_domain,
port, http_prefix, port, http_prefix,
federation_list, federation_list,
@ -534,62 +534,62 @@ def post_message_to_outbox(session, translate: {},
if debug: if debug:
print('DEBUG: handle skills changes requests') print('DEBUG: handle skills changes requests')
outbox_skills(base_dir, postToNickname, message_json, debug) outbox_skills(base_dir, post_to_nickname, message_json, debug)
if debug: if debug:
print('DEBUG: handle availability changes requests') print('DEBUG: handle availability changes requests')
outbox_availability(base_dir, postToNickname, message_json, debug) outbox_availability(base_dir, post_to_nickname, message_json, debug)
if debug: if debug:
print('DEBUG: handle any like requests') print('DEBUG: handle any like requests')
outbox_like(recent_posts_cache, outbox_like(recent_posts_cache,
base_dir, http_prefix, base_dir, http_prefix,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: handle any undo like requests') print('DEBUG: handle any undo like requests')
outbox_undo_like(recent_posts_cache, outbox_undo_like(recent_posts_cache,
base_dir, http_prefix, base_dir, http_prefix,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: handle any emoji reaction requests') print('DEBUG: handle any emoji reaction requests')
outbox_reaction(recent_posts_cache, outbox_reaction(recent_posts_cache,
base_dir, http_prefix, base_dir, http_prefix,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: handle any undo emoji reaction requests') print('DEBUG: handle any undo emoji reaction requests')
outbox_undo_reaction(recent_posts_cache, outbox_undo_reaction(recent_posts_cache,
base_dir, http_prefix, base_dir, http_prefix,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: handle any undo announce requests') print('DEBUG: handle any undo announce requests')
outbox_undo_announce(recent_posts_cache, outbox_undo_announce(recent_posts_cache,
base_dir, http_prefix, base_dir, http_prefix,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: handle any bookmark requests') print('DEBUG: handle any bookmark requests')
outbox_bookmark(recent_posts_cache, outbox_bookmark(recent_posts_cache,
base_dir, http_prefix, base_dir, http_prefix,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: handle any undo bookmark requests') print('DEBUG: handle any undo bookmark requests')
outbox_undo_bookmark(recent_posts_cache, outbox_undo_bookmark(recent_posts_cache,
base_dir, http_prefix, base_dir, http_prefix,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: handle delete requests') print('DEBUG: handle delete requests')
outbox_delete(base_dir, http_prefix, outbox_delete(base_dir, http_prefix,
postToNickname, domain, post_to_nickname, domain,
message_json, debug, message_json, debug,
allow_deletion, allow_deletion,
recent_posts_cache) recent_posts_cache)
@ -597,20 +597,20 @@ def post_message_to_outbox(session, translate: {},
if debug: if debug:
print('DEBUG: handle block requests') print('DEBUG: handle block requests')
outbox_block(base_dir, http_prefix, outbox_block(base_dir, http_prefix,
postToNickname, domain, post_to_nickname, domain,
port, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: handle undo block requests') print('DEBUG: handle undo block requests')
outbox_undo_block(base_dir, http_prefix, outbox_undo_block(base_dir, http_prefix,
postToNickname, domain, post_to_nickname, domain,
port, message_json, debug) port, message_json, debug)
if debug: if debug:
print('DEBUG: handle mute requests') print('DEBUG: handle mute requests')
outbox_mute(base_dir, http_prefix, outbox_mute(base_dir, http_prefix,
postToNickname, domain, post_to_nickname, domain,
port, port,
message_json, debug, message_json, debug,
recent_posts_cache) recent_posts_cache)
@ -618,14 +618,14 @@ def post_message_to_outbox(session, translate: {},
if debug: if debug:
print('DEBUG: handle undo mute requests') print('DEBUG: handle undo mute requests')
outbox_undo_mute(base_dir, http_prefix, outbox_undo_mute(base_dir, http_prefix,
postToNickname, domain, post_to_nickname, domain,
port, port,
message_json, debug, message_json, debug,
recent_posts_cache) recent_posts_cache)
if debug: if debug:
print('DEBUG: handle share uploads') print('DEBUG: handle share uploads')
outbox_share_upload(base_dir, http_prefix, postToNickname, domain, outbox_share_upload(base_dir, http_prefix, post_to_nickname, domain,
port, message_json, debug, city, port, message_json, debug, city,
system_language, translate, low_bandwidth, system_language, translate, low_bandwidth,
content_license_url) content_license_url)
@ -633,28 +633,28 @@ def post_message_to_outbox(session, translate: {},
if debug: if debug:
print('DEBUG: handle undo share uploads') print('DEBUG: handle undo share uploads')
outbox_undo_share_upload(base_dir, http_prefix, outbox_undo_share_upload(base_dir, http_prefix,
postToNickname, domain, post_to_nickname, domain,
port, message_json, debug) port, message_json, debug)
if debug: if debug:
print('DEBUG: handle actor updates from c2s') print('DEBUG: handle actor updates from c2s')
_person_receive_update_outbox(recent_posts_cache, _person_receive_update_outbox(recent_posts_cache,
base_dir, http_prefix, base_dir, http_prefix,
postToNickname, domain, port, post_to_nickname, domain, port,
message_json, debug) message_json, debug)
if debug: if debug:
print('DEBUG: sending c2s post to named addresses') print('DEBUG: sending c2s post to named addresses')
if message_json.get('to'): if message_json.get('to'):
print('c2s sender: ' + print('c2s sender: ' +
postToNickname + '@' + domain + ':' + str(port) + post_to_nickname + '@' + domain + ':' + str(port) +
' recipient: ' + str(message_json['to'])) ' recipient: ' + str(message_json['to']))
else: else:
print('c2s sender: ' + print('c2s sender: ' +
postToNickname + '@' + domain + ':' + str(port)) post_to_nickname + '@' + domain + ':' + str(port))
namedAddressesThread = \ namedAddressesThread = \
send_to_named_addresses_thread(server.session, base_dir, send_to_named_addresses_thread(server.session, base_dir,
postToNickname, post_to_nickname,
domain, onion_domain, i2p_domain, port, domain, onion_domain, i2p_domain, port,
http_prefix, http_prefix,
federation_list, federation_list,

View File

@ -92,7 +92,7 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
print('Sending scheduled post ' + post_id) print('Sending scheduled post ' + post_id)
if nickname: if nickname:
httpd.postToNickname = nickname httpd.post_to_nickname = nickname
if not post_message_to_outbox(httpd.session, if not post_message_to_outbox(httpd.session,
httpd.translate, httpd.translate,
post_json_object, nickname, post_json_object, nickname,

View File

@ -17,7 +17,7 @@ from filters import is_filtered
def convert_video_to_note(base_dir: str, nickname: str, domain: str, def convert_video_to_note(base_dir: str, nickname: str, domain: str,
system_language: str, system_language: str,
post_json_object: {}, blockedCache: {}) -> {}: post_json_object: {}, blocked_cache: {}) -> {}:
"""Converts a PeerTube Video ActivityPub(ish) object into """Converts a PeerTube Video ActivityPub(ish) object into
a Note, so that it can then be displayed in a timeline a Note, so that it can then be displayed in a timeline
""" """
@ -69,7 +69,7 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
return None return None
postDomainFull = get_full_domain(postDomain, postDomainPort) postDomainFull = get_full_domain(postDomain, postDomainPort)
if is_blocked(base_dir, nickname, domain, if is_blocked(base_dir, nickname, domain,
postNickname, postDomainFull, blockedCache): postNickname, postDomainFull, blocked_cache):
return None return None
# check that the content is valid # check that the content is valid

View File

@ -25,8 +25,8 @@ from webapp_post import individual_post_as_html
def html_confirm_delete(css_cache: {}, def html_confirm_delete(css_cache: {},
recent_posts_cache: {}, max_recent_posts: int, recent_posts_cache: {}, max_recent_posts: int,
translate, pageNumber: int, translate, page_number: int,
session, base_dir: str, messageId: str, session, base_dir: str, message_id: str,
http_prefix: str, project_version: str, http_prefix: str, project_version: str,
cached_webfingers: {}, person_cache: {}, cached_webfingers: {}, person_cache: {},
calling_domain: str, calling_domain: str,
@ -40,14 +40,14 @@ def html_confirm_delete(css_cache: {},
cw_lists: {}, lists_enabled: str) -> str: cw_lists: {}, lists_enabled: str) -> str:
"""Shows a screen asking to confirm the deletion of a post """Shows a screen asking to confirm the deletion of a post
""" """
if '/statuses/' not in messageId: if '/statuses/' not in message_id:
return None return None
actor = messageId.split('/statuses/')[0] actor = message_id.split('/statuses/')[0]
nickname = get_nickname_from_actor(actor) nickname = get_nickname_from_actor(actor)
domain, port = get_domain_from_actor(actor) domain, port = get_domain_from_actor(actor)
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
post_filename = locate_post(base_dir, nickname, domain, messageId) post_filename = locate_post(base_dir, nickname, domain, message_id)
if not post_filename: if not post_filename:
return None return None
@ -55,19 +55,19 @@ def html_confirm_delete(css_cache: {},
if not post_json_object: if not post_json_object:
return None return None
delete_postStr = None delete_post_str = None
css_filename = base_dir + '/epicyon-profile.css' css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'): if os.path.isfile(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css' css_filename = base_dir + '/epicyon.css'
instanceTitle = \ instance_title = \
get_config_param(base_dir, 'instanceTitle') get_config_param(base_dir, 'instanceTitle')
delete_postStr = \ delete_post_str = \
html_header_with_external_style(css_filename, instanceTitle, None) html_header_with_external_style(css_filename, instance_title, None)
delete_postStr += \ delete_post_str += \
individual_post_as_html(signing_priv_key_pem, individual_post_as_html(signing_priv_key_pem,
True, recent_posts_cache, max_recent_posts, True, recent_posts_cache, max_recent_posts,
translate, pageNumber, translate, page_number,
base_dir, session, base_dir, session,
cached_webfingers, person_cache, cached_webfingers, person_cache,
nickname, domain, port, post_json_object, nickname, domain, port, post_json_object,
@ -80,58 +80,58 @@ def html_confirm_delete(css_cache: {},
theme_name, system_language, max_like_count, theme_name, system_language, max_like_count,
False, False, False, False, False, False, False, False, False, False, False, False,
cw_lists, lists_enabled) cw_lists, lists_enabled)
delete_postStr += '<center>' delete_post_str += '<center>'
delete_postStr += \ delete_post_str += \
' <p class="followText">' + \ ' <p class="followText">' + \
translate['Delete this post?'] + '</p>' translate['Delete this post?'] + '</p>'
postActor = get_alt_path(actor, domain_full, calling_domain) post_actor = get_alt_path(actor, domain_full, calling_domain)
delete_postStr += \ delete_post_str += \
' <form method="POST" action="' + postActor + '/rmpost">\n' ' <form method="POST" action="' + post_actor + '/rmpost">\n'
delete_postStr += \ delete_post_str += \
' <input type="hidden" name="pageNumber" value="' + \ ' <input type="hidden" name="pageNumber" value="' + \
str(pageNumber) + '">\n' str(page_number) + '">\n'
delete_postStr += \ delete_post_str += \
' <input type="hidden" name="messageId" value="' + \ ' <input type="hidden" name="messageId" value="' + \
messageId + '">\n' message_id + '">\n'
delete_postStr += \ delete_post_str += \
' <button type="submit" class="button" name="submitYes">' + \ ' <button type="submit" class="button" name="submitYes">' + \
translate['Yes'] + '</button>\n' translate['Yes'] + '</button>\n'
delete_postStr += \ delete_post_str += \
' <a href="' + actor + '/inbox"><button class="button">' + \ ' <a href="' + actor + '/inbox"><button class="button">' + \
translate['No'] + '</button></a>\n' translate['No'] + '</button></a>\n'
delete_postStr += ' </form>\n' delete_post_str += ' </form>\n'
delete_postStr += '</center>\n' delete_post_str += '</center>\n'
delete_postStr += html_footer() delete_post_str += html_footer()
return delete_postStr return delete_post_str
def html_confirm_remove_shared_item(css_cache: {}, translate: {}, def html_confirm_remove_shared_item(css_cache: {}, translate: {},
base_dir: str, base_dir: str,
actor: str, itemID: str, actor: str, item_id: str,
calling_domain: str, calling_domain: str,
sharesFileType: str) -> str: shares_file_type: str) -> str:
"""Shows a screen asking to confirm the removal of a shared item """Shows a screen asking to confirm the removal of a shared item
""" """
nickname = get_nickname_from_actor(actor) nickname = get_nickname_from_actor(actor)
domain, port = get_domain_from_actor(actor) domain, port = get_domain_from_actor(actor)
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
sharesFile = \ shares_file = \
acct_dir(base_dir, nickname, domain) + '/' + sharesFileType + '.json' acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
if not os.path.isfile(sharesFile): if not os.path.isfile(shares_file):
print('ERROR: no ' + sharesFileType + ' file ' + sharesFile) print('ERROR: no ' + shares_file_type + ' file ' + shares_file)
return None return None
sharesJson = load_json(sharesFile) shares_json = load_json(shares_file)
if not sharesJson: if not shares_json:
print('ERROR: unable to load ' + sharesFileType + '.json') print('ERROR: unable to load ' + shares_file_type + '.json')
return None return None
if not sharesJson.get(itemID): if not shares_json.get(item_id):
print('ERROR: share named "' + itemID + '" is not in ' + sharesFile) print('ERROR: share named "' + item_id + '" is not in ' + shares_file)
return None return None
sharedItemDisplayName = sharesJson[itemID]['displayName'] shared_item_display_name = shares_json[item_id]['displayName']
sharedItemImageUrl = None shared_item_image_url = None
if sharesJson[itemID].get('imageUrl'): if shares_json[item_id].get('imageUrl'):
sharedItemImageUrl = sharesJson[itemID]['imageUrl'] shared_item_image_url = shares_json[item_id]['imageUrl']
set_custom_background(base_dir, 'shares-background', 'follow-background') set_custom_background(base_dir, 'shares-background', 'follow-background')
@ -139,50 +139,50 @@ def html_confirm_remove_shared_item(css_cache: {}, translate: {},
if os.path.isfile(base_dir + '/follow.css'): if os.path.isfile(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css' css_filename = base_dir + '/follow.css'
instanceTitle = get_config_param(base_dir, 'instanceTitle') instance_title = get_config_param(base_dir, 'instanceTitle')
sharesStr = html_header_with_external_style(css_filename, shares_str = html_header_with_external_style(css_filename,
instanceTitle, None) instance_title, None)
sharesStr += '<div class="follow">\n' shares_str += '<div class="follow">\n'
sharesStr += ' <div class="followAvatar">\n' shares_str += ' <div class="followAvatar">\n'
sharesStr += ' <center>\n' shares_str += ' <center>\n'
if sharedItemImageUrl: if shared_item_image_url:
sharesStr += ' <img loading="lazy" src="' + \ shares_str += ' <img loading="lazy" src="' + \
sharedItemImageUrl + '"/>\n' shared_item_image_url + '"/>\n'
sharesStr += \ shares_str += \
' <p class="followText">' + translate['Remove'] + \ ' <p class="followText">' + translate['Remove'] + \
' ' + sharedItemDisplayName + ' ?</p>\n' ' ' + shared_item_display_name + ' ?</p>\n'
postActor = get_alt_path(actor, domain_full, calling_domain) post_actor = get_alt_path(actor, domain_full, calling_domain)
if sharesFileType == 'shares': if shares_file_type == 'shares':
endpoint = 'rmshare' endpoint = 'rmshare'
else: else:
endpoint = 'rmwanted' endpoint = 'rmwanted'
sharesStr += \ shares_str += \
' <form method="POST" action="' + postActor + '/' + endpoint + '">\n' ' <form method="POST" action="' + post_actor + '/' + endpoint + '">\n'
sharesStr += \ shares_str += \
' <input type="hidden" name="actor" value="' + actor + '">\n' ' <input type="hidden" name="actor" value="' + actor + '">\n'
sharesStr += ' <input type="hidden" name="itemID" value="' + \ shares_str += ' <input type="hidden" name="itemID" value="' + \
itemID + '">\n' item_id + '">\n'
sharesStr += \ shares_str += \
' <button type="submit" class="button" name="submitYes">' + \ ' <button type="submit" class="button" name="submitYes">' + \
translate['Yes'] + '</button>\n' translate['Yes'] + '</button>\n'
sharesStr += \ shares_str += \
' <a href="' + actor + '/inbox' + '"><button class="button">' + \ ' <a href="' + actor + '/inbox' + '"><button class="button">' + \
translate['No'] + '</button></a>\n' translate['No'] + '</button></a>\n'
sharesStr += ' </form>\n' shares_str += ' </form>\n'
sharesStr += ' </center>\n' shares_str += ' </center>\n'
sharesStr += ' </div>\n' shares_str += ' </div>\n'
sharesStr += '</div>\n' shares_str += '</div>\n'
sharesStr += html_footer() shares_str += html_footer()
return sharesStr return shares_str
def html_confirm_follow(css_cache: {}, translate: {}, base_dir: str, def html_confirm_follow(css_cache: {}, translate: {}, base_dir: str,
originPathStr: str, origin_path_str: str,
followActor: str, follow_actor: str,
followProfileUrl: str) -> str: follow_profile_url: str) -> str:
"""Asks to confirm a follow """Asks to confirm a follow
""" """
followDomain, port = get_domain_from_actor(followActor) follow_domain, _ = get_domain_from_actor(follow_actor)
if os.path.isfile(base_dir + '/accounts/follow-background-custom.jpg'): if os.path.isfile(base_dir + '/accounts/follow-background-custom.jpg'):
if not os.path.isfile(base_dir + '/accounts/follow-background.jpg'): if not os.path.isfile(base_dir + '/accounts/follow-background.jpg'):
@ -193,42 +193,44 @@ def html_confirm_follow(css_cache: {}, translate: {}, base_dir: str,
if os.path.isfile(base_dir + '/follow.css'): if os.path.isfile(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css' css_filename = base_dir + '/follow.css'
instanceTitle = get_config_param(base_dir, 'instanceTitle') instance_title = get_config_param(base_dir, 'instanceTitle')
followStr = html_header_with_external_style(css_filename, follow_str = html_header_with_external_style(css_filename,
instanceTitle, None) instance_title, None)
followStr += '<div class="follow">\n' follow_str += '<div class="follow">\n'
followStr += ' <div class="followAvatar">\n' follow_str += ' <div class="followAvatar">\n'
followStr += ' <center>\n' follow_str += ' <center>\n'
followStr += ' <a href="' + followActor + '">\n' follow_str += ' <a href="' + follow_actor + '">\n'
followStr += ' <img loading="lazy" src="' + followProfileUrl + '"/></a>\n' follow_str += \
followStr += \ ' <img loading="lazy" src="' + follow_profile_url + '"/></a>\n'
follow_str += \
' <p class="followText">' + translate['Follow'] + ' ' + \ ' <p class="followText">' + translate['Follow'] + ' ' + \
get_nickname_from_actor(followActor) + '@' + followDomain + ' ?</p>\n' get_nickname_from_actor(follow_actor) + \
followStr += ' <form method="POST" action="' + \ '@' + follow_domain + ' ?</p>\n'
originPathStr + '/followconfirm">\n' follow_str += ' <form method="POST" action="' + \
followStr += ' <input type="hidden" name="actor" value="' + \ origin_path_str + '/followconfirm">\n'
followActor + '">\n' follow_str += ' <input type="hidden" name="actor" value="' + \
followStr += \ follow_actor + '">\n'
follow_str += \
' <button type="submit" class="button" name="submitYes">' + \ ' <button type="submit" class="button" name="submitYes">' + \
translate['Yes'] + '</button>\n' translate['Yes'] + '</button>\n'
followStr += \ follow_str += \
' <a href="' + originPathStr + '"><button class="button">' + \ ' <a href="' + origin_path_str + '"><button class="button">' + \
translate['No'] + '</button></a>\n' translate['No'] + '</button></a>\n'
followStr += ' </form>\n' follow_str += ' </form>\n'
followStr += '</center>\n' follow_str += '</center>\n'
followStr += '</div>\n' follow_str += '</div>\n'
followStr += '</div>\n' follow_str += '</div>\n'
followStr += html_footer() follow_str += html_footer()
return followStr return follow_str
def html_confirm_unfollow(css_cache: {}, translate: {}, base_dir: str, def html_confirm_unfollow(css_cache: {}, translate: {}, base_dir: str,
originPathStr: str, origin_path_str: str,
followActor: str, follow_actor: str,
followProfileUrl: str) -> str: follow_profile_url: str) -> str:
"""Asks to confirm unfollowing an actor """Asks to confirm unfollowing an actor
""" """
followDomain, port = get_domain_from_actor(followActor) follow_domain, _ = get_domain_from_actor(follow_actor)
if os.path.isfile(base_dir + '/accounts/follow-background-custom.jpg'): if os.path.isfile(base_dir + '/accounts/follow-background-custom.jpg'):
if not os.path.isfile(base_dir + '/accounts/follow-background.jpg'): if not os.path.isfile(base_dir + '/accounts/follow-background.jpg'):
@ -239,43 +241,44 @@ def html_confirm_unfollow(css_cache: {}, translate: {}, base_dir: str,
if os.path.isfile(base_dir + '/follow.css'): if os.path.isfile(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css' css_filename = base_dir + '/follow.css'
instanceTitle = get_config_param(base_dir, 'instanceTitle') instance_title = get_config_param(base_dir, 'instanceTitle')
followStr = html_header_with_external_style(css_filename, follow_str = html_header_with_external_style(css_filename,
instanceTitle, None) instance_title, None)
followStr += '<div class="follow">\n' follow_str += '<div class="follow">\n'
followStr += ' <div class="followAvatar">\n' follow_str += ' <div class="followAvatar">\n'
followStr += ' <center>\n' follow_str += ' <center>\n'
followStr += ' <a href="' + followActor + '">\n' follow_str += ' <a href="' + follow_actor + '">\n'
followStr += ' <img loading="lazy" src="' + followProfileUrl + '"/></a>\n' follow_str += \
followStr += \ ' <img loading="lazy" src="' + follow_profile_url + '"/></a>\n'
follow_str += \
' <p class="followText">' + translate['Stop following'] + \ ' <p class="followText">' + translate['Stop following'] + \
' ' + get_nickname_from_actor(followActor) + \ ' ' + get_nickname_from_actor(follow_actor) + \
'@' + followDomain + ' ?</p>\n' '@' + follow_domain + ' ?</p>\n'
followStr += ' <form method="POST" action="' + \ follow_str += ' <form method="POST" action="' + \
originPathStr + '/unfollowconfirm">\n' origin_path_str + '/unfollowconfirm">\n'
followStr += ' <input type="hidden" name="actor" value="' + \ follow_str += ' <input type="hidden" name="actor" value="' + \
followActor + '">\n' follow_actor + '">\n'
followStr += \ follow_str += \
' <button type="submit" class="button" name="submitYes">' + \ ' <button type="submit" class="button" name="submitYes">' + \
translate['Yes'] + '</button>\n' translate['Yes'] + '</button>\n'
followStr += \ follow_str += \
' <a href="' + originPathStr + '"><button class="button">' + \ ' <a href="' + origin_path_str + '"><button class="button">' + \
translate['No'] + '</button></a>\n' translate['No'] + '</button></a>\n'
followStr += ' </form>\n' follow_str += ' </form>\n'
followStr += '</center>\n' follow_str += '</center>\n'
followStr += '</div>\n' follow_str += '</div>\n'
followStr += '</div>\n' follow_str += '</div>\n'
followStr += html_footer() follow_str += html_footer()
return followStr return follow_str
def html_confirm_unblock(css_cache: {}, translate: {}, base_dir: str, def html_confirm_unblock(css_cache: {}, translate: {}, base_dir: str,
originPathStr: str, origin_path_str: str,
blockActor: str, block_actor: str,
blockProfileUrl: str) -> str: block_profile_url: str) -> str:
"""Asks to confirm unblocking an actor """Asks to confirm unblocking an actor
""" """
blockDomain, port = get_domain_from_actor(blockActor) block_domain, _ = get_domain_from_actor(block_actor)
set_custom_background(base_dir, 'block-background', 'follow-background') set_custom_background(base_dir, 'block-background', 'follow-background')
@ -283,30 +286,31 @@ def html_confirm_unblock(css_cache: {}, translate: {}, base_dir: str,
if os.path.isfile(base_dir + '/follow.css'): if os.path.isfile(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css' css_filename = base_dir + '/follow.css'
instanceTitle = get_config_param(base_dir, 'instanceTitle') instance_title = get_config_param(base_dir, 'instanceTitle')
blockStr = html_header_with_external_style(css_filename, block_str = html_header_with_external_style(css_filename,
instanceTitle, None) instance_title, None)
blockStr += '<div class="block">\n' block_str += '<div class="block">\n'
blockStr += ' <div class="blockAvatar">\n' block_str += ' <div class="blockAvatar">\n'
blockStr += ' <center>\n' block_str += ' <center>\n'
blockStr += ' <a href="' + blockActor + '">\n' block_str += ' <a href="' + block_actor + '">\n'
blockStr += ' <img loading="lazy" src="' + blockProfileUrl + '"/></a>\n' block_str += \
blockStr += \ ' <img loading="lazy" src="' + block_profile_url + '"/></a>\n'
block_str += \
' <p class="blockText">' + translate['Stop blocking'] + ' ' + \ ' <p class="blockText">' + translate['Stop blocking'] + ' ' + \
get_nickname_from_actor(blockActor) + '@' + blockDomain + ' ?</p>\n' get_nickname_from_actor(block_actor) + '@' + block_domain + ' ?</p>\n'
blockStr += ' <form method="POST" action="' + \ block_str += ' <form method="POST" action="' + \
originPathStr + '/unblockconfirm">\n' origin_path_str + '/unblockconfirm">\n'
blockStr += ' <input type="hidden" name="actor" value="' + \ block_str += ' <input type="hidden" name="actor" value="' + \
blockActor + '">\n' block_actor + '">\n'
blockStr += \ block_str += \
' <button type="submit" class="button" name="submitYes">' + \ ' <button type="submit" class="button" name="submitYes">' + \
translate['Yes'] + '</button>\n' translate['Yes'] + '</button>\n'
blockStr += \ block_str += \
' <a href="' + originPathStr + '"><button class="button">' + \ ' <a href="' + origin_path_str + '"><button class="button">' + \
translate['No'] + '</button></a>\n' translate['No'] + '</button></a>\n'
blockStr += ' </form>\n' block_str += ' </form>\n'
blockStr += '</center>\n' block_str += '</center>\n'
blockStr += '</div>\n' block_str += '</div>\n'
blockStr += '</div>\n' block_str += '</div>\n'
blockStr += html_footer() block_str += html_footer()
return blockStr return block_str

View File

@ -1500,7 +1500,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
announceJsonObject = None announceJsonObject = None
if post_json_object['type'] == 'Announce': if post_json_object['type'] == 'Announce':
announceJsonObject = post_json_object.copy() announceJsonObject = post_json_object.copy()
blockedCache = {} blocked_cache = {}
post_jsonAnnounce = \ post_jsonAnnounce = \
download_announce(session, base_dir, http_prefix, download_announce(session, base_dir, http_prefix,
nickname, domain, post_json_object, nickname, domain, post_json_object,
@ -1512,7 +1512,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
system_language, system_language,
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blockedCache) blocked_cache)
if not post_jsonAnnounce: if not post_jsonAnnounce:
# if the announce could not be downloaded then mark it as rejected # if the announce could not be downloaded then mark it as rejected
announcedPostId = remove_id_ending(post_json_object['id']) announcedPostId = remove_id_ending(post_json_object['id'])