@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cometchat/chat-uikit-react-native",
3
- "version": "5.2.2",
3
+ "version": "5.2.4",
4
4
  "description": "Ready-to-use Chat UI Components for React Native",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -26,6 +26,7 @@ import {
26
26
  CometChatUiKitConstants,
27
27
  CometChatUrlsFormatter,
28
28
  } from "../shared";
29
+ import { CometChatSearch } from "../CometChatSearch";
29
30
  import { SelectionMode } from "../shared/base/Types";
30
31
  import {
31
32
  ConversationTypeConstants,
@@ -49,6 +50,7 @@ import { ErrorEmptyView } from "../shared/views/ErrorEmptyView/ErrorEmptyView";
49
50
  import { useTheme } from "../theme";
50
51
  import { Skeleton } from "./Skeleton";
51
52
  import { ConversationStyle, Style } from "./style";
53
+ import MessageReceiptUtils from "../shared/utils/MessageReceiptUtils";
52
54
  import { deepMerge } from "../shared/helper/helperFunctions";
53
55
  import Delete from "../shared/icons/components/delete";
54
56
  import { DeepPartial } from "../shared/helper/types";
@@ -56,6 +58,7 @@ import { CometChatTheme } from "../theme/type";
56
58
  import { MenuItemInterface } from "../shared/views/CometChatTooltipMenu/CometChatTooltipMenu";
57
59
  import { JSX } from "react";
58
60
  import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
61
+ import { SuggestionItem } from "../shared/views/CometChatSuggestionList/SuggestionItem";
59
62
 
60
63
  // Unique listener IDs for conversation, user, group, message and call events.
61
64
  const conversationListenerId = "chatlist_" + new Date().getTime();
@@ -219,6 +222,27 @@ export interface ConversationInterface {
219
222
  * Toggle delete conversation option visibilty.
220
223
  */
221
224
  deleteConversationOptionVisibility?: boolean;
225
+ /**
226
+ * Toggle search bar visibility in the conversations header.
227
+ */
228
+ showSearchBar?: boolean;
229
+ /**
230
+ * Callback triggered when the search bar is clicked or focused.
231
+ */
232
+ onSearchBarClicked?: () => void;
233
+ /**
234
+ * Callback triggered when search text changes.
235
+ */
236
+ onSearchTextChanged?: (searchText: string) => void;
237
+ /**
238
+ * Current search text value.
239
+ */
240
+ searchText?: string;
241
+ /**
242
+ * Custom search view component to display in the conversations header.
243
+ */
244
+ SearchView?: () => JSX.Element;
245
+
222
246
  }
223
247
 
224
248
  /**
@@ -261,6 +285,11 @@ export const CometChatConversations = (props: ConversationInterface) => {
261
285
  usersStatusVisibility = true,
262
286
  groupTypeVisibility = true,
263
287
  deleteConversationOptionVisibility = true,
288
+ showSearchBar = false,
289
+ onSearchBarClicked,
290
+ onSearchTextChanged,
291
+ searchText = "",
292
+ SearchView,
264
293
  } = props;
265
294
 
266
295
  // Reference for accessing CometChatList methods
@@ -293,8 +322,37 @@ export const CometChatConversations = (props: ConversationInterface) => {
293
322
  const theme = useTheme();
294
323
  const { t } = useCometChatTranslation()
295
324
  const mergedStyles = useMemo(() => {
296
- return deepMerge(theme.conversationStyles, style ?? {});
297
- }, [theme.conversationStyles, style]);
325
+ const baseStyles = deepMerge(theme.conversationStyles, style ?? {});
326
+ // Add search styling for CometChatList component
327
+ return {
328
+ ...baseStyles,
329
+ searchStyle: {
330
+ textStyle: {
331
+ color: theme.color.textPrimary,
332
+ ...theme.typography.heading4.regular,
333
+ },
334
+ placehodlerTextStyle: {
335
+ color: theme.color.textTertiary,
336
+ },
337
+ containerStyle: {
338
+ backgroundColor: theme.color.background3,
339
+ borderRadius: theme.spacing.radius.max,
340
+ paddingHorizontal: theme.spacing.spacing.s3,
341
+ marginVertical: theme.spacing.spacing.s2,
342
+ flexDirection: 'row' as const,
343
+ alignItems: 'center' as const,
344
+ gap: theme.spacing.spacing.s1,
345
+ },
346
+ iconStyle: {
347
+ tintColor: theme.color.iconSecondary,
348
+ width: 24,
349
+ height: 24,
350
+ },
351
+ },
352
+ } as any;
353
+ }, [theme, style]);
354
+
355
+
298
356
 
299
357
  /**
300
358
  * ErrorStateView renders a view to show when an error occurs.
@@ -756,28 +814,27 @@ export const CometChatConversations = (props: ConversationInterface) => {
756
814
 
757
815
  if (lastMessage && typeof messageText === "string") {
758
816
  messageText = getFormattedText(lastMessage, messageText?.trim());
759
-
760
- if (
761
- lastMessage instanceof CometChat.TextMessage &&
762
- lastMessage.getCategory() === "message" &&
763
- lastMessage
764
- .getText()
765
- .substr(0, 50)
766
- .match(/http[s]{0,1}:\/\//)
767
- ) {
768
- messageText = getMessagePreviewInternal("link-fill", t("LINK"), { theme });
769
- } else {
770
- // Ensure ellipsis is applied if the text is too long.
771
- messageText = (
772
- <Text
773
- style={[mergedStyles.itemStyle.subtitleStyle, { flexShrink: 2 }]}
774
- numberOfLines={1}
775
- ellipsizeMode='tail'
776
- >
777
- {messageText}
778
- </Text>
779
- );
780
- }
817
+ }
818
+ if (
819
+ lastMessage instanceof CometChat.TextMessage &&
820
+ lastMessage.getCategory() === "message" &&
821
+ (() => {
822
+ // Guard against undefined text or non-string values.
823
+ const text = typeof lastMessage.getText === "function" ? lastMessage.getText() : undefined;
824
+ return typeof text === "string" && text.slice(0, 50).match(/https?:\/\//);
825
+ })()
826
+ ) {
827
+ messageText = getMessagePreviewInternal("link-fill", t("LINK"), { theme });
828
+ } else if (messageText) {
829
+ messageText = (
830
+ <Text
831
+ style={[mergedStyles.itemStyle.subtitleStyle, { flexShrink: 2 }]}
832
+ numberOfLines={1}
833
+ ellipsizeMode='tail'
834
+ >
835
+ {messageText}
836
+ </Text>
837
+ );
781
838
  }
782
839
 
783
840
  let groupText = "";
@@ -816,25 +873,48 @@ export const CometChatConversations = (props: ConversationInterface) => {
816
873
  function getFormattedText(message: CometChat.BaseMessage, subtitle: string) {
817
874
  let messageTextTmp: string | JSX.Element = subtitle;
818
875
  let allFormatters = [...(textFormatters || [])];
876
+ // Detect presence of @all alias token in raw string
877
+ const containsAllAlias =
878
+ typeof messageTextTmp === "string" && /<@all:(.*?)>/.test(messageTextTmp);
819
879
 
820
- if (message.getMentionedUsers().length) {
880
+ if (message.getMentionedUsers().length || containsAllAlias) {
821
881
  let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
822
882
  mentionsFormatter.setContext("conversation");
823
883
  mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser!);
824
884
  mentionsFormatter.setMentionsStyle(mergedStyles.mentionsStyles);
825
885
  mentionsFormatter.setTargetElement(MentionsTargetElement.conversation);
826
-
827
886
  mentionsFormatter.setMessage(message);
887
+
888
+ // Inject alias suggestion item if needed so formatter can render styled @All
889
+ if (containsAllAlias) {
890
+ const match = (messageTextTmp as string).match(/<@all:(.*?)>/);
891
+ const aliasLabel = match && match[1] ? match[1] : "all";
892
+ let existing = mentionsFormatter.getSuggestionItems();
893
+ const underlyingText = `<@all:${aliasLabel}>`;
894
+ const already = existing.find((it: any) => it.underlyingText === underlyingText);
895
+ if (!already) {
896
+ const aliasItem = new SuggestionItem({
897
+ id: aliasLabel,
898
+ name: aliasLabel,
899
+ promptText: aliasLabel,
900
+ trackingCharacter: "@",
901
+ underlyingText,
902
+ hideLeadingIcon: true,
903
+ });
904
+ mentionsFormatter.setSuggestionItems([...existing, aliasItem]);
905
+ }
906
+ }
907
+
828
908
  allFormatters.push(mentionsFormatter);
829
909
  }
830
910
 
831
911
  if (
832
912
  message instanceof CometChat.TextMessage &&
833
913
  message.getCategory() === "message" &&
834
- message
835
- .getText()
836
- .substr(0, 50)
837
- .match(/http[s]{0,1}:\/\//)
914
+ (() => {
915
+ const text = typeof message.getText === "function" ? message.getText() : undefined;
916
+ return typeof text === "string" && text.slice(0, 50).match(/https?:\/\//);
917
+ })()
838
918
  ) {
839
919
  // For link messages, simply return the text.
840
920
  return messageTextTmp;
@@ -896,13 +976,10 @@ export const CometChatConversations = (props: ConversationInterface) => {
896
976
  lastMessage.getSender().getUid() == loggedInUser.current!.getUid() &&
897
977
  !lastMessage.getDeletedAt()
898
978
  ) {
899
- let status: MessageReceipt = MessageReceipt.ERROR;
900
- if (lastMessage?.hasOwnProperty("readAt")) status = MessageReceipt.READ;
901
- else if (lastMessage?.hasOwnProperty("deliveredAt")) status = MessageReceipt.DELIVERED;
902
- else if (lastMessage?.hasOwnProperty("sentAt")) status = MessageReceipt.SENT;
979
+ const status = MessageReceiptUtils.getReceiptStatus(lastMessage);
903
980
  readReceipt =
904
981
  !receiptsVisibility || lastMessage?.getDeletedAt() ? null : (
905
- <CometChatReceipt receipt={status} style={mergedStyles.itemStyle.receiptStyles} />
982
+ <CometChatReceipt receipt={status as MessageReceipt} style={mergedStyles.itemStyle.receiptStyles} />
906
983
  );
907
984
  }
908
985
 
@@ -1569,6 +1646,64 @@ export const CometChatConversations = (props: ConversationInterface) => {
1569
1646
 
1570
1647
  return (
1571
1648
  <View style={mergedStyles.containerStyle}>
1649
+ <CometChatList
1650
+ AppBarOptions={AppBarOptions}
1651
+ onError={onError}
1652
+ ref={conversationListRef}
1653
+ LeadingView={LeadingView ? LeadingView : LeadingViewRaw}
1654
+ TitleView={TitleView ? TitleView : TitleViewRaw}
1655
+ SubtitleView={SubtitleView ? SubtitleView : SubtitleViewRaw}
1656
+ TrailingView={TrailingView ? TrailingView : TrailingViewRaw}
1657
+ requestBuilder={
1658
+ conversationsRequestBuilder || new CometChat.ConversationsRequestBuilder().setLimit(30)
1659
+ }
1660
+ hideStickyHeader={true}
1661
+ title={!hideHeader ? t("CHATS") : ""}
1662
+ listStyle={mergedStyles}
1663
+ hideSearch={!showSearchBar}
1664
+ hideHeader={hideHeader}
1665
+ hideSubmitButton={hideSubmitButton}
1666
+ SearchView={SearchView}
1667
+ onSearchBarClicked={onSearchBarClicked}
1668
+ onItemPress={(conversation) =>
1669
+ selectionMode === "none" ? conversationClicked(conversation) : null
1670
+ }
1671
+ onItemLongPress={(conversation: CometChat.Conversation, e?: GestureResponderEvent) => {
1672
+ if (selectionMode === "none") {
1673
+ if (onItemLongPress) {
1674
+ onItemLongPress(conversation);
1675
+ return;
1676
+ }
1677
+ if (e && "nativeEvent" in e) {
1678
+ longPressId.current = conversation.getConversationId();
1679
+ longPressedConversation.current = conversation;
1680
+ tooltipPositon.current = {
1681
+ pageX: e.nativeEvent.pageX,
1682
+ pageY: e.nativeEvent.pageY,
1683
+ };
1684
+ setTooltipVisible(true);
1685
+ }
1686
+ }
1687
+ }}
1688
+ listItemKey={"conversationId"}
1689
+ LoadingView={LoadingView ?? (() => <Skeleton style={mergedStyles.skeletonStyle} />)}
1690
+ ItemView={ItemView}
1691
+ EmptyView={EmptyView ? EmptyView : () => <EmptyStateView />}
1692
+ ErrorView={ErrorView ? ErrorView : () => <ErrorStateView />}
1693
+ onBack={onBack}
1694
+ hideBackButton={hideBackButton}
1695
+ onSelection={onSelection}
1696
+ onSubmit={onSubmit}
1697
+ selectionMode={selectionMode}
1698
+ hideError={hideError}
1699
+ onListFetched={(conversations: CometChat.Conversation[]) => {
1700
+ if (conversations.length === 0) {
1701
+ onEmpty?.();
1702
+ } else {
1703
+ onLoad?.(conversations);
1704
+ }
1705
+ }}
1706
+ />
1572
1707
  <CometChatTooltipMenu
1573
1708
  visible={tooltipVisible}
1574
1709
  onClose={() => {
@@ -1620,62 +1755,6 @@ export const CometChatConversations = (props: ConversationInterface) => {
1620
1755
  }}
1621
1756
  {...mergedStyles.confirmDialogStyle}
1622
1757
  />
1623
- <CometChatList
1624
- AppBarOptions={AppBarOptions}
1625
- onError={onError}
1626
- ref={conversationListRef}
1627
- LeadingView={LeadingView ? LeadingView : LeadingViewRaw}
1628
- TitleView={TitleView ? TitleView : TitleViewRaw}
1629
- SubtitleView={SubtitleView ? SubtitleView : SubtitleViewRaw}
1630
- TrailingView={TrailingView ? TrailingView : TrailingViewRaw}
1631
- requestBuilder={
1632
- conversationsRequestBuilder || new CometChat.ConversationsRequestBuilder().setLimit(30)
1633
- }
1634
- hideStickyHeader={true}
1635
- title={t("CHATS")}
1636
- listStyle={mergedStyles}
1637
- hideSearch={true}
1638
- hideSubmitButton={hideSubmitButton}
1639
- onItemPress={(conversation) =>
1640
- selectionMode === "none" ? conversationClicked(conversation) : null
1641
- }
1642
- onItemLongPress={(conversation: CometChat.Conversation, e?: GestureResponderEvent) => {
1643
- if (selectionMode === "none") {
1644
- if (onItemLongPress) {
1645
- onItemLongPress(conversation);
1646
- return;
1647
- }
1648
- if (e && "nativeEvent" in e) {
1649
- longPressId.current = conversation.getConversationId();
1650
- longPressedConversation.current = conversation;
1651
- tooltipPositon.current = {
1652
- pageX: e.nativeEvent.pageX,
1653
- pageY: e.nativeEvent.pageY,
1654
- };
1655
- setTooltipVisible(true);
1656
- }
1657
- }
1658
- }}
1659
- listItemKey={"conversationId"}
1660
- LoadingView={LoadingView ?? (() => <Skeleton style={mergedStyles.skeletonStyle} />)}
1661
- ItemView={ItemView}
1662
- EmptyView={EmptyView ? EmptyView : () => <EmptyStateView />}
1663
- ErrorView={ErrorView ? ErrorView : () => <ErrorStateView />}
1664
- onBack={onBack}
1665
- hideBackButton={hideBackButton}
1666
- onSelection={onSelection}
1667
- onSubmit={onSubmit}
1668
- selectionMode={selectionMode}
1669
- hideError={hideError}
1670
- hideHeader={hideHeader}
1671
- onListFetched={(conversations: CometChat.Conversation[]) => {
1672
- if (conversations.length === 0) {
1673
- onEmpty?.();
1674
- } else {
1675
- onLoad?.(conversations);
1676
- }
1677
- }}
1678
- />
1679
1758
  </View>
1680
1759
  );
1681
1760
  };