index.tsx raw

   1  import { ExtendedKind } from '@/constants'
   2  import { notificationFilter } from '@/lib/notification'
   3  import { useContentPolicy } from '@/providers/ContentPolicyProvider'
   4  import { useMuteList } from '@/providers/MuteListProvider'
   5  import { useNostr } from '@/providers/NostrProvider'
   6  import { useUserTrust } from '@/providers/UserTrustProvider'
   7  import { Event, kinds } from 'nostr-tools'
   8  import { useMemo } from 'react'
   9  import { HighlightNotification } from './HighlightNotification'
  10  import { MentionNotification } from './MentionNotification'
  11  import { PollResponseNotification } from './PollResponseNotification'
  12  import { ReactionNotification } from './ReactionNotification'
  13  import { RepostNotification } from './RepostNotification'
  14  import { ZapNotification } from './ZapNotification'
  15  
  16  export function NotificationItem({
  17    notification,
  18    isNew = false,
  19    navIndex
  20  }: {
  21    notification: Event
  22    isNew?: boolean
  23    navIndex?: number
  24  }) {
  25    const { pubkey } = useNostr()
  26    const { mutePubkeySet } = useMuteList()
  27    const { hideContentMentioningMutedUsers } = useContentPolicy()
  28    const { hideUntrustedNotifications, isUserTrusted } = useUserTrust()
  29    const canShow = useMemo(() => {
  30      return notificationFilter(notification, {
  31        pubkey,
  32        mutePubkeySet,
  33        hideContentMentioningMutedUsers,
  34        hideUntrustedNotifications,
  35        isUserTrusted
  36      })
  37    }, [
  38      notification,
  39      mutePubkeySet,
  40      hideContentMentioningMutedUsers,
  41      hideUntrustedNotifications,
  42      isUserTrusted
  43    ])
  44    if (!canShow) return null
  45  
  46    if (notification.kind === kinds.Reaction) {
  47      return <ReactionNotification notification={notification} isNew={isNew} navIndex={navIndex} />
  48    }
  49    if (
  50      notification.kind === kinds.ShortTextNote ||
  51      notification.kind === ExtendedKind.COMMENT ||
  52      notification.kind === ExtendedKind.VOICE_COMMENT ||
  53      notification.kind === ExtendedKind.POLL
  54    ) {
  55      return <MentionNotification notification={notification} isNew={isNew} navIndex={navIndex} />
  56    }
  57    if (notification.kind === kinds.Repost || notification.kind === kinds.GenericRepost) {
  58      return <RepostNotification notification={notification} isNew={isNew} navIndex={navIndex} />
  59    }
  60    if (notification.kind === kinds.Zap) {
  61      return <ZapNotification notification={notification} isNew={isNew} navIndex={navIndex} />
  62    }
  63    if (notification.kind === ExtendedKind.POLL_RESPONSE) {
  64      return <PollResponseNotification notification={notification} isNew={isNew} navIndex={navIndex} />
  65    }
  66    if (notification.kind === kinds.Highlights) {
  67      return <HighlightNotification notification={notification} isNew={isNew} navIndex={navIndex} />
  68    }
  69    return null
  70  }
  71