@cometchat/chat-uikit-react-native 5.0.0 → 5.0.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.
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +87 -49
- package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +10 -0
- package/ios/SoundPlayer.m +8 -0
- package/package.json +8 -9
- package/src/CometChatConversations/CometChatConversations.tsx +19 -14
- package/src/CometChatConversations/style.ts +6 -2
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +1 -0
- package/src/CometChatGroupMembers/style.ts +1 -0
- package/src/CometChatGroups/CometChatGroups.tsx +1 -0
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +227 -57
- package/src/CometChatMessageComposer/styles.tsx +3 -6
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +2 -2
- package/src/CometChatMessageHeader/styles.ts +1 -0
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +1 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +188 -111
- package/src/CometChatMessageList/style.ts +0 -16
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +1 -1
- package/src/CometChatUsers/CometChatUsers.tsx +1 -1
- package/src/calls/CallUtils.ts +18 -10
- package/src/calls/CallingExtensionDecorator.tsx +1 -1
- package/src/calls/CometChatCallBubble/CometChatCallBubble.tsx +8 -7
- package/src/calls/CometChatCallBubble/styles.ts +1 -0
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +6 -4
- package/src/calls/CometChatCallButtons/style.ts +2 -1
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +4 -3
- package/src/calls/CometChatCallLogs/style.ts +1 -0
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +4 -3
- package/src/calls/CometChatOngoingCall/CometChatOngoingCall.tsx +1 -0
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +3 -3
- package/src/calls/CometChatOutgoingCall/OutgoingCallConfiguration.ts +1 -0
- package/src/extensions/CollaborativeBubble/CometChatCollaborativeBubble.tsx +1 -1
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +1 -1
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +1 -1
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +15 -18
- package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +1 -1
- package/src/extensions/LinkPreview/style.ts +2 -2
- package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +20 -17
- package/src/extensions/Polls/Polls.tsx +45 -8
- package/src/extensions/Polls/PollsDecorator.tsx +1 -1
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -4
- package/src/extensions/Stickers/style.ts +3 -3
- package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +1 -1
- package/src/imageresolver.d.ts +4 -0
- package/src/index.ts +2 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +1 -2
- package/src/shared/base/Types.ts +1 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +114 -32
- package/src/shared/formatters/CometChatTextFormatter.ts +1 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +4 -4
- package/src/shared/framework/DataSource.ts +6 -2
- package/src/shared/framework/DataSourceDecorator.tsx +5 -4
- package/src/shared/framework/MessageDataSource.tsx +26 -28
- package/src/shared/helper/types/index.ts +1 -0
- package/src/shared/icons/Icon.tsx +1 -1
- package/src/shared/index.ts +41 -126
- package/src/shared/libs/ImageZoom/ReactNativeZoomableView.tsx +1 -1
- package/src/shared/libs/ImageZoom/ReactNativeZoomableViewWithGestures.tsx +4 -2
- package/src/shared/modals/CometChatMessageOption.ts +1 -0
- package/src/shared/modals/CometChatMessageTemplate.ts +1 -0
- package/src/shared/resources/CometChatSoundManager/index.ts +1 -0
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +0 -8
- package/src/shared/utils/CometChatMessagePreview/index.ts +1 -2
- package/src/shared/utils/CommonUtils.ts +2 -1
- package/src/shared/utils/MessageUtils.tsx +54 -62
- package/src/shared/utils/conversationUtils.ts +1 -0
- package/src/shared/utils/index.ts +1 -2
- package/src/shared/views/CometChatActionSheet/ActionItem.ts +1 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -1
- package/src/shared/views/CometChatAudioBubble/AnimatedAudioWaves.tsx +1 -1
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +9 -6
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +1 -1
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +1 -1
- package/src/shared/views/CometChatConfirmDialog/style.ts +1 -0
- package/src/shared/views/CometChatDeletedBubble/styles.ts +1 -0
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +1 -1
- package/src/shared/views/CometChatList/CometChatList.tsx +2 -2
- package/src/shared/views/CometChatList/Header.tsx +1 -1
- package/src/shared/views/CometChatMediaRecorder/AnimatingMic.tsx +2 -2
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +16 -10
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +7 -8
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -1
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +84 -70
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +1 -1
- package/src/shared/views/CometChatReactions/style.ts +5 -4
- package/src/shared/views/CometChatReceipt/style.ts +1 -0
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +1 -1
- package/src/shared/views/CometChatSuggestionList/style.ts +3 -2
- package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +1 -1
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +24 -47
- package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +68 -73
- package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +1 -0
- package/src/theme/CometChatThemeHelper.ts +69 -58
- package/src/theme/context.ts +2 -2
- package/src/theme/default/default.ts +204 -0
- package/src/theme/default/index.ts +0 -238
- package/src/theme/provider.tsx +7 -7
- package/src/theme/type.ts +5 -7
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/src/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js +0 -42
|
@@ -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,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
SuggestionItem,
|
|
31
31
|
} from "../shared";
|
|
32
32
|
import { Style } from "./styles";
|
|
33
|
-
|
|
33
|
+
//@ts-ignore
|
|
34
34
|
import { CheckPropertyExists } from "../shared/helper/functions";
|
|
35
35
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
36
36
|
import { ChatConfigurator, CometChatSoundManager } from "../shared";
|
|
@@ -58,6 +58,15 @@ import { useTheme } from "../theme";
|
|
|
58
58
|
import { ICONS } from "./resources";
|
|
59
59
|
import { CometChatTheme } from "../theme/type";
|
|
60
60
|
import { deepMerge } from "../shared/helper/helperFunctions";
|
|
61
|
+
import { JSX } from "react";
|
|
62
|
+
|
|
63
|
+
type MentionOverlap = {
|
|
64
|
+
key: string;
|
|
65
|
+
value: SuggestionItem;
|
|
66
|
+
start: number;
|
|
67
|
+
end: number;
|
|
68
|
+
};
|
|
69
|
+
|
|
61
70
|
const { FileManager, CommonUtil } = NativeModules;
|
|
62
71
|
|
|
63
72
|
const uiEventListenerShow = "uiEvent_show_" + new Date().getTime();
|
|
@@ -75,19 +84,6 @@ const MessagePreviewTray = (props: any) => {
|
|
|
75
84
|
) : null;
|
|
76
85
|
};
|
|
77
86
|
|
|
78
|
-
const ImageButton = (props: any) => {
|
|
79
|
-
const { image, onClick, buttonStyle, imageStyle, disable } = props;
|
|
80
|
-
return (
|
|
81
|
-
<TouchableOpacity
|
|
82
|
-
activeOpacity={disable ? 1 : undefined}
|
|
83
|
-
onPress={disable ? () => {} : onClick}
|
|
84
|
-
style={buttonStyle}
|
|
85
|
-
>
|
|
86
|
-
<Image source={image} style={[{ height: 24, width: 24 }, imageStyle]} />
|
|
87
|
-
</TouchableOpacity>
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
87
|
const AttachIconButton = (props: {
|
|
92
88
|
onPress: TouchableWithoutFeedbackProps["onPress"];
|
|
93
89
|
icon: ImageSourcePropType | JSX.Element;
|
|
@@ -532,6 +528,9 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
532
528
|
const [mentionsSearchData, setMentionsSearchData] = React.useState<Array<SuggestionItem>>([]);
|
|
533
529
|
const [suggestionListLoader, setSuggestionListLoader] = React.useState(false);
|
|
534
530
|
const [warningMessage, setWarningMessage] = React.useState("");
|
|
531
|
+
const [originalText, setOriginalText] = React.useState<string>("");
|
|
532
|
+
const [hasEdited, setHasEdited] = React.useState<boolean>(false);
|
|
533
|
+
const [plainText, setPlainText] = React.useState(initialComposertext ?? "");
|
|
535
534
|
|
|
536
535
|
const bottomSheetRef = React.useRef<any>(null);
|
|
537
536
|
|
|
@@ -551,7 +550,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
551
550
|
}
|
|
552
551
|
}, []);
|
|
553
552
|
|
|
554
|
-
const isTyping = useRef<
|
|
553
|
+
const isTyping = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
555
554
|
|
|
556
555
|
/**
|
|
557
556
|
* Event callback
|
|
@@ -639,7 +638,9 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
639
638
|
edits.sort((a: any, b: any) => a.startIndex - b.startIndex);
|
|
640
639
|
|
|
641
640
|
plainTextInput.current = getPlainString(message?.text, edits);
|
|
642
|
-
|
|
641
|
+
setPlainText(plainTextInput.current);
|
|
642
|
+
setOriginalText(plainTextInput.current.trim());
|
|
643
|
+
setHasEdited(false);
|
|
643
644
|
const hashMap = new Map();
|
|
644
645
|
let offset = 0; // Tracks shift in position due to replacements
|
|
645
646
|
|
|
@@ -731,6 +732,8 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
731
732
|
|
|
732
733
|
const clearInputBox = () => {
|
|
733
734
|
inputValueRef.current = "";
|
|
735
|
+
setPlainText("");
|
|
736
|
+
setHasEdited(false);
|
|
734
737
|
setInputMessage("");
|
|
735
738
|
setWarningMessage("");
|
|
736
739
|
};
|
|
@@ -1044,7 +1047,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1044
1047
|
const SendButtonViewElem = useCallback(() => {
|
|
1045
1048
|
if (hideSendButton) return <></>;
|
|
1046
1049
|
if (SendButtonView) return <SendButtonView user={user} group={group} composerId={id!} />;
|
|
1047
|
-
const disabled =
|
|
1050
|
+
const disabled = plainText.trim().length === 0 || (messagePreview && !hasEdited);
|
|
1048
1051
|
return (
|
|
1049
1052
|
<TouchableOpacity
|
|
1050
1053
|
onPress={sendTextMessage}
|
|
@@ -1071,7 +1074,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1071
1074
|
/>
|
|
1072
1075
|
</TouchableOpacity>
|
|
1073
1076
|
);
|
|
1074
|
-
}, [mergedComposerStyle, inputMessage]);
|
|
1077
|
+
}, [mergedComposerStyle, inputMessage, plainText, messagePreview, hasEdited]);
|
|
1075
1078
|
|
|
1076
1079
|
//fetch logged in user
|
|
1077
1080
|
useEffect(() => {
|
|
@@ -1081,6 +1084,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1081
1084
|
if (!disableMentions) {
|
|
1082
1085
|
let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
|
|
1083
1086
|
mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser!);
|
|
1087
|
+
mentionsFormatter.setContext("composer");
|
|
1084
1088
|
mentionsFormatter.setMentionsStyle(
|
|
1085
1089
|
mergedComposerStyle.mentionsStyle as CometChatTheme["mentionsStyle"]
|
|
1086
1090
|
);
|
|
@@ -1243,7 +1247,14 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1243
1247
|
|
|
1244
1248
|
useEffect(() => {
|
|
1245
1249
|
CometChatUIEventHandler.addMessageListener(editMessageListenerID, {
|
|
1246
|
-
ccMessageEdited: (item: any) =>
|
|
1250
|
+
ccMessageEdited: (item: any) => {
|
|
1251
|
+
const incomingParentId = item?.message?.getParentMessageId?.() ?? null;
|
|
1252
|
+
const myParentId = parentMessageId ?? null;
|
|
1253
|
+
|
|
1254
|
+
if (incomingParentId === myParentId) {
|
|
1255
|
+
previewMessage(item);
|
|
1256
|
+
}
|
|
1257
|
+
},
|
|
1247
1258
|
});
|
|
1248
1259
|
CometChatUIEventHandler.addUIListener(UiEventListenerID, {
|
|
1249
1260
|
ccToggleBottomSheet: (item) => {
|
|
@@ -1352,7 +1363,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1352
1363
|
);
|
|
1353
1364
|
}
|
|
1354
1365
|
|
|
1355
|
-
let timeoutId:
|
|
1366
|
+
let timeoutId: ReturnType<typeof setTimeout>;
|
|
1356
1367
|
const openList = (selection: { start: number; end: number }) => {
|
|
1357
1368
|
clearTimeout(timeoutId);
|
|
1358
1369
|
timeoutId = setTimeout(() => {
|
|
@@ -1431,24 +1442,183 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1431
1442
|
return _plainString;
|
|
1432
1443
|
};
|
|
1433
1444
|
|
|
1445
|
+
const parseMentionKey = (key: string): { start: number; end: number } | undefined => {
|
|
1446
|
+
const [startStr, endStr] = key.split("_");
|
|
1447
|
+
const start = Number(startStr);
|
|
1448
|
+
const end = Number(endStr);
|
|
1449
|
+
|
|
1450
|
+
const isValid = Number.isFinite(start) && Number.isFinite(end);
|
|
1451
|
+
|
|
1452
|
+
if (typeof __DEV__ !== "undefined" && __DEV__ && !isValid) {
|
|
1453
|
+
throw new Error(`Invalid mention key: "${key}" (expected "start_end")`);
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
return isValid ? { start, end } : undefined;
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
const calcDeletionRange = (
|
|
1460
|
+
selection: { start: number; end: number },
|
|
1461
|
+
deletionLength: number
|
|
1462
|
+
) => {
|
|
1463
|
+
return selection.start === selection.end
|
|
1464
|
+
? {
|
|
1465
|
+
start: Math.max(0, selection.start - deletionLength),
|
|
1466
|
+
end: selection.start,
|
|
1467
|
+
}
|
|
1468
|
+
: { start: selection.start, end: selection.end };
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
const collectOverlappingMentions = (
|
|
1472
|
+
range: { start: number; end: number },
|
|
1473
|
+
mentionMap: Map<string, SuggestionItem>
|
|
1474
|
+
): MentionOverlap[] => {
|
|
1475
|
+
const overlaps: MentionOverlap[] = [];
|
|
1476
|
+
|
|
1477
|
+
mentionMap.forEach((value, key) => {
|
|
1478
|
+
const mentionRange = parseMentionKey(key);
|
|
1479
|
+
if (!mentionRange) return;
|
|
1480
|
+
|
|
1481
|
+
const { start, end } = mentionRange;
|
|
1482
|
+
|
|
1483
|
+
// compare against the *deletion* range, not the mention itself
|
|
1484
|
+
if (range.start < end && range.end > start) {
|
|
1485
|
+
overlaps.push({ key, value, start, end });
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1489
|
+
overlaps.sort((a, b) => a.start - b.start);
|
|
1490
|
+
return overlaps;
|
|
1491
|
+
};
|
|
1492
|
+
|
|
1493
|
+
const removeMentionsFromTextAndMap = (
|
|
1494
|
+
text: string,
|
|
1495
|
+
overlaps: MentionOverlap[],
|
|
1496
|
+
map: Map<string, SuggestionItem>
|
|
1497
|
+
) => {
|
|
1498
|
+
let adjustment = 0;
|
|
1499
|
+
let newText = text;
|
|
1500
|
+
|
|
1501
|
+
overlaps.forEach(({ key, value, start, end }) => {
|
|
1502
|
+
const adjStart = start + adjustment;
|
|
1503
|
+
const adjEnd = end + adjustment;
|
|
1504
|
+
|
|
1505
|
+
newText = newText.slice(0, adjStart) + newText.slice(adjEnd);
|
|
1506
|
+
map.delete(key);
|
|
1507
|
+
adjustment -= adjEnd - adjStart;
|
|
1508
|
+
|
|
1509
|
+
// keep formatter in sync
|
|
1510
|
+
if (!ifIdExists(value.id, map)) {
|
|
1511
|
+
const fmt = allFormatters.current.get(value.trackingCharacter!);
|
|
1512
|
+
if (fmt instanceof CometChatMentionsFormatter) {
|
|
1513
|
+
const users = fmt.getSuggestionItems().filter((u) => u.id !== value.id);
|
|
1514
|
+
fmt.setSuggestionItems(users);
|
|
1515
|
+
if (!getMentionLimitView(fmt)) setWarningMessage("");
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
return { newText, totalShift: adjustment };
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
const shiftRemainingMentionKeys = (
|
|
1524
|
+
map: Map<string, SuggestionItem>,
|
|
1525
|
+
shiftStart: number,
|
|
1526
|
+
delta: number
|
|
1527
|
+
) => {
|
|
1528
|
+
if (delta === 0) return;
|
|
1529
|
+
const shifted = new Map<string, SuggestionItem>();
|
|
1530
|
+
|
|
1531
|
+
map.forEach((val, key) => {
|
|
1532
|
+
const range = parseMentionKey(key);
|
|
1533
|
+
if (!range) {
|
|
1534
|
+
// key was malformed → skip or handle as you wish
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
const { start, end } = range;
|
|
1539
|
+
if (start > shiftStart) {
|
|
1540
|
+
shifted.set(`${start + delta}_${end + delta}`, val);
|
|
1541
|
+
} else {
|
|
1542
|
+
shifted.set(key, val);
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
|
|
1546
|
+
map.clear();
|
|
1547
|
+
shifted.forEach((v, k) => map.set(k, v));
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1550
|
+
const deleteMentionHelper = (oldText: string, newText: string) => {
|
|
1551
|
+
const deletionLen = oldText.length - newText.length;
|
|
1552
|
+
const range = calcDeletionRange(selectionPosition, deletionLen);
|
|
1553
|
+
|
|
1554
|
+
const deletionMentionMap = new Map(mentionMap.current);
|
|
1555
|
+
const overlaps = collectOverlappingMentions(range, deletionMentionMap);
|
|
1556
|
+
|
|
1557
|
+
if (overlaps.length === 0) return false;
|
|
1558
|
+
|
|
1559
|
+
const { newText: finalText, totalShift } = removeMentionsFromTextAndMap(
|
|
1560
|
+
oldText,
|
|
1561
|
+
overlaps,
|
|
1562
|
+
deletionMentionMap
|
|
1563
|
+
);
|
|
1564
|
+
|
|
1565
|
+
shiftRemainingMentionKeys(deletionMentionMap, range.start, totalShift);
|
|
1566
|
+
|
|
1567
|
+
plainTextInput.current = finalText;
|
|
1568
|
+
setPlainText(finalText);
|
|
1569
|
+
onTextChange?.(finalText);
|
|
1570
|
+
mentionMap.current = deletionMentionMap;
|
|
1571
|
+
|
|
1572
|
+
const firstStart = overlaps[0].start;
|
|
1573
|
+
InteractionManager.runAfterInteractions(() => {
|
|
1574
|
+
messageInputRef.current?.setNativeProps({
|
|
1575
|
+
selection: { start: firstStart, end: firstStart },
|
|
1576
|
+
});
|
|
1577
|
+
});
|
|
1578
|
+
|
|
1579
|
+
setFormattedInputMessage();
|
|
1580
|
+
return true;
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1434
1583
|
const textChangeHandler = (txt: string) => {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1584
|
+
setPlainText(txt);
|
|
1585
|
+
if (messagePreview) {
|
|
1586
|
+
setHasEdited(txt.trim() !== originalText.trim());
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
const oldText = plainTextInput.current ?? "";
|
|
1590
|
+
const newText = txt;
|
|
1439
1591
|
|
|
1440
|
-
plainTextInput.current = txt;
|
|
1441
|
-
onTextChange && onTextChange(txt);
|
|
1442
1592
|
startTyping();
|
|
1443
1593
|
|
|
1594
|
+
// Check if this is a deletion
|
|
1595
|
+
if (oldText.length > newText.length) {
|
|
1596
|
+
const handled = deleteMentionHelper(oldText, newText);
|
|
1597
|
+
if (handled) return;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// Existing handling for non-deletion cases
|
|
1601
|
+
const removing = (plainTextInput.current?.length ?? 0) > txt.length;
|
|
1602
|
+
const adding = plainTextInput.current?.length < txt.length;
|
|
1603
|
+
const textDiff = txt.length - (plainTextInput.current?.length ?? 0);
|
|
1604
|
+
const notAtLast = selectionPosition.start + textDiff < txt.length;
|
|
1605
|
+
|
|
1444
1606
|
let decr = 0;
|
|
1445
1607
|
|
|
1446
|
-
|
|
1608
|
+
plainTextInput.current = newText;
|
|
1609
|
+
setPlainText(newText);
|
|
1610
|
+
|
|
1611
|
+
const newMentionMap: Map<string, SuggestionItem> = new Map(mentionMap.current);
|
|
1447
1612
|
|
|
1448
1613
|
mentionMap.current.forEach((value, key) => {
|
|
1449
|
-
|
|
1614
|
+
const range = parseMentionKey(key);
|
|
1615
|
+
if (!range) {
|
|
1616
|
+
// key was malformed → skip or handle as you wish
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1450
1619
|
|
|
1451
|
-
|
|
1620
|
+
const { start, end } = range;
|
|
1621
|
+
let position = { start, end };
|
|
1452
1622
|
|
|
1453
1623
|
if (
|
|
1454
1624
|
notAtLast &&
|
|
@@ -1457,48 +1627,43 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1457
1627
|
) {
|
|
1458
1628
|
if (removing) {
|
|
1459
1629
|
decr = selectionPosition.end - selectionPosition.start - textDiff;
|
|
1460
|
-
position
|
|
1630
|
+
position.start -= decr;
|
|
1631
|
+
position.end -= decr;
|
|
1461
1632
|
} else if (adding) {
|
|
1462
1633
|
decr = selectionPosition.end - selectionPosition.start + textDiff;
|
|
1463
|
-
position
|
|
1634
|
+
position.start += decr;
|
|
1635
|
+
position.end += decr;
|
|
1464
1636
|
}
|
|
1465
1637
|
if (removing || adding) {
|
|
1466
|
-
|
|
1467
|
-
position.start >= 0
|
|
1638
|
+
const newKey = `${position.start}_${position.end}`;
|
|
1639
|
+
if (position.start >= 0) newMentionMap.set(newKey, value);
|
|
1468
1640
|
newMentionMap.delete(key);
|
|
1469
1641
|
}
|
|
1470
1642
|
}
|
|
1471
1643
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
let newKey = `${position.start}_${position.end}`;
|
|
1477
|
-
newMentionMap.delete(newKey);
|
|
1644
|
+
/* delete mention that was edited/over-typed */
|
|
1645
|
+
const expected = plainTextInput.current?.substring(position.start, position.end);
|
|
1646
|
+
if (expected !== value.promptText) {
|
|
1647
|
+
newMentionMap.delete(`${position.start}_${position.end}`);
|
|
1478
1648
|
|
|
1479
1649
|
if (!ifIdExists(value.id, newMentionMap)) {
|
|
1480
|
-
|
|
1650
|
+
const targetedFormatter = allFormatters.current.get(value.trackingCharacter!);
|
|
1481
1651
|
if (!targetedFormatter) return;
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
if (userPosition !== -1) {
|
|
1487
|
-
existingCCUsers.splice(userPosition, 1);
|
|
1488
|
-
(targetedFormatter as CometChatMentionsFormatter).setSuggestionItems(existingCCUsers);
|
|
1489
|
-
}
|
|
1652
|
+
const users = [...targetedFormatter.getSuggestionItems()];
|
|
1653
|
+
const idx = users.findIndex((u) => u.id === value.id);
|
|
1654
|
+
if (idx !== -1) users.splice(idx, 1);
|
|
1655
|
+
|
|
1490
1656
|
if (targetedFormatter instanceof CometChatMentionsFormatter) {
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1657
|
+
targetedFormatter.setSuggestionItems(users);
|
|
1658
|
+
const warn = getMentionLimitView(targetedFormatter);
|
|
1659
|
+
if (!warn) setWarningMessage("");
|
|
1495
1660
|
}
|
|
1496
1661
|
}
|
|
1497
1662
|
}
|
|
1498
1663
|
});
|
|
1499
1664
|
|
|
1500
1665
|
mentionMap.current = newMentionMap;
|
|
1501
|
-
|
|
1666
|
+
onTextChange?.(plainTextInput.current);
|
|
1502
1667
|
setFormattedInputMessage();
|
|
1503
1668
|
};
|
|
1504
1669
|
|
|
@@ -1537,7 +1702,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1537
1702
|
mentionPos += 1;
|
|
1538
1703
|
}
|
|
1539
1704
|
|
|
1540
|
-
// Code to delete mention from hashmap 👇
|
|
1541
1705
|
if (
|
|
1542
1706
|
position.end === selectionPosition.end ||
|
|
1543
1707
|
(selectionPosition.start > position.start && selectionPosition.end <= position.end)
|
|
@@ -1670,7 +1834,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1670
1834
|
let targetedFormatter =
|
|
1671
1835
|
allFormatters.current.get(activeCharacter.current) ?? targettedFormatterParam;
|
|
1672
1836
|
if (!(targetedFormatter instanceof CometChatMentionsFormatter)) {
|
|
1673
|
-
return;
|
|
1837
|
+
return false;
|
|
1674
1838
|
}
|
|
1675
1839
|
let shouldWarn;
|
|
1676
1840
|
let limit;
|
|
@@ -1784,7 +1948,13 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1784
1948
|
CustomViewHeader // Render it directly if it's a React node
|
|
1785
1949
|
))}
|
|
1786
1950
|
<MessagePreviewTray
|
|
1787
|
-
onClose={() =>
|
|
1951
|
+
onClose={() => {
|
|
1952
|
+
setMessagePreview(null);
|
|
1953
|
+
clearInputBox();
|
|
1954
|
+
mentionMap.current = new Map();
|
|
1955
|
+
plainTextInput.current = "";
|
|
1956
|
+
setOriginalText("");
|
|
1957
|
+
}}
|
|
1788
1958
|
text={messagePreview?.message?.text}
|
|
1789
1959
|
shouldShow={messagePreview != null}
|
|
1790
1960
|
/>
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import { ActionSheetStyle, CometChatTheme } from "../theme/type";
|
|
10
10
|
import { Icon } from "../shared/icons/Icon";
|
|
11
11
|
import { DeepPartial } from "../shared/helper/types";
|
|
12
|
+
import { JSX } from "react";
|
|
12
13
|
|
|
13
14
|
export const Style = StyleSheet.create({
|
|
14
15
|
container: {
|
|
@@ -80,7 +81,7 @@ export type MessageComposerStyle = {
|
|
|
80
81
|
active: ImageStyle;
|
|
81
82
|
inactive: ImageStyle;
|
|
82
83
|
};
|
|
83
|
-
mediaRecorderStyle: CometChatTheme[
|
|
84
|
+
mediaRecorderStyle: CometChatTheme["mediaRecorderStyle"];
|
|
84
85
|
attachmentOptionsStyles: ActionSheetStyle;
|
|
85
86
|
};
|
|
86
87
|
|
|
@@ -129,14 +130,10 @@ export const getComposerStyle = (
|
|
|
129
130
|
textStyle: {
|
|
130
131
|
...typography.body.regular,
|
|
131
132
|
color: color.textHighlight,
|
|
132
|
-
// backgroundColor: '#6852D633',
|
|
133
|
-
// paddingHorizontal: spacing.padding.p0_5
|
|
134
133
|
},
|
|
135
134
|
selfTextStyle: {
|
|
136
135
|
...typography.body.regular,
|
|
137
136
|
color: color.warning,
|
|
138
|
-
// backgroundColor: '#FFAB0033',
|
|
139
|
-
// paddingHorizontal: spacing.padding.p0_5
|
|
140
137
|
},
|
|
141
138
|
},
|
|
142
139
|
stickerIconStyle: {
|
|
@@ -147,6 +144,6 @@ export const getComposerStyle = (
|
|
|
147
144
|
tintColor: color.primary,
|
|
148
145
|
},
|
|
149
146
|
},
|
|
150
|
-
attachmentOptionsStyles: getAttachmentOptionsStyle(color, spacing, typography)
|
|
147
|
+
attachmentOptionsStyles: getAttachmentOptionsStyle(color, spacing, typography),
|
|
151
148
|
};
|
|
152
149
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
1
|
+
import React, { JSX, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { Text, TouchableOpacity, View } from "react-native";
|
|
3
3
|
import { ChatConfigurator, localize } from "../shared";
|
|
4
4
|
import { listners } from "./listners";
|
|
@@ -222,7 +222,7 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
|
|
|
222
222
|
);
|
|
223
223
|
|
|
224
224
|
const statusIndicatorType = useMemo(() => {
|
|
225
|
-
if (groupObj?.getType() === GroupTypeConstants.password) return "
|
|
225
|
+
if (groupObj?.getType() === GroupTypeConstants.password) return "password";
|
|
226
226
|
if (groupObj?.getType() === GroupTypeConstants.private) return "private";
|
|
227
227
|
if (userStatus === "online") return "online";
|
|
228
228
|
return "offline";
|
|
@@ -3,6 +3,7 @@ import { CallButtonStyle } from "../calls/CometChatCallButtons";
|
|
|
3
3
|
import { AvatarStyle } from "../shared/views/CometChatAvatar";
|
|
4
4
|
import { StatusIndicatorStyles } from "../shared/views/CometChatStatusIndicator";
|
|
5
5
|
import { CometChatTheme } from "../theme/type";
|
|
6
|
+
import { JSX } from "react";
|
|
6
7
|
|
|
7
8
|
export const styles = StyleSheet.create({
|
|
8
9
|
container: { flexDirection: "row", width: "100%" },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
2
|
-
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import React, { JSX, useCallback, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { FlatList, ScrollView, Text, View } from "react-native";
|
|
4
4
|
import {
|
|
5
5
|
ChatConfigurator,
|