Add custom emoji parsing and display

This commit is contained in:
Jon Staab
2025-05-12 15:10:24 -07:00
parent 58afb8fa0c
commit 263a803875
11 changed files with 119 additions and 66 deletions
+39 -12
View File
@@ -2,20 +2,29 @@
import {onMount} from "svelte"
import type {Snippet} from "svelte"
import {groupBy, uniq, uniqBy, batch, displayList} from "@welshman/lib"
import {REACTION, getReplyFilters, getTag, REPORT, DELETE} from "@welshman/util"
import type {TrustedEvent} from "@welshman/util"
import {
REACTION,
getReplyFilters,
getEmojiTags,
getEmojiTag,
getTag,
REPORT,
DELETE,
} from "@welshman/util"
import type {TrustedEvent, EventContent} from "@welshman/util"
import {deriveEvents} from "@welshman/store"
import {load} from "@welshman/net"
import {pubkey, repository, displayProfileByPubkey} from "@welshman/app"
import {isMobile, preventDefault, stopPropagation} from "@lib/html"
import Icon from "@lib/components/Icon.svelte"
import Reaction from "@app/components/Reaction.svelte"
import EventReportDetails from "@app/components/EventReportDetails.svelte"
import {displayReaction} from "@app/state"
import {pushModal} from "@app/modal"
interface Props {
event: any
onReactionClick: any
event: TrustedEvent
deleteReaction: (event: TrustedEvent) => void
createReaction: (event: EventContent) => void
url?: string
reactionClass?: string
noTooltip?: boolean
@@ -24,7 +33,8 @@
const {
event,
onReactionClick,
deleteReaction,
createReaction,
url = "",
reactionClass = "",
noTooltip = false,
@@ -39,14 +49,31 @@
filters: [{kinds: [REACTION], "#e": [event.id]}],
})
const onReactionClick = (events: TrustedEvent[]) => {
const reaction = events.find(e => e.pubkey === $pubkey)
if (reaction) {
deleteReaction(reaction)
} else {
const [event] = events
createReaction({
content: event.content,
tags: getEmojiTags(event.content.replace(/:/g, ""), event.tags),
})
}
}
const onReportClick = () => pushModal(EventReportDetails, {url, event})
const reportReasons = $derived(uniq($reports.map(e => getTag("e", e.tags)?.[2])))
const getReactionKey = (e: TrustedEvent) => getEmojiTag(e.content, e.tags)?.join("") || e.content
const groupedReactions = $derived(
groupBy(
e => e.content,
uniqBy(e => e.pubkey + e.content, $reactions),
getReactionKey,
uniqBy(e => `${e.pubkey}${getReactionKey(e)}`, $reactions),
),
)
@@ -86,12 +113,12 @@
<span>{$reports.length}</span>
</button>
{/if}
{#each groupedReactions.entries() as [content, events]}
{#each groupedReactions.entries() as [key, events]}
{@const pubkeys = events.map(e => e.pubkey)}
{@const isOwn = $pubkey && pubkeys.includes($pubkey)}
{@const info = displayList(pubkeys.map(pubkey => displayProfileByPubkey(pubkey)))}
{@const tooltip = `${info} reacted ${displayReaction(content)}`}
{@const onClick = () => onReactionClick(content, events)}
{@const tooltip = `${info} reacted`}
{@const onClick = () => onReactionClick(events)}
<button
type="button"
data-tip={tooltip}
@@ -101,7 +128,7 @@
class:border-solid={isOwn}
class:border-primary={isOwn}
onclick={stopPropagation(preventDefault(onClick))}>
<span>{displayReaction(content)}</span>
<Reaction event={events[0]} />
{#if events.length > 1}
<span>{events.length}</span>
{/if}