{% endif %}
{# Recursive macro for rendering comments and replies #}
{% macro render_comment(comment, is_reply=false) %}
{{ comment.author_username }}{{ comment.created_at.strftime('%Y-%m-%d %H:%M') }}
{% if not comment.is_deleted %}
{% if current_user.is_authenticated and comment.author_username == current_user.username %}
{% elif current_user.is_authenticated and current_user.is_admin() %}
{% endif %}
{% endif %}
{% if comment.is_deleted %}
{% if comment.deleted_by == 'admin' %}
[This comment has been removed by a moderator]
{% else %}
[This comment has been deleted by the author]
{% endif %}
{% else %}
{{ comment.content | urlize }}
{% if current_user.is_authenticated and comment.author_username == current_user.username %}
{% endif %}
{% endif %}
{# Reply button - available for all comments (deleted or not) #}
{% if current_user.is_authenticated %}
{% endif %}
{# Display nested replies recursively #}
{% if comment.replies %}
{% for reply in comment.replies %}
{{ render_comment(reply, is_reply=true) }}
{% endfor %}
{% endif %}
{% endmacro %}
{% set top_level_comments = video.comments | selectattr('parent_id', 'none') | list %}
{% if top_level_comments %}
{% for comment in top_level_comments %}
{{ render_comment(comment) }}
{% endfor %}
{% else %}
No comments yet. Be the first to comment!
{% endif %}
{% endif %}
{% if current_user.is_authenticated and video %}
Comments ({{ video.comments | length }})
{% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for category, message in messages %} {% endfor %} {% endif %} {% endwith %} {% if current_user.is_authenticated %} {% else %}Log in to post a comment.
{% endif %} {# Recursive macro for rendering comments and replies #} {% macro render_comment(comment, is_reply=false) %}{% for reply in comment.replies %} {{ render_comment(reply, is_reply=true) }} {% endfor %}
{% endif %}{% for comment in top_level_comments %} {{ render_comment(comment) }} {% endfor %}
{% else %}No comments yet. Be the first to comment!
{% endif %}