Conversation view by non-authorized viewers

main
Bob Mottram 2023-03-01 14:34:41 +00:00
parent a7c0e187b5
commit f076bf3d05
4 changed files with 29 additions and 13 deletions

View File

@ -109,7 +109,8 @@ def unmute_conversation(base_dir: str, nickname: str, domain: str,
conversation_filename + '.muted')
def download_conversation_posts(session, http_prefix: str, base_dir: str,
def download_conversation_posts(authorized: bool, session,
http_prefix: str, base_dir: str,
nickname: str, domain: str,
post_id: str, debug: bool) -> []:
"""Downloads all posts for a conversation and returns a list of the
@ -126,13 +127,15 @@ def download_conversation_posts(session, http_prefix: str, base_dir: str,
post_id = remove_id_ending(post_id)
post_filename = \
locate_post(base_dir, nickname, domain, post_id)
post_json_object = None
if post_filename:
post_json_object = load_json(post_filename)
else:
post_json_object = \
get_json(signing_priv_key_pem, session, post_id,
as_header, None, debug, __version__,
http_prefix, domain)
if authorized:
post_json_object = \
get_json(signing_priv_key_pem, session, post_id,
as_header, None, debug, __version__,
http_prefix, domain)
if debug:
if not post_json_object:
print(post_id + ' returned no json')
@ -181,6 +184,9 @@ def download_conversation_posts(session, http_prefix: str, base_dir: str,
harmless_markup(post_json_object)
conversation_view = [post_json_object] + conversation_view
if not authorized:
# only show a single post to non-authorized viewers
break
if not post_json_object['object'].get('inReplyTo'):
if debug:
print(post_id + ' is not a reply')
@ -189,13 +195,15 @@ def download_conversation_posts(session, http_prefix: str, base_dir: str,
post_id = remove_id_ending(post_id)
post_filename = \
locate_post(base_dir, nickname, domain, post_id)
post_json_object = None
if post_filename:
post_json_object = load_json(post_filename)
else:
post_json_object = \
get_json(signing_priv_key_pem, session, post_id,
as_header, None, debug, __version__,
http_prefix, domain)
if authorized:
post_json_object = \
get_json(signing_priv_key_pem, session, post_id,
as_header, None, debug, __version__,
http_prefix, domain)
if debug:
if not post_json_object:
print(post_id + ' returned no json')

View File

@ -12330,7 +12330,8 @@ class PubServer(BaseHTTPRequestHandler):
if self.server.bold_reading.get(nickname):
bold_reading = True
conv_str = \
html_conversation_view(post_id, self.server.translate,
html_conversation_view(authorized,
post_id, self.server.translate,
base_dir,
http_prefix,
nickname,

View File

@ -1181,7 +1181,7 @@ def _command_options() -> None:
if not nickname:
print('Please specify a nickname with the --nickname option')
sys.exit()
conv_json = download_conversation_posts(session, http_prefix,
conv_json = download_conversation_posts(True, session, http_prefix,
base_dir, nickname, domain,
post_id, argb.debug)
if conv_json:

View File

@ -13,6 +13,7 @@ from conversation import download_conversation_posts
from utils import get_config_param
from utils import get_nickname_from_actor
from utils import get_domain_from_actor
from utils import is_public_post
from blocking import is_blocked
from webapp_utils import html_header_with_external_style
from webapp_utils import html_post_separator
@ -20,7 +21,7 @@ from webapp_utils import html_footer
from webapp_post import individual_post_as_html
def html_conversation_view(post_id: str,
def html_conversation_view(authorized: bool, post_id: str,
translate: {}, base_dir: str,
http_prefix: str,
nickname: str, domain: str,
@ -50,7 +51,8 @@ def html_conversation_view(post_id: str,
"""Show a page containing a conversation thread
"""
conv_posts = \
download_conversation_posts(session, http_prefix, base_dir,
download_conversation_posts(authorized,
session, http_prefix, base_dir,
nickname, domain,
post_id, debug)
@ -74,6 +76,11 @@ def html_conversation_view(post_id: str,
minimize_all_images = True
for post_json_object in conv_posts:
show_individual_post_icons = True
# if not authorized then only show public posts
if not authorized:
show_individual_post_icons = False
if not is_public_post(post_json_object):
continue
from_actor = post_json_object['object']['attributedTo']
from_nickname = get_nickname_from_actor(from_actor)
from_domain, _ = get_domain_from_actor(from_actor)