{# Message bubble loop. Shared by _conversation.html (initial render) and
_history_page.html (load-older paging). Expects `msgs` (list, oldest-first)
and `is_group` (bool). #}
{% for m in msgs %}
{% if is_group and not m.from_me and m.sender_name %}
{% endif %}
{% if m.attachments %}
{# Split: ready images go to the gallery grid; everything else falls through #}
{% set ready_imgs = m.attachments | selectattr('kind', 'equalto', 'image') | selectattr('ready') | list %}
{% set other_atts = (m.attachments | rejectattr('kind', 'equalto', 'image') | list)
+ (m.attachments | selectattr('kind', 'equalto', 'image') | rejectattr('ready') | list) %}
{# --- Gallery grid for ready images --- #}
{% if ready_imgs %}
{% set n = ready_imgs | length %}
{# Choose grid class; cap display at 4 cells, show "+N" on the 4th when n>4 #}
{% set grid_cls = 'gallery-' ~ (n if n <= 4 else '5p') %}
{% set shown = ready_imgs[:4] %}
{% set overflow = n - 4 if n > 4 else 0 %}