{% macro comments_input(category, user, reply_to) %} {% set reply_mode = reply_to is not null %} {% from 'macros.twig' import avatar %} {% from '_layout/input.twig' import input_hidden, input_csrf, input_checkbox %}
{{ input_hidden('comment[category]', category.id) }} {{ input_csrf() }} {% if reply_mode %} {{ input_hidden('comment[reply]', reply_to.id) }} {% endif %}
{{ avatar(user.id, reply_mode ? 40 : 50, user.username) }}
{% if not reply_mode %} {% if user.commentPerms.can_pin|default(false) %} {{ input_checkbox('comment[pin]', 'Pin this comment', false, 'comment__action') }} {% endif %} {% if user.commentPerms.can_lock|default(false) %} {{ input_checkbox('comment[lock]', 'Toggle locked status', false, 'comment__action') }} {% endif %} {% endif %}
{% endmacro %} {% macro comments_entry(comment, indent, category, user) %} {% from 'macros.twig' import avatar %} {% from '_layout/input.twig' import input_checkbox_raw %} {% set hide_details = comment.userId < 1 or comment.deleted and not user.commentPerms.can_delete_any|default(false) %} {% if user.commentPerms.can_delete_any|default(false) or (not comment.deleted or comment.replies(user)|length > 0) %}
{% if hide_details %}
{{ avatar(0, indent > 1 ? 40 : 50) }}
{% else %} {{ avatar(comment.user.id, indent > 1 ? 40 : 50, comment.user.username) }} {% endif %}
{% if not hide_details %} {{ comment.user.username }} {% endif %} {% if comment.pinned %} {% apply spaceless %} Pinned {% if comment.pinnedTime != comment.createdTime %} {% endif %} {% endapply %} {% endif %}
{{ hide_details ? '(deleted)' : comment.parsedText|raw }}
{% if not comment.deleted and user is not null %} {% if user.commentPerms.can_vote|default(false) %} {% set like_vote_state = comment.userVote > 0 ? 0 : 1 %} {% set dislike_vote_state = comment.userVote < 0 ? 0 : -1 %} Like {% if comment.likes > 0 %} ({{ comment.likes|number_format }}) {% endif %} Dislike {% if comment.dislikes > 0 %} ({{ comment.dislikes|number_format }}) {% endif %} {% endif %} {% if user.commentPerms.can_comment|default(false) %} {% endif %} {% if user.commentPerms.can_delete_any|default(false) or (comment.user.id|default(0) == user.id and user.commentPerms.can_delete|default(false)) %} Delete {% endif %} {# if user is not null %} Report {% endif #} {% if not comment.hasParent and user.commentPerms.can_pin|default(false) %} {{ comment.pinned ? 'Unpin' : 'Pin' }} {% endif %} {% elseif user.commentPerms.can_delete_any|default(false) %} Restore {% endif %}
{% from _self import comments_entry, comments_input %} {% if user|default(null) is not null and category|default(null) is not null and user.commentPerms.can_comment|default(false) %} {{ input_checkbox_raw('', false, 'comment__reply-toggle', '', false, {'id':'comment-reply-toggle-' ~ comment.id}) }} {{ comments_input(category, user, comment) }} {% endif %} {% if comment.replies|length > 0 %} {% for reply in comment.replies %} {{ comments_entry(reply, indent + 1, category, user) }} {% endfor %} {% endif %}
{% endif %} {% endmacro %} {% macro comments_section(category, user) %}
{% if user|default(null) is null %}
Please login to comment.
{% elseif category|default(null) is null %}
Posting new comments here is disabled.
{% elseif not user.commentPerms.can_lock|default(false) and category.locked %}
This comment section was locked, .
{% elseif not user.commentPerms.can_comment|default(false) %}
You are not allowed to post comments.
{% else %} {% from _self import comments_input %} {{ comments_input(category, user) }} {% endif %}
{% if user.commentPerms.can_lock|default(false) and category.locked %}
This comment section was locked, .
{% endif %} {##}
{% if category.posts|length > 0 %} {% from _self import comments_entry %} {% for comment in category.posts(user) %} {{ comments_entry(comment, 1, category, user) }} {% endfor %} {% else %}
There are no comments yet.
{% endif %}
{% endmacro %}