@cometchat/chat-uikit-react-native 5.0.1 → 5.1.0

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 (132) hide show
  1. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  3. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/.gradle/7.4/gc.properties +0 -0
  5. package/android/.gradle/vcs-1/gc.properties +0 -0
  6. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +87 -41
  7. package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +10 -0
  8. package/ios/SoundPlayer.m +8 -0
  9. package/lib/CometChatMessageList/CometChatMessageList.js +1 -1
  10. package/lib/CometChatMessageList/CometChatMessageList.js.map +1 -1
  11. package/lib/extensions/Stickers/StickersExtensionDecorator.d.ts +1 -2
  12. package/lib/extensions/Stickers/StickersExtensionDecorator.js +1 -2
  13. package/lib/extensions/Stickers/StickersExtensionDecorator.js.map +1 -1
  14. package/lib/shared/CometChatUiKit/CometChatUIKit.d.ts +2 -1
  15. package/lib/shared/CometChatUiKit/CometChatUIKit.js +2 -1
  16. package/lib/shared/CometChatUiKit/CometChatUIKit.js.map +1 -1
  17. package/lib/shared/index.d.ts +15 -13
  18. package/lib/shared/index.js +30 -12
  19. package/lib/shared/index.js.map +1 -1
  20. package/lib/shared/utils/CometChatMessagePreview/CometChatMessagePreview.d.ts +10 -1
  21. package/lib/shared/utils/CometChatMessagePreview/CometChatMessagePreview.js +8 -0
  22. package/lib/shared/utils/CometChatMessagePreview/CometChatMessagePreview.js.map +1 -1
  23. package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.d.ts +29 -0
  24. package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js +29 -0
  25. package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js.map +1 -0
  26. package/lib/shared/utils/CometChatMessagePreview/index.d.ts +2 -1
  27. package/lib/shared/utils/CometChatMessagePreview/index.js +3 -1
  28. package/lib/shared/utils/CometChatMessagePreview/index.js.map +1 -1
  29. package/lib/shared/utils/CometChatMessagePreview/style.d.ts +16 -16
  30. package/lib/shared/utils/MessageUtils.js +11 -10
  31. package/lib/shared/utils/MessageUtils.js.map +1 -1
  32. package/lib/shared/utils/index.d.ts +2 -2
  33. package/lib/shared/utils/index.js +2 -2
  34. package/lib/shared/utils/index.js.map +1 -1
  35. package/lib/theme/context.js +1 -1
  36. package/lib/theme/context.js.map +1 -1
  37. package/lib/theme/default/index.d.ts +6 -0
  38. package/lib/theme/default/index.js +178 -0
  39. package/lib/theme/default/index.js.map +1 -1
  40. package/lib/theme/provider.js +1 -1
  41. package/lib/theme/provider.js.map +1 -1
  42. package/package.json +6 -4
  43. package/react-native-cometchat-ui-kit.podspec +1 -1
  44. package/src/CometChatConversations/CometChatConversations.tsx +34 -29
  45. package/src/CometChatConversations/style.ts +5 -2
  46. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +56 -44
  47. package/src/CometChatGroups/CometChatGroups.tsx +13 -10
  48. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +203 -57
  49. package/src/CometChatMessageComposer/styles.tsx +2 -6
  50. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +8 -48
  51. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +8 -14
  52. package/src/CometChatMessageList/CometChatMessageList.tsx +18 -10
  53. package/src/CometChatMessageList/style.ts +0 -16
  54. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +3 -2
  55. package/src/CometChatUsers/CometChatUsers.tsx +9 -8
  56. package/src/calls/CallUtils.ts +14 -14
  57. package/src/calls/CallingExtensionDecorator.tsx +13 -12
  58. package/src/calls/CometChatCallBubble/CometChatCallBubble.tsx +4 -3
  59. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +15 -12
  60. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +8 -6
  61. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +4 -2
  62. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +7 -6
  63. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +7 -6
  64. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +3 -2
  65. package/src/extensions/MessageTranslation/MessageTranslationBubble.tsx +3 -2
  66. package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +26 -17
  67. package/src/extensions/Polls/Polls.tsx +53 -17
  68. package/src/extensions/Polls/PollsDecorator.tsx +5 -3
  69. package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +5 -4
  70. package/src/extensions/Stickers/CometChatStickerKeyboard/hooks.ts +3 -2
  71. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +5 -2
  72. package/src/index.ts +10 -4
  73. package/src/shared/CometChatUiKit/CometChatUIKit.ts +1 -2
  74. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +116 -32
  75. package/src/shared/framework/DataSource.ts +5 -2
  76. package/src/shared/framework/DataSourceDecorator.tsx +4 -4
  77. package/src/shared/framework/MessageDataSource.tsx +178 -46
  78. package/src/shared/helper/LocalizedDateHelper.ts +317 -0
  79. package/src/shared/helper/functions.js +69 -1
  80. package/src/shared/helper/useLocalizedDateHook.tsx +16 -0
  81. package/src/shared/index.ts +7 -2
  82. package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +106 -0
  83. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +99 -0
  84. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizeContext.tsx +15 -0
  85. package/src/shared/resources/CometChatLocalizeNew/LocalizationManager.ts +65 -0
  86. package/src/shared/resources/CometChatLocalizeNew/index.ts +25 -0
  87. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/de/translation.json +10 -1
  88. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/en/translation.json +10 -1
  89. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/es/translation.json +10 -1
  90. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/fr/translation.json +10 -1
  91. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/hi/translation.json +11 -1
  92. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/hu/translation.json +10 -1
  93. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +456 -0
  94. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +456 -0
  95. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +456 -0
  96. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/lt/translation.json +10 -1
  97. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/ms/translation.json +10 -1
  98. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +456 -0
  99. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/pt/translation.json +10 -1
  100. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/ru/translation.json +10 -1
  101. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/sv/translation.json +11 -1
  102. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +456 -0
  103. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/zh/translation.json +11 -1
  104. package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/zh-tw/translation.json +10 -1
  105. package/src/shared/resources/CometChatLocalizeNew/type.ts +7 -0
  106. package/src/shared/resources/CometChatLocalizeNew/useCometChatTranslationHook.ts +24 -0
  107. package/src/shared/resources/index.ts +2 -2
  108. package/src/shared/utils/CommonUtils.ts +2 -1
  109. package/src/shared/utils/PermissionUtil.ts +5 -4
  110. package/src/shared/utils/conversationUtils.ts +11 -9
  111. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +8 -5
  112. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +1 -1
  113. package/src/shared/views/CometChatDate/CometChatDate.tsx +17 -14
  114. package/src/shared/views/CometChatDateSeperator/CometChatDateSeparator.tsx +6 -4
  115. package/src/shared/views/CometChatDeletedBubble/CometChatDeletedBubble.tsx +3 -2
  116. package/src/shared/views/CometChatEmojiKeyboard/emojis.ts +11 -8
  117. package/src/shared/views/CometChatList/CometChatList.tsx +5 -4
  118. package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +15 -9
  119. package/src/shared/views/CometChatMediaRecorder/CometChatMediaRecorder.tsx +5 -4
  120. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -2
  121. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +7 -6
  122. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +10 -7
  123. package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +1 -0
  124. package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +24 -47
  125. package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +68 -73
  126. package/src/theme/type.ts +0 -2
  127. package/lib/theme/default/default.d.ts +0 -6
  128. package/lib/theme/default/default.js +0 -179
  129. package/lib/theme/default/default.js.map +0 -1
  130. package/src/shared/resources/CometChatLocalize/CometChatLocalize.ts +0 -183
  131. package/src/shared/resources/CometChatLocalize/index.ts +0 -3
  132. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +0 -447
@@ -2,9 +2,9 @@ import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from
2
2
  import {
3
3
  ColorValue,
4
4
  Dimensions,
5
- Image,
6
5
  ImageSourcePropType,
7
6
  ImageStyle,
7
+ InteractionManager,
8
8
  KeyboardAvoidingView,
9
9
  KeyboardAvoidingViewProps,
10
10
  Modal,
@@ -26,7 +26,6 @@ import {
26
26
  CometChatTextFormatter,
27
27
  CometChatUIKit,
28
28
  CometChatUrlsFormatter,
29
- localize,
30
29
  SuggestionItem,
31
30
  } from "../shared";
32
31
  import { Style } from "./styles";
@@ -59,6 +58,14 @@ import { ICONS } from "./resources";
59
58
  import { CometChatTheme } from "../theme/type";
60
59
  import { deepMerge } from "../shared/helper/helperFunctions";
61
60
  import { JSX } from "react";
61
+ import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
62
+
63
+ type MentionOverlap = {
64
+ key: string;
65
+ value: SuggestionItem;
66
+ start: number;
67
+ end: number;
68
+ };
62
69
 
63
70
  const { FileManager, CommonUtil } = NativeModules;
64
71
 
@@ -67,9 +74,10 @@ const uiEventListenerHide = "uiEvent_hide_" + new Date().getTime();
67
74
 
68
75
  const MessagePreviewTray = (props: any) => {
69
76
  const { shouldShow = false, text = "", onClose = () => {} } = props;
77
+ const {t}= useCometChatTranslation()
70
78
  return shouldShow ? (
71
79
  <CometChatMessagePreview
72
- messagePreviewTitle={localize("EDIT_MESSAGE")}
80
+ messagePreviewTitle={t("EDIT_MESSAGE")}
73
81
  messagePreviewSubtitle={text}
74
82
  closeIconURL={ICONS.CLOSE}
75
83
  onCloseClick={onClose}
@@ -77,19 +85,6 @@ const MessagePreviewTray = (props: any) => {
77
85
  ) : null;
78
86
  };
79
87
 
80
- const ImageButton = (props: any) => {
81
- const { image, onClick, buttonStyle, imageStyle, disable } = props;
82
- return (
83
- <TouchableOpacity
84
- activeOpacity={disable ? 1 : undefined}
85
- onPress={disable ? () => {} : onClick}
86
- style={buttonStyle}
87
- >
88
- <Image source={image} style={[{ height: 24, width: 24 }, imageStyle]} />
89
- </TouchableOpacity>
90
- );
91
- };
92
-
93
88
  const AttachIconButton = (props: {
94
89
  onPress: TouchableWithoutFeedbackProps["onPress"];
95
90
  icon: ImageSourcePropType | JSX.Element;
@@ -444,6 +439,7 @@ export const CometChatMessageComposer = React.forwardRef(
444
439
  const UiEventListenerID = "UiEventListener_" + new Date().getTime();
445
440
 
446
441
  const theme = useTheme();
442
+ const {t} = useCometChatTranslation()
447
443
  const {
448
444
  id,
449
445
  user,
@@ -556,7 +552,7 @@ export const CometChatMessageComposer = React.forwardRef(
556
552
  }
557
553
  }, []);
558
554
 
559
- const isTyping = useRef<NodeJS.Timeout | null>(null);
555
+ const isTyping = useRef<ReturnType<typeof setTimeout> | null>(null);
560
556
 
561
557
  /**
562
558
  * Event callback
@@ -645,7 +641,7 @@ export const CometChatMessageComposer = React.forwardRef(
645
641
 
646
642
  plainTextInput.current = getPlainString(message?.text, edits);
647
643
  setPlainText(plainTextInput.current);
648
- setOriginalText(plainTextInput.current.trim());
644
+ setOriginalText(plainTextInput.current.trim());
649
645
  setHasEdited(false);
650
646
  const hashMap = new Map();
651
647
  let offset = 0; // Tracks shift in position due to replacements
@@ -1090,6 +1086,7 @@ export const CometChatMessageComposer = React.forwardRef(
1090
1086
  if (!disableMentions) {
1091
1087
  let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
1092
1088
  mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser!);
1089
+ mentionsFormatter.setContext("composer");
1093
1090
  mentionsFormatter.setMentionsStyle(
1094
1091
  mergedComposerStyle.mentionsStyle as CometChatTheme["mentionsStyle"]
1095
1092
  );
@@ -1368,7 +1365,7 @@ export const CometChatMessageComposer = React.forwardRef(
1368
1365
  );
1369
1366
  }
1370
1367
 
1371
- let timeoutId: NodeJS.Timeout;
1368
+ let timeoutId: ReturnType<typeof setTimeout>;
1372
1369
  const openList = (selection: { start: number; end: number }) => {
1373
1370
  clearTimeout(timeoutId);
1374
1371
  timeoutId = setTimeout(() => {
@@ -1447,28 +1444,183 @@ export const CometChatMessageComposer = React.forwardRef(
1447
1444
  return _plainString;
1448
1445
  };
1449
1446
 
1447
+ const parseMentionKey = (key: string): { start: number; end: number } | undefined => {
1448
+ const [startStr, endStr] = key.split("_");
1449
+ const start = Number(startStr);
1450
+ const end = Number(endStr);
1451
+
1452
+ const isValid = Number.isFinite(start) && Number.isFinite(end);
1453
+
1454
+ if (typeof __DEV__ !== "undefined" && __DEV__ && !isValid) {
1455
+ throw new Error(`Invalid mention key: "${key}" (expected "start_end")`);
1456
+ }
1457
+
1458
+ return isValid ? { start, end } : undefined;
1459
+ };
1460
+
1461
+ const calcDeletionRange = (
1462
+ selection: { start: number; end: number },
1463
+ deletionLength: number
1464
+ ) => {
1465
+ return selection.start === selection.end
1466
+ ? {
1467
+ start: Math.max(0, selection.start - deletionLength),
1468
+ end: selection.start,
1469
+ }
1470
+ : { start: selection.start, end: selection.end };
1471
+ };
1472
+
1473
+ const collectOverlappingMentions = (
1474
+ range: { start: number; end: number },
1475
+ mentionMap: Map<string, SuggestionItem>
1476
+ ): MentionOverlap[] => {
1477
+ const overlaps: MentionOverlap[] = [];
1478
+
1479
+ mentionMap.forEach((value, key) => {
1480
+ const mentionRange = parseMentionKey(key);
1481
+ if (!mentionRange) return;
1482
+
1483
+ const { start, end } = mentionRange;
1484
+
1485
+ // compare against the *deletion* range, not the mention itself
1486
+ if (range.start < end && range.end > start) {
1487
+ overlaps.push({ key, value, start, end });
1488
+ }
1489
+ });
1490
+
1491
+ overlaps.sort((a, b) => a.start - b.start);
1492
+ return overlaps;
1493
+ };
1494
+
1495
+ const removeMentionsFromTextAndMap = (
1496
+ text: string,
1497
+ overlaps: MentionOverlap[],
1498
+ map: Map<string, SuggestionItem>
1499
+ ) => {
1500
+ let adjustment = 0;
1501
+ let newText = text;
1502
+
1503
+ overlaps.forEach(({ key, value, start, end }) => {
1504
+ const adjStart = start + adjustment;
1505
+ const adjEnd = end + adjustment;
1506
+
1507
+ newText = newText.slice(0, adjStart) + newText.slice(adjEnd);
1508
+ map.delete(key);
1509
+ adjustment -= adjEnd - adjStart;
1510
+
1511
+ // keep formatter in sync
1512
+ if (!ifIdExists(value.id, map)) {
1513
+ const fmt = allFormatters.current.get(value.trackingCharacter!);
1514
+ if (fmt instanceof CometChatMentionsFormatter) {
1515
+ const users = fmt.getSuggestionItems().filter((u) => u.id !== value.id);
1516
+ fmt.setSuggestionItems(users);
1517
+ if (!getMentionLimitView(fmt)) setWarningMessage("");
1518
+ }
1519
+ }
1520
+ });
1521
+
1522
+ return { newText, totalShift: adjustment };
1523
+ };
1524
+
1525
+ const shiftRemainingMentionKeys = (
1526
+ map: Map<string, SuggestionItem>,
1527
+ shiftStart: number,
1528
+ delta: number
1529
+ ) => {
1530
+ if (delta === 0) return;
1531
+ const shifted = new Map<string, SuggestionItem>();
1532
+
1533
+ map.forEach((val, key) => {
1534
+ const range = parseMentionKey(key);
1535
+ if (!range) {
1536
+ // key was malformed → skip or handle as you wish
1537
+ return;
1538
+ }
1539
+
1540
+ const { start, end } = range;
1541
+ if (start > shiftStart) {
1542
+ shifted.set(`${start + delta}_${end + delta}`, val);
1543
+ } else {
1544
+ shifted.set(key, val);
1545
+ }
1546
+ });
1547
+
1548
+ map.clear();
1549
+ shifted.forEach((v, k) => map.set(k, v));
1550
+ };
1551
+
1552
+ const deleteMentionHelper = (oldText: string, newText: string) => {
1553
+ const deletionLen = oldText.length - newText.length;
1554
+ const range = calcDeletionRange(selectionPosition, deletionLen);
1555
+
1556
+ const deletionMentionMap = new Map(mentionMap.current);
1557
+ const overlaps = collectOverlappingMentions(range, deletionMentionMap);
1558
+
1559
+ if (overlaps.length === 0) return false;
1560
+
1561
+ const { newText: finalText, totalShift } = removeMentionsFromTextAndMap(
1562
+ oldText,
1563
+ overlaps,
1564
+ deletionMentionMap
1565
+ );
1566
+
1567
+ shiftRemainingMentionKeys(deletionMentionMap, range.start, totalShift);
1568
+
1569
+ plainTextInput.current = finalText;
1570
+ setPlainText(finalText);
1571
+ onTextChange?.(finalText);
1572
+ mentionMap.current = deletionMentionMap;
1573
+
1574
+ const firstStart = overlaps[0].start;
1575
+ InteractionManager.runAfterInteractions(() => {
1576
+ messageInputRef.current?.setNativeProps({
1577
+ selection: { start: firstStart, end: firstStart },
1578
+ });
1579
+ });
1580
+
1581
+ setFormattedInputMessage();
1582
+ return true;
1583
+ };
1584
+
1450
1585
  const textChangeHandler = (txt: string) => {
1451
1586
  setPlainText(txt);
1452
1587
  if (messagePreview) {
1453
1588
  setHasEdited(txt.trim() !== originalText.trim());
1454
1589
  }
1455
- let removing = plainTextInput.current?.length ?? 0 > txt.length;
1456
- let adding = plainTextInput.current?.length < txt.length;
1457
- let textDiff = txt.length - (plainTextInput.current?.length ?? 0);
1458
- let notAtLast = selectionPosition.start + textDiff < txt.length;
1459
1590
 
1460
- plainTextInput.current = txt;
1461
- onTextChange && onTextChange(txt);
1591
+ const oldText = plainTextInput.current ?? "";
1592
+ const newText = txt;
1593
+
1462
1594
  startTyping();
1463
1595
 
1596
+ // Check if this is a deletion
1597
+ if (oldText.length > newText.length) {
1598
+ const handled = deleteMentionHelper(oldText, newText);
1599
+ if (handled) return;
1600
+ }
1601
+
1602
+ // Existing handling for non-deletion cases
1603
+ const removing = (plainTextInput.current?.length ?? 0) > txt.length;
1604
+ const adding = plainTextInput.current?.length < txt.length;
1605
+ const textDiff = txt.length - (plainTextInput.current?.length ?? 0);
1606
+ const notAtLast = selectionPosition.start + textDiff < txt.length;
1607
+
1464
1608
  let decr = 0;
1465
1609
 
1466
- let newMentionMap: any = new Map(mentionMap.current);
1610
+ plainTextInput.current = newText;
1611
+ setPlainText(newText);
1612
+
1613
+ const newMentionMap: Map<string, SuggestionItem> = new Map(mentionMap.current);
1467
1614
 
1468
1615
  mentionMap.current.forEach((value, key) => {
1469
- let position = { start: parseInt(key.split("_")[0]), end: parseInt(key.split("_")[1]) };
1616
+ const range = parseMentionKey(key);
1617
+ if (!range) {
1618
+ // key was malformed → skip or handle as you wish
1619
+ return;
1620
+ }
1470
1621
 
1471
- //Runs when cursor before the mention and before the last position
1622
+ const { start, end } = range;
1623
+ let position = { start, end };
1472
1624
 
1473
1625
  if (
1474
1626
  notAtLast &&
@@ -1477,48 +1629,43 @@ export const CometChatMessageComposer = React.forwardRef(
1477
1629
  ) {
1478
1630
  if (removing) {
1479
1631
  decr = selectionPosition.end - selectionPosition.start - textDiff;
1480
- position = { start: position.start - decr, end: position.end - decr };
1632
+ position.start -= decr;
1633
+ position.end -= decr;
1481
1634
  } else if (adding) {
1482
1635
  decr = selectionPosition.end - selectionPosition.start + textDiff;
1483
- position = { start: position.start + decr, end: position.end + decr };
1636
+ position.start += decr;
1637
+ position.end += decr;
1484
1638
  }
1485
1639
  if (removing || adding) {
1486
- let newKey = `${position.start}_${position.end}`;
1487
- position.start >= 0 && newMentionMap.set(newKey, value);
1640
+ const newKey = `${position.start}_${position.end}`;
1641
+ if (position.start >= 0) newMentionMap.set(newKey, value);
1488
1642
  newMentionMap.delete(key);
1489
1643
  }
1490
1644
  }
1491
1645
 
1492
- // Code to delete mention from hashmap 👇
1493
- let expctedMentionPos = plainTextInput.current?.substring(position.start, position.end);
1494
-
1495
- if (expctedMentionPos !== `${value.promptText}`) {
1496
- let newKey = `${position.start}_${position.end}`;
1497
- newMentionMap.delete(newKey);
1646
+ /* delete mention that was edited/over-typed */
1647
+ const expected = plainTextInput.current?.substring(position.start, position.end);
1648
+ if (expected !== value.promptText) {
1649
+ newMentionMap.delete(`${position.start}_${position.end}`);
1498
1650
 
1499
1651
  if (!ifIdExists(value.id, newMentionMap)) {
1500
- let targetedFormatter = allFormatters.current.get(value.trackingCharacter!);
1652
+ const targetedFormatter = allFormatters.current.get(value.trackingCharacter!);
1501
1653
  if (!targetedFormatter) return;
1502
- let existingCCUsers = [...targetedFormatter.getSuggestionItems()];
1503
- let userPosition = existingCCUsers.findIndex(
1504
- (item: SuggestionItem) => item.id === value.id
1505
- );
1506
- if (userPosition !== -1) {
1507
- existingCCUsers.splice(userPosition, 1);
1508
- (targetedFormatter as CometChatMentionsFormatter).setSuggestionItems(existingCCUsers);
1509
- }
1654
+ const users = [...targetedFormatter.getSuggestionItems()];
1655
+ const idx = users.findIndex((u) => u.id === value.id);
1656
+ if (idx !== -1) users.splice(idx, 1);
1657
+
1510
1658
  if (targetedFormatter instanceof CometChatMentionsFormatter) {
1511
- let showWarning = getMentionLimitView(targetedFormatter);
1512
- if (!showWarning) {
1513
- setWarningMessage("");
1514
- }
1659
+ targetedFormatter.setSuggestionItems(users);
1660
+ const warn = getMentionLimitView(targetedFormatter);
1661
+ if (!warn) setWarningMessage("");
1515
1662
  }
1516
1663
  }
1517
1664
  }
1518
1665
  });
1519
1666
 
1520
1667
  mentionMap.current = newMentionMap;
1521
-
1668
+ onTextChange?.(plainTextInput.current);
1522
1669
  setFormattedInputMessage();
1523
1670
  };
1524
1671
 
@@ -1557,7 +1704,6 @@ export const CometChatMessageComposer = React.forwardRef(
1557
1704
  mentionPos += 1;
1558
1705
  }
1559
1706
 
1560
- // Code to delete mention from hashmap 👇
1561
1707
  if (
1562
1708
  position.end === selectionPosition.end ||
1563
1709
  (selectionPosition.start > position.start && selectionPosition.end <= position.end)
@@ -1710,9 +1856,9 @@ export const CometChatMessageComposer = React.forwardRef(
1710
1856
  setWarningMessage(
1711
1857
  targetedFormatter?.getErrorString
1712
1858
  ? targetedFormatter?.getErrorString()
1713
- : `${localize("MENTION_UPTO")} ${limit} ${
1714
- limit === 1 ? localize("TIME") : localize("TIMES")
1715
- } ${localize("AT_A_TIME")}.`
1859
+ : `${t("MENTION_UPTO")} ${limit} ${
1860
+ limit === 1 ? t("TIME") : t("TIMES")
1861
+ } ${t("AT_A_TIME")}.`
1716
1862
  );
1717
1863
  return true;
1718
1864
  };
@@ -1818,7 +1964,7 @@ export const CometChatMessageComposer = React.forwardRef(
1818
1964
  <CometChatMessageInput
1819
1965
  messageInputRef={messageInputRef}
1820
1966
  text={inputMessage as string}
1821
- placeHolderText={localize("ENTER_YOUR_MESSAGE_HERE")}
1967
+ placeHolderText={t("ENTER_YOUR_MESSAGE_HERE")}
1822
1968
  style={mergedComposerStyle.messageInputStyles}
1823
1969
  onSelectionChange={({ nativeEvent: { selection } }) => {
1824
1970
  setSelectionPosition(selection);
@@ -81,7 +81,7 @@ export type MessageComposerStyle = {
81
81
  active: ImageStyle;
82
82
  inactive: ImageStyle;
83
83
  };
84
- mediaRecorderStyle: CometChatTheme['mediaRecorderStyle'];
84
+ mediaRecorderStyle: CometChatTheme["mediaRecorderStyle"];
85
85
  attachmentOptionsStyles: ActionSheetStyle;
86
86
  };
87
87
 
@@ -130,14 +130,10 @@ export const getComposerStyle = (
130
130
  textStyle: {
131
131
  ...typography.body.regular,
132
132
  color: color.textHighlight,
133
- // backgroundColor: '#6852D633',
134
- // paddingHorizontal: spacing.padding.p0_5
135
133
  },
136
134
  selfTextStyle: {
137
135
  ...typography.body.regular,
138
136
  color: color.warning,
139
- // backgroundColor: '#FFAB0033',
140
- // paddingHorizontal: spacing.padding.p0_5
141
137
  },
142
138
  },
143
139
  stickerIconStyle: {
@@ -148,6 +144,6 @@ export const getComposerStyle = (
148
144
  tintColor: color.primary,
149
145
  },
150
146
  },
151
- attachmentOptionsStyles: getAttachmentOptionsStyle(color, spacing, typography)
147
+ attachmentOptionsStyles: getAttachmentOptionsStyle(color, spacing, typography),
152
148
  };
153
149
  };
@@ -1,6 +1,6 @@
1
1
  import React, { JSX, useCallback, useEffect, useMemo, useRef, useState } from "react";
2
2
  import { Text, TouchableOpacity, View } from "react-native";
3
- import { ChatConfigurator, localize } from "../shared";
3
+ import { ChatConfigurator, getLastSeenTime } from "../shared";
4
4
  import { listners } from "./listners";
5
5
  import { CometChat } from "@cometchat/chat-sdk-react-native";
6
6
  import { GroupTypeConstants, UserStatusConstants } from "../shared/constants/UIKitConstants";
@@ -13,6 +13,7 @@ import { useTheme } from "../theme";
13
13
  import { MessageHeaderStyle } from "./styles";
14
14
  import { CommonUtils } from "../shared/utils/CommonUtils";
15
15
  import { DeepPartial } from "../shared/helper/types";
16
+ import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
16
17
 
17
18
  export type CometChatMessageHeaderInterface = {
18
19
  /**
@@ -113,6 +114,7 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
113
114
  const msgTypingListenerId = "message_typing_" + new Date().getTime();
114
115
  const groupListenerId = "head_group_" + new Date().getTime();
115
116
  const theme = useTheme();
117
+ const {t}= useCometChatTranslation()
116
118
 
117
119
  const {
118
120
  TitleView,
@@ -158,48 +160,6 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
158
160
  hoursAgo: (hours: number) => `${hours} hour${hours === 1 ? "" : "s"} ago`,
159
161
  };
160
162
 
161
- /**
162
- * Returns a formatted last seen string.
163
- */
164
- function getLastSeenTime(timestamp: number, translations: Translations): string {
165
- try {
166
- if (timestamp === null) return `${translations.lastSeen} Unknown`;
167
-
168
- if (String(timestamp).length === 10) timestamp *= 1000;
169
-
170
- const now = new Date();
171
- const lastSeen = new Date(timestamp);
172
- const diffInMillis = now.getTime() - lastSeen.getTime();
173
- const diffInMinutes = Math.floor(diffInMillis / (1000 * 60));
174
- const diffInHours = Math.floor(diffInMillis / (1000 * 60 * 60));
175
-
176
- if (diffInMinutes === 0) return `${translations.lastSeen} ${translations.minutesAgo(1)}`;
177
- if (diffInMinutes < 60)
178
- return `${translations.lastSeen} ${translations.minutesAgo(diffInMinutes)}`;
179
- if (diffInHours < 24) return `${translations.lastSeen} ${translations.hoursAgo(diffInHours)}`;
180
-
181
- const isSameYear = lastSeen.getFullYear() === now.getFullYear();
182
- const dateOptions: Intl.DateTimeFormatOptions = {
183
- day: "2-digit",
184
- month: "short",
185
- ...(isSameYear ? {} : { year: "numeric" }),
186
- };
187
- const timeOptions: Intl.DateTimeFormatOptions = {
188
- hour: "2-digit",
189
- minute: "2-digit",
190
- hour12: true,
191
- };
192
-
193
- const formattedDate = lastSeen.toLocaleDateString(undefined, dateOptions);
194
- const formattedTime = lastSeen.toLocaleTimeString(undefined, timeOptions);
195
-
196
- if (formattedDate === "Invalid Date" || formattedTime === "Invalid Date") return "Offline";
197
- return `${translations.lastSeen} ${formattedDate} at ${formattedTime}`;
198
- } catch (e) {
199
- errorHandler(e);
200
- return "";
201
- }
202
- }
203
163
 
204
164
  /**
205
165
  * Renders the back button.
@@ -279,7 +239,7 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
279
239
  if (groupObj) {
280
240
  const count = groupObj?.["membersCount"];
281
241
  if (count || count === 0) {
282
- subtitle = `${count} ${localize(count === 1 ? "MEMBER" : "MEMBERS")}`;
242
+ subtitle = `${count} ${t(count === 1 ? "MEMBER" : "MEMBERS")}`;
283
243
  }
284
244
  }
285
245
 
@@ -291,8 +251,8 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
291
251
  ) {
292
252
  subtitle =
293
253
  userStatus === UserStatusConstants.online
294
- ? localize("ONLINE")
295
- : getLastSeenTime(userObj.getLastActiveAt(), translations);
254
+ ? t("ONLINE")
255
+ : getLastSeenTime(userObj.getLastActiveAt()); // Updated to use getLastSeenTime function
296
256
  }
297
257
 
298
258
  if (subtitle) {
@@ -335,7 +295,7 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
335
295
  groupObj?.getGuid() === typist.getReceiverId()
336
296
  ) {
337
297
  setTypingText(
338
- status === "typing" ? `${typist.getSender().getName()}: ${localize("IS_TYPING")}` : ""
298
+ status === "typing" ? `${typist.getSender().getName()}: ${t("IS_TYPING")}` : ""
339
299
  );
340
300
  } else if (
341
301
  receiverTypeRef.current === CometChat.RECEIVER_TYPE.USER &&
@@ -343,7 +303,7 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
343
303
  userObj?.getUid() === typist.getSender().getUid()
344
304
  && !(userObj.getBlockedByMe() || userObj.getHasBlockedMe())
345
305
  ) {
346
- setTypingText(status === "typing" ? localize("TYPING") : "");
306
+ setTypingText(status === "typing" ? t("TYPING") : "");
347
307
  }
348
308
  };
349
309
 
@@ -7,7 +7,6 @@ import {
7
7
  CometChatMessageTemplate,
8
8
  CometChatUIEventHandler,
9
9
  CometChatUiKitConstants,
10
- localize,
11
10
  } from "../shared";
12
11
  import { MessageUtils } from "../shared/utils/MessageUtils";
13
12
  import { Style } from "./styles";
@@ -20,6 +19,7 @@ import { MessageReceipt } from "../shared/constants/UIKitConstants";
20
19
  import { CometChatTheme } from "../theme/type";
21
20
  import { deepMerge } from "../shared/helper/helperFunctions";
22
21
  import { DeepPartial } from "../shared/helper/types";
22
+ import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
23
23
 
24
24
  const listenerId = "uiEvents_" + new Date().getTime();
25
25
 
@@ -54,8 +54,9 @@ export interface CometChatMessageInformationInterface {
54
54
  * @returns A JSX.Element containing the rendered message information.
55
55
  */
56
56
  export const CometChatMessageInformation = (props: CometChatMessageInformationInterface) => {
57
+ const {t} = useCometChatTranslation()
57
58
  const {
58
- title = localize("MESSAGE_INFORMATION"),
59
+ title = t("MESSAGE_INFORMATION"),
59
60
  message,
60
61
  template,
61
62
  BubbleView,
@@ -124,7 +125,7 @@ export const CometChatMessageInformation = (props: CometChatMessageInformationIn
124
125
  {receiverTypeIsUser && (
125
126
  <CometChatReceipt receipt={status} style={mergedStyle.receiptItemStyle.receiptStyles} />
126
127
  )}
127
- <Text style={statusTextStyle}>{localize(status)}</Text>
128
+ <Text style={statusTextStyle}>{t(status)}</Text>
128
129
  </View>
129
130
  {time && time !== defaultReceiptTimestampForUser ? (
130
131
  receiptDatePattern ? (
@@ -132,15 +133,8 @@ export const CometChatMessageInformation = (props: CometChatMessageInformationIn
132
133
  ) : (
133
134
  <CometChatDate
134
135
  style={{ textStyle: mergedStyle.receiptItemStyle.subtitleStyle }}
135
- customDateString={new Date(time * 1000).toLocaleString("en-GB", {
136
- year: "numeric",
137
- month: "numeric",
138
- day: "numeric",
139
- hour: "numeric",
140
- minute: "numeric",
141
- hour12: true,
142
- })}
143
- timeStamp={time}
136
+ pattern="dayDateTimeFormat"
137
+ timeStamp={time*1000}
144
138
  />
145
139
  )
146
140
  ) : (
@@ -324,8 +318,8 @@ export const CometChatMessageInformation = (props: CometChatMessageInformationIn
324
318
  if (ErrorStateView) return <ErrorStateView />;
325
319
  return (
326
320
  <ErrorEmptyView
327
- subTitle={localize("WRONG_TEXT")}
328
- tertiaryTitle={localize("WRONG_TEXT_TRY_AGAIN")}
321
+ subTitle={t("WRONG_TEXT")}
322
+ tertiaryTitle={t("WRONG_TEXT_TRY_AGAIN")}
329
323
  containerStyle={mergedStyle.errorStateStyle?.containerStyle}
330
324
  titleStyle={mergedStyle.errorStateStyle?.titleStyle}
331
325
  subTitleStyle={mergedStyle.errorStateStyle?.subtitleStyle}