# {{ _('Publicaciones y Mensajes') }} {{ posts | length }} {{ _('mensajes') }}
{% set pinned = posts | selectattr('is_pinned') | list %}
{% if pinned %}
{% set IMG_EXTS = ['png','jpg','jpeg','gif','webp','svg'] %}
{% for f in p.files %}
{% set fext = f.original_name.rsplit('.',1)[-1].lower() %}
{% if fext in IMG_EXTS %}
{% else %}
📎 {{ f.original_name }}
({{ (f.file_size/1024)|round(1) }} KB)
{% endif %}
{% endfor %}
{% if p.user_id == current_user.id or is_admin %}
{% endfor %}
{% else %}
{% set current_date = namespace(val=None) %}
{% for p in posts %}
{% set msg_date = p.created_at.strftime('%d %b %Y') %}
{% if msg_date != current_date.val %}
{% set IMG_EXTS = ['png','jpg','jpeg','gif','webp','svg'] %}
{% for f in p.files %}
{% set fext = f.original_name.rsplit('.',1)[-1].lower() %}
{% if fext in IMG_EXTS %}
{% else %}
📎 {{ f.original_name }}
({{ (f.file_size/1024)|round(1) }} KB)
{% endif %}
{% endfor %}
{% if p.user_id == current_user.id or is_admin %}
{# ── Thread: replies + composer ── #}
{% set post_replies = p.replies.order_by('created_at').all() %}
{% endif %}
{% endfor %}
{% endif %}
📌 {{ _('Mensajes fijados') }}
{% for p in pinned %}
{{ p.user.username[0] }}
@{{ p.user.username }}
{{ p.created_at.strftime('%H:%M · %d %b') }}
📌 {{ _('fijado') }}
{{ p.content }}
{% for f in p.files %}
📎 {{ f.original_name }}
{% endfor %}
{% if p.user_id == current_user.id %}{% endif %}
{% endif %}
{{ _('Todos los mensajes') }}
{% endif %}
{% if not posts %}
💬
{{ _('Sé el primero en escribir en este canal') }}
{{ msg_date }}
{% set current_date.val = msg_date %}
{% endif %}
{# ── Wrapper post + thread ── #}
{% if p.parent_id is none %}
{{ p.user.username[0] }}
@{{ p.user.username }}
{{ p.created_at.strftime('%H:%M') }}
{% if p.updated_at and (p.updated_at - p.created_at).total_seconds() > 2 %}({{ _('editado') }}){% endif %}
{{ p.content }}
{% for f in p.files %}
📎 {{ f.original_name }}
{% endfor %}
{% if p.user_id == current_user.id %}{% endif %}
{% endif %}
{# Replies existentes #}
{% set post_replies = p.replies.order_by('created_at').all() %}
{% for r in post_replies %}
{% if r.user_id == current_user.id or is_admin %}
{% endfor %}
{# Botón + composer #}
{{ r.user.username[0] }}
@{{ r.user.username }}
{{ r.created_at.strftime('%H:%M') }}
{{ r.content }}
{% if r.user_id == current_user.id %}
{% endif %}
{% endif %}