feat: add more trust score badge

This commit is contained in:
codytseng 2025-12-26 20:41:02 +08:00
parent 6f64aafdae
commit 234c5228b0
2 changed files with 25 additions and 4 deletions

View file

@ -1,6 +1,7 @@
import ContentPreview from '@/components/ContentPreview' import ContentPreview from '@/components/ContentPreview'
import { FormattedTimestamp } from '@/components/FormattedTimestamp' import { FormattedTimestamp } from '@/components/FormattedTimestamp'
import StuffStats from '@/components/StuffStats' import StuffStats from '@/components/StuffStats'
import TrustScoreBadge from '@/components/TrustScoreBadge'
import { Skeleton } from '@/components/ui/skeleton' import { Skeleton } from '@/components/ui/skeleton'
import UserAvatar from '@/components/UserAvatar' import UserAvatar from '@/components/UserAvatar'
import Username from '@/components/Username' import Username from '@/components/Username'
@ -62,7 +63,16 @@ export default function Notification({
onClick={handleClick} onClick={handleClick}
> >
<div className="flex gap-2 items-center flex-1 w-0"> <div className="flex gap-2 items-center flex-1 w-0">
<div className="relative">
<UserAvatar userId={sender} size="small" /> <UserAvatar userId={sender} size="small" />
<TrustScoreBadge
pubkey={sender}
classNames={{
container:
'absolute inset-0 w-full h-full rounded-full bg-background/60 backdrop-blur-sm flex flex-col justify-center items-center pointer-events-none'
}}
/>
</div>
{icon} {icon}
{middle} {middle}
{targetEvent && ( {targetEvent && (
@ -99,6 +109,7 @@ export default function Notification({
className="flex-1 max-w-fit truncate font-semibold" className="flex-1 max-w-fit truncate font-semibold"
skeletonClassName="h-4" skeletonClassName="h-4"
/> />
<TrustScoreBadge pubkey={sender} />
<div className="shrink-0 text-muted-foreground text-sm">{description}</div> <div className="shrink-0 text-muted-foreground text-sm">{description}</div>
</div> </div>
{unread && ( {unread && (

View file

@ -8,10 +8,14 @@ import { useTranslation } from 'react-i18next'
export default function TrustScoreBadge({ export default function TrustScoreBadge({
pubkey, pubkey,
className className,
classNames
}: { }: {
pubkey: string pubkey: string
className?: string className?: string
classNames?: {
container?: string
}
}) { }) {
const { t } = useTranslation() const { t } = useTranslation()
const { isUserTrusted } = useUserTrust() const { isUserTrusted } = useUserTrust()
@ -54,7 +58,10 @@ export default function TrustScoreBadge({
// percentile < 60: suspicious (yellow warning) // percentile < 60: suspicious (yellow warning)
if (percentile < 40) { if (percentile < 40) {
return ( return (
<div title={t('Likely spam account (Trust score: {{percentile}}%)', { percentile })}> <div
title={t('Likely spam account (Trust score: {{percentile}}%)', { percentile })}
className={classNames?.container}
>
<ShieldAlert className={cn('!size-4 text-red-500', className)} /> <ShieldAlert className={cn('!size-4 text-red-500', className)} />
</div> </div>
) )
@ -62,7 +69,10 @@ export default function TrustScoreBadge({
if (percentile < 60) { if (percentile < 60) {
return ( return (
<div title={t('Suspicious account (Trust score: {{percentile}}%)', { percentile })}> <div
title={t('Suspicious account (Trust score: {{percentile}}%)', { percentile })}
className={classNames?.container}
>
<AlertTriangle className={cn('!size-4 text-yellow-600 dark:text-yellow-500', className)} /> <AlertTriangle className={cn('!size-4 text-yellow-600 dark:text-yellow-500', className)} />
</div> </div>
) )