@cometchat/chat-uikit-react-native 5.4.1 → 5.5.1

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.
Files changed (105) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +562 -5
  3. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +28 -1
  4. package/ios/CometChatClipboardModule.m +5 -0
  5. package/ios/CometChatClipboardModule.swift +22 -0
  6. package/ios/RichTextEditorView.swift +636 -31
  7. package/ios/RichTextEditorViewManager.m +3 -0
  8. package/ios/RichTextEditorViewManager.swift +24 -0
  9. package/package.json +5 -2
  10. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +283 -64
  11. package/src/CometChatCompactMessageComposer/index.ts +2 -0
  12. package/src/CometChatConversations/CometChatConversations.tsx +299 -15
  13. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
  14. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +15 -3
  15. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
  16. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
  17. package/src/CometChatMessageList/CometChatMessageList.tsx +572 -16
  18. package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
  19. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +21 -9
  20. package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
  21. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +964 -0
  22. package/src/CometChatPinnedMessages/index.ts +5 -0
  23. package/src/CometChatPinnedMessages/style.ts +216 -0
  24. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
  25. package/src/CometChatRichTextEditor/index.tsx +31 -1
  26. package/src/CometChatRichTextEditor/types.ts +21 -1
  27. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +871 -0
  28. package/src/CometChatSavedMessages/index.ts +5 -0
  29. package/src/CometChatSavedMessages/style.ts +159 -0
  30. package/src/CometChatSearch/CometChatSearch.tsx +71 -341
  31. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
  32. package/src/index.ts +60 -0
  33. package/src/shared/CometChatUiKit/CometChatUIKit.ts +18 -1
  34. package/src/shared/base/Types.ts +5 -0
  35. package/src/shared/constants/UIKitConstants.ts +16 -17
  36. package/src/shared/constants/textPatterns.ts +27 -0
  37. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -225
  38. package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
  39. package/src/shared/events/ListenerInitializer.ts +20 -1
  40. package/src/shared/events/messages.ts +18 -0
  41. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +123 -25
  42. package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
  43. package/src/shared/formatters/applyRawFormatters.ts +31 -0
  44. package/src/shared/formatters/index.ts +14 -0
  45. package/src/shared/formatters/richTextWireFormat.ts +165 -0
  46. package/src/shared/framework/MessageDataSource.tsx +309 -10
  47. package/src/shared/icons/components/thread-follow.tsx +13 -0
  48. package/src/shared/icons/components/thread-unfollow.tsx +13 -0
  49. package/src/shared/icons/components/unsave.tsx +13 -0
  50. package/src/shared/icons/icon-mapping.tsx +6 -0
  51. package/src/shared/index.ts +37 -0
  52. package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
  53. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
  54. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
  55. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -1
  56. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
  57. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
  58. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
  59. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
  60. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
  61. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
  62. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
  63. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
  64. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
  65. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
  66. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
  67. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
  68. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
  69. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
  70. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
  71. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
  72. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
  73. package/src/shared/utils/MarkdownUtils.ts +57 -6
  74. package/src/shared/utils/MessageUtils.tsx +80 -5
  75. package/src/shared/utils/PinConversationHelper.ts +245 -0
  76. package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
  77. package/src/shared/utils/PinSaveHelper.ts +549 -0
  78. package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
  79. package/src/shared/utils/SavedMessagesHelper.ts +267 -0
  80. package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
  81. package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
  82. package/src/shared/utils/cloneRequestBuilder.ts +25 -0
  83. package/src/shared/utils/conversationUtils.ts +8 -1
  84. package/src/shared/utils/stripRichText.ts +7 -0
  85. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +32 -0
  86. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
  87. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
  88. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
  89. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
  90. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +5 -1
  91. package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
  92. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
  93. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
  94. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +5 -0
  95. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +5 -0
  96. package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
  97. package/src/shared/views/CometChatList/Header.tsx +8 -2
  98. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
  99. package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
  100. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
  101. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +5 -0
  102. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
  103. package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
  104. package/src/theme/default/default.ts +6 -0
  105. 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,16 +5,11 @@ 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';
11
12
 
12
- const WINDOW_HEIGHT = Dimensions.get('window').height;
13
- const SHEET_MAX_HEIGHT_RATIO = 0.52;
14
- // Quick reactions row height (~56) + sheet paddingTop (25) + safety margin
15
- const RESERVED_HEIGHT = 100;
16
- const ACTION_SHEET_MAX_HEIGHT = WINDOW_HEIGHT * SHEET_MAX_HEIGHT_RATIO - RESERVED_HEIGHT;
17
-
18
13
  interface MessageOptionsSheetProps {
19
14
  bottomSheetRef: React.RefObject<any>;
20
15
  isOpen: boolean;
@@ -65,6 +60,8 @@ export const MessageOptionsSheet: React.FC<MessageOptionsSheetProps> = ({
65
60
  setMessageInfo,
66
61
  setShowEmojiKeyboard,
67
62
  }) => {
63
+ const quickActions = partitionQuickActions(showMessageOptions);
64
+
68
65
  return (
69
66
  <CometChatBottomSheet
70
67
  ref={bottomSheetRef}
@@ -109,7 +106,9 @@ export const MessageOptionsSheet: React.FC<MessageOptionsSheetProps> = ({
109
106
  style={mergedTheme?.messageListStyles?.messageInformationStyles}
110
107
  />
111
108
  ) : (
112
- <View style={{ flex: 1 }}>
109
+ // flexShrink rather than flex: 1 — in React Native flex: 1 never shrinks below its
110
+ // content, so the column would keep its full height and the list could never scroll.
111
+ <View style={{ flexShrink: 1 }}>
113
112
  {/* Show quick reactions for disapproved messages */}
114
113
  {!hideReactionOption && getModerationStatus(selectedMessage) !== 'disapproved' && (
115
114
  <CometChatQuickReactions
@@ -128,9 +127,22 @@ export const MessageOptionsSheet: React.FC<MessageOptionsSheetProps> = ({
128
127
  />
129
128
  )}
130
129
 
131
- <View style={{ maxHeight: ACTION_SHEET_MAX_HEIGHT }}>
130
+ {/* One split, two halves: promoted actions are REMOVED from the list, so nothing
131
+ appears twice. With Pin and Save both unavailable the row is empty and every
132
+ option — Reply included — stays in the list, leaving the sheet exactly as it was
133
+ before this feature existed. */}
134
+ <MessageQuickActions
135
+ actions={quickActions.tiles}
136
+ message={selectedMessage}
137
+ theme={mergedTheme}
138
+ />
139
+
140
+ {/* The list takes whatever height the sheet has left after the rows above it, and
141
+ scrolls within that. A fixed cap has to guess the height of those rows, and a guess
142
+ that misses pushes the last options below the screen where they can't be reached. */}
143
+ <View style={{ flexShrink: 1 }}>
132
144
  <CometChatActionSheet
133
- actions={showMessageOptions}
145
+ actions={quickActions.list}
134
146
  style={mergedTheme.messageListStyles.messageOptionsStyles}
135
147
  />
136
148
  </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
+ });