@cometchat/chat-uikit-react-native 5.2.2 → 5.2.4

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 (79) hide show
  1. package/package.json +1 -1
  2. package/src/CometChatConversations/CometChatConversations.tsx +170 -91
  3. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +312 -116
  4. package/src/CometChatMessageComposer/styles.tsx +2 -1
  5. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +83 -17
  6. package/src/CometChatMessageList/CometChatMessageList.tsx +603 -65
  7. package/src/CometChatMessageList/style.ts +47 -2
  8. package/src/CometChatSearch/CometChatSearch.tsx +1718 -0
  9. package/src/CometChatSearch/SearchConstants.ts +46 -0
  10. package/src/CometChatSearch/Skeleton.tsx +192 -0
  11. package/src/CometChatSearch/index.ts +1 -0
  12. package/src/CometChatSearch/style.ts +414 -0
  13. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +43 -7
  14. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +45 -7
  15. package/src/extensions/Polls/Polls.tsx +36 -2
  16. package/src/extensions/Polls/PollsBubble.tsx +13 -9
  17. package/src/extensions/Polls/PollsDecorator.tsx +13 -1
  18. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +50 -11
  19. package/src/extensions/Stickers/style.ts +0 -1
  20. package/src/index.ts +5 -0
  21. package/src/shared/base/Types.ts +8 -0
  22. package/src/shared/constants/UIKitConstants.ts +2 -0
  23. package/src/shared/events/CometChatMessageEvents/index.ts +8 -7
  24. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +3 -0
  25. package/src/shared/events/CometChatUIEventHandler/Listener.ts +8 -0
  26. package/src/shared/events/ListenerInitializer.ts +3 -0
  27. package/src/shared/events/messages.ts +1 -0
  28. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +158 -27
  29. package/src/shared/framework/DataSource.ts +7 -0
  30. package/src/shared/framework/DataSourceDecorator.tsx +12 -0
  31. package/src/shared/framework/MessageDataSource.tsx +182 -1
  32. package/src/shared/helper/functions.js +0 -67
  33. package/src/shared/helper/helperFunctions.ts +73 -0
  34. package/src/shared/icons/components/documents.tsx +23 -0
  35. package/src/shared/icons/components/empty-search.tsx +52 -0
  36. package/src/shared/icons/components/message-blocked.tsx +32 -0
  37. package/src/shared/icons/components/unread.tsx +29 -0
  38. package/src/shared/icons/icon-mapping.tsx +9 -0
  39. package/src/shared/index.ts +2 -1
  40. package/src/shared/modals/CometChatMessageTemplate.ts +23 -0
  41. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +4 -4
  42. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +22 -4
  43. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +75 -36
  44. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +65 -27
  45. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +42 -4
  46. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +66 -27
  47. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +42 -4
  48. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +43 -4
  49. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +43 -4
  50. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +43 -4
  51. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +45 -7
  52. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +42 -4
  53. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +43 -4
  54. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +42 -4
  55. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +42 -4
  56. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +43 -5
  57. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +43 -4
  58. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +42 -4
  59. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +45 -7
  60. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +274 -23
  61. package/src/shared/utils/MessageReceiptUtils.ts +32 -0
  62. package/src/shared/utils/MessageUtils.tsx +106 -4
  63. package/src/shared/views/CometChatAudioBubble/style.ts +0 -2
  64. package/src/shared/views/CometChatFileBubble/style.ts +0 -4
  65. package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +1 -0
  66. package/src/shared/views/CometChatList/CometChatList.tsx +12 -0
  67. package/src/shared/views/CometChatList/Header.tsx +79 -49
  68. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +14 -4
  69. package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +390 -0
  70. package/src/shared/views/CometChatReportDialog/index.ts +3 -0
  71. package/src/shared/views/CometChatReportDialog/style.ts +164 -0
  72. package/src/shared/views/CometChatStatusIndicator/private.png +0 -0
  73. package/src/shared/views/CometChatStatusIndicator/protected.png +0 -0
  74. package/src/shared/views/CometChatStatusIndicator/styles.ts +2 -2
  75. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +18 -2
  76. package/src/shared/views/index.ts +6 -0
  77. package/src/theme/default/default.ts +3 -0
  78. package/src/theme/provider.tsx +7 -5
  79. package/src/theme/type.ts +21 -1
@@ -36,7 +36,9 @@ type MessageUIEvents = {
36
36
  onMessageReactionRemoved?: Function;
37
37
  onMessagesDeliveredToAll?: Function;
38
38
  onMessagesReadByAll?: Function;
39
+ onMessageModerated?: Function;
39
40
  onAIAssistantMessageReceived?: Function;
41
+ onMessageReply?: Function;
40
42
  };
41
43
  export class MessageUIEventListener {
42
44
  ccMessageSent?: Function = undefined;
@@ -65,7 +67,9 @@ export class MessageUIEventListener {
65
67
  onMessageReactionRemoved?: Function = undefined;
66
68
  onMessagesDeliveredToAll?: Function = undefined;
67
69
  onMessagesReadByAll?: Function = undefined;
70
+ onMessageModerated?: Function = undefined;
68
71
  onAIAssistantMessageReceived?: Function = undefined;
72
+ onMessageReply?: Function = undefined;
69
73
  constructor({
70
74
  ccMessageSent,
71
75
  ccMessageEdited,
@@ -93,7 +97,9 @@ export class MessageUIEventListener {
93
97
  onMessageReactionRemoved,
94
98
  onMessagesDeliveredToAll,
95
99
  onMessagesReadByAll,
100
+ onMessageModerated,
96
101
  onAIAssistantMessageReceived,
102
+ onMessageReply,
97
103
  }: MessageUIEvents) {
98
104
  if (!isFalsy(ccMessageError)) this.ccMessageError = ccMessageError;
99
105
  if (!isFalsy(ccMessageDelivered)) this.ccMessageDelivered = ccMessageDelivered;
@@ -129,6 +135,8 @@ export class MessageUIEventListener {
129
135
  this.onMessagesDeliveredToAll = onMessagesDeliveredToAll;
130
136
  if (!isFalsy(onMessagesReadByAll)) this.onMessagesReadByAll = onMessagesReadByAll;
131
137
  if (!isFalsy(onAIAssistantMessageReceived)) this.onAIAssistantMessageReceived = onAIAssistantMessageReceived;
138
+ if (!isFalsy(onMessageReply)) this.onMessageReply = onMessageReply;
139
+ if (!isFalsy(onMessageModerated)) this.onMessageModerated = onMessageModerated;
132
140
  }
133
141
  }
134
142
 
@@ -87,6 +87,9 @@ export class ListenerInitializer {
87
87
  },
88
88
  onAIAssistantMessageReceived: (message: CometChat.AIAssistantMessage) => {
89
89
  CometChatUIEventHandler.emitMessageEvent(MessageEvents.onAIAssistantMessageReceived, message);
90
+ },
91
+ onMessageModerated: (message: CometChat.BaseMessage) => {
92
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.onMessageModerated, message);
90
93
  }
91
94
  });
92
95
  }
@@ -24,5 +24,6 @@ export enum MessageEvents {
24
24
  onCustomInteractiveMessageReceived = "onCustomInteractiveMessageReceived",
25
25
  onMessageReactionAdded = "onMessageReactionAdded",
26
26
  onMessageReactionRemoved = "onMessageReactionRemoved",
27
+ onMessageModerated = "onMessageModerated",
27
28
  onAIAssistantMessageReceived = "onAIAssistantMessageReceived",
28
29
  }
@@ -123,7 +123,8 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
123
123
  */
124
124
  constructor(themeOrUser?: CometChatTheme | CometChat.User, loggedInUser?: CometChat.User) {
125
125
  super();
126
- this.regexPattern = /<@uid:(.*?)>/g;
126
+ // Support user mentions <@uid:UID> and group-wide alias mentions <@all:Alias>
127
+ this.regexPattern = /<@(?:uid|all):(.*?)>/g;
127
128
  this.trackCharacter = "@";
128
129
 
129
130
  const theme = isCometChatTheme(themeOrUser) ? themeOrUser : undefined;
@@ -150,6 +151,42 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
150
151
  this.conversationStyle = this.incomingBubbleStyle;
151
152
  }
152
153
 
154
+ /** Group-wide alias mention feature */
155
+ private mentionAllLabel: string = "all";
156
+ private disableMentionAll: boolean = false;
157
+
158
+ setMentionAllLabel(label: string) {
159
+ if (label && label.trim()) this.mentionAllLabel = label.trim();
160
+ return this;
161
+ }
162
+
163
+ setDisableMentionAll(disable: boolean) {
164
+ this.disableMentionAll = !!disable;
165
+ return this;
166
+ }
167
+
168
+ getMentionAllLabel() {
169
+ return this.mentionAllLabel;
170
+ }
171
+
172
+ isMentionAllDisabled() {
173
+ return this.disableMentionAll;
174
+ }
175
+
176
+ private buildGroupMentionItem(): SuggestionItem | null {
177
+ if (this.disableMentionAll) return null;
178
+ if (!this.group) return null; // only relevant inside a group context
179
+ const alias = this.mentionAllLabel || "all";
180
+ return new SuggestionItem({
181
+ id: alias, // id matches regex capture for highlighting
182
+ name: alias,
183
+ promptText: "@" + alias,
184
+ trackingCharacter: "@",
185
+ underlyingText: `<@all:${alias}>`,
186
+ hideLeadingIcon: false,
187
+ });
188
+ }
189
+
153
190
  /**
154
191
  * Sets the message object.
155
192
  *
@@ -163,6 +200,30 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
163
200
  let cometchatUIUserArray: Array<SuggestionItem> =
164
201
  this.convertCCUsersToSuggestionsItem(mentionedUsers);
165
202
 
203
+ // Inject alias mentions present in raw text (incoming/outgoing)
204
+ try {
205
+ const rawText = (messageObject as any)?.getText?.() || "";
206
+ const aliasRegex = /<@all:(.*?)>/g;
207
+ let m: RegExpExecArray | null;
208
+ while ((m = aliasRegex.exec(rawText)) !== null) {
209
+ const alias = m[1];
210
+ if (alias && !cometchatUIUserArray.find((i) => i.underlyingText === `<@all:${alias}>`)) {
211
+ cometchatUIUserArray.push(
212
+ new SuggestionItem({
213
+ id: alias,
214
+ name: alias,
215
+ promptText: "@" + alias,
216
+ trackingCharacter: "@",
217
+ underlyingText: `<@all:${alias}>`,
218
+ hideLeadingIcon: true,
219
+ })
220
+ );
221
+ }
222
+ }
223
+ } catch (e) {
224
+ console.log("🚀 ~ CometChatMentionsFormatter ~ setMessage ~ e:", e);
225
+ }
226
+
166
227
  this.setSuggestionItems(cometchatUIUserArray);
167
228
  }
168
229
 
@@ -175,19 +236,54 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
175
236
  }
176
237
 
177
238
  handlePreMessageSend(message: CometChat.TextMessage): CometChat.TextMessage {
178
- let CCUsers = this.getSuggestionItems().map((item) => {
179
- let user = new CometChat.User(item.id);
180
- user.setAvatar(item?.leadingIconUrl!);
181
- user.setName(item?.name!);
182
- return user;
183
- });
184
- message.setMentionedUsers(CCUsers);
239
+ let CCUsers = this.getSuggestionItems()
240
+ .filter((item) => !item.underlyingText.startsWith("<@all:"))
241
+ .map((item) => {
242
+ let user = new CometChat.User(item.id);
243
+ user.setAvatar(item?.leadingIconUrl!);
244
+ user.setName(item?.name!);
245
+ return user;
246
+ });
247
+ if (CCUsers.length) message.setMentionedUsers(CCUsers);
185
248
  return message;
186
249
  }
187
250
 
188
251
  handleComposerPreview(message: CometChat.TextMessage): void {
189
- let users = this.convertCCUsersToSuggestionsItem(message.getMentionedUsers());
190
- this.setSuggestionItems(users);
252
+ const userItems = this.convertCCUsersToSuggestionsItem(message.getMentionedUsers());
253
+
254
+ // Preserve any existing @all alias items we discovered in setMessage
255
+ let aliasItems = this.SuggestionItems.filter((item) =>
256
+ item.underlyingText?.startsWith("<@all:")
257
+ );
258
+
259
+ // If alias items are missing (common on re-open edit), parse from message text
260
+ try {
261
+ const rawText = message.getText?.() || "";
262
+ const aliasRegex = /<@all:(.*?)>/g;
263
+ let m: RegExpExecArray | null;
264
+ while ((m = aliasRegex.exec(rawText)) !== null) {
265
+ const alias = m[1];
266
+ if (
267
+ alias &&
268
+ !aliasItems.find((i) => i.underlyingText === `<@all:${alias}>`)
269
+ ) {
270
+ const aliasItem = new SuggestionItem({
271
+ id: alias,
272
+ name: alias,
273
+ promptText: "@" + alias,
274
+ trackingCharacter: "@",
275
+ underlyingText: `<@all:${alias}>`,
276
+ hideLeadingIcon: true,
277
+ });
278
+ aliasItems.push(aliasItem);
279
+ }
280
+ }
281
+ } catch (e) {
282
+ console.log("🚀 ~ CometChatMentionsFormatter ~ handleComposerPreview ~ e:", e)
283
+ }
284
+
285
+ const merged = [...aliasItems, ...userItems];
286
+ this.setSuggestionItems(merged);
191
287
  }
192
288
 
193
289
  private convertCCUsersToSuggestionsItem(users: CometChat.User[]) {
@@ -239,8 +335,14 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
239
335
  : new CometChat.UsersRequestBuilder());
240
336
 
241
337
  this.searchRequest = requestBuilder.setLimit(10).setSearchKeyword(searchKey).build();
242
-
243
338
  this.searchData = [];
339
+ // Prepend group-wide alias suggestion if enabled and matches search
340
+ const groupItem = this.buildGroupMentionItem();
341
+ if (groupItem) {
342
+ const include =
343
+ !searchKey || groupItem.name?.toLowerCase().startsWith(searchKey.toLowerCase());
344
+ if (include) this.searchData.push(groupItem);
345
+ }
244
346
  this.fetchNext(true);
245
347
  }
246
348
 
@@ -251,8 +353,9 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
251
353
  ?.fetchNext()
252
354
  .then((users: CometChat.User[]) => {
253
355
  let structuredData = this.convertCCUsersToSuggestionsItem(users);
356
+ // Preserve any pre-added items (like @all alias) in searchData when freshCall
254
357
  this.searchData = freshCall
255
- ? [...structuredData]
358
+ ? [...this.searchData, ...structuredData]
256
359
  : [...this.searchData, ...structuredData];
257
360
  this.setSearchData(this.searchData);
258
361
  })
@@ -292,7 +395,9 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
292
395
  const uniqueUserIds: Set<number | string> = new Set();
293
396
 
294
397
  // Populate the Set with user IDs from the existing user list
295
- this.SuggestionItems.forEach((user) => uniqueUserIds.add(user.id));
398
+ this.SuggestionItems.forEach((item) => {
399
+ if (!item.underlyingText.startsWith("<@all:")) uniqueUserIds.add(item.id);
400
+ });
296
401
 
297
402
  return uniqueUserIds;
298
403
  }
@@ -428,10 +533,13 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
428
533
 
429
534
  if (this.SuggestionItems) {
430
535
  const userRegistry: { [key: string]: string } = {};
536
+ const aliasIdSet: Set<string> = new Set();
431
537
  for (let i = 0; i < this.SuggestionItems?.length; i++) {
432
- const userUid = this.SuggestionItems[i].id;
433
- const userName = this.SuggestionItems[i].promptText;
538
+ const item = this.SuggestionItems[i];
539
+ const userUid = item.id;
540
+ const userName = item.promptText;
434
541
  userRegistry[userUid] = userName!;
542
+ if (item.underlyingText.startsWith("<@all:")) aliasIdSet.add(userUid);
435
543
  }
436
544
 
437
545
  // Define the regex pattern
@@ -466,46 +574,69 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
466
574
  if (userRegistry.hasOwnProperty(segment)) {
467
575
  let _loggedInUser = this.loggedInUser || CometChatUIKit.loggedInUser;
468
576
 
469
- const isSelf = _loggedInUser?.getUid() === segment;
577
+ const isAlias = aliasIdSet.has(segment);
578
+ const isSelf = isAlias || _loggedInUser?.getUid() === segment;
579
+
470
580
  const isOutgoing =
471
581
  this.messageObject?.getSender()?.getUid() === _loggedInUser?.getUid();
472
582
 
473
583
  if (this.target === MentionsTargetElement.textbubble) {
474
- // Only for bubbles – keep whatever was set for conversation & composer
475
584
  this.setContext(isOutgoing ? "outgoing" : "incoming");
476
585
  }
586
+
477
587
  const textStyle = this.resolveStyle(isSelf);
478
- let onPressProp = this.temp
479
- ? { onPress: (event: any) => this.onMentionClick(event, segment) }
480
- : {};
588
+
589
+ let onPressProp =
590
+ this.temp && !isAlias
591
+ ? { onPress: (event: any) => this.onMentionClick(event, segment) }
592
+ : {}; // still suppress click for alias
481
593
 
482
594
  if (this.target === MentionsTargetElement.textbubble) {
483
595
  return (
484
- // <View>
485
596
  <Text suppressHighlighting={true} key={index} {...onPressProp} style={[textStyle]}>
486
597
  {userRegistry[segment]}
487
598
  </Text>
488
- // </View>
489
599
  );
490
600
  }
491
601
 
492
- //conv
493
602
  return (
494
603
  <Text suppressHighlighting={true} key={index} {...onPressProp} style={[textStyle]}>
495
604
  {userRegistry[segment]}
496
605
  </Text>
497
606
  );
498
607
  } else {
608
+ // Handle group-wide alias formatting if present
609
+ const aliasItem = this.SuggestionItems.find(
610
+ (it) => it.underlyingText === `<@all:${segment}>`
611
+ );
612
+ if (aliasItem) {
613
+ const styleResolved = this.resolveStyle(true);
614
+ // If context is 'conversation', render @all and description inline
615
+ if (this.currentContext === "conversation") {
616
+ return (
617
+ <Text suppressHighlighting={true} key={index} style={[styleResolved]}>
618
+ <Text style={[styleResolved, { fontWeight: "700" }]}>
619
+ @{aliasItem.promptText}
620
+ </Text>
621
+ <Text style={[styleResolved, { fontWeight: "normal", opacity: 0.7 }]}>
622
+ {" "}
623
+ {t("MESSAGE_COMPOSER_MENTION_NOTIFY_EVERYONE_LABEL")}
624
+ </Text>
625
+ </Text>
626
+ );
627
+ }
628
+ return (
629
+ <Text suppressHighlighting={true} key={index} style={[styleResolved]}>
630
+ {aliasItem.promptText}
631
+ </Text>
632
+ );
633
+ }
499
634
  if (this.target === MentionsTargetElement.textbubble)
500
635
  return (
501
- // <View>
502
636
  <Text key={index} style={{ ...this.textStyle }}>
503
637
  {segment}
504
638
  </Text>
505
- // </View>
506
639
  );
507
-
508
- //conv
509
640
  return (
510
641
  <Text key={index} style={{ ...this.textStyle }}>
511
642
  {segment}
@@ -74,6 +74,11 @@ export interface DataSource {
74
74
  message: CometChat.BaseMessage,
75
75
  alignment: MessageBubbleAlignmentType
76
76
  ): JSX.Element | null;
77
+ getReplyView?(
78
+ message: CometChat.BaseMessage,
79
+ theme: CometChatTheme,
80
+ additionalParams?: AdditionalParams
81
+ ): JSX.Element | null;
77
82
  getDeleteMessageBubble(message: CometChat.BaseMessage, theme: CometChatTheme): JSX.Element;
78
83
  getVideoMessageBubble(
79
84
  videoUrl: string,
@@ -233,4 +238,6 @@ export interface DataSource {
233
238
  theme?: CometChatTheme
234
239
  ): CometChatMentionsFormatter;
235
240
  getUrlsFormatter(loggedInUser?: CometChat.User): CometChatUrlsFormatter;
241
+
242
+ getMessagePreviewSubtitle(message: CometChat.BaseMessage): string;
236
243
  }
@@ -326,4 +326,16 @@ export class DataSourceDecorator implements DataSource {
326
326
  getUrlsFormatter(loggedInUser?: CometChat.User): CometChatUrlsFormatter {
327
327
  return this.dataSource.getUrlsFormatter(loggedInUser);
328
328
  }
329
+
330
+ getMessagePreviewSubtitle(message: CometChat.BaseMessage): string {
331
+ return this.dataSource.getMessagePreviewSubtitle(message);
332
+ }
333
+
334
+ getReplyView(
335
+ message: CometChat.BaseMessage,
336
+ theme: CometChatTheme,
337
+ additionalParams?: AdditionalParams
338
+ ): JSX.Element | null {
339
+ return this.dataSource.getReplyView?.(message, theme, additionalParams) || null;
340
+ }
329
341
  }
@@ -32,6 +32,7 @@ import { CometChatAudioBubble } from "../views/CometChatAudioBubble";
32
32
  import { CometChatDeletedBubble } from "../views/CometChatDeletedBubble";
33
33
  import { CometChatFileBubble } from "../views/CometChatFileBubble";
34
34
  import { CometChatImageBubble } from "../views/CometChatImageBubble";
35
+ import { CometChatMessagePreview } from "../utils/CometChatMessagePreview";
35
36
  import { CometChatTextBubble } from "../views/CometChatTextBubble";
36
37
  import { CometChatVideoBubble } from "../views/CometChatVideoBubble";
37
38
  import CometChatAIAssistantMessageBubble from '../views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble';
@@ -39,9 +40,10 @@ import CometChatStreamMessageBubble from '../views/CometChatStreamMessageBubble/
39
40
  import { ChatConfigurator } from "./ChatConfigurator";
40
41
  import { DataSource } from "./DataSource";
41
42
  import { CommonUtils } from "../utils/CommonUtils";
42
- import { DimensionValue, TouchableOpacity, ViewStyle } from "react-native";
43
+ import { DimensionValue, TouchableOpacity, ViewStyle, View, Text } from "react-native";
43
44
  import Clipboard from "@react-native-clipboard/clipboard";
44
45
  import { getCometChatTranslation } from "../resources/CometChatLocalizeNew/LocalizationManager";
46
+ import { CometChatMessageEvents } from "../events/CometChatMessageEvents";
45
47
 
46
48
  const t = getCometChatTranslation();
47
49
 
@@ -233,6 +235,27 @@ export class MessageDataSource implements DataSource {
233
235
  ),
234
236
  };
235
237
  }
238
+
239
+ getReportOption(theme: CometChatTheme): CometChatMessageOption {
240
+ return {
241
+ id: MessageOptionConstants.reportMessage,
242
+ title: t("Message_List_Option_Flag_Message"),
243
+ icon: (
244
+ <Icon
245
+ name='info'
246
+ color={
247
+ theme.messageListStyles.messageOptionsStyles?.optionsItemStyle?.iconStyle?.tintColor
248
+ }
249
+ height={theme.messageListStyles.messageOptionsStyles?.optionsItemStyle?.iconStyle?.height}
250
+ width={theme.messageListStyles.messageOptionsStyles?.optionsItemStyle?.iconStyle?.width}
251
+ containerStyle={
252
+ theme.messageListStyles.messageOptionsStyles?.optionsItemStyle?.iconContainerStyle
253
+ }
254
+ ></Icon>
255
+ ),
256
+ };
257
+ }
258
+
236
259
  getShareOption(theme: CometChatTheme): CometChatMessageOption {
237
260
  return {
238
261
  id: MessageOptionConstants.shareMessage,
@@ -329,6 +352,17 @@ export class MessageDataSource implements DataSource {
329
352
  let messageOptionList: CometChatMessageOption[] = [];
330
353
 
331
354
  if (isDeletedMessage(messageObject)) return messageOptionList;
355
+ if (
356
+ this.validateOption(
357
+ loggedInUser,
358
+ messageObject,
359
+ MessageOptionConstants.replyMessage,
360
+ group,
361
+ additionalParams
362
+ )
363
+ ) {
364
+ messageOptionList.push(this.getReplyOption(theme));
365
+ }
332
366
 
333
367
  if (
334
368
  this.validateOption(
@@ -402,6 +436,18 @@ export class MessageDataSource implements DataSource {
402
436
  messageOptionList.push(this.getDeleteOption(theme));
403
437
  }
404
438
 
439
+ if (
440
+ this.validateOption(
441
+ loggedInUser,
442
+ messageObject,
443
+ MessageOptionConstants.reportMessage,
444
+ group,
445
+ additionalParams
446
+ )
447
+ ) {
448
+ messageOptionList.push(this.getReportOption(theme));
449
+ }
450
+
405
451
  if (
406
452
  this.validateOption(
407
453
  loggedInUser,
@@ -589,6 +635,13 @@ export class MessageDataSource implements DataSource {
589
635
  group?: CometChat.Group | null,
590
636
  additionalParams?: AdditionalParams
591
637
  ): boolean {
638
+ if (
639
+ MessageOptionConstants.replyMessage === optionId &&
640
+ !additionalParams?.hideReplyOption
641
+ ) {
642
+ return true;
643
+ }
644
+
592
645
  if (
593
646
  MessageOptionConstants.replyInThread === optionId &&
594
647
  (!messageObject.getParentMessageId() || messageObject.getParentMessageId() === 0) &&
@@ -655,6 +708,14 @@ export class MessageDataSource implements DataSource {
655
708
  return true;
656
709
  }
657
710
 
711
+ if (
712
+ MessageOptionConstants.reportMessage === optionId &&
713
+ !isSentByMe &&
714
+ !additionalParams?.hideReportMessageOption
715
+ ) {
716
+ return true;
717
+ }
718
+
658
719
  return false;
659
720
  }
660
721
 
@@ -668,6 +729,17 @@ export class MessageDataSource implements DataSource {
668
729
  let messageOptionList: CometChatMessageOption[] = [];
669
730
 
670
731
  if (isDeletedMessage(messageObject)) return messageOptionList;
732
+ if (
733
+ this.validateOption(
734
+ loggedInUser,
735
+ messageObject,
736
+ MessageOptionConstants.replyMessage,
737
+ group,
738
+ additionalParams
739
+ )
740
+ ) {
741
+ messageOptionList.push(this.getReplyOption(theme));
742
+ }
671
743
 
672
744
  if (
673
745
  this.validateOption(
@@ -717,6 +789,18 @@ export class MessageDataSource implements DataSource {
717
789
  messageOptionList.push(this.getDeleteOption(theme));
718
790
  }
719
791
 
792
+ if (
793
+ this.validateOption(
794
+ loggedInUser,
795
+ messageObject,
796
+ MessageOptionConstants.reportMessage,
797
+ group,
798
+ additionalParams
799
+ )
800
+ ) {
801
+ messageOptionList.push(this.getReportOption(theme));
802
+ }
803
+
720
804
  if (
721
805
  this.validateOption(
722
806
  loggedInUser,
@@ -869,6 +953,75 @@ export class MessageDataSource implements DataSource {
869
953
  return null;
870
954
  }
871
955
 
956
+ getReplyView(
957
+ message: CometChat.BaseMessage,
958
+ theme: CometChatTheme,
959
+ additionalParams?: AdditionalParams
960
+ ): JSX.Element | null {
961
+ const hasQuotedMessage = message.getQuotedMessage();
962
+
963
+ if (!hasQuotedMessage ||
964
+ message instanceof CometChat.Action ||
965
+ message.getDeletedAt()) {
966
+ return null;
967
+ }
968
+
969
+ // Check if the original message is outgoing to determine styling
970
+ const loggedInUser = CometChatUIKit.loggedInUser;
971
+ const isOutgoingMessage = loggedInUser && message.getSender().getUid() === loggedInUser.getUid();
972
+
973
+ const isQuotedMessageDeleted = hasQuotedMessage.getDeletedBy() != null;
974
+
975
+ // Create custom theme with overridden colors for reply view
976
+ const replyTheme = {
977
+ ...theme,
978
+ color: {
979
+ ...theme.color,
980
+ textPrimary: isOutgoingMessage ? theme.color.staticWhite : theme.color.textHighlight,
981
+ textSecondary: isOutgoingMessage ? theme.color.staticWhite : theme.color.textSecondary,
982
+ }
983
+ };
984
+
985
+ // Handle click to navigate to quoted message
986
+ const handleReplyClick = () => {
987
+ if (!isQuotedMessageDeleted) {
988
+ const messageId = String(hasQuotedMessage.getId());
989
+ if (additionalParams?.onReplyClick) {
990
+ additionalParams.onReplyClick(messageId);
991
+ }
992
+ }
993
+ };
994
+
995
+ const previewComponent = (
996
+ <CometChatMessagePreview
997
+ message={hasQuotedMessage}
998
+ theme={replyTheme}
999
+ style={{
1000
+ backgroundColor: isOutgoingMessage ? theme.color.extendedPrimary800 : theme.color.neutral400,
1001
+ borderRadius: 8,
1002
+ borderWidth: 0,
1003
+ borderLeftWidth: 3,
1004
+ borderLeftColor: isOutgoingMessage ? theme.color.staticWhite : theme.color.borderHighlight,
1005
+ margin:2,
1006
+ width:"98%"
1007
+ }}
1008
+ showCloseIcon={false}
1009
+ isDeletedMessage={isQuotedMessageDeleted}
1010
+ />
1011
+ );
1012
+
1013
+ // Wrap with TouchableOpacity for click handling
1014
+ if (additionalParams?.onReplyClick && !isQuotedMessageDeleted) {
1015
+ return (
1016
+ <TouchableOpacity onPress={handleReplyClick} activeOpacity={0.7}>
1017
+ {previewComponent}
1018
+ </TouchableOpacity>
1019
+ );
1020
+ }
1021
+
1022
+ return previewComponent;
1023
+ }
1024
+
872
1025
  getDeleteMessageBubble(message: CometChat.BaseMessage, theme: CometChatTheme): JSX.Element {
873
1026
  let loggedInUser = CometChatUIKit.loggedInUser;
874
1027
 
@@ -1192,6 +1345,10 @@ export class MessageDataSource implements DataSource {
1192
1345
  group,
1193
1346
  additionalParams
1194
1347
  ),
1348
+ ReplyView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1349
+ const replyView = ChatConfigurator.dataSource.getReplyView?.(message, theme, additionalParams) || null;
1350
+ return replyView;
1351
+ },
1195
1352
  BottomView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1196
1353
  return ChatConfigurator.dataSource.getBottomView(message, alignment);
1197
1354
  },
@@ -1219,6 +1376,9 @@ export class MessageDataSource implements DataSource {
1219
1376
  group,
1220
1377
  additionalParams
1221
1378
  ),
1379
+ ReplyView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1380
+ return ChatConfigurator.dataSource.getReplyView?.(message, theme, additionalParams) || null;
1381
+ },
1222
1382
  BottomView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1223
1383
  return ChatConfigurator.dataSource.getBottomView(message, alignment);
1224
1384
  },
@@ -1245,6 +1405,9 @@ export class MessageDataSource implements DataSource {
1245
1405
  group,
1246
1406
  additionalParams
1247
1407
  ),
1408
+ ReplyView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1409
+ return ChatConfigurator.dataSource.getReplyView?.(message, theme, additionalParams) || null;
1410
+ },
1248
1411
  BottomView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1249
1412
  return ChatConfigurator.dataSource.getBottomView(message, alignment);
1250
1413
  },
@@ -1271,6 +1434,9 @@ export class MessageDataSource implements DataSource {
1271
1434
  group,
1272
1435
  additionalParams
1273
1436
  ),
1437
+ ReplyView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1438
+ return ChatConfigurator.dataSource.getReplyView?.(message, theme, additionalParams) || null;
1439
+ },
1274
1440
  BottomView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1275
1441
  return ChatConfigurator.dataSource.getBottomView(message, alignment);
1276
1442
  },
@@ -1297,6 +1463,9 @@ export class MessageDataSource implements DataSource {
1297
1463
  group,
1298
1464
  additionalParams
1299
1465
  ),
1466
+ ReplyView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1467
+ return ChatConfigurator.dataSource.getReplyView?.(message, theme, additionalParams) || null;
1468
+ },
1300
1469
  BottomView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1301
1470
  return ChatConfigurator.dataSource.getBottomView(message, alignment);
1302
1471
  },
@@ -1839,6 +2008,18 @@ export class MessageDataSource implements DataSource {
1839
2008
  getUrlsFormatter(loggedInUser?: CometChat.User): CometChatUrlsFormatter {
1840
2009
  return new CometChatUrlsFormatter(loggedInUser);
1841
2010
  }
2011
+
2012
+ getMessagePreviewSubtitle(message: CometChat.BaseMessage): string {
2013
+ if (message instanceof CometChat.TextMessage) {
2014
+ return message.getText() || "";
2015
+ } else if (message instanceof CometChat.MediaMessage) {
2016
+ const data = message.getData() as any;
2017
+ return data?.name || message.getType() || "";
2018
+ } else if (message.getType() === "groupMember") {
2019
+ return "Group action";
2020
+ }
2021
+ return message.getType() || "";
2022
+ }
1842
2023
  }
1843
2024
  //for internal use only
1844
2025
  export const internalMessageDataSource = new MessageDataSource();