2024-08-15 21:30:55 +00:00
|
|
|
<script lang="ts">
|
2025-10-06 18:23:19 +00:00
|
|
|
import cx from "classnames"
|
2026-08-31 17:03:01 +00:00
|
|
|
import {readable} from "svelte/store"
|
2026-04-10 22:27:36 +00:00
|
|
|
import {
|
|
|
|
|
gte,
|
|
|
|
|
now,
|
2026-08-22 20:12:11 +00:00
|
|
|
uniq,
|
2026-04-10 22:27:36 +00:00
|
|
|
displayList,
|
|
|
|
|
formatTimestampAsTime,
|
|
|
|
|
formatTimestampAsDate,
|
|
|
|
|
} from "@welshman/lib"
|
2025-05-12 22:10:24 +00:00
|
|
|
import type {TrustedEvent, EventContent} from "@welshman/util"
|
2026-08-17 15:42:14 +00:00
|
|
|
import {
|
|
|
|
|
MESSAGE,
|
|
|
|
|
getCommentFiltersForParent,
|
|
|
|
|
getIdOrAddress,
|
|
|
|
|
matchTag,
|
|
|
|
|
tagSpec,
|
|
|
|
|
tagValue,
|
|
|
|
|
} from "@welshman/util"
|
2024-10-24 22:48:45 +00:00
|
|
|
import {isMobile} from "@lib/html"
|
2025-10-06 18:23:19 +00:00
|
|
|
import Pen from "@assets/icons/pen.svg?dataurl"
|
|
|
|
|
import Reply from "@assets/icons/reply-2.svg?dataurl"
|
|
|
|
|
import ReplyAlt from "@assets/icons/reply.svg?dataurl"
|
2025-03-03 21:59:38 +00:00
|
|
|
import TapTarget from "@lib/components/TapTarget.svelte"
|
2024-11-19 21:24:18 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2025-10-06 18:23:19 +00:00
|
|
|
import Link from "@lib/components/Link.svelte"
|
2024-11-19 21:24:18 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
2025-08-19 21:03:04 +00:00
|
|
|
import ThunkFailure from "@app/components/ThunkFailure.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {publishReaction, retractReaction} from "@app/reactions"
|
2026-08-22 20:12:11 +00:00
|
|
|
import {deriveDisplaysByPubkey} from "@app/social"
|
2024-12-16 20:54:17 +00:00
|
|
|
import ProfileDetail from "@app/components/ProfileDetail.svelte"
|
2025-11-11 21:39:32 +00:00
|
|
|
import ProfileCircle from "@app/components/ProfileCircle.svelte"
|
2024-10-24 16:45:27 +00:00
|
|
|
import ReactionSummary from "@app/components/ReactionSummary.svelte"
|
2025-10-30 22:36:14 +00:00
|
|
|
import RoomItemZapButton from "@app/components/RoomItemZapButton.svelte"
|
|
|
|
|
import RoomItemEmojiButton from "@app/components/RoomItemEmojiButton.svelte"
|
|
|
|
|
import RoomItemMenuButton from "@app/components/RoomItemMenuButton.svelte"
|
|
|
|
|
import RoomItemMenuMobile from "@app/components/RoomItemMenuMobile.svelte"
|
|
|
|
|
import RoomItemContent from "@app/components/RoomItemContent.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {profiles, thunks, user} from "@app/core"
|
2026-08-31 17:03:01 +00:00
|
|
|
import {noThunks, thunksByEventId} from "@app/thunks"
|
2026-09-07 23:09:02 +00:00
|
|
|
import {colorFor} from "@app/theme"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {ENABLE_ZAPS} from "@app/env"
|
2026-08-29 16:19:01 +00:00
|
|
|
import type {FeedContext} from "@app/feeds"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {deriveEvent, deriveEventsForUrl} from "@app/repository"
|
2026-08-14 15:47:36 +00:00
|
|
|
import {makeContentPath} from "@app/routes"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2024-08-15 21:30:55 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
type Props = {
|
2025-04-15 18:03:27 +00:00
|
|
|
url: string
|
2025-02-04 00:37:14 +00:00
|
|
|
event: TrustedEvent
|
2025-04-15 18:03:27 +00:00
|
|
|
replyTo?: (event: TrustedEvent) => void
|
2025-02-04 00:37:14 +00:00
|
|
|
showPubkey?: boolean
|
2026-08-29 16:19:01 +00:00
|
|
|
context: FeedContext
|
2025-10-15 14:00:23 +00:00
|
|
|
canEdit: (event: TrustedEvent) => boolean
|
|
|
|
|
onEdit: (event: TrustedEvent) => void
|
2025-02-04 00:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-29 16:19:01 +00:00
|
|
|
const {
|
|
|
|
|
url,
|
|
|
|
|
event,
|
|
|
|
|
replyTo = undefined,
|
|
|
|
|
showPubkey = false,
|
|
|
|
|
context,
|
|
|
|
|
canEdit,
|
|
|
|
|
onEdit,
|
|
|
|
|
}: Props = $props()
|
2024-08-15 21:30:55 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const h = tagValue(tagSpec("h"), event.tags)
|
2025-01-24 21:35:09 +00:00
|
|
|
const today = formatTimestampAsDate(now())
|
2026-07-28 16:16:26 +00:00
|
|
|
const profileDisplay = $profiles.display(event.pubkey, [url]).$
|
2026-08-31 17:03:01 +00:00
|
|
|
const thunk = $derived($thunks.merge($thunksByEventId.get(event.id) ?? noThunks))
|
2026-09-07 23:09:02 +00:00
|
|
|
const colorValue = colorFor(event.pubkey)
|
2026-04-10 22:27:36 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const qTag = matchTag(tagSpec("q"), event.tags)
|
2026-04-10 22:27:36 +00:00
|
|
|
const isQuoteOnly = Boolean(
|
|
|
|
|
gte(qTag?.length, 2) && event.content.trim().match(/^nostr:n(event|addr)1\w+\s*$/),
|
|
|
|
|
)
|
|
|
|
|
const innerEvent = isQuoteOnly ? deriveEvent(qTag![1], [url]) : readable(undefined)
|
2026-08-17 15:42:14 +00:00
|
|
|
const innerComments = $derived(
|
|
|
|
|
$innerEvent ? deriveEventsForUrl(url, getCommentFiltersForParent([$innerEvent])) : readable([]),
|
|
|
|
|
)
|
2024-08-15 21:30:55 +00:00
|
|
|
|
2026-08-14 15:50:17 +00:00
|
|
|
const path = $derived(
|
|
|
|
|
$innerEvent && makeContentPath(url, $innerEvent.kind, getIdOrAddress($innerEvent)),
|
|
|
|
|
)
|
|
|
|
|
|
2026-08-22 20:12:11 +00:00
|
|
|
const commenterDisplays = $derived(
|
|
|
|
|
deriveDisplaysByPubkey(uniq($innerComments.map(e => e.pubkey)), url),
|
|
|
|
|
)
|
|
|
|
|
|
2025-04-15 18:03:27 +00:00
|
|
|
const reply = () => replyTo!(event)
|
2026-08-14 15:50:17 +00:00
|
|
|
|
2025-10-15 14:00:23 +00:00
|
|
|
const edit = canEdit(event) ? () => onEdit(event) : undefined
|
2024-11-19 21:24:18 +00:00
|
|
|
|
2025-10-30 22:36:14 +00:00
|
|
|
const onTap = () => pushModal(RoomItemMenuMobile, {url, event, reply, edit})
|
2024-10-25 23:59:12 +00:00
|
|
|
|
2025-04-15 18:03:27 +00:00
|
|
|
const openProfile = () => pushModal(ProfileDetail, {pubkey: event.pubkey, url})
|
2024-12-16 20:54:17 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const deleteReaction = (reaction: TrustedEvent) => retractReaction(reaction, {url, h})
|
2024-09-25 20:46:10 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const createReaction = (values: EventContent) => publishReaction(event, values, {url, h})
|
2024-08-15 21:30:55 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-03-03 21:59:38 +00:00
|
|
|
<TapTarget
|
2024-11-19 21:24:18 +00:00
|
|
|
data-event={event.id}
|
2026-04-10 22:27:36 +00:00
|
|
|
{onTap}
|
2026-04-07 16:50:53 +00:00
|
|
|
class={cx(
|
2026-06-24 20:56:53 +00:00
|
|
|
"room__item group relative flex w-full cursor-default flex-col px-2 py-0.5 text-left transition-colors",
|
2026-06-04 21:31:07 +00:00
|
|
|
{"mt-1.5": showPubkey},
|
2026-04-07 16:50:53 +00:00
|
|
|
)}>
|
2024-11-13 00:44:34 +00:00
|
|
|
<div class="flex w-full gap-3 overflow-auto">
|
2024-10-25 23:59:12 +00:00
|
|
|
{#if showPubkey}
|
2026-04-07 16:50:53 +00:00
|
|
|
<Button onclick={openProfile} class="flex items-start pt-1.5 justify-center w-8 shrink-0">
|
2025-11-11 21:39:32 +00:00
|
|
|
<ProfileCircle
|
|
|
|
|
pubkey={event.pubkey}
|
2026-06-24 20:56:53 +00:00
|
|
|
class="border border-solid"
|
|
|
|
|
style="border-color: var(--line)"
|
2025-11-11 21:39:32 +00:00
|
|
|
size={8} />
|
2024-12-16 20:54:17 +00:00
|
|
|
</Button>
|
2024-10-25 23:59:12 +00:00
|
|
|
{:else}
|
2026-04-07 16:50:53 +00:00
|
|
|
<div class="w-8 shrink-0"></div>
|
2024-10-25 23:59:12 +00:00
|
|
|
{/if}
|
2026-04-07 21:53:19 +00:00
|
|
|
<div class="min-w-0 grow pr-1">
|
2024-08-15 21:30:55 +00:00
|
|
|
{#if showPubkey}
|
2024-10-25 23:59:12 +00:00
|
|
|
<div class="flex items-center gap-2">
|
2025-02-04 01:21:46 +00:00
|
|
|
<Button onclick={openProfile} class="text-sm font-bold" style="color: {colorValue}">
|
2025-04-16 17:36:21 +00:00
|
|
|
{$profileDisplay}
|
2024-12-16 20:54:17 +00:00
|
|
|
</Button>
|
2025-01-24 21:35:09 +00:00
|
|
|
<span class="text-xs opacity-50">
|
|
|
|
|
{#if formatTimestampAsDate(event.created_at) === today}
|
|
|
|
|
Today
|
|
|
|
|
{:else}
|
|
|
|
|
{formatTimestampAsDate(event.created_at)}
|
|
|
|
|
{/if}
|
|
|
|
|
at {formatTimestampAsTime(event.created_at)}
|
|
|
|
|
</span>
|
2024-10-25 23:59:12 +00:00
|
|
|
</div>
|
2024-08-15 21:30:55 +00:00
|
|
|
{/if}
|
2025-10-06 18:23:19 +00:00
|
|
|
<div class:mt-2={showPubkey && event.kind !== MESSAGE}>
|
2026-04-10 22:27:36 +00:00
|
|
|
<RoomItemContent {url} event={$innerEvent ?? event} />
|
2024-10-25 23:59:12 +00:00
|
|
|
{#if thunk}
|
2026-06-04 21:10:00 +00:00
|
|
|
<ThunkFailure showToastOnRetry {thunk} class="mt-1 flex justify-end" />
|
2024-08-23 20:33:36 +00:00
|
|
|
{/if}
|
2024-10-17 17:34:13 +00:00
|
|
|
</div>
|
2024-08-23 21:42:50 +00:00
|
|
|
</div>
|
2024-10-25 23:59:12 +00:00
|
|
|
</div>
|
2026-06-24 20:56:53 +00:00
|
|
|
<div class="flex gap-2 ml-10 mt-1 pl-1">
|
2025-05-12 22:10:24 +00:00
|
|
|
<ReactionSummary
|
|
|
|
|
{url}
|
|
|
|
|
{event}
|
2026-08-29 16:19:01 +00:00
|
|
|
{context}
|
2025-05-12 22:10:24 +00:00
|
|
|
{deleteReaction}
|
|
|
|
|
{createReaction}
|
2026-06-24 20:56:53 +00:00
|
|
|
reactionClass="tip-right"
|
2026-04-10 22:27:36 +00:00
|
|
|
innerEvent={$innerEvent} />
|
|
|
|
|
{#if path && $innerComments.length > 0}
|
|
|
|
|
{@const pubkeys = $innerComments.map(e => e.pubkey)}
|
2026-07-28 16:16:26 +00:00
|
|
|
{@const isOwn = pubkeys.includes($user.pubkey)}
|
2026-08-22 20:12:11 +00:00
|
|
|
{@const info = displayList(pubkeys.map(pubkey => $commenterDisplays.get(pubkey) ?? ""))}
|
2025-10-06 18:23:19 +00:00
|
|
|
{@const tooltip = `${info} commented`}
|
2026-06-24 20:56:53 +00:00
|
|
|
<div data-tip={tooltip} class="tip tip-right flex">
|
2025-10-06 18:23:19 +00:00
|
|
|
<Link
|
|
|
|
|
href={path}
|
2026-06-24 20:56:53 +00:00
|
|
|
class={cx("button button-xs gap-1 rounded-full", {
|
|
|
|
|
"button-neutral": !isOwn,
|
|
|
|
|
"button-primary": isOwn,
|
2025-10-06 18:23:19 +00:00
|
|
|
})}>
|
|
|
|
|
<Icon icon={ReplyAlt} />
|
2026-04-10 22:27:36 +00:00
|
|
|
<span>{$innerComments.length} comment{$innerComments.length === 1 ? "" : "s"}</span>
|
2025-10-06 18:23:19 +00:00
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2024-10-25 23:59:12 +00:00
|
|
|
</div>
|
2025-04-16 21:19:09 +00:00
|
|
|
{#if !isMobile}
|
2025-03-04 18:20:06 +00:00
|
|
|
<button
|
2026-07-15 21:23:43 +00:00
|
|
|
class="room__item-actions join absolute right-2 top-0.5 opacity-0 transition-all"
|
2025-03-04 18:20:06 +00:00
|
|
|
class:group-hover:opacity-100={!isMobile}>
|
2025-07-17 21:39:59 +00:00
|
|
|
{#if ENABLE_ZAPS}
|
2025-10-30 22:36:14 +00:00
|
|
|
<RoomItemZapButton {url} {event} />
|
2025-07-17 21:39:59 +00:00
|
|
|
{/if}
|
2025-10-30 22:36:14 +00:00
|
|
|
<RoomItemEmojiButton {url} {event} />
|
2025-03-04 18:20:06 +00:00
|
|
|
{#if replyTo}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-xs button-neutral join-item" onclick={reply}>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={Reply} size={4} />
|
2025-03-04 18:20:06 +00:00
|
|
|
</Button>
|
|
|
|
|
{/if}
|
2025-10-15 14:00:23 +00:00
|
|
|
{#if edit}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-xs button-neutral join-item" onclick={edit}>
|
2025-10-15 14:00:23 +00:00
|
|
|
<Icon icon={Pen} size={4} />
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
2025-10-30 22:36:14 +00:00
|
|
|
<RoomItemMenuButton {url} {event} />
|
2025-03-04 18:20:06 +00:00
|
|
|
</button>
|
|
|
|
|
{/if}
|
2025-03-03 21:59:38 +00:00
|
|
|
</TapTarget>
|