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. 21
      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 @@
import { useFetchEvent } from '@/hooks' import { useFetchEvent } from '@/hooks'
import { getZapInfoFromEvent } from '@/lib/event-metadata' import { getZapInfoFromEvent } from '@/lib/event-metadata'
import { shouldHideInteractions } from '@/lib/event-filtering'
import { formatAmount } from '@/lib/lightning' import { formatAmount } from '@/lib/lightning'
import { toNote, toProfile } from '@/lib/link' import { toNote, toProfile } from '@/lib/link'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
@ -12,11 +13,29 @@ import Username from '../Username'
import UserAvatar from '../UserAvatar' import UserAvatar from '../UserAvatar'
export default function Zap({ event, className }: { event: Event; className?: string }) { 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 { t } = useTranslation()
const { navigateToNote } = useSmartNoteNavigation() const { navigateToNote } = useSmartNoteNavigation()
const { push } = useSecondaryPage() 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 // Determine if this is an event zap or profile zap
const isEventZap = targetEvent || zapInfo?.eventId const isEventZap = targetEvent || zapInfo?.eventId

4
src/components/NoteStats/LikeButton.tsx

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

21
src/components/NoteStats/Likes.tsx

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

4
src/components/ReactionList/index.tsx

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

7
src/components/ZapList/index.tsx

@ -1,5 +1,6 @@
import { useSecondaryPage } from '@/PageManager' import { useSecondaryPage } from '@/PageManager'
import { useNoteStatsById } from '@/hooks/useNoteStatsById' import { useNoteStatsById } from '@/hooks/useNoteStatsById'
import { shouldHideInteractions } from '@/lib/event-filtering'
import { formatAmount } from '@/lib/lightning' import { formatAmount } from '@/lib/lightning'
import { toProfile } from '@/lib/link' import { toProfile } from '@/lib/link'
import { useScreenSize } from '@/providers/ScreenSizeProvider' import { useScreenSize } from '@/providers/ScreenSizeProvider'
@ -16,6 +17,12 @@ import Username from '../Username'
const SHOW_COUNT = 20 const SHOW_COUNT = 20
export default function ZapList({ event }: { event: Event }) { 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 { t } = useTranslation()
const { push } = useSecondaryPage() const { push } = useSecondaryPage()
const { isSmallScreen } = useScreenSize() const { isSmallScreen } = useScreenSize()

Loading…
Cancel
Save