@cometchat/chat-uikit-react-native 5.5.0 → 5.5.2

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 (104) hide show
  1. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  3. package/android/build.gradle +23 -89
  4. package/android/gradle.properties +5 -5
  5. package/android/src/main/java/com/reactnativecometchatuikit/CometChatSoundModule.java +5 -1
  6. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +52 -0
  7. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +37 -4
  8. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +9 -1
  9. package/ios/FileManager.m +77 -3
  10. package/ios/RichTextEditorView.swift +52 -1
  11. package/ios/RichTextEditorViewManager.m +1 -0
  12. package/ios/RichTextEditorViewManager.swift +8 -0
  13. package/package.json +8 -5
  14. package/react-native-cometchat-ui-kit.podspec +5 -19
  15. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +69 -36
  16. package/src/CometChatConversations/CometChatConversations.tsx +12 -1
  17. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
  18. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +50 -31
  19. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
  20. package/src/CometChatMessageList/CometChatMessageList.tsx +24 -19
  21. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +7 -8
  22. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +43 -19
  23. package/src/CometChatRichTextEditor/index.tsx +6 -1
  24. package/src/CometChatRichTextEditor/types.ts +2 -0
  25. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +251 -14
  26. package/src/CometChatSearch/CometChatSearch.tsx +39 -11
  27. package/src/calls/CometChatOngoingCall/CometChatOngoingCall.tsx +56 -17
  28. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +12 -9
  29. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +13 -10
  30. package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +34 -27
  31. package/src/extensions/Polls/Polls.tsx +7 -7
  32. package/src/extensions/Polls/PollsBubble.tsx +2 -2
  33. package/src/globals.d.ts +6 -0
  34. package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -1
  35. package/src/shared/constants/UIKitConstants.ts +3 -17
  36. package/src/shared/constants/textPatterns.ts +45 -0
  37. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -259
  38. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +22 -11
  39. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +56 -32
  40. package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
  41. package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +8 -0
  42. package/src/shared/formatters/applyRawFormatters.ts +31 -0
  43. package/src/shared/formatters/codeElements.ts +21 -0
  44. package/src/shared/framework/MessageDataSource.tsx +14 -8
  45. package/src/shared/helper/types/index.ts +5 -0
  46. package/src/shared/libs/ImageZoom/ReactNativeZoomableView.tsx +4 -4
  47. package/src/shared/libs/ImageZoom/types/index.ts +2 -0
  48. package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
  49. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
  50. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
  51. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +0 -1
  52. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
  53. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
  54. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
  55. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
  56. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
  57. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
  58. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
  59. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
  60. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
  61. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
  62. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
  63. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
  64. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
  65. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
  66. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
  67. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
  68. package/src/shared/resources/CometChatSoundManager/sound.js +2 -3
  69. package/src/shared/services/UploadQueueService.ts +7 -0
  70. package/src/shared/utils/CometChatMessageHelper/index.ts +3 -0
  71. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
  72. package/src/shared/utils/MarkdownUtils.ts +42 -5
  73. package/src/shared/utils/MessageUtils.tsx +7 -5
  74. package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
  75. package/src/shared/utils/SavedMessagesHelper.ts +42 -6
  76. package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
  77. package/src/shared/utils/cloneRequestBuilder.ts +25 -0
  78. package/src/shared/utils/groupMemberAddedRows.ts +28 -0
  79. package/src/shared/utils/linkPreviewSelection.ts +109 -0
  80. package/src/shared/utils/mentionTokens.ts +77 -0
  81. package/src/shared/utils/runAfterInteractions.ts +26 -0
  82. package/src/shared/utils/stripRichText.ts +2 -1
  83. package/src/shared/utils/tapGesture.ts +23 -0
  84. package/src/shared/utils/videoThumbnail.ts +74 -0
  85. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +15 -4
  86. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +21 -13
  87. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +13 -15
  88. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
  89. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +4 -1
  90. package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
  91. package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +1 -1
  92. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +2 -1
  93. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +7 -1
  94. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +8 -26
  95. package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +4 -2
  96. package/src/shared/views/CometChatList/Header.tsx +9 -3
  97. package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +2 -1
  98. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +28 -8
  99. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -4
  100. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +36 -4
  101. package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +2 -1
  102. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +62 -30
  103. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
  104. package/src/CometChatMessageList/MANUAL_TEST_CASES.md +0 -154
@@ -1,4 +1,3 @@
1
- import { SuggestionItem } from "../../views";
2
1
  import {
3
2
  CallListener,
4
3
  CallUIEventListener,
@@ -26,60 +25,28 @@ export class CometChatUIEventHandler {
26
25
 
27
26
  constructor() {}
28
27
 
29
- static emitPanelEvent(name: string, param: object) {
30
- CometChatUIEventHandler.panelHandlers?.map((listener) => {
31
- switch (name) {
32
- case listener._eventListener?.ccHidePanel?.name:
33
- listener._eventListener?.ccHidePanel?.(param);
34
- break;
35
- case listener._eventListener?.ccShowPanel?.name:
36
- listener._eventListener?.ccShowPanel?.(param);
37
- break;
38
- }
28
+ private static dispatch(
29
+ handlers: ReadonlyArray<{ _eventListener?: object }> | undefined,
30
+ name: string,
31
+ param: object
32
+ ) {
33
+ // Never dispatch to an inherited built-in ("constructor", "toString", "__proto__", …).
34
+ if (name in Object.prototype) return;
35
+
36
+ handlers?.forEach(({ _eventListener }) => {
37
+ const listener = _eventListener as Record<string, unknown> | undefined;
38
+ const handler = listener?.[name];
39
+ // .call keeps the receiver, so a method handler's `this` is its own listener object.
40
+ if (typeof handler === "function") (handler as (p: object) => void).call(listener, param);
39
41
  });
40
42
  }
41
43
 
44
+ static emitPanelEvent(name: string, param: object) {
45
+ CometChatUIEventHandler.dispatch(CometChatUIEventHandler.panelHandlers, name, param);
46
+ }
47
+
42
48
  static emitCallEvent(name: string, param: object) {
43
- CometChatUIEventHandler.callHandlers?.map((listener) => {
44
- switch (name) {
45
- case listener._eventListener?.ccIncomingCallReceived?.name:
46
- listener._eventListener?.ccIncomingCallReceived?.(param);
47
- break;
48
- case listener._eventListener?.ccOutgoingCallAccepted?.name:
49
- listener._eventListener?.ccOutgoingCallAccepted?.(param);
50
- break;
51
- case listener._eventListener?.ccOutgoingCallRejected?.name:
52
- listener._eventListener?.ccOutgoingCallRejected?.(param);
53
- break;
54
- case listener._eventListener?.ccIncomingCallCancelled?.name:
55
- listener._eventListener?.ccIncomingCallCancelled?.(param);
56
- break;
57
- case listener._eventListener?.ccOutgoingCall?.name:
58
- listener._eventListener?.ccOutgoingCall?.(param);
59
- break;
60
- case listener._eventListener?.ccCallAccepted?.name:
61
- listener._eventListener?.ccCallAccepted?.(param);
62
- break;
63
- case listener._eventListener?.ccCallRejected?.name:
64
- listener._eventListener?.ccCallRejected?.(param);
65
- break;
66
- case listener._eventListener?.ccCallEnded?.name:
67
- listener._eventListener?.ccCallEnded?.(param);
68
- break;
69
- case listener._eventListener?.ccOutgoingCallCancelled?.name:
70
- listener._eventListener?.ccOutgoingCallCancelled?.(param);
71
- break;
72
- case listener._eventListener?.ccCallInitiated?.name:
73
- listener._eventListener?.ccCallInitiated?.(param);
74
- break;
75
- case listener._eventListener?.ccShowOngoingCall?.name:
76
- listener._eventListener?.ccShowOngoingCall?.(param);
77
- break;
78
- case listener._eventListener?.ccCallFailed?.name:
79
- listener._eventListener?.ccCallFailed?.(param);
80
- break;
81
- }
82
- });
49
+ CometChatUIEventHandler.dispatch(CometChatUIEventHandler.callHandlers, name, param);
83
50
  }
84
51
 
85
52
  static addCallListener(name: string, callHandler: CallUIEventListener) {
@@ -111,125 +78,7 @@ export class CometChatUIEventHandler {
111
78
  }
112
79
 
113
80
  static emitMessageEvent(name: string, param: object) {
114
- CometChatUIEventHandler.messageHandlers?.map((listener) => {
115
- switch (name) {
116
- case listener._eventListener?.ccThreadSubscriptionChanged?.name:
117
- listener._eventListener?.ccThreadSubscriptionChanged?.(param);
118
- break;
119
- case listener._eventListener?.ccMessageDeleted?.name:
120
- listener._eventListener?.ccMessageDeleted?.(param);
121
- break;
122
- case listener._eventListener?.ccMessageEdited?.name:
123
- listener._eventListener?.ccMessageEdited?.(param);
124
- break;
125
- case listener._eventListener?.ccMessageRead?.name:
126
- listener._eventListener?.ccMessageRead?.(param);
127
- break;
128
- case listener._eventListener?.ccMessageSent?.name:
129
- listener._eventListener?.ccMessageSent?.(param);
130
- break;
131
- case listener._eventListener?.ccMessageDelivered?.name:
132
- listener._eventListener?.ccMessageSent?.(param);
133
- break;
134
- case listener._eventListener?.ccActiveChatChanged?.name:
135
- listener._eventListener?.ccActiveChatChanged?.(param);
136
- break;
137
- case listener._eventListener?.onTextMessageReceived?.name:
138
- listener._eventListener?.onTextMessageReceived?.(param);
139
- break;
140
- case listener._eventListener?.onMediaMessageReceived?.name:
141
- listener._eventListener?.onMediaMessageReceived?.(param);
142
- break;
143
- case listener._eventListener?.onCustomMessageReceived?.name:
144
- listener._eventListener?.onCustomMessageReceived?.(param);
145
- break;
146
- case listener._eventListener?.onTypingStarted?.name:
147
- listener._eventListener?.onTypingStarted?.(param);
148
- break;
149
- case listener._eventListener?.onTypingEnded?.name:
150
- listener._eventListener?.onTypingEnded?.(param);
151
- break;
152
- case listener._eventListener?.onMessagesDelivered?.name:
153
- listener._eventListener?.onMessagesDelivered?.(param);
154
- break;
155
- case listener._eventListener?.onMessagesRead?.name:
156
- listener._eventListener?.onMessagesRead?.(param);
157
- break;
158
- case listener._eventListener?.onMessageEdited?.name:
159
- listener._eventListener?.onMessageEdited?.(param);
160
- break;
161
- case listener._eventListener?.onMessageDeleted?.name:
162
- listener._eventListener?.onMessageDeleted?.(param);
163
- break;
164
- case listener._eventListener?.onTransientMessageReceived?.name:
165
- listener._eventListener?.onTransientMessageReceived?.(param);
166
- break;
167
- case listener._eventListener?.onFormMessageReceived?.name:
168
- listener._eventListener?.onFormMessageReceived?.(param);
169
- break;
170
- case listener._eventListener?.onCardMessageReceived?.name:
171
- listener._eventListener?.onCardMessageReceived?.(param);
172
- break;
173
- case listener._eventListener?.onSchedulerMessageReceived?.name:
174
- listener._eventListener?.onSchedulerMessageReceived?.(param);
175
- break;
176
- case listener._eventListener?.onCustomInteractiveMessageReceived?.name:
177
- listener._eventListener?.onCustomInteractiveMessageReceived?.(param);
178
- break;
179
- case listener._eventListener?.onInteractionGoalCompleted?.name:
180
- listener._eventListener?.onInteractionGoalCompleted?.(param);
181
- break;
182
- case listener._eventListener?.onMessageReactionRemoved?.name:
183
- listener._eventListener?.onMessageReactionRemoved?.(param);
184
- break;
185
- case listener._eventListener?.onMessageReactionAdded?.name:
186
- listener._eventListener?.onMessageReactionAdded?.(param);
187
- break;
188
- case listener._eventListener?.onMessagesDeliveredToAll?.name:
189
- listener._eventListener?.onMessagesDeliveredToAll?.(param);
190
- break;
191
- case listener._eventListener?.onMessagesReadByAll?.name:
192
- listener._eventListener?.onMessagesReadByAll?.(param);
193
- break;
194
- case listener._eventListener?.onAIAssistantMessageReceived?.name:
195
- listener._eventListener?.onAIAssistantMessageReceived?.(param);
196
- break;
197
- case listener._eventListener?.onMessageModerated?.name:
198
- listener._eventListener?.onMessageModerated?.(param);
199
- break;
200
- // Pin & Save realtime. Without these four the SDK parses the socket frame,
201
- // ListenerInitializer emits it, and the emit lands in a switch that matches
202
- // nothing — so a pin made by another participant never reaches the message
203
- // list and only appears on the next fetch.
204
- case listener._eventListener?.onMessagePinned?.name:
205
- listener._eventListener?.onMessagePinned?.(param);
206
- break;
207
- case listener._eventListener?.onMessageUnpinned?.name:
208
- listener._eventListener?.onMessageUnpinned?.(param);
209
- break;
210
- case listener._eventListener?.onMessageSaved?.name:
211
- listener._eventListener?.onMessageSaved?.(param);
212
- break;
213
- case listener._eventListener?.onMessageUnsaved?.name:
214
- listener._eventListener?.onMessageUnsaved?.(param);
215
- break;
216
- // The cc* half: emitted by the device that PERFORMED the action, so a panel
217
- // open next to the message list updates without waiting for a socket echo
218
- // (and in a 1-1, where no echo is coming at all).
219
- case listener._eventListener?.ccMessagePinned?.name:
220
- listener._eventListener?.ccMessagePinned?.(param);
221
- break;
222
- case listener._eventListener?.ccMessageUnpinned?.name:
223
- listener._eventListener?.ccMessageUnpinned?.(param);
224
- break;
225
- case listener._eventListener?.ccMessageSaved?.name:
226
- listener._eventListener?.ccMessageSaved?.(param);
227
- break;
228
- case listener._eventListener?.ccMessageUnsaved?.name:
229
- listener._eventListener?.ccMessageUnsaved?.(param);
230
- break;
231
- }
232
- });
81
+ CometChatUIEventHandler.dispatch(CometChatUIEventHandler.messageHandlers, name, param);
233
82
  }
234
83
 
235
84
  static addMessageListener(name: string, messageHandler: MessageUIEventListener) {
@@ -261,17 +110,7 @@ export class CometChatUIEventHandler {
261
110
  }
262
111
 
263
112
  static emitConversationEvent(name: string, param: object) {
264
- CometChatUIEventHandler.conversationHandlers?.map((listener) => {
265
- switch (name) {
266
- case listener._eventListener?.ccConversationDeleted?.name:
267
- listener._eventListener?.ccConversationDeleted?.(param);
268
- break;
269
- //added for markAsUnread
270
- case listener._eventListener?.ccUpdateConversation?.name:
271
- listener._eventListener?.ccUpdateConversation?.(param);
272
- break;
273
- }
274
- });
113
+ CometChatUIEventHandler.dispatch(CometChatUIEventHandler.conversationHandlers, name, param);
275
114
  }
276
115
 
277
116
  static addConversationListener(name: string, conversationHandler: ConversationUIEventListener) {
@@ -303,40 +142,7 @@ export class CometChatUIEventHandler {
303
142
  }
304
143
 
305
144
  static emitGroupEvent(name: string, param: object) {
306
- CometChatUIEventHandler.groupHandlers?.map((listener) => {
307
- switch (name) {
308
- case listener._eventListener?.ccGroupCreated?.name:
309
- listener._eventListener?.ccGroupCreated?.(param);
310
- break;
311
- case listener._eventListener?.ccGroupDeleted?.name:
312
- listener._eventListener?.ccGroupDeleted?.(param);
313
- break;
314
- case listener._eventListener?.ccGroupLeft?.name:
315
- listener._eventListener?.ccGroupLeft?.(param);
316
- break;
317
- case listener._eventListener?.ccGroupMemberBanned?.name:
318
- listener._eventListener?.ccGroupMemberBanned?.(param);
319
- break;
320
- case listener._eventListener?.ccGroupMemberJoined?.name:
321
- listener._eventListener?.ccGroupMemberJoined?.(param);
322
- break;
323
- case listener._eventListener?.ccGroupMemberKicked?.name:
324
- listener._eventListener?.ccGroupMemberKicked?.(param);
325
- break;
326
- case listener._eventListener?.ccGroupMemberScopeChanged?.name:
327
- listener._eventListener?.ccGroupMemberScopeChanged?.(param);
328
- break;
329
- case listener._eventListener?.ccGroupMemberUnBanned?.name:
330
- listener._eventListener?.ccGroupMemberUnBanned?.(param);
331
- break;
332
- case listener._eventListener?.ccOwnershipChanged?.name:
333
- listener._eventListener?.ccOwnershipChanged?.(param);
334
- break;
335
- case listener._eventListener?.ccGroupMemberAdded?.name:
336
- listener._eventListener?.ccGroupMemberAdded?.(param);
337
- break;
338
- }
339
- });
145
+ CometChatUIEventHandler.dispatch(CometChatUIEventHandler.groupHandlers, name, param);
340
146
  }
341
147
 
342
148
  static addGroupListener(name: string, groupHandler: GroupUIEventListener) {
@@ -368,16 +174,7 @@ export class CometChatUIEventHandler {
368
174
  }
369
175
 
370
176
  static emitUserEvent(name: string, param: object) {
371
- CometChatUIEventHandler.userHandlers?.map((listener) => {
372
- switch (name) {
373
- case listener._eventListener?.ccUserBlocked?.name:
374
- listener._eventListener?.ccUserBlocked?.(param);
375
- break;
376
- case listener._eventListener?.ccUserUnBlocked?.name:
377
- listener._eventListener?.ccUserUnBlocked?.(param);
378
- break;
379
- }
380
- });
177
+ CometChatUIEventHandler.dispatch(CometChatUIEventHandler.userHandlers, name, param);
381
178
  }
382
179
 
383
180
  static addUserListener(name: string, userHandler: UserUIEventListener) {
@@ -409,38 +206,7 @@ export class CometChatUIEventHandler {
409
206
  }
410
207
 
411
208
  static emitUIEvent(name: string, param: object) {
412
- CometChatUIEventHandler.uiHandlers?.map((listener) => {
413
- switch (name) {
414
- case listener._eventListener?.hidePanel?.name:
415
- listener._eventListener?.hidePanel?.(param);
416
- break;
417
- case listener._eventListener?.showPanel?.name:
418
- listener._eventListener?.showPanel?.(param);
419
- break;
420
- case listener._eventListener?.openChat?.name:
421
- listener._eventListener?.openChat?.(param);
422
- break;
423
- case listener._eventListener?.ccToggleBottomSheet?.name:
424
- listener._eventListener?.ccToggleBottomSheet?.(param);
425
- break;
426
- case listener._eventListener?.ccComposeMessage?.name:
427
- listener._eventListener?.ccComposeMessage?.(param);
428
- break;
429
- // case listener._eventListener?.ccMentionClick?.name:
430
- // listener._eventListener?.ccMentionClick(param);
431
- // break;
432
- case listener._eventListener?.ccSuggestionData?.name:
433
- listener._eventListener?.ccSuggestionData?.(
434
- param as { id: string; data: Array<SuggestionItem> }
435
- );
436
- break;
437
- case listener._eventListener?.ccCardActionClicked?.name:
438
- listener._eventListener?.ccCardActionClicked?.(
439
- param as { message: any; action: any }
440
- );
441
- break;
442
- }
443
- });
209
+ CometChatUIEventHandler.dispatch(CometChatUIEventHandler.uiHandlers, name, param);
444
210
  }
445
211
 
446
212
  static addUIListener(name: string, uiHandlers: UIEventListener) {
@@ -461,13 +227,13 @@ export class CometChatUIEventHandler {
461
227
 
462
228
  static removeUIListener(name: string) {
463
229
  try {
464
- CometChatUIEventHandler.userHandlers = CometChatUIEventHandler.userHandlers?.filter(
230
+ CometChatUIEventHandler.uiHandlers = CometChatUIEventHandler.uiHandlers?.filter(
465
231
  (listener) => {
466
232
  return listener._name !== name;
467
233
  }
468
234
  );
469
235
  } catch (err) {
470
- console.log("removeUserListener", err);
236
+ console.log("removeUIListener", err);
471
237
  }
472
238
  }
473
239
  }
@@ -12,6 +12,7 @@ import { SuggestionItem } from "../../views/CometChatSuggestionList";
12
12
  import { CometChatTextFormatter } from "../CometChatTextFormatter";
13
13
  import { CometChatTheme } from "../../../theme/type";
14
14
  import { deepMerge } from "../../helper/helperFunctions";
15
+ import { unescapeTypedMentionTokensInTree } from "../../utils/mentionTokens";
15
16
  import { getCometChatTranslation } from "../../resources/CometChatLocalizeNew/LocalizationManager";
16
17
 
17
18
  const t = getCometChatTranslation();
@@ -544,7 +545,8 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
544
545
  return "";
545
546
  }
546
547
  let formattedText = this.addMentionsView(inputText, textStyle);
547
- return formattedText;
548
+ // Only now, with every real mention resolved, may escaped typed text read as `<@all:…>`.
549
+ return unescapeTypedMentionTokensInTree(formattedText);
548
550
  }
549
551
 
550
552
  temp!: Function;
@@ -604,8 +606,10 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
604
606
  segments.push(inputText.slice(lastIndex, match.index));
605
607
  }
606
608
 
607
- // Add UID segment
608
- segments.push(match[1]);
609
+ // Add the whole token; it is resolved to its id below. Pushing only the id rendered an
610
+ // unresolved `<@uid:someone>` as just "someone", and let plain text that happened to
611
+ // equal a mentioned uid become a chip.
612
+ segments.push(match[0]);
609
613
 
610
614
  // Update lastIndex
611
615
  lastIndex = match.index + match[0].length;
@@ -618,12 +622,19 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
618
622
 
619
623
  // Now create an array of JSX elements from the segments
620
624
  const elements = segments.map((segment, index) => {
621
- // Check if segment is a UID
622
- if (userRegistry.hasOwnProperty(segment)) {
625
+ // A token segment resolves to its id; anything else is plain text.
626
+ const token = /^<@(?:uid|all):(.*?)>$/.exec(segment);
627
+ const id = token ? token[1] : undefined;
628
+ // `<@all:x>` resolves only to an @all alias and `<@uid:x>` only to a user.
629
+ if (
630
+ id !== undefined &&
631
+ userRegistry.hasOwnProperty(id) &&
632
+ aliasIdSet.has(id) === segment.startsWith("<@all:")
633
+ ) {
623
634
  let _loggedInUser = this.loggedInUser || CometChatUIKit.loggedInUser;
624
635
 
625
- const isAlias = aliasIdSet.has(segment);
626
- const isSelf = isAlias || _loggedInUser?.getUid() === segment;
636
+ const isAlias = aliasIdSet.has(id);
637
+ const isSelf = isAlias || _loggedInUser?.getUid() === id;
627
638
 
628
639
  const isOutgoing =
629
640
  this.messageObject?.getSender()?.getUid() === _loggedInUser?.getUid();
@@ -636,7 +647,7 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
636
647
 
637
648
  let onPressProp =
638
649
  this.temp && !isAlias
639
- ? { onPress: (event: any) => this.onMentionClick(event, segment) }
650
+ ? { onPress: (event: any) => this.onMentionClick(event, id) }
640
651
  : {}; // still suppress click for alias
641
652
 
642
653
  const mentionContainerStyle = backgroundColor ? {
@@ -648,20 +659,20 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
648
659
  if (this.target === MentionsTargetElement.textbubble) {
649
660
  return (
650
661
  <Text suppressHighlighting={true} key={index} {...onPressProp} style={[textStyle, mentionContainerStyle]}>
651
- {userRegistry[segment]}
662
+ {userRegistry[id]}
652
663
  </Text>
653
664
  );
654
665
  }
655
666
 
656
667
  return (
657
668
  <Text suppressHighlighting={true} key={index} {...onPressProp} style={[textStyle, mentionContainerStyle]}>
658
- {userRegistry[segment]}
669
+ {userRegistry[id]}
659
670
  </Text>
660
671
  );
661
672
  } else {
662
673
  // Handle group-wide alias formatting if present
663
674
  const aliasItem = this.SuggestionItems.find(
664
- (it) => it.underlyingText === `<@all:${segment}>`
675
+ (it) => token !== null && it.underlyingText === segment
665
676
  );
666
677
  if (aliasItem) {
667
678
  const { textStyle: styleResolved, backgroundColor } = this.resolveStyle(true);
@@ -3,7 +3,9 @@ import React, { JSX } from "react";
3
3
  import { Text, TextStyle, ViewStyle, Platform, Linking, View } from "react-native";
4
4
  import { CometChatTextFormatter } from "../CometChatTextFormatter";
5
5
  import { COLOR_OPEN_TAG, HEX_COLOR_REGEX, findColorTag, stripColorTags } from "../richTextWireFormat";
6
+ import { markCode } from "../codeElements";
6
7
  import { isTextElement, isViewElement } from "../../utils/elementType";
8
+ import { urlPattern, emailPattern, markdownLinkPattern } from "../../constants/textPatterns";
7
9
 
8
10
  /**
9
11
  * Style configuration for rich text formatting
@@ -29,13 +31,21 @@ export interface RichTextStyle {
29
31
  // Pre-compiled regex patterns — avoids recompilation on every call
30
32
  const ORDERED_LIST_REGEX = /^(\d+)\.(?:\s(.*))?$/;
31
33
  const ORDERED_LIST_DETECT_REGEX = /^\d+\.(\s|$)/;
32
- const LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/;
34
+ const LINK_REGEX = new RegExp(markdownLinkPattern);
35
+ // Global form, for stashing each half of every markdown link before URLs are stashed.
36
+ const LINK_REGEX_GLOBAL = new RegExp(markdownLinkPattern, "g");
33
37
  const URL_PROTOCOL_REGEX = /^(https?|mailto|tel):/i;
34
38
  // Patterns for detecting list items inside blockquote content (ENG-31998)
35
39
  const QUOTE_BULLET_REGEX = /^- (.*)$/;
36
40
  const QUOTE_ORDERED_REGEX = /^(\s*)(\d+)\.\s(.*)$/;
37
41
  // Mention pattern — used to exclude mention UIDs from markdown marker detection
38
42
  const MENTION_PATTERN_REGEX = /<@(?:uid|all):[^>]*>/g;
43
+ // URL pattern — used to exclude URLs from markdown marker detection (ENG-38182)
44
+ const URL_PATTERN_REGEX = new RegExp(urlPattern, "gi");
45
+ // Emails are stashed BEFORE urls: the url pattern matches only the DOMAIN of an address, so
46
+ // `my_name@corp.co.uk` had its local part left exposed and two such addresses in one message
47
+ // paired their underscores into italics — `my_name@` and `my_alt@` rendered as `myname@`/`myalt@`.
48
+ const EMAIL_PATTERN_REGEX = new RegExp(emailPattern, "gi");
39
49
 
40
50
  // Pre-allocated style objects — avoids creating new objects on every render
41
51
  const LIST_ROW_STYLE = { flexDirection: 'row' as const, flexShrink: 1 as const };
@@ -282,7 +292,7 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
282
292
  style here — but it must never reach the reader as literal markup either.
283
293
  Messages sent before the serializer fix still carry the token inside the
284
294
  fence, so strip rather than render (ENG-38253). */}
285
- <Text style={[this.style.codeBlockStyle]}>{stripColorTags(content)}</Text>
295
+ {markCode(<Text style={[this.style.codeBlockStyle]}>{stripColorTags(content)}</Text>)}
286
296
  </View>
287
297
  );
288
298
  lineIndex++;
@@ -326,13 +336,15 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
326
336
  this.style.codeBlockContainerStyle,
327
337
  ]}
328
338
  >
329
- <Text
330
- style={[
331
- this.style.codeBlockStyle,
332
- ]}
333
- >
334
- {stripColorTags(codeLines.join("\n"))}
335
- </Text>
339
+ {markCode(
340
+ <Text
341
+ style={[
342
+ this.style.codeBlockStyle,
343
+ ]}
344
+ >
345
+ {stripColorTags(codeLines.join("\n"))}
346
+ </Text>
347
+ )}
336
348
  </View>
337
349
  );
338
350
  if (lineIndex < lines.length) {
@@ -563,29 +575,41 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
563
575
  return text;
564
576
  }
565
577
 
566
- // Replace mention patterns with null-byte placeholders before parsing so
567
- // findItalic/findNextFormat never see underscores or brackets inside UIDs.
568
- // After parsing, restore the original mention strings in the output.
569
- const mentionSlots: string[] = [];
570
- const sanitized = text.replace(MENTION_PATTERN_REGEX, (match) => {
571
- const idx = mentionSlots.length;
572
- mentionSlots.push(match);
578
+ // Replace mention patterns and URLs with null-byte placeholders before parsing so
579
+ // findItalic/findNextFormat never see underscores inside UIDs or URLs.
580
+ const protectedSlots: string[] = [];
581
+ const stash = (match: string) => {
582
+ const idx = protectedSlots.length;
583
+ protectedSlots.push(match);
573
584
  return `\x00M${idx}\x00`;
574
- });
585
+ };
586
+ let sanitized = text.replace(MENTION_PATTERN_REGEX, stash);
587
+ try {
588
+ // Markdown links first, one half at a time. The url pattern accepts `[ ] ( )`, so on a
589
+ // link whose label is itself an address — `[https://x/p](https://x/p)`, what a pasted or
590
+ // copied link is stored as — it matched `https://x/p](https://x/p` as ONE url. That hid
591
+ // the `](`, findLink never saw a link, and the bubble showed the raw markdown.
592
+ sanitized = sanitized.replace(LINK_REGEX_GLOBAL, (_m, label: string, url: string) =>
593
+ `[${label.replace(URL_PATTERN_REGEX, stash)}](${stash(url)})`
594
+ );
595
+ sanitized = sanitized.replace(EMAIL_PATTERN_REGEX, stash);
596
+ sanitized = sanitized.replace(URL_PATTERN_REGEX, stash);
597
+ } catch {
598
+ }
575
599
 
576
- // Restore mention placeholders in a string or JSX tree
577
- const restoreMentions = (node: JSX.Element | string): JSX.Element | string => {
600
+ // Restore mention/URL placeholders in a string or JSX tree
601
+ const restoreProtected = (node: JSX.Element | string): JSX.Element | string => {
578
602
  if (typeof node === 'string') {
579
- if (mentionSlots.length === 0 || node.indexOf('\x00') < 0) return node;
580
- return node.replace(/\x00M(\d+)\x00/g, (_, idx) => mentionSlots[Number(idx)] ?? _);
603
+ if (protectedSlots.length === 0 || node.indexOf('\x00') < 0) return node;
604
+ return node.replace(/\x00M(\d+)\x00/g, (_, idx) => protectedSlots[Number(idx)] ?? _);
581
605
  }
582
606
  if (!React.isValidElement(node)) return node;
583
607
  const el = node as React.ReactElement<any>;
584
608
  const children = el.props.children;
585
609
  if (!children) return node;
586
610
  const restored = React.Children.map(children, (child: any) => {
587
- if (typeof child === 'string') return restoreMentions(child);
588
- if (React.isValidElement(child)) return restoreMentions(child as JSX.Element);
611
+ if (typeof child === 'string') return restoreProtected(child);
612
+ if (React.isValidElement(child)) return restoreProtected(child as JSX.Element);
589
613
  return child;
590
614
  });
591
615
  return React.cloneElement(el, {}, ...(restored || []));
@@ -602,16 +626,16 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
602
626
  const match = this.findNextFormat(remaining);
603
627
  if (match) {
604
628
  if (match.startIndex > 0) {
605
- elements.push(restoreMentions(remaining.substring(0, match.startIndex)) as string);
629
+ elements.push(restoreProtected(remaining.substring(0, match.startIndex)) as string);
606
630
  }
607
- // Restore mentions in matched content before recursive parsing
631
+ // Restore mentions/URLs in matched content before recursive parsing
608
632
  const restoredContent = (typeof match.content === 'string' && match.content.indexOf('\x00') >= 0)
609
- ? restoreMentions(match.content) as string
633
+ ? restoreProtected(match.content) as string
610
634
  : match.content;
611
635
  if (match.type === "link" && match.url) {
612
636
  // Render link as tappable blue underlined text (same as CometChatUrlsFormatter)
613
637
  const innerContent = this.parseInlineFormats(restoredContent);
614
- const linkUrl = match.url;
638
+ const linkUrl = restoreProtected(match.url) as string;
615
639
  elements.push(
616
640
  <Text
617
641
  key={`fmt-${keyCounter++}`}
@@ -632,19 +656,19 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
632
656
  // Use a single Text element (not View) so inline code stays on the
633
657
  // same text baseline as surrounding content (mentions, plain text).
634
658
  // Text supports backgroundColor, borderRadius, and padding in RN.
635
- elements.push(
659
+ elements.push(markCode(
636
660
  <Text key={`fmt-${keyCounter++}`} style={[this.style.inlineCodeContainerStyle, this.style.inlineCodeStyle]}>{innerContent}</Text>
637
- );
661
+ ));
638
662
  } else if (match.type === "codeBlock") {
639
663
  // Inline ```text``` — render identically to single-backtick inline code
640
664
  // (compact pill with background, no block-level padding).
641
665
  // Block-level code block rendering with View container is handled in renderMarkdown.
642
- elements.push(
666
+ elements.push(markCode(
643
667
  <Text
644
668
  key={`fmt-${keyCounter++}`}
645
669
  style={[this.style.inlineCodeContainerStyle, this.style.inlineCodeStyle]}
646
670
  >{restoredContent}</Text>
647
- );
671
+ ));
648
672
  } else if (match.type === "textColor" && match.color) {
649
673
  // Re-validate at render time: the hex reaching here came off the wire, and an
650
674
  // unparseable value must fall back to the base style rather than reach RN.
@@ -675,7 +699,7 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
675
699
  }
676
700
  remaining = remaining.substring(match.endIndex);
677
701
  } else {
678
- elements.push(restoreMentions(remaining) as string);
702
+ elements.push(restoreProtected(remaining) as string);
679
703
  remaining = "";
680
704
  }
681
705
  }
@@ -214,6 +214,28 @@ export abstract class CometChatTextFormatter {
214
214
  return inputText;
215
215
  }
216
216
 
217
+ /**
218
+ * Rewrites the message's stored text before the UI Kit parses any of it.
219
+ *
220
+ * Runs on every surface a message appears on — bubble, conversation row, reply/edit preview,
221
+ * search result, media caption, message information — and on the text loaded back into the
222
+ * composer for editing, always BEFORE the built-in markdown, mention and link handling.
223
+ *
224
+ * This is where a formatter maps its own wire token onto markup the UI Kit already draws,
225
+ * e.g. `(#e5484d)red()` to `<color=#e5484d>red</color>`. `getFormattedText` cannot do that
226
+ * job: by then markdown has already turned the text into elements, so a pattern that spans
227
+ * any of that markup no longer matches.
228
+ *
229
+ * Returns the text untouched by default, so a formatter that does not override it behaves
230
+ * exactly as it did before this hook existed.
231
+ *
232
+ * @param text - The message text as stored on the server.
233
+ * @returns The text to render, written in the UI Kit's own grammar.
234
+ */
235
+ formatRawText(text: string): string {
236
+ return text;
237
+ }
238
+
217
239
  /**
218
240
  * Handles the message before sending it.
219
241
  * @param message - The message to handle.
@@ -3,6 +3,7 @@ import React, { JSX } from "react";
3
3
  import { ColorValue, Linking, Text, TextStyle } from "react-native";
4
4
  import { emailPattern, phoneNumPattern, urlPattern } from "../../constants/UIKitConstants";
5
5
  import { CometChatTextFormatter } from "../CometChatTextFormatter";
6
+ import { isCode } from "../codeElements";
6
7
 
7
8
  export class CometChatUrlsFormatter extends CometChatTextFormatter {
8
9
  protected style: {
@@ -117,6 +118,13 @@ export class CometChatUrlsFormatter extends CometChatTextFormatter {
117
118
  return <Text>{str}</Text>;
118
119
  } else if (React.isValidElement(str)) {
119
120
  // str is a React element
121
+ if ((str as React.ReactElement<any>).props.onPress || isCode(str)) {
122
+ // Already a link (a markdown `[label](url)` from the rich-text formatter). Linkifying its
123
+ // label again nests a second link inside it, and the inner one wins the tap: the label
124
+ // of `[www.google.com](https://drive…)` opened google.com instead of the Drive address.
125
+ // Code is literal: an address inside `backticks` stays text.
126
+ return str;
127
+ }
120
128
  if ((str as React.ReactElement<any>).props.children) {
121
129
  // If the React element have children, we map over these children
122
130
  // and call addMentionsSpan recursively for each child.