Browse Source

emojis become likes, in quiet mode

imwald
Silberengel 4 months ago
parent
commit
0c10138a80
  1. 23
      src/components/Note/Zap.tsx
  2. 4
      src/components/NoteStats/LikeButton.tsx
  3. 13
      src/components/NoteStats/Likes.tsx
  4. 4
      src/components/ReactionList/index.tsx
  5. 7
      src/components/ZapList/index.tsx

23
src/components/Note/Zap.tsx

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
import { useFetchEvent } from '@/hooks'
import { getZapInfoFromEvent } from '@/lib/event-metadata'
import { shouldHideInteractions } from '@/lib/event-filtering'
import { formatAmount } from '@/lib/lightning'
import { toNote, toProfile } from '@/lib/link'
import { cn } from '@/lib/utils'
@ -12,11 +13,29 @@ import Username from '../Username' @@ -12,11 +13,29 @@ import Username from '../Username'
import UserAvatar from '../UserAvatar'
export default function Zap({ event, className }: { event: Event; className?: string }) {
// In quiet mode, we need to check the target event (if this is a zap receipt for an event)
// For profile zaps, we can't check quiet mode since we don't have an event
const zapInfo = useMemo(() => getZapInfoFromEvent(event), [event])
const { event: targetEvent } = useFetchEvent(zapInfo?.eventId)
// Check if the target event (if any) is in quiet mode
const inQuietMode = targetEvent ? shouldHideInteractions(targetEvent) : false
// Hide zap receipts in quiet mode as they contain emojis and text
if (inQuietMode) {
return null
}
const { t } = useTranslation()
const { navigateToNote } = useSmartNoteNavigation()
const { push } = useSecondaryPage()
const zapInfo = useMemo(() => getZapInfoFromEvent(event), [event])
const { event: targetEvent } = useFetchEvent(zapInfo?.eventId)
if (!zapInfo || !zapInfo.senderPubkey || !zapInfo.amount) {
return (
<div className={cn('text-sm text-muted-foreground p-4 border rounded-lg', className)}>
[{t('Invalid zap receipt')}]
</div>
)
}
// Determine if this is an event zap or profile zap
const isEventZap = targetEvent || zapInfo?.eventId

4
src/components/NoteStats/LikeButton.tsx

@ -6,6 +6,7 @@ import { @@ -6,6 +6,7 @@ import {
} from '@/components/ui/dropdown-menu'
import { ExtendedKind } from '@/constants'
import { useNoteStatsById } from '@/hooks/useNoteStatsById'
import { shouldHideInteractions } from '@/lib/event-filtering'
import { createDeletionRequestDraftEvent, createReactionDraftEvent } from '@/lib/draft-event'
import { getRootEventHexId } from '@/lib/event'
import { useNostr } from '@/providers/NostrProvider'
@ -34,6 +35,7 @@ export default function LikeButton({ event, hideCount = false }: { event: Event; @@ -34,6 +35,7 @@ export default function LikeButton({ event, hideCount = false }: { event: Event;
const [isPickerOpen, setIsPickerOpen] = useState(false)
const noteStats = useNoteStatsById(event.id)
const isDiscussion = event.kind === ExtendedKind.DISCUSSION
const inQuietMode = shouldHideInteractions(event)
// Check if this is a reply to a discussion event
const [isReplyToDiscussion, setIsReplyToDiscussion] = useState(false)
@ -143,7 +145,7 @@ export default function LikeButton({ event, hideCount = false }: { event: Event; @@ -143,7 +145,7 @@ export default function LikeButton({ event, hideCount = false }: { event: Event;
<Loader className="animate-spin" />
) : myLastEmoji ? (
<>
<Emoji emoji={myLastEmoji} classNames={{ img: 'size-4' }} />
<Emoji emoji={inQuietMode ? '+' : myLastEmoji} classNames={{ img: 'size-4' }} />
{!hideCount && !!likeCount && <div className="text-sm">{formatCount(likeCount)}</div>}
</>
) : (

13
src/components/NoteStats/Likes.tsx

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'
import { useNoteStatsById } from '@/hooks/useNoteStatsById'
import { shouldHideInteractions } from '@/lib/event-filtering'
import { createReactionDraftEvent } from '@/lib/draft-event'
import { cn } from '@/lib/utils'
import { useNostr } from '@/providers/NostrProvider'
@ -11,6 +12,7 @@ import { useMemo, useRef, useState } from 'react' @@ -11,6 +12,7 @@ import { useMemo, useRef, useState } from 'react'
import Emoji from '../Emoji'
export default function Likes({ event }: { event: Event }) {
const inQuietMode = shouldHideInteractions(event)
const { pubkey, checkLogin, publish } = useNostr()
const noteStats = useNoteStatsById(event.id)
const [liking, setLiking] = useState<string | null>(null)
@ -24,14 +26,23 @@ export default function Likes({ event }: { event: Event }) { @@ -24,14 +26,23 @@ export default function Likes({ event }: { event: Event }) {
const stats = new Map<string, { key: string; emoji: TEmoji | string; pubkeys: Set<string> }>()
_likes.forEach((item) => {
// In quiet mode, normalize all emojis to "+" to prevent trolling with funny emojis
if (inQuietMode) {
const key = '+'
if (!stats.has(key)) {
stats.set(key, { key, pubkeys: new Set(), emoji: '+' })
}
stats.get(key)?.pubkeys.add(item.pubkey)
} else {
const key = typeof item.emoji === 'string' ? item.emoji : item.emoji.url
if (!stats.has(key)) {
stats.set(key, { key, pubkeys: new Set(), emoji: item.emoji })
}
stats.get(key)?.pubkeys.add(item.pubkey)
}
})
return Array.from(stats.values()).sort((a, b) => b.pubkeys.size - a.pubkeys.size)
}, [noteStats, event])
}, [noteStats, event, inQuietMode])
if (!likes.length) return null

4
src/components/ReactionList/index.tsx

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
import { useSecondaryPage } from '@/PageManager'
import { ExtendedKind } from '@/constants'
import { useNoteStatsById } from '@/hooks/useNoteStatsById'
import { shouldHideInteractions } from '@/lib/event-filtering'
import { toProfile } from '@/lib/link'
import { useScreenSize } from '@/providers/ScreenSizeProvider'
import { useUserTrust } from '@/providers/UserTrustProvider'
@ -16,6 +17,7 @@ import Username from '../Username' @@ -16,6 +17,7 @@ import Username from '../Username'
const SHOW_COUNT = 20
export default function ReactionList({ event }: { event: Event }) {
const inQuietMode = shouldHideInteractions(event)
const { t } = useTranslation()
const { push } = useSecondaryPage()
const { isSmallScreen } = useScreenSize()
@ -59,7 +61,7 @@ export default function ReactionList({ event }: { event: Event }) { @@ -59,7 +61,7 @@ export default function ReactionList({ event }: { event: Event }) {
>
<div className="w-6 flex flex-col items-center">
<Emoji
emoji={like.emoji}
emoji={inQuietMode ? '+' : like.emoji}
classNames={{
text: 'text-xl'
}}

7
src/components/ZapList/index.tsx

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
import { useSecondaryPage } from '@/PageManager'
import { useNoteStatsById } from '@/hooks/useNoteStatsById'
import { shouldHideInteractions } from '@/lib/event-filtering'
import { formatAmount } from '@/lib/lightning'
import { toProfile } from '@/lib/link'
import { useScreenSize } from '@/providers/ScreenSizeProvider'
@ -16,6 +17,12 @@ import Username from '../Username' @@ -16,6 +17,12 @@ import Username from '../Username'
const SHOW_COUNT = 20
export default function ZapList({ event }: { event: Event }) {
const inQuietMode = shouldHideInteractions(event)
// Hide zap receipts in quiet mode as they contain emojis and text
if (inQuietMode) {
return null
}
const { t } = useTranslation()
const { push } = useSecondaryPage()
const { isSmallScreen } = useScreenSize()

Loading…
Cancel
Save