@cometchat/chat-uikit-react-native 5.4.1 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +542 -5
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +20 -1
- package/ios/CometChatClipboardModule.m +5 -0
- package/ios/CometChatClipboardModule.swift +22 -0
- package/ios/RichTextEditorView.swift +593 -31
- package/ios/RichTextEditorViewManager.m +2 -0
- package/ios/RichTextEditorViewManager.swift +16 -0
- package/package.json +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +245 -55
- package/src/CometChatCompactMessageComposer/index.ts +2 -0
- package/src/CometChatConversations/CometChatConversations.tsx +291 -14
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
- package/src/CometChatMessageList/CometChatMessageList.tsx +568 -15
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +154 -0
- package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +14 -1
- package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +940 -0
- package/src/CometChatPinnedMessages/index.ts +5 -0
- package/src/CometChatPinnedMessages/style.ts +216 -0
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
- package/src/CometChatRichTextEditor/index.tsx +27 -1
- package/src/CometChatRichTextEditor/types.ts +19 -1
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +634 -0
- package/src/CometChatSavedMessages/index.ts +5 -0
- package/src/CometChatSavedMessages/style.ts +159 -0
- package/src/CometChatSearch/CometChatSearch.tsx +47 -340
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
- package/src/index.ts +60 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +16 -0
- package/src/shared/base/Types.ts +5 -0
- package/src/shared/constants/UIKitConstants.ts +13 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +34 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
- package/src/shared/events/ListenerInitializer.ts +20 -1
- package/src/shared/events/messages.ts +18 -0
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +92 -6
- package/src/shared/formatters/index.ts +14 -0
- package/src/shared/formatters/richTextWireFormat.ts +165 -0
- package/src/shared/framework/MessageDataSource.tsx +296 -3
- package/src/shared/icons/components/thread-follow.tsx +13 -0
- package/src/shared/icons/components/thread-unfollow.tsx +13 -0
- package/src/shared/icons/components/unsave.tsx +13 -0
- package/src/shared/icons/icon-mapping.tsx +6 -0
- package/src/shared/index.ts +37 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -0
- package/src/shared/utils/MarkdownUtils.ts +25 -4
- package/src/shared/utils/MessageUtils.tsx +80 -5
- package/src/shared/utils/PinConversationHelper.ts +245 -0
- package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
- package/src/shared/utils/PinSaveHelper.ts +549 -0
- package/src/shared/utils/SavedMessagesHelper.ts +231 -0
- package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
- package/src/shared/utils/conversationUtils.ts +8 -1
- package/src/shared/utils/stripRichText.ts +7 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +21 -0
- package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +1 -0
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
- package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
- package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
- package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
- package/src/theme/default/default.ts +6 -0
- package/src/theme/type.ts +4 -0
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
- package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +0 -313
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Manual Test Cases — `loadLastAgentConversation`
|
|
2
|
+
|
|
3
|
+
## Prerequisites
|
|
4
|
+
- An `@agentic` user configured in your CometChat dashboard
|
|
5
|
+
- The example app running with `loadLastAgentConversation={true}` on `CometChatMessageList`
|
|
6
|
+
- At least one previous conversation with the agent (send a message, get a response)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## TC-1: Auto-loads last conversation on open
|
|
11
|
+
|
|
12
|
+
**Steps:**
|
|
13
|
+
1. Have at least one previous conversation with the agent (send "Hello", wait for reply)
|
|
14
|
+
2. Navigate away from the agent chat (go back to conversation list)
|
|
15
|
+
3. Open the agent chat again
|
|
16
|
+
|
|
17
|
+
**Expected:**
|
|
18
|
+
- A loading indicator appears briefly
|
|
19
|
+
- The previous conversation messages load automatically
|
|
20
|
+
- You see your last messages and the agent's responses
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## TC-2: Shows greeting/empty state when no previous conversation exists
|
|
25
|
+
|
|
26
|
+
**Steps:**
|
|
27
|
+
1. Use a fresh `@agentic` user with no message history (or use a new logged-in user who hasn't chatted with the agent)
|
|
28
|
+
2. Open the agent chat
|
|
29
|
+
|
|
30
|
+
**Expected:**
|
|
31
|
+
- The agent greeting view appears (avatar, greeting message, suggested messages)
|
|
32
|
+
- No loading spinner hangs indefinitely
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## TC-3: "New Chat" button from header shows empty state
|
|
37
|
+
|
|
38
|
+
**Steps:**
|
|
39
|
+
1. Open the agent chat (previous conversation auto-loads)
|
|
40
|
+
2. Tap the "New Chat" button (pencil/compose icon) in the header
|
|
41
|
+
|
|
42
|
+
**Expected:**
|
|
43
|
+
- The screen resets to the greeting/empty state
|
|
44
|
+
- The previous conversation is NOT re-loaded
|
|
45
|
+
- You can type a fresh message to start a new conversation
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## TC-4: "New Chat" button from Chat History drawer works
|
|
50
|
+
|
|
51
|
+
**Steps:**
|
|
52
|
+
1. Open the agent chat
|
|
53
|
+
2. Tap the "Chat History" button in the header to open the history drawer
|
|
54
|
+
3. Tap the "New Chat" button inside the history drawer
|
|
55
|
+
|
|
56
|
+
**Expected:**
|
|
57
|
+
- The history drawer closes
|
|
58
|
+
- The message list resets to greeting/empty state
|
|
59
|
+
- The previous conversation is NOT re-loaded
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## TC-5: Loading a specific conversation from Chat History still works
|
|
64
|
+
|
|
65
|
+
**Steps:**
|
|
66
|
+
1. Open the agent chat (previous conversation auto-loads)
|
|
67
|
+
2. Tap the "Chat History" button in the header
|
|
68
|
+
3. Tap on a specific past conversation from the list
|
|
69
|
+
|
|
70
|
+
**Expected:**
|
|
71
|
+
- The selected conversation loads with all its messages
|
|
72
|
+
- Streaming/responses still work if you send a new message in that thread
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## TC-6: Sending a new message after "New Chat" starts a new thread
|
|
77
|
+
|
|
78
|
+
**Steps:**
|
|
79
|
+
1. Open the agent chat (previous conversation auto-loads)
|
|
80
|
+
2. Tap "New Chat" (message list resets to empty)
|
|
81
|
+
3. Type and send a message (e.g., "What's the weather?")
|
|
82
|
+
|
|
83
|
+
**Expected:**
|
|
84
|
+
- Your message appears in the list
|
|
85
|
+
- A streaming indicator shows while the agent responds
|
|
86
|
+
- The agent's reply appears correctly
|
|
87
|
+
- This is now a NEW conversation thread (not appended to the old one)
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## TC-7: Re-opening after new chat shows the NEW conversation
|
|
92
|
+
|
|
93
|
+
**Steps:**
|
|
94
|
+
1. Complete TC-6 (start a new chat, send message, get reply)
|
|
95
|
+
2. Navigate away from the agent chat
|
|
96
|
+
3. Open the agent chat again
|
|
97
|
+
|
|
98
|
+
**Expected:**
|
|
99
|
+
- The most recent conversation (from step 1-2) auto-loads
|
|
100
|
+
- You see the "What's the weather?" message and the agent's response
|
|
101
|
+
- NOT the older conversation from before
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## TC-8: `loadLastAgentConversation={false}` preserves existing behavior
|
|
106
|
+
|
|
107
|
+
**Steps:**
|
|
108
|
+
1. Change the prop to `loadLastAgentConversation={false}` (or remove it) in Messages.tsx
|
|
109
|
+
2. Open the agent chat (even with previous conversations)
|
|
110
|
+
|
|
111
|
+
**Expected:**
|
|
112
|
+
- The greeting/empty state shows immediately
|
|
113
|
+
- No automatic loading of previous conversation
|
|
114
|
+
- Behaves exactly as before this feature was added
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## TC-9: Non-agentic users are unaffected
|
|
119
|
+
|
|
120
|
+
**Steps:**
|
|
121
|
+
1. With `loadLastAgentConversation={true}` still set
|
|
122
|
+
2. Open a regular (non-agentic) user chat that has message history
|
|
123
|
+
|
|
124
|
+
**Expected:**
|
|
125
|
+
- Messages load normally (standard behavior)
|
|
126
|
+
- No change in behavior — the prop only applies to `@agentic` users
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## TC-10: Scroll up to load older messages in auto-loaded conversation
|
|
131
|
+
|
|
132
|
+
**Steps:**
|
|
133
|
+
1. Have a long conversation history with the agent (30+ messages)
|
|
134
|
+
2. Open the agent chat (auto-loads last conversation)
|
|
135
|
+
3. Scroll up to the top of the loaded messages
|
|
136
|
+
|
|
137
|
+
**Expected:**
|
|
138
|
+
- Older messages load (pagination works)
|
|
139
|
+
- No crash or infinite spinner
|
|
140
|
+
- The loading indicator appears at the top while fetching
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## TC-11: Delete all history from Chat History panel
|
|
145
|
+
|
|
146
|
+
**Steps:**
|
|
147
|
+
1. Open the agent chat
|
|
148
|
+
2. Open Chat History drawer
|
|
149
|
+
3. Long-press and delete all conversations one by one until none remain
|
|
150
|
+
|
|
151
|
+
**Expected:**
|
|
152
|
+
- When the last conversation is deleted, the list shows empty state
|
|
153
|
+
- The message list resets to greeting/empty view
|
|
154
|
+
- Re-opening the chat shows greeting (no conversation to auto-load)
|
|
@@ -7,6 +7,11 @@ import { CometChatTheme } from '../../theme/type';
|
|
|
7
7
|
interface MessageModalsProps {
|
|
8
8
|
showDeleteModal: boolean;
|
|
9
9
|
showReportDialog: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The pending unpin/unsave, or null when nothing is awaiting confirmation.
|
|
12
|
+
* Pin and save deliberately have no dialog — see requestPinSaveAction.
|
|
13
|
+
*/
|
|
14
|
+
pinSaveConfirm: { message: CometChat.BaseMessage; action: 'unpin' | 'unsave' } | null;
|
|
10
15
|
deleteItem: React.MutableRefObject<CometChat.BaseMessage | undefined>;
|
|
11
16
|
reportedMessageRef: React.MutableRefObject<CometChat.BaseMessage | null>;
|
|
12
17
|
theme: CometChatTheme;
|
|
@@ -16,11 +21,14 @@ interface MessageModalsProps {
|
|
|
16
21
|
onDeleteConfirm: (message: CometChat.BaseMessage) => void;
|
|
17
22
|
onReportCancel: () => void;
|
|
18
23
|
onReportSubmit: (payload: any) => void;
|
|
24
|
+
onPinSaveCancel: () => void;
|
|
25
|
+
onPinSaveConfirm: () => void;
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
export const MessageModals: React.FC<MessageModalsProps> = ({
|
|
22
29
|
showDeleteModal,
|
|
23
30
|
showReportDialog,
|
|
31
|
+
pinSaveConfirm,
|
|
24
32
|
deleteItem,
|
|
25
33
|
reportedMessageRef,
|
|
26
34
|
theme,
|
|
@@ -30,7 +38,10 @@ export const MessageModals: React.FC<MessageModalsProps> = ({
|
|
|
30
38
|
onDeleteConfirm,
|
|
31
39
|
onReportCancel,
|
|
32
40
|
onReportSubmit,
|
|
41
|
+
onPinSaveCancel,
|
|
42
|
+
onPinSaveConfirm,
|
|
33
43
|
}) => {
|
|
44
|
+
const isUnpin = pinSaveConfirm?.action === 'unpin';
|
|
34
45
|
return (
|
|
35
46
|
<>
|
|
36
47
|
<CometChatConfirmDialog
|
|
@@ -48,6 +59,25 @@ export const MessageModals: React.FC<MessageModalsProps> = ({
|
|
|
48
59
|
}}
|
|
49
60
|
/>
|
|
50
61
|
|
|
62
|
+
{/* Unpin/unsave only. Both are removals with no on-screen undo, which is the
|
|
63
|
+
whole reason they ask and their additive counterparts do not. */}
|
|
64
|
+
<CometChatConfirmDialog
|
|
65
|
+
titleText={isUnpin ? t('UNPIN_MESSAGE_TITLE') : t('UNSAVE_MESSAGE_TITLE')}
|
|
66
|
+
icon={
|
|
67
|
+
<Icon
|
|
68
|
+
name={isUnpin ? 'keep-off' : 'unsave'}
|
|
69
|
+
size={theme.spacing.spacing.s12}
|
|
70
|
+
color={theme.color.error}
|
|
71
|
+
/>
|
|
72
|
+
}
|
|
73
|
+
cancelButtonText={t('CANCEL')}
|
|
74
|
+
confirmButtonText={isUnpin ? t('UNPIN') : t('UNSAVE')}
|
|
75
|
+
messageText={isUnpin ? t('UNPIN_MESSAGE_CONFIRM') : t('UNSAVE_MESSAGE_CONFIRM')}
|
|
76
|
+
isOpen={pinSaveConfirm != null}
|
|
77
|
+
onCancel={onPinSaveCancel}
|
|
78
|
+
onConfirm={onPinSaveConfirm}
|
|
79
|
+
/>
|
|
80
|
+
|
|
51
81
|
<CometChatReportDialog
|
|
52
82
|
isOpen={showReportDialog}
|
|
53
83
|
message={reportedMessageRef.current || undefined}
|
|
@@ -5,6 +5,7 @@ import { CometChatBottomSheet } from '../../shared/views';
|
|
|
5
5
|
import { CometChatMessageInformation } from '../../CometChatMessageInformation/CometChatMessageInformation';
|
|
6
6
|
import { CometChatQuickReactions } from '../../shared/views/CometChatQuickReactions';
|
|
7
7
|
import { CometChatActionSheet } from '../../shared';
|
|
8
|
+
import { MessageQuickActions, partitionQuickActions } from './MessageQuickActions';
|
|
8
9
|
import { CometChatTheme } from '../../theme/type';
|
|
9
10
|
import { CometChatMessageTemplate } from '../../shared/modals/CometChatMessageTemplate';
|
|
10
11
|
import { getModerationStatus } from '../../shared/utils/MessageUtils';
|
|
@@ -65,6 +66,8 @@ export const MessageOptionsSheet: React.FC<MessageOptionsSheetProps> = ({
|
|
|
65
66
|
setMessageInfo,
|
|
66
67
|
setShowEmojiKeyboard,
|
|
67
68
|
}) => {
|
|
69
|
+
const quickActions = partitionQuickActions(showMessageOptions);
|
|
70
|
+
|
|
68
71
|
return (
|
|
69
72
|
<CometChatBottomSheet
|
|
70
73
|
ref={bottomSheetRef}
|
|
@@ -128,9 +131,19 @@ export const MessageOptionsSheet: React.FC<MessageOptionsSheetProps> = ({
|
|
|
128
131
|
/>
|
|
129
132
|
)}
|
|
130
133
|
|
|
134
|
+
{/* One split, two halves: promoted actions are REMOVED from the list, so nothing
|
|
135
|
+
appears twice. With Pin and Save both unavailable the row is empty and every
|
|
136
|
+
option — Reply included — stays in the list, leaving the sheet exactly as it was
|
|
137
|
+
before this feature existed. */}
|
|
138
|
+
<MessageQuickActions
|
|
139
|
+
actions={quickActions.tiles}
|
|
140
|
+
message={selectedMessage}
|
|
141
|
+
theme={mergedTheme}
|
|
142
|
+
/>
|
|
143
|
+
|
|
131
144
|
<View style={{ maxHeight: ACTION_SHEET_MAX_HEIGHT }}>
|
|
132
145
|
<CometChatActionSheet
|
|
133
|
-
actions={
|
|
146
|
+
actions={quickActions.list}
|
|
134
147
|
style={mergedTheme.messageListStyles.messageOptionsStyles}
|
|
135
148
|
/>
|
|
136
149
|
</View>
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import React, { JSX } from "react";
|
|
2
|
+
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
|
|
3
|
+
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
4
|
+
import { CometChatMessageOption } from "../../shared/modals/CometChatMessageOption";
|
|
5
|
+
import { MessageOptionConstants } from "../../shared/constants/UIKitConstants";
|
|
6
|
+
import { CometChatTheme } from "../../theme/type";
|
|
7
|
+
import { useCometChatTranslation } from "../../shared/resources/CometChatLocalizeNew";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The three actions promoted out of the options list into a row of tiles at the top of the sheet
|
|
11
|
+
* (§6.2). Order is fixed and deliberate — Reply, then the pin/save pair — so the row does not
|
|
12
|
+
* reshuffle under the user's thumb as a message's state changes.
|
|
13
|
+
*
|
|
14
|
+
* Each entry is a PAIR because pin and save flip on state: whichever of the two the DataSource
|
|
15
|
+
* built for this message is the one that gets a tile.
|
|
16
|
+
*/
|
|
17
|
+
/** The pin/save pairs, in row order. Pairs, because each flips to its opposite on state. */
|
|
18
|
+
const PIN_SAVE_ORDER: string[][] = [
|
|
19
|
+
[MessageOptionConstants.pinMessage, MessageOptionConstants.unpinMessage],
|
|
20
|
+
[MessageOptionConstants.saveMessage, MessageOptionConstants.unsaveMessage],
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Splits the options into the tile row and the list beneath it.
|
|
25
|
+
*
|
|
26
|
+
* The row is **conditional on Pin/Save existing at all**. Reply is promoted only to accompany
|
|
27
|
+
* them — it never earns a tile on its own. So:
|
|
28
|
+
*
|
|
29
|
+
* - both features on → 3 tiles (Reply · Pin · Save)
|
|
30
|
+
* - one of them on → 2 tiles (Reply · the survivor)
|
|
31
|
+
* - neither → NO row, and Reply stays in the list. The sheet is exactly what it
|
|
32
|
+
* was before this feature existed.
|
|
33
|
+
*
|
|
34
|
+
* Nothing is fabricated: an action becomes a tile only if the DataSource already offered it, so
|
|
35
|
+
* every rule that governs availability — the dashboard flags an integrator feeds into
|
|
36
|
+
* PinSaveConfig, the group role gate, an ineligible message that is still sending or deleted —
|
|
37
|
+
* lands here without this component knowing any of them.
|
|
38
|
+
*
|
|
39
|
+
* Returning both halves from ONE function is deliberate: computing them separately let the row
|
|
40
|
+
* and the list disagree about whether Reply had been promoted.
|
|
41
|
+
*/
|
|
42
|
+
export const partitionQuickActions = (
|
|
43
|
+
options: CometChatMessageOption[]
|
|
44
|
+
): { tiles: CometChatMessageOption[]; list: CometChatMessageOption[] } => {
|
|
45
|
+
const pinSave = PIN_SAVE_ORDER.map((ids) =>
|
|
46
|
+
options.find((option) => ids.includes(option.id))
|
|
47
|
+
).filter(Boolean) as CometChatMessageOption[];
|
|
48
|
+
|
|
49
|
+
if (!pinSave.length) return { tiles: [], list: options };
|
|
50
|
+
|
|
51
|
+
const reply = options.find(
|
|
52
|
+
(option) => option.id === MessageOptionConstants.replyMessage
|
|
53
|
+
);
|
|
54
|
+
const tiles = reply ? [reply, ...pinSave] : pinSave;
|
|
55
|
+
const promoted = new Set(tiles.map((option) => option.id));
|
|
56
|
+
|
|
57
|
+
return { tiles, list: options.filter((option) => !promoted.has(option.id)) };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Tiles use the SHORT label, not the option's own title.
|
|
62
|
+
*
|
|
63
|
+
* The list needs "Unsave message" to read as a sentence among its neighbours; a tile is a fixed
|
|
64
|
+
* third of the row and "Unsave message" simply does not fit — it wraps or ellipsises, and the
|
|
65
|
+
* row stops looking like a row. Same reason Slack's tiles say Reply / Forward / Save.
|
|
66
|
+
*
|
|
67
|
+
* These keys already exist (they are the confirm-dialog button copy), so this adds no new strings
|
|
68
|
+
* to translate. Anything unmapped falls back to the option's title rather than rendering blank.
|
|
69
|
+
*/
|
|
70
|
+
const SHORT_LABEL_KEY: Record<string, string> = {
|
|
71
|
+
[MessageOptionConstants.replyMessage]: "REPLY",
|
|
72
|
+
[MessageOptionConstants.pinMessage]: "PIN",
|
|
73
|
+
[MessageOptionConstants.unpinMessage]: "UNPIN",
|
|
74
|
+
[MessageOptionConstants.saveMessage]: "SAVE",
|
|
75
|
+
[MessageOptionConstants.unsaveMessage]: "UNSAVE",
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export interface MessageQuickActionsProps {
|
|
79
|
+
/** Already filtered through `partitionQuickActions`. */
|
|
80
|
+
actions: CometChatMessageOption[];
|
|
81
|
+
/** Null while no message is selected — the sheet holds it as a nullable ref. */
|
|
82
|
+
message?: CometChat.BaseMessage | null;
|
|
83
|
+
theme: CometChatTheme;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Slack-style row of prominent actions above the options list. Renders nothing when there is
|
|
88
|
+
* nothing to promote, so the sheet keeps its original shape rather than showing an empty band.
|
|
89
|
+
*/
|
|
90
|
+
export const MessageQuickActions = ({
|
|
91
|
+
actions,
|
|
92
|
+
message,
|
|
93
|
+
theme,
|
|
94
|
+
}: MessageQuickActionsProps): JSX.Element | null => {
|
|
95
|
+
const { t } = useCometChatTranslation();
|
|
96
|
+
|
|
97
|
+
if (!actions.length) return null;
|
|
98
|
+
|
|
99
|
+
const labelFor = (action: CometChatMessageOption): string => {
|
|
100
|
+
const key = SHORT_LABEL_KEY[action.id];
|
|
101
|
+
const short = key ? t(key) : undefined;
|
|
102
|
+
// t() echoes the key back when a translation is missing — treat that as no translation
|
|
103
|
+
// rather than printing "UNSAVE" at the user.
|
|
104
|
+
return short && short !== key ? short : action.title;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<View style={styles.row} testID='MessageOptions.quickActions'>
|
|
109
|
+
{actions.map((action) => (
|
|
110
|
+
<TouchableOpacity
|
|
111
|
+
key={action.id}
|
|
112
|
+
testID={`QuickAction.${action.id}`}
|
|
113
|
+
accessibilityRole='button'
|
|
114
|
+
// The FULL title for screen readers — "Unsave message" is unambiguous read aloud,
|
|
115
|
+
// where the visible tile has to stay short to fit.
|
|
116
|
+
accessibilityLabel={action.title}
|
|
117
|
+
style={[
|
|
118
|
+
styles.tile,
|
|
119
|
+
{
|
|
120
|
+
backgroundColor: theme.color.background3,
|
|
121
|
+
borderRadius: theme.spacing.radius.r2,
|
|
122
|
+
},
|
|
123
|
+
]}
|
|
124
|
+
onPress={() => message && action.onPress?.(message)}
|
|
125
|
+
>
|
|
126
|
+
<View style={styles.icon}>{action.icon as JSX.Element}</View>
|
|
127
|
+
<Text
|
|
128
|
+
numberOfLines={1}
|
|
129
|
+
// Shrink before truncating: a long word in a translated locale loses a point or two
|
|
130
|
+
// of size rather than becoming "Unsav…".
|
|
131
|
+
adjustsFontSizeToFit
|
|
132
|
+
minimumFontScale={0.85}
|
|
133
|
+
style={[
|
|
134
|
+
theme.typography.button.medium,
|
|
135
|
+
styles.label,
|
|
136
|
+
{ color: theme.color.textPrimary },
|
|
137
|
+
]}
|
|
138
|
+
>
|
|
139
|
+
{labelFor(action)}
|
|
140
|
+
</Text>
|
|
141
|
+
</TouchableOpacity>
|
|
142
|
+
))}
|
|
143
|
+
</View>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const styles = StyleSheet.create({
|
|
148
|
+
row: { flexDirection: "row", gap: 8, paddingHorizontal: 16, paddingBottom: 8 },
|
|
149
|
+
// flex:1 rather than a fixed width: with Pin unavailable the two survivors stretch to fill the
|
|
150
|
+
// row instead of leaving a gap where the third tile was.
|
|
151
|
+
tile: {
|
|
152
|
+
flex: 1,
|
|
153
|
+
alignItems: "center",
|
|
154
|
+
justifyContent: "center",
|
|
155
|
+
paddingVertical: 14,
|
|
156
|
+
paddingHorizontal: 4,
|
|
157
|
+
gap: 6,
|
|
158
|
+
},
|
|
159
|
+
icon: { alignItems: "center", justifyContent: "center" },
|
|
160
|
+
// Keeps the label off the tile's rounded edges when a locale gives a longer word.
|
|
161
|
+
label: { textAlign: "center" },
|
|
162
|
+
});
|