From acb6e94ae137208934699f03d90180689d8cd4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Fri, 23 Jun 2023 18:01:56 +0300 Subject: [PATCH 1/1] Improvements to comment view layout and functionality * Begin with a "Re:" link. * Harmonize metadata presentation vs. a top-level post. * Show per-post notifications. * Show only later Git commits in the thread. * "Original Post" is shown at the bottom always. --- 50_bubble.py | 2 +- feeds.py | 44 +++++++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/50_bubble.py b/50_bubble.py index 7527a20..64bc77b 100644 --- a/50_bubble.py +++ b/50_bubble.py @@ -356,7 +356,7 @@ Bubble is open source: else: total_votes_msg = f'{total_votes} vote{plural_s(total_votes)} {("was" if total_votes==1 else "were") if show_results else ("have been" if total_votes != 1 else "has been")} cast.\n' - src = '## Poll Results\n' if cur_vote or show_results else '## Poll\n' + src = '## Poll Results\n\n' if cur_vote or show_results else '## Poll\n' if not show_results: if not cur_vote: src += "\nVote for an option:\n" diff --git a/feeds.py b/feeds.py index 2e2e153..d2e87a9 100644 --- a/feeds.py +++ b/feeds.py @@ -219,6 +219,9 @@ def make_post_page_or_configure_feed(session): def make_post_page(session, post): + """Page containing a post and its discussion thread. If `post` is a comment, a partial + discussion thread is shown.""" + db = session.db user = session.user post_id = post.id @@ -234,15 +237,17 @@ def make_post_page(session, post): post_id = post.parent post = db.get_post(id=post_id) if post: - page += f'=> {post.page_url()} Comment on: "{post.title if post.title else shorten_text(strip_links(clean_title(post.summary)), 60)}" in {("u/" if post.sub_owner else "s/") + post.sub_name}\n' + page += f'=> {post.page_url()} Re: "{post.title if post.title else shorten_text(strip_links(clean_title(post.summary)), 60)}"\n' + sub_name = ("u/" if post.sub_owner else "s/") + post.sub_name + page += f'=> /{sub_name} Comment in: {sub_name}\n\n' else: if not session.user or session.user.id != focused_cmt.user: # Can't view others' comments on deleted posts, just your own. return 51, 'Not found' - page += f'=> /help/deleted-post ๐Ÿ”’ Comment on a deleted post (ID:{post_id})\n' - page += f'=> /u/{focused_cmt.poster_name} {focused_cmt.poster_avatar} {focused_cmt.poster_name}\n' - page += f'{last_age}\n\n' + page += f'=> /help/deleted-post ๐Ÿ”’ Comment on a deleted post (ID:{post_id})\n\n' page += session.render_post(focused_cmt) + page += f'\n=> /u/{focused_cmt.poster_name} {focused_cmt.poster_avatar} {focused_cmt.poster_name}\n' + page += f'{last_age}\n' # Comment actions. actions = [] @@ -255,19 +260,17 @@ def make_post_page(session, post): actions.append(f'=> /thanks/{focused_cmt.id} ๐Ÿ™ Give thanks\n') if session.is_deletable(focused_cmt) and (not session.is_editable(focused_cmt) or not post): actions.append(f'=> /edit/{focused_cmt.id}/delete/{session.get_token()} โŒ Delete comment\n') - actions.append(session.dashboard_link()) +# actions.append(session.dashboard_link()) if actions: - page += '\n' + ''.join(actions) + page += '\n## Actions\n' + ''.join(actions) + page += '\n' + session.dashboard_link() if post: op_section = '\n## Original Post\n\n' + session.feed_entry(post) else: op_section = '' - if not display_order_desc: - page += op_section - else: page += session.render_post(post) @@ -401,14 +404,16 @@ def make_post_page(session, post): page += '\n' + session.dashboard_link() - notifs = db.get_notifications(user=user, post_id=post.id, sort_desc=True) - if notifs: - page += f'{len(notifs)} notification{plural_s(len(notifs))} on this page:\n' - for notif in notifs: - link, label = notif.entry(with_title=False) - page += f'=> {link} {label}\n' - if len(notifs) > 1: - page += f'=> {post.page_url()}/clear-notif/{session.get_token()} ๐Ÿงน Clear\n' + # Notification on this page. + if post: + notifs = db.get_notifications(user=user, post_id=post.id, sort_desc=True) + if notifs: + page += f'{len(notifs)} notification{plural_s(len(notifs))} about this post:\n' + for notif in notifs: + link, label = notif.entry(with_title=False) + page += f'=> {link} {label}\n' + if len(notifs) > 1: + page += f'=> {post.page_url()}/clear-notif/{session.get_token()} ๐Ÿงน Clear\n' # Comments, repository commits, and issue cross-references. comments = db.get_posts(parent=post_id, @@ -446,7 +451,8 @@ def make_post_page(session, post): # Commits are shown as links to the Git viewer. if isinstance(cmt, Commit): - rendered_comments.append(cmt.entry(repo.view_url)) + if not focused_cmt or cmt.ts > focused_cmt.ts_created: + rendered_comments.append(cmt.entry(repo.view_url)) continue # Cross-references incoming from other issues. @@ -497,7 +503,7 @@ def make_post_page(session, post): for rendered in rendered_comments: page += '\n' + rendered - if is_comment_page and display_order_desc: + if is_comment_page: page += op_section # Show the Comment action at the appropriate place wrt reading direction. -- 2.34.1