import { MESSAGE_CUSTOM_TYPE } from '@linktr.ee/messaging-taxonomy' import { GiftIcon } from '@phosphor-icons/react' import { LocalMessage } from 'stream-chat' interface MessageTagProps { message: LocalMessage /** When true, renders sender-side chatbot variants */ isMyMessage?: boolean /** Whether the message includes an attachment */ hasAttachment?: boolean } const SparkleIcon = ({ size = 15 }: { size?: number }) => ( ) /** Check if a message is a paid message based on metadata */ const isPaidMessage = (message: LocalMessage): boolean => { return message.metadata?.custom_type === MESSAGE_CUSTOM_TYPE.PAID } /** Check if a message is a chatbot message based on metadata */ export const isChatbotMessage = (message: LocalMessage): boolean => { return message.metadata?.custom_type === MESSAGE_CUSTOM_TYPE.CHATBOT } /** Check if a message is a locked attachment */ export const isAttachmentMessage = (message: LocalMessage): boolean => { return message.metadata?.custom_type === MESSAGE_CUSTOM_TYPE.ATTACHMENT } export const isTextAttachmentMessage = (message: LocalMessage): boolean => { return ( isAttachmentMessage(message) && message.metadata?.attachment_content_type === 'text' ) } export const isMediaAttachmentMessage = (message: LocalMessage): boolean => { return ( isAttachmentMessage(message) && message.metadata?.attachment_content_type !== 'text' ) } /** Check if the footer tag on this message already reads "Delivered with …" */ export const hasPaidDeliveryTag = (message: LocalMessage): boolean => { return isPaidMessage(message) && !!message.metadata?.amount_text } export const MessageTag = ({ message, isMyMessage = false, hasAttachment = false, }: MessageTagProps) => { const isPaid = isPaidMessage(message) const isChatbot = isChatbotMessage(message) if (!isPaid && !isChatbot) { return null } if (isPaid) { const amountText = message.metadata?.amount_text if (!amountText) return null return (
Delivered with {amountText} message
) } const isSenderAttachmentVariant = isMyMessage && hasAttachment const chatbotLabel = isSenderAttachmentVariant ? 'Sent with AI' : 'Sent by AI Assistant' const chatbotBase = 'inline-flex items-center text-[10px] font-normal leading-4 tracking-[0.2px]' const chatbotVariant = isSenderAttachmentVariant ? 'justify-end gap-2 text-black/30' : isMyMessage ? 'w-full justify-start gap-1.5 mt-3 px-4 text-white/55' : 'w-full justify-start gap-1.5 mt-3 px-4 text-black/30' const label = {chatbotLabel} const icon = ( ) return (
{isMyMessage && !isSenderAttachmentVariant ? ( <> {label} {icon} ) : ( <> {icon} {label} )}
) }