{messages.map((msg, i) => {
const mine = msg.user_id === user?.id
const prev = messages[i - 1]
// Mattermost-style grouping: every message shows who sent it, but
// consecutive messages from the same sender only repeat the
// avatar/name/timestamp header on the first one in the run --
// applies uniformly, including to your own messages.
const isGroupStart = !prev || prev.user_id !== msg.user_id
const editing = editingId === msg.id
const deleted = !!msg.deleted_at
return (
{isGroupStart && (
)}
{isGroupStart && (
{displayNameFor(msg.username, members)}
{new Date(msg.created_at).toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })}
)}
{deleted ? (
This message was deleted
) : editing ? (
{!editing && !deleted && (
{reactingId === msg.id && (
{
onReact(msg.id, emoji)
setReactingId(null)
}}
onClose={() => setReactingId(null)}
placement={reactionPlacement}
align="right"
/>
)}
{mine && (
)}
{mine && (
)}
)}
)
})}
{lightboxSrc &&
setLightboxSrc(null)} />}
{videoLightbox && (
setVideoLightbox(null)}
/>
)}
{previewFile && (
setPreviewFile(null)}
/>
)}
)
}