2023-08-31 14:39:50 +00:00
{% macro comments_input ( category , user , perms , reply_to , return_url ) %}
2022-09-13 13:14:49 +00:00
{% set reply_mode = reply_to is not null %}
{% from 'macros.twig' import avatar %}
{% from '_layout/input.twig' import input_hidden , input_csrf , input_checkbox %}
<form class="comment comment--input {% if reply_mode %} comment--reply {% endif %} "
2023-08-31 14:39:50 +00:00
method="post" action=" {{ url ( 'comment-create' , { 'return' : return_url } ) }} "
2022-09-13 13:14:49 +00:00
id="comment- {{ reply_mode ? 'reply-' ~ reply_to .id : 'create-' ~ category .id }} ">
{{ input_hidden ( 'comment[category]' , category .id ) }}
{{ input_csrf ( ) }}
{% if reply_mode %}
{{ input_hidden ( 'comment[reply]' , reply_to .id ) }}
{% endif %}
<div class="comment__container">
<div class="avatar comment__avatar">
2023-08-02 22:12:47 +00:00
{{ avatar ( user .id , reply_mode ? 4 0 : 5 0 , user .name ) }}
2022-09-13 13:14:49 +00:00
</div>
<div class="comment__content">
<textarea
class="comment__text input__textarea comment__text--input"
name="comment[text]" placeholder="Share your extensive insights..."></textarea>
<div class="comment__actions">
{% if not reply_mode %}
2023-07-29 18:15:30 +00:00
{% if perms .can_pin | default ( false ) %}
2022-09-13 13:14:49 +00:00
{{ input_checkbox ( 'comment[pin]' , 'Pin this comment' , false , 'comment__action' ) }}
{% endif %}
2023-07-29 18:15:30 +00:00
{% if perms .can_lock | default ( false ) %}
2022-09-13 13:14:49 +00:00
{{ input_checkbox ( 'comment[lock]' , 'Toggle locked status' , false , 'comment__action' ) }}
{% endif %}
{% endif %}
<button class="input__button comment__action comment__action--button comment__action--post">
{{ reply_mode ? 'Reply' : 'Post' }}
</button>
</div>
</div>
</div>
</form>
{% endmacro %}
2023-08-31 14:39:50 +00:00
{% macro comments_entry ( comment , indent , category , user , colour , perms , return_url ) %}
2022-09-13 13:14:49 +00:00
{% from 'macros.twig' import avatar %}
{% from '_layout/input.twig' import input_checkbox_raw %}
2023-07-15 23:58:17 +00:00
{% set replies = comment .replies %}
{% set poster = comment .user | default ( null ) %}
{% if comment .post is defined %}
{% set userVote = comment .vote .weight %}
2023-08-28 13:33:39 +00:00
{% set commenterColour = comment .colour %}
2023-07-15 23:58:17 +00:00
{% set comment = comment .post %}
{% set body = comment .body %}
{% set likes = comment .votesPositive %}
{% set dislikes = comment .votesNegative %}
{% set isReply = comment .isReply %}
{% else %}
{% set body = comment .text %}
2023-08-28 13:33:39 +00:00
{% set commenterColour = null %}
2023-07-15 23:58:17 +00:00
{% set userVote = comment .userVote %}
{% set likes = comment .likes %}
{% set dislikes = comment .dislikes %}
{% set isReply = comment .hasParent %}
{% endif %}
2023-07-29 18:15:30 +00:00
{% set hide_details = poster is null or comment .deleted and not perms .can_delete_any | default ( false ) %}
2023-07-15 23:58:17 +00:00
2023-07-29 18:15:30 +00:00
{% if perms .can_delete_any | default ( false ) or ( not comment .deleted or replies | length > 0 ) %}
2022-09-13 13:14:49 +00:00
<div class="comment {% if comment .deleted %} comment--deleted {% endif %} " id="comment- {{ comment .id }} ">
<div class="comment__container">
{% if hide_details %}
<div class="comment__avatar">
{{ avatar ( 0 , indent > 1 ? 4 0 : 5 0 ) }}
</div>
{% else %}
2023-07-15 23:58:17 +00:00
<a class="comment__avatar" href=" {{ url ( 'user-profile' , { 'user' : poster .id } ) }} ">
2023-08-02 22:12:47 +00:00
{{ avatar ( poster .id , indent > 1 ? 4 0 : 5 0 , poster .name ) }}
2022-09-13 13:14:49 +00:00
</a>
{% endif %}
<div class="comment__content">
<div class="comment__info">
{% if not hide_details %}
<a class="comment__user comment__user--link"
2023-07-15 23:58:17 +00:00
href=" {{ url ( 'user-profile' , { 'user' : poster .id } ) }} "
2023-08-28 13:33:39 +00:00
style="--user-colour: {{ commenterColour }} "> {{ poster .name }} </a>
2022-09-13 13:14:49 +00:00
{% endif %}
<a class="comment__link" href="#comment- {{ comment .id }} ">
<time class="comment__date"
title=" {{ comment .createdTime | date ( 'r' ) }} "
datetime=" {{ comment .createdTime | date ( 'c' ) }} ">
2023-07-18 23:12:47 +00:00
{{ comment .createdTime | time_format }}
2022-09-13 13:14:49 +00:00
</time>
</a>
{% if comment .pinned %}
<span class="comment__pin"> {% apply spaceless %}
Pinned
{% if comment .pinnedTime != comment .createdTime %}
<time title=" {{ comment .pinnedTime | date ( 'r' ) }} "
datetime=" {{ comment .pinnedTime | date ( 'c' ) }} ">
2023-07-18 23:12:47 +00:00
{{ comment .pinnedTime | time_format }}
2022-09-13 13:14:49 +00:00
</time>
{% endif %}
{% endapply %} </span>
{% endif %}
</div>
<div class="comment__text">
2023-08-02 22:12:47 +00:00
{{ hide_details ? '(deleted)' : body }}
2022-09-13 13:14:49 +00:00
</div>
<div class="comment__actions">
{% if not comment .deleted and user is not null %}
2023-07-29 18:15:30 +00:00
{% if perms .can_vote | default ( false ) %}
2023-07-15 23:58:17 +00:00
{% set like_vote_state = userVote > 0 ? 0 : 1 %}
{% set dislike_vote_state = userVote < 0 ? 0 : - 1 %}
2022-09-13 13:14:49 +00:00
2023-07-15 23:58:17 +00:00
<a class="comment__action comment__action--link comment__action--vote comment__action--like {% if userVote > 0 %} comment__action--voted {% endif %} " data-comment-id=" {{ comment .id }} " data-comment-vote=" {{ like_vote_state }} "
2023-08-31 14:39:50 +00:00
href=" {{ url ( 'comment-vote' , { 'comment' : comment .id , 'vote' : like_vote_state , 'return' : return_url } ) }} ">
2022-09-13 13:14:49 +00:00
Like
2023-07-15 23:58:17 +00:00
{% if likes > 0 %}
( {{ likes | number_format }} )
2022-09-13 13:14:49 +00:00
{% endif %}
</a>
2023-07-15 23:58:17 +00:00
<a class="comment__action comment__action--link comment__action--vote comment__action--dislike {% if userVote < 0 %} comment__action--voted {% endif %} " data-comment-id=" {{ comment .id }} " data-comment-vote=" {{ dislike_vote_state }} "
2023-08-31 14:39:50 +00:00
href=" {{ url ( 'comment-vote' , { 'comment' : comment .id , 'vote' : dislike_vote_state , 'return' : return_url } ) }} ">
2022-09-13 13:14:49 +00:00
Dislike
2023-07-15 23:58:17 +00:00
{% if dislikes > 0 %}
( {{ dislikes | number_format }} )
2022-09-13 13:14:49 +00:00
{% endif %}
</a>
{% endif %}
2023-08-30 22:37:21 +00:00
{% if perms .can_post | default ( false ) %}
2022-09-13 13:14:49 +00:00
<label class="comment__action comment__action--link" for="comment-reply-toggle- {{ comment .id }} ">Reply</label>
{% endif %}
2023-07-29 18:15:30 +00:00
{% if perms .can_delete_any | default ( false ) or ( poster .id | default ( 0 ) == user .id and perms .can_delete | default ( false ) ) %}
2023-08-31 14:39:50 +00:00
<a class="comment__action comment__action--link comment__action--hide comment__action--delete" data-comment-id=" {{ comment .id }} " href=" {{ url ( 'comment-delete' , { 'comment' : comment .id , 'return' : return_url } ) }} ">Delete</a>
2022-09-13 13:14:49 +00:00
{% endif %}
{ # if user is not null %}
<a class="comment__action comment__action--link comment__action--hide" href="#">Report</a>
{% endif # }
2023-07-29 18:15:30 +00:00
{% if not isReply and perms .can_pin | default ( false ) %}
2023-08-31 14:39:50 +00:00
<a class="comment__action comment__action--link comment__action--hide comment__action--pin" data-comment-id=" {{ comment .id }} " data-comment-pinned=" {{ comment .pinned ? '1' : '0' }} " href=" {{ url ( 'comment-' ~ ( comment .pinned ? 'unpin' : 'pin' ) , { 'comment' : comment .id , 'return' : return_url } ) }} "> {{ comment .pinned ? 'Unpin' : 'Pin' }} </a>
2022-09-13 13:14:49 +00:00
{% endif %}
2023-07-29 18:15:30 +00:00
{% elseif perms .can_delete_any | default ( false ) %}
2023-08-31 14:39:50 +00:00
<a class="comment__action comment__action--link comment__action--restore" data-comment-id=" {{ comment .id }} " href=" {{ url ( 'comment-restore' , { 'comment' : comment .id , 'return' : return_url } ) }} ">Restore</a>
2022-09-13 13:14:49 +00:00
{% endif %}
</div>
</div>
</div>
<div class="comment__replies comment__replies--indent- {{ indent }} " id="comment- {{ comment .id }} -replies">
{% from _self import comments_entry , comments_input %}
2023-08-30 22:37:21 +00:00
{% if user | default ( null ) is not null and category | default ( null ) is not null and perms .can_post | default ( false ) %}
2022-09-13 13:14:49 +00:00
{{ input_checkbox_raw ( '' , false , 'comment__reply-toggle' , '' , false , { 'id' :'comment-reply-toggle-' ~ comment .id } ) }}
2023-08-31 14:39:50 +00:00
{{ comments_input ( category , user , perms , comment , return_url ) }}
2022-09-13 13:14:49 +00:00
{% endif %}
2023-07-15 23:58:17 +00:00
{% if replies | length > 0 %}
{% for reply in replies %}
2023-08-31 14:39:50 +00:00
{{ comments_entry ( reply , indent + 1 , category , user , colour , perms , return_url ) }}
2022-09-13 13:14:49 +00:00
{% endfor %}
{% endif %}
</div>
</div>
{% endif %}
{% endmacro %}
2023-08-31 14:39:50 +00:00
{% macro comments_section ( category , return_url ) %}
2023-07-29 18:15:30 +00:00
{% set user = category .user %}
2023-08-02 22:12:47 +00:00
{% set colour = category .colour %}
2023-07-29 18:15:30 +00:00
{% set posts = category .posts %}
{% set perms = category .perms %}
{% set category = category .category %}
2023-07-15 23:58:17 +00:00
2022-09-13 13:14:49 +00:00
<div class="comments" id="comments">
<div class="comments__input">
{% if user | default ( null ) is null %}
<div class="comments__notice">
Please <a href=" {{ url ( 'auth-login' ) }} " class="comments__notice__link">login</a> to comment.
</div>
{% elseif category | default ( null ) is null %}
<div class="comments__notice">
Posting new comments here is disabled.
</div>
2023-07-29 18:15:30 +00:00
{% elseif not perms .can_lock | default ( false ) and category .locked %}
2022-09-13 13:14:49 +00:00
<div class="comments__notice">
2023-07-18 23:12:47 +00:00
This comment section was locked, <time datetime=" {{ category .lockedTime | date ( 'c' ) }} " title=" {{ category .lockedTime | date ( 'r' ) }} "> {{ category .lockedTime | time_format }} </time>.
2022-09-13 13:14:49 +00:00
</div>
2023-08-30 22:37:21 +00:00
{% elseif not perms .can_post | default ( false ) %}
2022-09-13 13:14:49 +00:00
<div class="comments__notice">
You are not allowed to post comments.
</div>
{% else %}
{% from _self import comments_input %}
2023-08-31 14:39:50 +00:00
{{ comments_input ( category , user , perms , null , return_url ) }}
2022-09-13 13:14:49 +00:00
{% endif %}
</div>
2023-07-29 18:15:30 +00:00
{% if perms .can_lock | default ( false ) and category .locked %}
2022-09-13 13:14:49 +00:00
<div class="comments__notice comments__notice--staff">
2023-07-18 23:12:47 +00:00
This comment section was locked, <time datetime=" {{ category .lockedTime | date ( 'c' ) }} " title=" {{ category .lockedTime | date ( 'r' ) }} "> {{ category .lockedTime | time_format }} </time>.
2022-09-13 13:14:49 +00:00
</div>
{% endif %}
<div class="comments__listing">
2023-07-15 23:58:17 +00:00
{% if posts | length > 0 %}
2022-09-13 13:14:49 +00:00
{% from _self import comments_entry %}
2023-07-15 23:58:17 +00:00
{% for comment in posts %}
2023-08-31 14:39:50 +00:00
{{ comments_entry ( comment , 1 , category , user , colour , perms , return_url ) }}
2022-09-13 13:14:49 +00:00
{% endfor %}
{% else %}
<div class="comments__none" id="_no_comments_notice_ {{ category .id }} ">
There are no comments yet.
</div>
{% endif %}
</div>
</div>
{% endmacro %}