Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import {ChatBskyConvoDefs} from '@atproto/api'import {type I18n} from '@lingui/core'import {msg} from '@lingui/core/macro'
import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name'import {isDidBlockedInConvo} from '#/components/dms/getMessageInfo'import type * as bsky from '#/types/bsky'
export type UserReactionInfo = { message: string createdAt: string isBlocked: boolean}
export function getReactionInfo({ convo, currentAccountDid, primaryProfile, i18n,}: { convo: ChatBskyConvoDefs.ConvoView currentAccountDid: string | undefined primaryProfile?: bsky.profile.AnyProfileView i18n: I18n}): UserReactionInfo | null { if (!ChatBskyConvoDefs.isMessageAndReactionView(convo.lastReaction)) { return null }
const {reaction, message: reactedTo} = convo.lastReaction const isFromMe = reaction.sender.did === currentAccountDid const senderDid = reaction.sender.did const sender = convo.members.find(m => m.did === senderDid) const name = sender ? createSanitizedDisplayName(sender) : null
// Hide the preview when either the reactor or the author of the reacted-to // message is blocked - otherwise a blocked reactor's name or a blocked // sender's message text would leak into the chat list. const isBlocked = isDidBlockedInConvo({ did: senderDid, members: convo.members, primaryProfile, }) || isDidBlockedInConvo({ did: reactedTo.sender?.did, members: convo.members, primaryProfile, })
const lastMessageText = reactedTo.text const fallbackMessage = i18n._( msg({ message: 'a message', comment: 'If last message does not contain text, fall back to "{user} reacted to {a message}"', }), ) const target = lastMessageText ? `"${lastMessageText}"` : fallbackMessage
let message: string if (isFromMe) { message = i18n._(msg`You reacted ${reaction.value} to ${target}`) } else if (name) { message = i18n._(msg`${name} reacted ${reaction.value} to ${target}`) } else { message = i18n._(msg`Someone reacted ${reaction.value} to ${target}`) }
return { message, createdAt: reaction.createdAt, isBlocked, }}