Merge pull request 'Cleanup: Replace macro render_comment [feedback requested]' (#376) from h3ndrik/pyfedi:render_comment2 into main

Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/376
This commit is contained in:
rimu 2024-12-07 04:59:16 +00:00
commit 9dd17f62d2
7 changed files with 40 additions and 139 deletions

View file

@ -1344,6 +1344,7 @@ time {
.comment {
clear: both;
margin-left: 15px;
padding-left: 0px;
padding-top: 8px;
}
.comment .limit_height {

View file

@ -998,6 +998,7 @@ time {
.comment {
clear: both;
margin-left: 15px;
padding-left: 0px;
padding-top: 8px;
.limit_height {

View file

@ -33,7 +33,7 @@
<h2 class="mt-4" id="comments">Deleted comments</h2>
<div class="post_list">
{% for post_reply in post_replies.items %}
{% with teaser=True, disable_voting=True, no_collapse=True %}
{% with teaser=True, disable_voting=True, no_collapse=True, show_deleted=True %}
{% include 'post/_post_reply_teaser.html' %}
{% endwith %}
<hr />

View file

@ -19,7 +19,7 @@
<h2 class="mt-4" id="comments">Downvoted comments</h2>
<div class="post_list">
{% for post_reply in post_replies.items %}
{% with teaser=True, disable_voting=True, no_collapse=True %}
{% with teaser=True, disable_voting=True, no_collapse=True, show_deleted=True %}
{% include 'post/_post_reply_teaser.html' %}
{% endwith %}
<hr />

View file

@ -2,6 +2,8 @@
teaser: Renders just a teaser
disable_voting: Disable voting buttons (to prevent mass downvoting)
no_collapse: Don't collapse for admin and moderator views
show_deleted: Show deleted content (for admin views)
children: replies to this reply
#}
{% if current_user.is_authenticated -%}
{% set collapsed = ((post_reply.score <= current_user.reply_collapse_threshold) or post_reply.deleted)
@ -9,7 +11,7 @@
{% else -%}
{% set collapsed = (post_reply.score <= -10) and not no_collapse -%}
{% endif -%}
<div class="container comment{% if post_reply.score <= -10 %} low_score{% endif %}" id="comment_{{ post_reply.id }}">
<div class="container comment{% if post_reply.score and post_reply.score <= -10 %} low_score{% endif %}{% if post_reply.author.id == post_reply.post.author.id %} original_poster{% endif %}" id="comment_{{ post_reply.id }}"{% if post_reply.language_id and post_reply.language.code != 'en' %} lang="{{ post_reply.language.code }}"{% endif %} aria-level="{{ post_reply.depth+1 }}" role="treeitem">
{% if not post_reply.author.indexable -%}<!--googleoff: all-->{% endif -%}
{% if teaser -%}
<div class="row">
@ -52,7 +54,15 @@
<div class="row comment_body hidable{% if post_reply.reports and current_user.is_authenticated and post_reply.post.community.is_moderator(current_user) %} reported{% endif %}">
<div class="col-12">
{{ post_reply.body_html | community_links | safe }}
{% if post_reply.deleted and not show_deleted -%}
{% if post_reply.deleted_by is none or post_reply.deleted_by != post_reply.user_id -%}
<p>Deleted by moderator</p>
{% else -%}
<p>Deleted by author</p>
{% endif -%}
{% else -%}
{{ post_reply.body_html | community_links | safe }}
{% endif -%}
</div>
</div>
<div class="comment_actions hidable">
@ -76,7 +86,7 @@
{% endif -%}
</div>
<div class="notify_toggle">
{% if current_user.is_authenticated -%}
{% if current_user.is_authenticated and current_user.verified -%}
{% with comment=dict(comment=post_reply) -%}
{% include "post/_reply_notification_toggle.html" -%}
{% endwith -%}
@ -87,6 +97,23 @@
{% endif -%}
</div>
{% if not post_reply.author.indexable -%}<!--googleon all-->{% endif -%}
{% if children -%}
<div class="replies hidable" role="group">
{% if not THREAD_CUTOFF_DEPTH or post_reply.depth <= THREAD_CUTOFF_DEPTH -%}
{% for reply in children -%}
{% with post_reply=reply['comment'], children=reply['replies'] %}
{% include 'post/_post_reply_teaser.html' %}
{% endwith %}
{% endfor -%}
{% else -%}
<div class="continue_thread hidable">
<a href="{{ url_for('post.continue_discussion', post_id=post_reply.post.id, comment_id=post_reply.id, _anchor='replies') }}">Continue thread</a>
</div>
{% endif -%}
</div>
{% endif -%}
{% if collapsed -%}
<script nonce="{{ session['nonce'] }}" type="text/javascript">
if (typeof(toBeHidden) === 'undefined') {

View file

@ -12,68 +12,11 @@
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id, _anchor='replies') }}">Back to main discussion</a></p>
<div class="row post_replies">
<div class="col">
{% macro render_comment(comment) %}
<div id="comment_{{ comment['comment'].id }}" class="comment {% if comment['comment'].author.id == post.author.id %}original_poster{% endif %}" role="treeitem"
{% if comment['comment'].language_id and comment['comment'].language.code != 'en' %} lang="{{ comment['comment'].language.code }}"{% endif %}>
<div class="limit_height">
<div class="comment_author">
{% with collapsed = comment['comment'].score < -10 -%}
{{ render_username(comment['comment'].author) }}
{% endwith -%}
{% if comment['comment'].author.id == post.author.id %}<span title="Submitter of original post" aria-label="submitter" class="small">[OP] </span>{% endif %}
<span class="text-muted small">{{ comment['comment'].posted_at_localized(locale) }}{% if comment['comment'].edited_at %}, edited {{ arrow.get(comment['comment'].edited_at).humanize(locale=locale) }} {% endif %}</span>
<a class="unhide" href="#"><span class="fe fe-expand"></span></a>
{% if comment['comment'].reports and current_user.is_authenticated and post.community.is_moderator(current_user)%}
<span class="red fe fe-report" title="{{ _('Reported. Check comment for issues.') }}"></span>
{% endif %}
</div>
<div class="comment_body hidable {% if comment['comment'].reports and current_user.is_authenticated and post.community.is_moderator(current_user) %}reported{% endif %}">
{% if comment['comment'].deleted -%}
{% if comment['comment'].deleted_by is none or comment['comment'].deleted_by != comment['comment'].user_id -%}
<p>Deleted by moderator</p>
{% else -%}
<p>Deleted by author</p>
{% endif -%}
{% else -%}
{{ comment['comment'].body_html | community_links | safe }}
{% endif -%}
</div>
</div>
<div class="comment_actions hidable">
{% if post.comments_enabled %}
<a href="{{ url_for('post.add_reply', post_id=post.id, comment_id=comment['comment'].id) }}" rel="nofollow"><span class="fe fe-reply"></span> reply</a>
{% endif %}
<div class="voting_buttons_new">
{% with comment=comment['comment'] %}
{% include "post/_comment_voting_buttons.html" %}
{% endwith %}
</div>
<div class="hide_button">
{% if comment['comment'].score <= -10 %}
<a href='#'><span class="fe fe-expand"></span></a>
{% else %}
<a href='#'><span class="fe fe-collapse"></span></a>
{% endif %}
</div>
<div class="notify_toggle">
{% if current_user.is_authenticated and current_user.verified and current_user.id == comment['comment'].author.id %}
{% include "post/_reply_notification_toggle.html" %}
{% endif %}
</div>
<a href="{{ url_for('post.post_reply_options', post_id=post.id, comment_id=comment['comment'].id) }}" class="comment_actions_link" rel="nofollow"><span class="fe fe-options" title="Options"> </span></a>
</div>
{% if comment['replies'] %}
<div class="replies hidable" role="group">
{% for reply in comment['replies'] %}
{{ render_comment(reply) | safe }}
{% endfor %}
</div>
{% endif %}
</div>
{% endmacro %}
<div id="replies" class="comments" role="tree">
{% for reply in replies %}
{{ render_comment(reply) | safe }}
{% with post_reply=reply['comment'], children=reply['replies'] %}
{% include 'post/_post_reply_teaser.html' %}
{% endwith %}
{% endfor %}
</div>
</div>

View file

@ -73,83 +73,12 @@
{{ _('New') }}
</a>
</div>
{% macro render_comment(comment) -%}
<div id="comment_{{ comment['comment'].id }}" class="comment {% if comment['comment'].score <= -10 -%}low_score{% endif -%}
{% if comment['comment'].author.id == post.author.id -%}original_poster{% endif -%}"
{% if comment['comment'].language_id and comment['comment'].language.code != 'en' -%} lang="{{ comment['comment'].language.code }}"{% endif %}
aria-level="{{ comment['comment'].depth + 1 }}" role="treeitem" aria-expanded="true" tabindex="0">
<div class="limit_height">{% if not comment['comment'].author.indexable -%}<!--googleoff: all-->{% endif -%}
<div class="comment_author">
{% with collapsed = (comment['comment'].score < reply_collapse_threshold or comment['comment'].deleted) -%}
{{ render_username(comment['comment'].author) }}
{% endwith -%}
{% if comment['comment'].author.id == post.author.id -%}<span title="Submitter of original post" aria-label="{{ _('Post creator') }}" class="small">[OP] </span>{% endif -%}
<a href="#comment_{{ comment['comment'].id }}" class="text-muted small" aria_label="{{ _('When: ') }}">{{ comment['comment'].posted_at_localized(locale) }}{% if comment['comment'].edited_at -%}, edited {{ arrow.get(comment['comment'].edited_at).humanize(locale=locale) }} {% endif -%}</a>
<a class="unhide" href="#"><span class="fe fe-expand"></span></a>
{% if comment['comment'].reports and current_user.is_authenticated and post.community.is_moderator(current_user)%}
<span class="red fe fe-report" title="{{ _('Reported. Check comment for issues.') }}"></span>
{% endif -%}
</div>
<div class="comment_body hidable {% if comment['comment'].reports and current_user.is_authenticated and post.community.is_moderator(current_user) -%}reported{% endif -%}">
{% if comment['comment'].deleted -%}
{% if comment['comment'].deleted_by is none or comment['comment'].deleted_by != comment['comment'].user_id -%}
<p>Deleted by moderator</p>
{% else -%}
<p>Deleted by author</p>
{% endif -%}
{% else -%}
{{ comment['comment'].body_html | community_links | safe }}
{% endif -%}
</div>{% if not comment['comment'].author.indexable -%}<!--googleon: all-->{% endif -%}
</div>
<div class="comment_actions hidable">
{% if post.comments_enabled -%}
<a href="{{ url_for('post.add_reply', post_id=post.id, comment_id=comment['comment'].id) }}" rel="nofollow noindex"><span class="fe fe-reply"></span> reply</a>
{% endif -%}
<div class="voting_buttons_new">
{% with comment=comment['comment'] -%}
{% include "post/_comment_voting_buttons.html" -%}
{% endwith -%}
</div>
<div class="hide_button">
{% if comment['comment'].score <= reply_collapse_threshold or comment['comment'].deleted -%}
<a href='#'><span class="fe fe-expand"></span></a>
{% else -%}
<a href='#'><span class="fe fe-collapse"></span></a>
{% endif -%}
</div>
<div class="notify_toggle">
{% if current_user.is_authenticated and current_user.verified -%}
{% include "post/_reply_notification_toggle.html" -%}
{% endif -%}
</div>
<a href="{{ url_for('post.post_reply_options', post_id=post.id, comment_id=comment['comment'].id) }}" class="comment_actions_link" rel="nofollow noindex" aria-label="{{ _('Comment options') }}"><span class="fe fe-options" title="Options"> </span></a>
</div>
{% if comment['replies'] -%}
{% if comment['comment'].depth <= THREAD_CUTOFF_DEPTH -%}
<div class="replies hidable" role="group">
{% for reply in comment['replies'] -%}
{{ render_comment(reply) | safe }}
{% endfor -%}
</div>
{% else -%}
<div class="continue_thread hidable">
<a href="{{ url_for('post.continue_discussion', post_id=post.id, comment_id=comment['comment'].id, _anchor='replies') }}">
Continue thread</a>
</div>
{% endif -%}
{% endif -%}
</div>
{% if comment['comment'].score <= reply_collapse_threshold or comment['comment'].deleted -%}
<script nonce="{{ session['nonce'] }}" type="text/javascript">
toBeHidden.push({{ comment['comment'].id }});
</script>
{% endif -%}
{% endmacro -%}
<div id="replies" class="comments" role="tree" aria-label="{{ _('Comments') }}" aria-expanded="true">
{% for reply in replies -%}
{{ render_comment(reply) | safe }}
{% with post_reply=reply['comment'], children=reply['replies'] %}
{% include 'post/_post_reply_teaser.html' %}
{% endwith %}
{% endfor -%}
</div>
</div>