@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
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Helpers for the user-level Saved Messages surface (§6.4).
3
+ *
4
+ * The interesting part is `sourceLabelFor`. The design doc's recipe assumed rows
5
+ * might arrive without conversation context, and prescribed a lazy hydrate showing
6
+ * a raw id in the meantime. Verified against staging 2026-07-30: saved rows DO
7
+ * carry `conversationId`, `receiver`, `receiverType` and `sender`, so the label is
8
+ * derivable synchronously and no hydration call is needed. That deletes the whole
9
+ * placeholder-then-refresh path the doc called for.
10
+ *
11
+ * @module SavedMessagesHelper
12
+ */
13
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
14
+ import { cloneRequestBuilder } from "./cloneRequestBuilder";
15
+
16
+ /** What a saved row needs to render its "where did this come from" line. */
17
+ export interface SavedMessageSource {
18
+ /** `group` | `user` — drives the sigil and the open-conversation call. */
19
+ receiverType: string;
20
+ /** guid, or the uid of the OTHER party in a 1-1. */
21
+ receiverId: string;
22
+ /** Display text, e.g. `#engineering` or `@alice`. */
23
+ label: string;
24
+ /** Plain display name with no sigil — what the row TITLE shows. */
25
+ name: string;
26
+ /** Group icon or user avatar URL, when the payload carries a hydrated party. */
27
+ avatar?: string;
28
+ }
29
+
30
+ const RECEIVER_TYPE = { user: "user", group: "group" };
31
+
32
+ /**
33
+ * Best display name for a User/Group, falling back to its id.
34
+ *
35
+ * A parsed message hands back a hydrated object, but a degenerate payload can
36
+ * leave `receiver` as a bare string id — hence the typeof branch rather than
37
+ * assuming the object shape.
38
+ */
39
+ const nameOf = (party: any, fallbackId: string): string => {
40
+ try {
41
+ if (!party) return fallbackId;
42
+ if (typeof party === "string") return party;
43
+ if (typeof party.getName === "function" && party.getName()) return party.getName();
44
+ if (typeof party.getUid === "function" && party.getUid()) return party.getUid();
45
+ if (typeof party.getGuid === "function" && party.getGuid()) return party.getGuid();
46
+ return fallbackId;
47
+ } catch {
48
+ return fallbackId;
49
+ }
50
+ };
51
+
52
+ /**
53
+ * Avatar/icon URL for a User or Group, or undefined.
54
+ *
55
+ * Same defensive shape as nameOf: a degenerate payload can leave the party as a
56
+ * bare id string, which has neither accessor.
57
+ */
58
+ const avatarOf = (party: any): string | undefined => {
59
+ try {
60
+ if (!party || typeof party === "string") return undefined;
61
+ if (typeof party.getAvatar === "function" && party.getAvatar()) return party.getAvatar();
62
+ if (typeof party.getIcon === "function" && party.getIcon()) return party.getIcon();
63
+ return undefined;
64
+ } catch {
65
+ return undefined;
66
+ }
67
+ };
68
+
69
+ /**
70
+ * Icon + label for a message type, for the row's subtitle.
71
+ *
72
+ * Mirrors the conversation list's preview vocabulary so a saved row reads the same
73
+ * as the chat it came from. `label` is a LOCALE KEY, not display text — the caller
74
+ * translates, because this module has no theme or translator of its own.
75
+ *
76
+ * A caption, when present, replaces the generic label: the design shows
77
+ * "🖼 Check this out from yesterday!" rather than "🖼 Image".
78
+ */
79
+ export const PREVIEW_BY_TYPE: Record<string, { icon: string; labelKey: string }> = {
80
+ image: { icon: "photo-fill", labelKey: "MESSAGE_IMAGE" },
81
+ video: { icon: "videocam-fill", labelKey: "MESSAGE_VIDEO" },
82
+ audio: { icon: "mic-fill", labelKey: "MESSAGE_AUDIO" },
83
+ file: { icon: "description-fill", labelKey: "MESSAGE_FILE" },
84
+ extension_sticker: { icon: "sticker-fill", labelKey: "CUSTOM_MESSAGE_STICKER" },
85
+ extension_poll: { icon: "poll-fill", labelKey: "CUSTOM_MESSAGE_POLL" },
86
+ extension_document: { icon: "description-fill", labelKey: "CUSTOM_MESSAGE_DOCUMENT" },
87
+ extension_whiteboard: { icon: "description-fill", labelKey: "CUSTOM_MESSAGE_DOCUMENT" },
88
+ };
89
+
90
+ /** What a saved row's subtitle should render. */
91
+ export interface SavedMessagePreview {
92
+ /** Icon name, or null for a plain-text row which shows no glyph. */
93
+ icon: string | null;
94
+ /** Locale key to translate, or null when `text` is already display-ready. */
95
+ labelKey: string | null;
96
+ /** Literal text — a text message's body, or a media caption. */
97
+ text: string | null;
98
+ }
99
+
100
+ /**
101
+ * The subtitle content for a saved row. Never throws; an unrecognised type falls
102
+ * back to the generic document glyph rather than rendering an empty line.
103
+ */
104
+ /**
105
+ * Returns the preview's RAW text — inline formatting included. The component renders
106
+ * it through CometChatRichTextFormatter, the same way the conversation list does, so
107
+ * a coloured message reads coloured in the row rather than as `<color=#e11d48>`.
108
+ */
109
+ export const previewFor = (message?: CometChat.BaseMessage | null): SavedMessagePreview => {
110
+ const empty: SavedMessagePreview = { icon: "description-fill", labelKey: null, text: null };
111
+ try {
112
+ if (!message) return empty;
113
+
114
+ if (message instanceof CometChat.TextMessage) {
115
+ return { icon: null, labelKey: null, text: message.getText() ?? "" };
116
+ }
117
+
118
+ const entry = PREVIEW_BY_TYPE[message.getType()];
119
+ const caption =
120
+ message instanceof CometChat.MediaMessage ? (message.getCaption() ?? "").trim() : "";
121
+
122
+ if (caption) return { icon: entry?.icon ?? empty.icon, labelKey: null, text: caption };
123
+ if (entry) return { icon: entry.icon, labelKey: entry.labelKey, text: null };
124
+
125
+ // Unknown custom type: show the glyph and let the caller fall back to the type
126
+ // string, which is more useful than a blank subtitle.
127
+ return { icon: empty.icon, labelKey: null, text: message.getType() ?? null };
128
+ } catch {
129
+ return empty;
130
+ }
131
+ };
132
+
133
+ /**
134
+ * The source conversation for a saved row, or null when the payload is unusable.
135
+ *
136
+ * Pass `loggedInUserUid` for correct 1-1 labelling. On an INCOMING 1-1 message the
137
+ * receiver is the logged-in user, so labelling purely by receiver would render
138
+ * every received row as "@me"; when the receiver is us, the counterparty is the
139
+ * sender. Groups need no such flip.
140
+ *
141
+ * Never throws, and never returns a half-built label: a row whose source cannot be
142
+ * determined still renders — the caller just omits the source line — rather than
143
+ * being dropped, per the design doc's first rule.
144
+ */
145
+ /**
146
+ * Who wrote this saved row, as the subtitle prefix — `"You"`, a sender name, or null
147
+ * for no prefix at all.
148
+ *
149
+ * Returns the NAME, not the punctuation: the component owns the `": "` so a
150
+ * localisation that separates differently has one place to change.
151
+ *
152
+ * Three outcomes, and the asymmetry is the point:
153
+ * - **You wrote it** → `"You"`, in a 1-1 as much as in a group. Without this a DM row
154
+ * you sent and a DM row you received render identically — same avatar, same title,
155
+ * same date — and only the preview text tells them apart.
156
+ * - **Someone else, in a group** → their name. There are many possible authors, so
157
+ * the row is ambiguous without it.
158
+ * - **Someone else, in a 1-1** → null. There is exactly one other author and the row
159
+ * TITLE already names them; repeating it in the subtitle is noise.
160
+ */
161
+ export const subtitlePrefixNameFor = (
162
+ message?: CometChat.BaseMessage | null,
163
+ loggedInUserUid?: string | null,
164
+ youLabel: string = "You"
165
+ ): string | null => {
166
+ try {
167
+ if (!message) return null;
168
+ const senderUid = message.getSender?.()?.getUid?.();
169
+ if (senderUid && loggedInUserUid && senderUid === loggedInUserUid) return youLabel;
170
+ if (message.getReceiverType?.() !== RECEIVER_TYPE.group) return null;
171
+ return message.getSender?.()?.getName?.() || null;
172
+ } catch {
173
+ return null;
174
+ }
175
+ };
176
+
177
+ export const sourceLabelFor = (
178
+ message?: CometChat.BaseMessage | null,
179
+ loggedInUserUid?: string | null
180
+ ): SavedMessageSource | null => {
181
+ try {
182
+ if (!message) return null;
183
+
184
+ const receiverType = message.getReceiverType?.();
185
+ if (receiverType !== RECEIVER_TYPE.user && receiverType !== RECEIVER_TYPE.group) return null;
186
+
187
+ const receiver = message.getReceiver?.();
188
+ const receiverId = message.getReceiverId?.() ?? "";
189
+
190
+ if (receiverType === RECEIVER_TYPE.group) {
191
+ const name = nameOf(receiver, receiverId);
192
+ return { receiverType, receiverId, label: `#${name}`, name, avatar: avatarOf(receiver) };
193
+ }
194
+
195
+ // 1-1: flip to the sender when the row was addressed to us.
196
+ if (loggedInUserUid && receiverId === loggedInUserUid) {
197
+ const sender = message.getSender?.();
198
+ const senderUid = sender && typeof sender.getUid === "function" ? sender.getUid() : "";
199
+ if (senderUid) {
200
+ const name = nameOf(sender, senderUid);
201
+ return {
202
+ receiverType,
203
+ receiverId: senderUid,
204
+ label: `@${name}`,
205
+ name,
206
+ avatar: avatarOf(sender),
207
+ };
208
+ }
209
+ }
210
+
211
+ const name = nameOf(receiver, receiverId);
212
+ return { receiverType, receiverId, label: `@${name}`, name, avatar: avatarOf(receiver) };
213
+ } catch {
214
+ return null;
215
+ }
216
+ };
217
+
218
+ /**
219
+ * A fresh request for the logged-in user's saved messages, newest save first.
220
+ *
221
+ * The ordinary messages request, filtered to saved rows. Deliberately carries NO
222
+ * uid/guid: `saved=1` is account-wide, and scoping it to a conversation would turn
223
+ * this cross-conversation inbox into a per-chat list. Paging is the ordinary sentAt
224
+ * cursor walk — setSavedOnly() changes what the list contains, not how it pages.
225
+ *
226
+ * Single-use by design — build a new one to refresh. The server caps the whole set
227
+ * at 100.
228
+ */
229
+ export const buildSavedMessagesRequest = (
230
+ limit?: number,
231
+ messagesRequestBuilder?: CometChat.MessagesRequestBuilder
232
+ ) => {
233
+ // A COPY of the integrator's builder, never their object. They may hand the same
234
+ // instance to CometChatPinnedMessages too, and the invariants below are contradictory
235
+ // between the two panels — mutating in place would make whichever built second
236
+ // corrupt the first. See cloneRequestBuilder for why the copy is prototype-preserving.
237
+ const builder = messagesRequestBuilder
238
+ ? cloneRequestBuilder(messagesRequestBuilder)
239
+ : new CometChat.MessagesRequestBuilder();
240
+
241
+ // The full invariant, not just half of it. setSavedOnly alone is not enough: a builder
242
+ // carrying pinnedOnly=true makes the SDK reject the request with
243
+ // PINNED_AND_SAVED_BOTH_SET before any network call, and the panel shows its error
244
+ // state instead of the saved list.
245
+ builder.setSavedOnly(true);
246
+ builder.setPinnedOnly(false);
247
+
248
+ // ALWAYS set, on every path. The SDK has no default: MessagesRequestBuilder.limit
249
+ // stays undefined unless setLimit() is called, and makeAPICall() then rejects with
250
+ // SET_LIMIT_IS_COMPULSORY *before* any request goes out — an error screen with an
251
+ // empty network log. So a passed-in builder cannot be trusted to have set one.
252
+ // Precedence: the `limit` argument, else the builder's own, else 30 (the SDK's
253
+ // DEFAULT_VALUES.MSGS_LIMIT).
254
+ const builderLimit = (builder as unknown as { limit?: number }).limit;
255
+ builder.setLimit(limit ?? builderLimit ?? 30);
256
+
257
+ // Deliberately NO uid/guid: `saved=1` is account-wide, and scoping it to one
258
+ // conversation would turn this cross-conversation inbox into a per-chat list. The
259
+ // JSDoc asks callers not to set them; this enforces it, because a builder shared with
260
+ // the pinned panel arrives already carrying one. Cleared on our copy, so the caller's
261
+ // own builder keeps whatever scope they gave it. There is no setter that unsets these.
262
+ const scope = builder as unknown as { uid?: string; guid?: string };
263
+ scope.uid = undefined;
264
+ scope.guid = undefined;
265
+
266
+ return builder.build();
267
+ };