Skip to content

Commit 0036880

Browse files
committed
refactor: replace reply button with long press, update tests
1 parent f084649 commit 0036880

2 files changed

Lines changed: 68 additions & 182 deletions

File tree

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

Lines changed: 24 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function ChatMessageComponent<
5252
parentDisplayName,
5353
replyBody,
5454
replyDisplayName,
55-
parentColor,
55+
parentColor: _,
5656
notice_tags,
5757
onReply,
5858
onBadgePress,
@@ -203,6 +203,24 @@ function ChatMessageComponent<
203203
));
204204
}, [badges, handleBadgePress]);
205205

206+
const isSystemNotice = message.some(
207+
part =>
208+
part.type === 'stv_emote_added' || part.type === 'stv_emote_removed',
209+
);
210+
211+
const canReply =
212+
onReply &&
213+
!message.some(
214+
part =>
215+
part.type === 'sub' ||
216+
part.type === 'resub' ||
217+
part.type === 'anongiftpaidupgrade' ||
218+
part.type === 'anongift',
219+
) &&
220+
!isSystemNotice &&
221+
userstate.username &&
222+
sender?.toLowerCase() !== 'system';
223+
206224
const handleLongPress = useCallback(() => {
207225
const messageData = {
208226
id,
@@ -218,14 +236,17 @@ function ChatMessageComponent<
218236
replyDisplayName,
219237
} as ChatMessageType<TNoticeType>;
220238

221-
onReply?.(messageData);
239+
if (canReply) {
240+
onReply?.(messageData);
241+
}
222242
onMessageLongPress?.({
223243
message,
224244
username: userstate.username,
225245
messageData,
226246
});
227247
}, [
228248
onReply,
249+
canReply,
229250
onMessageLongPress,
230251
message,
231252
userstate,
@@ -254,53 +275,11 @@ function ChatMessageComponent<
254275
// eslint-disable-next-line react-hooks/exhaustive-deps
255276
}, [userId, paintId]);
256277

257-
const isSystemNotice = message.some(
258-
part =>
259-
part.type === 'stv_emote_added' || part.type === 'stv_emote_removed',
260-
);
261-
262278
const isFirstMessage = userstate['first-msg'] === '1';
263279

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-
302280
return (
303281
<Button
282+
testID="chat-message"
304283
onLongPress={handleLongPress}
305284
style={[
306285
styles.chatContainer,
@@ -309,29 +288,6 @@ function ChatMessageComponent<
309288
isFirstMessage && styles.firstMessageContainer,
310289
]}
311290
>
312-
{isReply && (
313-
<View style={styles.replyIndicatorWrapper} testID="reply-indicator">
314-
<Text style={styles.replyLabel}></Text>
315-
<Text
316-
style={[
317-
styles.replyUsername,
318-
parentColor && { color: lightenColor(parentColor) },
319-
]}
320-
>
321-
@{parentDisplayName}
322-
</Text>
323-
{replyBody ? (
324-
<Text
325-
style={styles.replyBodyPreview}
326-
numberOfLines={1}
327-
ellipsizeMode="tail"
328-
>
329-
{replyBody}
330-
</Text>
331-
) : null}
332-
</View>
333-
)}
334-
335291
{isSubscriptionNotice && (
336292
<View style={styles.subscriptionNoticeContainer}>
337293
{message.map(renderMessagePart)}
@@ -362,15 +318,6 @@ function ChatMessageComponent<
362318
{isFirstMessage && (
363319
<Text style={styles.firstMessageText}>first message</Text>
364320
)}
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-
)}
374321
</View>
375322
</View>
376323
)}
@@ -445,15 +392,6 @@ const styles = StyleSheet.create(theme => ({
445392
justifyContent: 'space-between',
446393
width: '100%',
447394
},
448-
replyButton: {
449-
padding: theme.spacing.xs,
450-
marginLeft: theme.spacing.xs,
451-
opacity: 0.4,
452-
},
453-
replyButtonText: {
454-
fontSize: theme.font.fontSize.xs,
455-
color: theme.colors.gray.accentAlpha,
456-
},
457395
messagePrefix: {
458396
flexDirection: 'row',
459397
alignItems: 'flex-start',

0 commit comments

Comments
 (0)