Something went wrong. Try again.
An all-affirming social network based on the AT Protocol. nagi.suibari.com
Something went wrong. Try again.
5.4 kB · 190 lines
Svelte
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191<script lang="ts"> import type { ActorView, FeedItem, PostView } from '$lib/api/types'; import ChatBubble from './ChatBubble.svelte'; import { m } from '$lib/i18n/i18n.svelte'; import BotReplyStatus from './BotReplyStatus.svelte'; import ThreadFlags from './ThreadFlags.svelte'; import { replyIndent } from '$lib/thread/replyIndent'; let { item, botActor, ondeleted, onposted, canPin = false, pinChannelUri, pinnedPostUri, hiddenPostUri, pinBusy = false, ontogglepin, unread = false, }: { item: FeedItem; botActor?: ActorView; ondeleted?: (uri: string) => void; onposted?: () => void | Promise<void>; canPin?: boolean; /** ピン操作を許可する所属チャンネル。異なるチャンネルの親投稿は対象外にする。 */ pinChannelUri?: string; pinnedPostUri?: string; /** ピン枠と重複するこのURIの吹き出しだけを通常タイムラインから省く。 */ hiddenPostUri?: string; pinBusy?: boolean; ontogglepin?: (post: PostView) => void | Promise<void>; /** 前回このフィードを見た時点より新しいスレッドか。カード全体に1本だけマークを出す。 */ unread?: boolean; } = $props(); // 会話グループ(group モード)では待機状態は conversation.awaitingBotReply が持つ。 let conv = $derived(item.conversation); let botState = $derived(conv ? conv.awaitingBotReply : item.botReplyState); let fullThreadHref = $derived( conv ? `/thread/${conv.root.author.did}/${conv.root.uri.split('/').pop()}` : '', ); let convChannel = $derived( conv?.root.channel ?? conv?.bubbles.find((b) => b.post.channel)?.post.channel, ); let convKossori = $derived( Boolean(conv && (conv.root.threadKossori ?? conv.root.kossori ?? conv.root.channelOnly)), ); let channel = $derived(item.channel ?? item.replyParent?.channel ?? item.botReply?.channel); let threadKossori = $derived( Boolean( item.threadKossori ?? item.replyParent?.threadKossori ?? item.botReply?.threadKossori ?? item.kossori ?? item.channelOnly, ), ); let showParent = $derived(Boolean(item.replyParent && item.replyParent.uri !== hiddenPostUri)); let showItem = $derived(item.uri !== hiddenPostUri); let showBotReply = $derived(Boolean(item.botReply && item.botReply.uri !== hiddenPostUri)); let hasVisiblePost = $derived(showParent || showItem || showBotReply); const canPinPost = (post: PostView) => canPin && (!pinChannelUri || post.channel?.uri === pinChannelUri);</script>
{#if conv} <article class="thread-unit" class:unread class:optimistic={Boolean(item.optimisticState)} data-post-uri={item.uri} data-optimistic-key={item.optimisticKey} > <ThreadFlags channel={convChannel} kossori={convKossori} /> <ChatBubble post={conv.root} {botActor} {ondeleted} {onposted} canPin={canPinPost(conv.root)} pinned={conv.root.uri === pinnedPostUri} {pinBusy} {ontogglepin} /> {#if conv.hiddenCount > 0}<a class="thread-gap" href={fullThreadHref} aria-label={m.threadViewAll()}>{m.threadMore({ count: conv.hiddenCount })}</a >{/if} {#each conv.bubbles as bubble (bubble.post.uri)} <div class="thread-reply" style="--reply-indent: {replyIndent(bubble.depth)}"> <ChatBubble post={bubble.post} {botActor} {ondeleted} {onposted} canPin={canPinPost(bubble.post)} pinned={bubble.post.uri === pinnedPostUri} {pinBusy} {ontogglepin} /> </div> {/each} <BotReplyStatus state={botState} createdAt={item.createdAt} {botActor} optimistic={Boolean(item.optimisticState)} /> </article>{:else if hasVisiblePost} <article class="thread-unit" class:unread class:optimistic={Boolean(item.optimisticState)} data-post-uri={item.uri} data-optimistic-key={item.optimisticKey} > <ThreadFlags {channel} kossori={threadKossori} /> {#if showParent && item.replyParent} <ChatBubble post={item.replyParent} {botActor} {ondeleted} {onposted} canPin={canPinPost(item.replyParent)} pinned={item.replyParent.uri === pinnedPostUri} {pinBusy} {ontogglepin} /> {/if} {#if showItem} {#if showParent}<div class="thread-reply"> <ChatBubble post={item} {botActor} {ondeleted} {onposted} canPin={canPinPost(item)} pinned={item.uri === pinnedPostUri} {pinBusy} {ontogglepin} /> </div> {:else}<ChatBubble post={item} {botActor} {ondeleted} {onposted} canPin={canPinPost(item)} pinned={item.uri === pinnedPostUri} {pinBusy} {ontogglepin} /> {/if} {/if} {#if !item.optimisticState && showBotReply && item.botReply} {#if showItem}<div class="thread-reply"> <ChatBubble post={item.botReply} {botActor} {ondeleted} {onposted} canPin={canPinPost(item.botReply)} pinned={item.botReply.uri === pinnedPostUri} {pinBusy} {ontogglepin} /> </div> {:else}<ChatBubble post={item.botReply} {botActor} {ondeleted} {onposted} canPin={canPinPost(item.botReply)} pinned={item.botReply.uri === pinnedPostUri} {pinBusy} {ontogglepin} /> {/if} {:else if showItem} <BotReplyStatus state={item.botReplyState} createdAt={item.createdAt} {botActor} optimistic={Boolean(item.optimisticState)} /> {/if} </article>{/if}