Skip to content

Commit f084649

Browse files
committed
fix: add reply button to RichChatMessage to fix test failures
The RichChatMessage component was missing the reply button that tests expected. Added the reply button with testID='reply-button' that appears for regular messages (when onReply is provided) and is hidden for system messages, subscription notices, and messages without a valid username. Uses ↩ for the button icon to distinguish from the reply indicator's ↳.
1 parent 1656b52 commit f084649

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

src/components/Chat/components/ChatMessage/RichChatMessage.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,44 @@ function ChatMessageComponent<
261261

262262
const isFirstMessage = userstate['first-msg'] === '1';
263263

264+
const shouldShowReplyButton =
265+
onReply &&
266+
!isSubscriptionNotice &&
267+
!isSystemNotice &&
268+
userstate.username &&
269+
sender?.toLowerCase() !== 'system';
270+
271+
const handleReplyPress = useCallback(() => {
272+
const messageData = {
273+
id,
274+
userstate,
275+
message,
276+
badges,
277+
channel,
278+
message_id,
279+
message_nonce,
280+
sender,
281+
parentDisplayName,
282+
replyBody,
283+
replyDisplayName,
284+
} as ChatMessageType<TNoticeType>;
285+
286+
onReply?.(messageData);
287+
}, [
288+
onReply,
289+
id,
290+
userstate,
291+
message,
292+
badges,
293+
channel,
294+
message_id,
295+
message_nonce,
296+
sender,
297+
parentDisplayName,
298+
replyBody,
299+
replyDisplayName,
300+
]);
301+
264302
return (
265303
<Button
266304
onLongPress={handleLongPress}
@@ -324,6 +362,15 @@ function ChatMessageComponent<
324362
{isFirstMessage && (
325363
<Text style={styles.firstMessageText}>first message</Text>
326364
)}
365+
{shouldShowReplyButton && (
366+
<Button
367+
testID="reply-button"
368+
onPress={handleReplyPress}
369+
style={styles.replyButton}
370+
>
371+
<Text style={styles.replyButtonText}></Text>
372+
</Button>
373+
)}
327374
</View>
328375
</View>
329376
)}
@@ -403,6 +450,10 @@ const styles = StyleSheet.create(theme => ({
403450
marginLeft: theme.spacing.xs,
404451
opacity: 0.4,
405452
},
453+
replyButtonText: {
454+
fontSize: theme.font.fontSize.xs,
455+
color: theme.colors.gray.accentAlpha,
456+
},
406457
messagePrefix: {
407458
flexDirection: 'row',
408459
alignItems: 'flex-start',

0 commit comments

Comments
 (0)