From 019a51aedc5cc138a43b812a1bb6182109b7fd48 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Sun, 8 Sep 2024 19:46:25 -0700 Subject: [PATCH] feat: add hasAttachments to MessagePrimitive.If (#788) --- .../src/primitive-hooks/message/useMessageIf.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/react/src/primitive-hooks/message/useMessageIf.tsx b/packages/react/src/primitive-hooks/message/useMessageIf.tsx index b8515923a..39206e257 100644 --- a/packages/react/src/primitive-hooks/message/useMessageIf.tsx +++ b/packages/react/src/primitive-hooks/message/useMessageIf.tsx @@ -11,6 +11,7 @@ type MessageIfFilters = { copied: boolean | undefined; lastOrHover: boolean | undefined; speaking: boolean | undefined; + hasAttachments: boolean | undefined; }; export type UseMessageIfProps = RequireAtLeastOne; @@ -30,10 +31,22 @@ export const useMessageIf = (props: UseMessageIfProps) => { if (props.copied === true && !isCopied) return false; if (props.copied === false && isCopied) return false; - + if (props.speaking === true && !isSpeaking) return false; if (props.speaking === false && isSpeaking) return false; + if ( + props.hasAttachments === true && + (message.role !== "user" || !message.attachments.length) + ) + return false; + if ( + props.hasAttachments === false && + message.role === "user" && + !!message.attachments.length + ) + return false; + return true; }, );