{#if messages} {@const messageList = messages.slice().reverse()}
{#if !top}
{ console.log('visible'); if (!messagesLoading) { loadMoreMessages(); } }} >
Loading...
{:else if !thread}
{#if channel}
{channel.name}
This channel was created on {dayjs(channel.created_at / 1000000).format( 'MMMM D, YYYY' )}. This is the very beginning of the {channel.name} channel.
{:else}
Start of the channel
{/if} {#if messageList.length > 0}
{/if}
{/if} {#each messageList as message, messageIdx (id ? `${id}-${message.id}` : message.id)}
{ messages = messages.filter((m) => m.id !== message.id); const res = deleteMessage(localStorage.token, message.channel_id, message.id).catch( (error) => { toast.error(error); return null; } ); }} onEdit={(content) => { messages = messages.map((m) => { if (m.id === message.id) { m.content = content; } return m; }); const res = updateMessage(localStorage.token, message.channel_id, message.id, { content: content }).catch((error) => { toast.error(error); return null; }); }} onThread={(id) => { onThread(id); }} onReaction={(name) => { if ( (message?.reactions ?? []) .find((reaction) => reaction.name === name) ?.user_ids?.includes($user.id) ?? false ) { messages = messages.map((m) => { if (m.id === message.id) { const reaction = m.reactions.find((reaction) => reaction.name === name); if (reaction) { reaction.user_ids = reaction.user_ids.filter((id) => id !== $user.id); reaction.count = reaction.user_ids.length; if (reaction.count === 0) { m.reactions = m.reactions.filter((r) => r.name !== name); } } } return m; }); const res = removeReaction( localStorage.token, message.channel_id, message.id, name ).catch((error) => { toast.error(error); return null; }); } else { messages = messages.map((m) => { if (m.id === message.id) { if (m.reactions) { const reaction = m.reactions.find((reaction) => reaction.name === name); if (reaction) { reaction.user_ids.push($user.id); reaction.count = reaction.user_ids.length; } else { m.reactions.push({ name: name, user_ids: [$user.id], count: 1 }); } } } return m; }); const res = addReaction(localStorage.token, message.channel_id, message.id, name).catch( (error) => { toast.error(error); return null; } ); } }} /> {/each}
{/if}