2024-08-15 21:30:55 +00:00
|
|
|
<script lang="ts">
|
2024-10-17 23:03:50 +00:00
|
|
|
import {readable} from "svelte/store"
|
2024-10-23 21:20:24 +00:00
|
|
|
import {hash} from "@welshman/lib"
|
2024-08-19 16:06:39 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2024-10-17 23:03:50 +00:00
|
|
|
import {deriveProfile, deriveProfileDisplay, formatTimestampAsTime, pubkey} from "@welshman/app"
|
2024-10-16 22:57:18 +00:00
|
|
|
import type {Thunk} from "@welshman/app"
|
2024-10-24 22:48:45 +00:00
|
|
|
import {isMobile} from "@lib/html"
|
2024-10-17 23:03:50 +00:00
|
|
|
import {slideAndFade, conditionalTransition} from "@lib/transition"
|
2024-10-25 23:59:12 +00:00
|
|
|
import LongPress from "@lib/components/LongPress.svelte"
|
2024-08-16 17:50:38 +00:00
|
|
|
import Avatar from "@lib/components/Avatar.svelte"
|
2024-10-24 19:50:49 +00:00
|
|
|
import Link from "@lib/components/Link.svelte"
|
2024-09-24 23:30:32 +00:00
|
|
|
import Content from "@app/components/Content.svelte"
|
2024-10-16 22:57:18 +00:00
|
|
|
import ThunkStatus from "@app/components/ThunkStatus.svelte"
|
2024-10-24 16:45:27 +00:00
|
|
|
import ReplySummary from "@app/components/ReplySummary.svelte"
|
|
|
|
|
import ReactionSummary from "@app/components/ReactionSummary.svelte"
|
2024-10-24 22:50:45 +00:00
|
|
|
import ChannelConversation from "@app/components/ChannelConversation.svelte"
|
2024-10-03 21:43:17 +00:00
|
|
|
import ChannelMessageEmojiButton from "@app/components/ChannelMessageEmojiButton.svelte"
|
2024-10-16 18:27:27 +00:00
|
|
|
import ChannelMessageMenuButton from "@app/components/ChannelMessageMenuButton.svelte"
|
2024-10-24 22:48:45 +00:00
|
|
|
import ChannelMessageMenuMobile from "@app/components/ChannelMessageMenuMobile.svelte"
|
2024-10-24 19:50:49 +00:00
|
|
|
import {colors, tagRoom, deriveEvent, pubkeyLink} from "@app/state"
|
2024-09-25 22:49:17 +00:00
|
|
|
import {publishDelete, publishReaction} from "@app/commands"
|
2024-10-24 22:48:45 +00:00
|
|
|
import {pushDrawer, pushModal} from "@app/modal"
|
2024-08-15 21:30:55 +00:00
|
|
|
|
2024-10-23 21:20:24 +00:00
|
|
|
export let url, room
|
2024-08-19 16:06:39 +00:00
|
|
|
export let event: TrustedEvent
|
2024-10-16 22:57:18 +00:00
|
|
|
export let thunk: Thunk
|
2024-10-01 18:47:21 +00:00
|
|
|
export let showPubkey = false
|
2024-10-24 22:50:45 +00:00
|
|
|
export let isHead = false
|
2024-10-25 00:25:28 +00:00
|
|
|
export let inert = false
|
2024-08-15 21:30:55 +00:00
|
|
|
|
|
|
|
|
const profile = deriveProfile(event.pubkey)
|
2024-08-20 20:20:45 +00:00
|
|
|
const profileDisplay = deriveProfileDisplay(event.pubkey)
|
2024-10-01 18:47:21 +00:00
|
|
|
const rootTag = event.tags.find(t => t[0].match(/^e$/i))
|
|
|
|
|
const rootId = rootTag?.[1]
|
|
|
|
|
const rootHints = [rootTag?.[2]].filter(Boolean) as string[]
|
|
|
|
|
const rootEvent = rootId ? deriveEvent(rootId, rootHints) : readable(null)
|
2024-10-17 23:03:50 +00:00
|
|
|
const [_, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
|
2024-08-15 21:30:55 +00:00
|
|
|
|
2024-10-17 17:34:13 +00:00
|
|
|
const transition = conditionalTransition(thunk, slideAndFade)
|
|
|
|
|
|
2024-10-24 22:48:45 +00:00
|
|
|
const onClick = () => {
|
2024-10-25 23:59:12 +00:00
|
|
|
const root = $rootEvent || event
|
2024-10-01 18:47:21 +00:00
|
|
|
|
2024-10-25 23:59:12 +00:00
|
|
|
pushDrawer(ChannelConversation, {url, room, event: root})
|
2024-10-01 18:47:21 +00:00
|
|
|
}
|
2024-09-25 20:46:10 +00:00
|
|
|
|
2024-10-25 23:59:12 +00:00
|
|
|
const onLongPress = () =>
|
|
|
|
|
pushModal(ChannelMessageMenuMobile, {url, event})
|
|
|
|
|
|
2024-09-25 20:46:10 +00:00
|
|
|
const onReactionClick = (content: string, events: TrustedEvent[]) => {
|
|
|
|
|
const reaction = events.find(e => e.pubkey === $pubkey)
|
|
|
|
|
|
|
|
|
|
if (reaction) {
|
2024-09-25 22:49:17 +00:00
|
|
|
publishDelete({relays: [url], event: reaction})
|
2024-09-25 20:46:10 +00:00
|
|
|
} else {
|
2024-09-25 22:49:17 +00:00
|
|
|
publishReaction({
|
|
|
|
|
event,
|
|
|
|
|
content,
|
|
|
|
|
relays: [url],
|
2024-10-01 18:47:21 +00:00
|
|
|
tags: [tagRoom(room, url)],
|
2024-09-25 22:49:17 +00:00
|
|
|
})
|
2024-09-25 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-08-15 21:30:55 +00:00
|
|
|
</script>
|
|
|
|
|
|
2024-10-25 23:59:12 +00:00
|
|
|
<LongPress
|
|
|
|
|
on:click={isMobile || inert ? null : onClick}
|
|
|
|
|
onLongPress={inert ? null : onLongPress}
|
|
|
|
|
class="group relative flex w-full flex-col gap-1 p-2 text-left transition-colors {inert ? 'hover:bg-base-300' : ''}">
|
|
|
|
|
<div class="flex w-full gap-3">
|
|
|
|
|
{#if showPubkey}
|
|
|
|
|
<Link external href={pubkeyLink(event.pubkey)} class="flex items-start">
|
|
|
|
|
<Avatar
|
|
|
|
|
src={$profile?.picture}
|
|
|
|
|
class="border border-solid border-base-content"
|
|
|
|
|
size={10} />
|
|
|
|
|
</Link>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="w-10 min-w-10 max-w-10" />
|
|
|
|
|
{/if}
|
|
|
|
|
<div class="-mt-1 flex-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">
|
|
|
|
|
<Link
|
|
|
|
|
external
|
|
|
|
|
href={pubkeyLink(event.pubkey)}
|
|
|
|
|
class="text-sm font-bold"
|
|
|
|
|
style="color: {colorValue}">
|
|
|
|
|
{$profileDisplay}
|
|
|
|
|
</Link>
|
|
|
|
|
<span class="text-xs opacity-50">{formatTimestampAsTime(event.created_at)}</span>
|
|
|
|
|
</div>
|
2024-08-15 21:30:55 +00:00
|
|
|
{/if}
|
2024-10-25 23:59:12 +00:00
|
|
|
<div class="text-sm">
|
|
|
|
|
<Content {event} />
|
|
|
|
|
{#if thunk}
|
|
|
|
|
<ThunkStatus {thunk} />
|
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>
|
|
|
|
|
<div class="row-2 ml-12">
|
|
|
|
|
{#if !isHead}
|
|
|
|
|
<ReplySummary {event} />
|
|
|
|
|
{/if}
|
|
|
|
|
<ReactionSummary {event} {onReactionClick} />
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
class="join absolute right-1 top-1 border border-solid border-neutral text-xs opacity-0 transition-all"
|
|
|
|
|
class:group-hover:opacity-100={!isMobile}
|
|
|
|
|
on:click|stopPropagation>
|
|
|
|
|
<ChannelMessageEmojiButton {url} {room} {event} />
|
|
|
|
|
<ChannelMessageMenuButton {url} {event} />
|
2024-10-01 18:47:21 +00:00
|
|
|
</button>
|
2024-10-25 23:59:12 +00:00
|
|
|
</LongPress>
|