@cometchat/chat-uikit-react-native 5.4.0 → 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/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +605 -6
- 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 +648 -35
- package/ios/RichTextEditorViewManager.m +2 -0
- package/ios/RichTextEditorViewManager.swift +16 -0
- package/package.json +2 -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/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 +95 -8
- 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/CometChatMessagePreview/CometChatMessagePreview.tsx +2 -1
- 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/elementType.tsx +38 -0
- 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 +28 -14
- 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/CometChatTextBubble/CometChatTextBubble.tsx +4 -3
- package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
- package/src/theme/default/default.ts +6 -0
- package/src/theme/type.ts +4 -0
|
@@ -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
|
+
});
|