@cometchat/chat-uikit-react-native 4.3.3 → 4.3.5
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/README.md +11 -21
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +6 -6
- package/ios/CommonUtil.h +4 -0
- package/ios/CommonUtil.m +27 -0
- package/package.json +10 -5
- package/src/AI/AIAssistBot/AIAssistBotDecorator.tsx +0 -3
- package/src/CometChatConversations/CometChatConversations.tsx +143 -72
- package/src/CometChatConversations/ConversationsConfiguration.ts +25 -4
- package/src/CometChatConversationsWithMessages/CometChatConversationsWithMessages.tsx +29 -29
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +11 -1
- package/src/CometChatGroups/CometChatGroups.tsx +10 -0
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +554 -52
- package/src/CometChatMessageComposer/MessageComposerConfiguration.tsx +12 -1
- package/src/CometChatMessageComposer/resources/Info.png +0 -0
- package/src/CometChatMessageComposer/resources/index.ts +3 -1
- package/src/CometChatMessageHeader/listners.ts +0 -2
- package/src/CometChatMessageList/CometChatMessageList.tsx +124 -15
- package/src/CometChatMessageList/MessageListConfiguration.ts +14 -1
- package/src/CometChatMessages/CometChatMessages.tsx +16 -16
- package/src/CometChatThreadedMessages/CometChatThreadedMessages.tsx +6 -1
- package/src/calls/CallingExtentionDecorator.tsx +11 -9
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +3 -3
- package/src/calls/CometChatCallLogHistory/CometChatCallLogHistory.tsx +10 -0
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +10 -0
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +2 -0
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +2 -0
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +3 -3
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +3 -3
- package/src/extensions/LinkPreview/LinkPreviewExtentionDecorator.tsx +4 -4
- package/src/extensions/MessageTranslation/MessageTranslationBubble.tsx +31 -9
- package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +83 -6
- package/src/extensions/Polls/Polls.tsx +106 -70
- package/src/extensions/Polls/PollsDecorator.tsx +3 -2
- package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +3 -3
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +14 -6
- package/src/extensions/TextModeration/TextModerationExtensionDecorator.tsx +3 -3
- package/src/index.ts +21 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +150 -25
- package/src/shared/CometChatUiKit/index.ts +1 -1
- package/src/shared/base/vars.ts +13 -0
- package/src/shared/constants/UIKitConstants.ts +6 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +7 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +11 -1
- package/src/shared/events/CometChatUIEvents.ts +3 -1
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +380 -0
- package/src/shared/formatters/CometChatMentionsFormatter/MentionTextStyle.ts +14 -0
- package/src/shared/formatters/CometChatMentionsFormatter/index.ts +7 -0
- package/src/shared/formatters/CometChatTextFormatter.ts +253 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +146 -0
- package/src/shared/formatters/index.ts +11 -0
- package/src/shared/framework/DataSource.ts +21 -16
- package/src/shared/framework/DataSourceDecorator.tsx +29 -13
- package/src/shared/framework/MessageDataSource.tsx +215 -49
- package/src/shared/helper/useKeyboard.tsx +20 -2
- package/src/shared/index.ts +23 -3
- package/src/shared/resources/CometChatLocalize/CometChatLocalize.ts +2 -0
- package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/de/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/en/translation.json +10 -1
- package/src/shared/resources/CometChatLocalize/resources/es/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +10 -1
- package/src/shared/resources/CometChatLocalize/resources/hu/translation.json +315 -0
- package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +12 -1
- package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +11 -1
- package/src/shared/resources/CometChatTheme/Palette.ts +16 -0
- package/src/shared/utils/InteractiveMessageUtils.ts +39 -1
- package/src/shared/utils/PermissionUtil.ts +142 -0
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +8 -6
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +5 -1
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +12 -11
- package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +7 -5
- package/src/shared/views/CometChatList/CometChatList.tsx +12 -0
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +11 -2
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -2
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +3 -3
- package/src/shared/views/CometChatSchedulerBubble/CometChatSchedulerBubble.tsx +12 -0
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +64 -0
- package/src/shared/views/CometChatSuggestionList/SuggestionItem.ts +48 -0
- package/src/shared/views/CometChatSuggestionList/SuggestionListConfiguration.ts +23 -0
- package/src/shared/views/CometChatSuggestionList/index.ts +11 -0
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +33 -46
- package/src/shared/views/CometChatTextBubble/TextBubbleStyle.ts +0 -14
- package/src/shared/views/CometChatTextBubble/index.ts +2 -3
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +5 -3
- package/src/shared/views/index.ts +9 -3
- package/src/shared/utils/PermissionUtilIOS.ts +0 -104
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useEffect,
|
|
1
|
+
import React, { useContext, useEffect, useLayoutEffect } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
Image,
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
KeyboardAvoidingView,
|
|
9
9
|
Modal,
|
|
10
10
|
KeyboardAvoidingViewProps,
|
|
11
|
+
Dimensions,
|
|
12
|
+
Text,
|
|
11
13
|
} from 'react-native';
|
|
12
14
|
import { Style } from './styles';
|
|
13
15
|
import {
|
|
@@ -19,6 +21,13 @@ import {
|
|
|
19
21
|
CometChatActionSheet,
|
|
20
22
|
ActionSheetStyles,
|
|
21
23
|
CometChatContext,
|
|
24
|
+
CometChatMentionsFormatter,
|
|
25
|
+
CometChatUrlsFormatter,
|
|
26
|
+
CometChatTextFormatter,
|
|
27
|
+
MentionTextStyle,
|
|
28
|
+
CometChatSuggestionList,
|
|
29
|
+
SuggestionItem,
|
|
30
|
+
CometChatUIKit,
|
|
22
31
|
} from '../shared';
|
|
23
32
|
|
|
24
33
|
import { CheckPropertyExists } from '../shared/helper/functions';
|
|
@@ -51,8 +60,10 @@ import { CometChatUIEventHandler } from '../shared/events/CometChatUIEventHandle
|
|
|
51
60
|
import { CometChatMessageComposerActionInterface } from '../shared/helper/types';
|
|
52
61
|
import { CometChatMediaRecorder, MediaRecorderStyle } from '../shared/views/CometChatMediaRecorder';
|
|
53
62
|
import { AIOptionsStyle } from '../AI/AIOptionsStyle';
|
|
54
|
-
import {
|
|
55
|
-
|
|
63
|
+
import { CommonUtils } from '../shared/utils/CommonUtils';
|
|
64
|
+
import { permissionUtil } from '../shared/utils/PermissionUtil';
|
|
65
|
+
import { commonVars } from '../shared/base/vars';
|
|
66
|
+
const { FileManager, CommonUtil } = NativeModules;
|
|
56
67
|
|
|
57
68
|
const uiEventListenerShow = 'uiEvent_show_' + new Date().getTime();
|
|
58
69
|
const uiEventListenerHide = 'uiEvent_hide_' + new Date().getTime();
|
|
@@ -510,11 +521,17 @@ export interface CometChatMessageComposerInterface {
|
|
|
510
521
|
* AI Options Style.
|
|
511
522
|
*/
|
|
512
523
|
aiOptionsStyle?: AIOptionsStyle;
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
524
|
+
/**
|
|
525
|
+
* To override keyboardAvoidingViewProps.
|
|
526
|
+
*/
|
|
516
527
|
keyboardAvoidingViewProps?: KeyboardAvoidingViewProps
|
|
517
528
|
/**
|
|
529
|
+
* Collection of text formatter class
|
|
530
|
+
* @type {Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>}
|
|
531
|
+
*/
|
|
532
|
+
textFormatters?: Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>;
|
|
533
|
+
disableMentions?: boolean;
|
|
534
|
+
/*
|
|
518
535
|
* To manually manage image quality taken from the camera (100 means no compression).
|
|
519
536
|
* @default 20
|
|
520
537
|
*/
|
|
@@ -563,6 +580,8 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
563
580
|
AIIconURL,
|
|
564
581
|
aiOptionsStyle,
|
|
565
582
|
keyboardAvoidingViewProps,
|
|
583
|
+
textFormatters,
|
|
584
|
+
disableMentions,
|
|
566
585
|
imageQuality = 20
|
|
567
586
|
} = props;
|
|
568
587
|
|
|
@@ -583,8 +602,16 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
583
602
|
const chatWithId = React.useRef<any>(null);
|
|
584
603
|
const messageInputRef = React.useRef<any>(null);
|
|
585
604
|
const chatRef = React.useRef<any>(chatWith);
|
|
605
|
+
const inputValueRef = React.useRef<any>(null);
|
|
606
|
+
const plainTextInput = React.useRef<string>("");
|
|
607
|
+
let mentionMap = React.useRef<Map<string, SuggestionItem>>(new Map());
|
|
608
|
+
let trackingCharacters = React.useRef<string[]>([])
|
|
609
|
+
let allFormatters = React.useRef<Map<string, CometChatTextFormatter | CometChatMentionsFormatter>>(new Map());
|
|
610
|
+
let activeCharacter = React.useRef("")
|
|
611
|
+
let searchStringRef = React.useRef("");
|
|
612
|
+
|
|
586
613
|
const [selectionPosition, setSelectionPosition] = React.useState<any>({});
|
|
587
|
-
const [inputMessage, setInputMessage] = React.useState(text || '');
|
|
614
|
+
const [inputMessage, setInputMessage] = React.useState<string | JSX.Element>(text || '');
|
|
588
615
|
const [showReaction, setShowReaction] = React.useState(false);
|
|
589
616
|
const [showEmojiboard, setShowEmojiboard] = React.useState(false);
|
|
590
617
|
const [showActionSheet, setShowActionSheet] = React.useState(false);
|
|
@@ -598,9 +625,29 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
598
625
|
const [CustomViewHeader, setCustomViewHeader] = React.useState(null);
|
|
599
626
|
const [CustomViewFooter, setCustomViewFooter] = React.useState(null);
|
|
600
627
|
const [isVisible, setIsVisible] = React.useState(false);
|
|
628
|
+
const [kbOffset, setKbOffset] = React.useState(59);
|
|
629
|
+
const [showMentionList, setShowMentionList] = React.useState(false);
|
|
630
|
+
const [mentionsSearchData, setMentionsSearchData] = React.useState<Array<SuggestionItem>>([]);
|
|
631
|
+
const [suggestionListLoader, setSuggestionListLoader] = React.useState(false);
|
|
601
632
|
|
|
602
633
|
const bottomSheetRef = React.useRef<any>(null);
|
|
603
634
|
|
|
635
|
+
useLayoutEffect(() => {
|
|
636
|
+
if (Platform.OS === "ios") {
|
|
637
|
+
if (Number.isInteger(commonVars.safeAreaInsets.top)) {
|
|
638
|
+
setKbOffset(commonVars.safeAreaInsets.top)
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
CommonUtil.getSafeAreaInsets().then(res => {
|
|
642
|
+
if (Number.isInteger(res.top)) {
|
|
643
|
+
commonVars.safeAreaInsets.top = res.top;
|
|
644
|
+
commonVars.safeAreaInsets.bottom = res.bottom;
|
|
645
|
+
setKbOffset(res.top)
|
|
646
|
+
}
|
|
647
|
+
})
|
|
648
|
+
}
|
|
649
|
+
}, []);
|
|
650
|
+
|
|
604
651
|
const AIStyles = new AIOptionsStyle({
|
|
605
652
|
//NEED TO ADD DEFAULT STYLE HERE
|
|
606
653
|
backgroundColor: theme.palette.getBackgroundColor(),
|
|
@@ -624,12 +671,67 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
624
671
|
|
|
625
672
|
const previewMessage = ({ message, status }: any) => {
|
|
626
673
|
if (status === messageStatus.inprogress) {
|
|
674
|
+
|
|
675
|
+
let textComponents = message?.text;
|
|
676
|
+
|
|
677
|
+
let rawText = message?.text;
|
|
678
|
+
|
|
679
|
+
let users: { key: string, value: SuggestionItem } = {};
|
|
680
|
+
let regexes: Array<RegExp> = [];
|
|
681
|
+
|
|
682
|
+
allFormatters.current.forEach((formatter: CometChatTextFormatter, key) => {
|
|
683
|
+
formatter.handleComposerPreview(message);
|
|
684
|
+
if (!regexes.includes(formatter.getRegexPattern())) {
|
|
685
|
+
regexes.push(formatter.getRegexPattern());
|
|
686
|
+
}
|
|
687
|
+
let suggestionUsers = formatter.getSuggestionItems();
|
|
688
|
+
suggestionUsers.forEach(item => users[item.underlyingText] = item);
|
|
689
|
+
let resp = formatter.getFormattedText(textComponents);
|
|
690
|
+
textComponents = resp;
|
|
691
|
+
})
|
|
692
|
+
|
|
693
|
+
let edits = [];
|
|
694
|
+
|
|
695
|
+
regexes.forEach(regex => {
|
|
696
|
+
let match;
|
|
697
|
+
while ((match = regex.exec(rawText)) !== null) {
|
|
698
|
+
const user = users[match[0]];
|
|
699
|
+
if (user) {
|
|
700
|
+
edits.push({
|
|
701
|
+
startIndex: match.index,
|
|
702
|
+
endIndex: regex.lastIndex,
|
|
703
|
+
replacement: user.promptText,
|
|
704
|
+
user
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
// Sort edits by startIndex to apply them in order
|
|
711
|
+
edits.sort((a, b) => a.startIndex - b.startIndex);
|
|
712
|
+
|
|
713
|
+
plainTextInput.current = getPlainString(message?.text, edits)
|
|
714
|
+
|
|
715
|
+
const hashMap = new Map();
|
|
716
|
+
let offset = 0; // Tracks shift in position due to replacements
|
|
717
|
+
|
|
718
|
+
edits.forEach(edit => {
|
|
719
|
+
const adjustedStartIndex = edit.startIndex + offset;
|
|
720
|
+
rawText = rawText.substring(0, adjustedStartIndex) + edit.replacement + rawText.substring(edit.endIndex);
|
|
721
|
+
offset += edit.replacement.length - (edit.endIndex - edit.startIndex);
|
|
722
|
+
const rangeKey = `${adjustedStartIndex}_${adjustedStartIndex + edit.replacement.length}`;
|
|
723
|
+
hashMap.set(rangeKey, edit.user);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
mentionMap.current = hashMap;
|
|
727
|
+
|
|
627
728
|
setMessagePreview({
|
|
628
|
-
message: message,
|
|
729
|
+
message: { ...message, text: textComponents },
|
|
629
730
|
mode: ConversationOptionConstants.edit,
|
|
630
731
|
});
|
|
631
732
|
|
|
632
|
-
|
|
733
|
+
inputValueRef.current = textComponents ?? '';
|
|
734
|
+
setInputMessage(textComponents ?? '');
|
|
633
735
|
messageInputRef.current.focus();
|
|
634
736
|
}
|
|
635
737
|
};
|
|
@@ -651,40 +753,40 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
651
753
|
chatWith.current
|
|
652
754
|
);
|
|
653
755
|
}
|
|
654
|
-
|
|
756
|
+
|
|
655
757
|
const fileInputHandler = async (fileType: string) => {
|
|
656
758
|
if (fileType === MessageTypeConstants.takePhoto) {
|
|
657
|
-
if (!(await
|
|
759
|
+
if (!(await permissionUtil.startResourceBasedTask(["camera"]))) {
|
|
658
760
|
return;
|
|
659
761
|
}
|
|
660
762
|
let quality = imageQuality
|
|
661
|
-
if(isNaN(imageQuality) || imageQuality < 1 || imageQuality > 100) {
|
|
763
|
+
if (isNaN(imageQuality) || imageQuality < 1 || imageQuality > 100) {
|
|
662
764
|
quality = 20
|
|
663
765
|
}
|
|
664
|
-
if(Platform.OS === "android") {
|
|
766
|
+
if (Platform.OS === "android") {
|
|
665
767
|
FileManager.openCamera(
|
|
666
|
-
fileType,
|
|
768
|
+
fileType,
|
|
667
769
|
Math.round(quality),
|
|
668
770
|
cameraCallback
|
|
669
771
|
);
|
|
670
772
|
} else {
|
|
671
773
|
FileManager.openCamera(
|
|
672
|
-
fileType,
|
|
774
|
+
fileType,
|
|
673
775
|
cameraCallback
|
|
674
776
|
);
|
|
675
777
|
}
|
|
676
778
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
779
|
+
else if (Platform.OS === 'ios' && fileType === MessageTypeConstants.video) {
|
|
780
|
+
NativeModules.VideoPickerModule.pickVideo(((file) => {
|
|
781
|
+
if (file.uri)
|
|
782
|
+
sendMediaMessage(
|
|
783
|
+
chatWithId.current,
|
|
784
|
+
file,
|
|
785
|
+
MessageTypeConstants.video,
|
|
786
|
+
chatWith.current
|
|
787
|
+
);
|
|
788
|
+
}))
|
|
789
|
+
}
|
|
688
790
|
else
|
|
689
791
|
FileManager.openFileChooser(fileType, async (fileInfo: any) => {
|
|
690
792
|
if (CheckPropertyExists(fileInfo, 'error')) {
|
|
@@ -718,12 +820,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
718
820
|
}
|
|
719
821
|
};
|
|
720
822
|
|
|
721
|
-
const textChangeHandler = (txt: string) => {
|
|
722
|
-
onChangeText && onChangeText(txt);
|
|
723
|
-
startTyping();
|
|
724
|
-
setInputMessage(txt);
|
|
725
|
-
};
|
|
726
|
-
|
|
727
823
|
const liveReactionHandler = () => {
|
|
728
824
|
if (hideLiveReaction) return;
|
|
729
825
|
if (!showReaction) {
|
|
@@ -755,6 +851,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
755
851
|
};
|
|
756
852
|
|
|
757
853
|
const clearInputBox = () => {
|
|
854
|
+
inputValueRef.current = '';
|
|
758
855
|
setInputMessage('');
|
|
759
856
|
};
|
|
760
857
|
|
|
@@ -766,20 +863,29 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
766
863
|
return;
|
|
767
864
|
}
|
|
768
865
|
|
|
866
|
+
let finalTextInput = getRegexString(plainTextInput.current);
|
|
867
|
+
|
|
769
868
|
let textMessage = new CometChat.TextMessage(
|
|
770
869
|
chatWithId.current,
|
|
771
|
-
|
|
870
|
+
finalTextInput,
|
|
772
871
|
chatWith.current
|
|
773
872
|
);
|
|
774
873
|
|
|
775
874
|
textMessage.setSender(loggedInUser.current);
|
|
776
875
|
textMessage.setReceiver(chatWith.current);
|
|
777
|
-
textMessage.setText(
|
|
876
|
+
textMessage.setText(finalTextInput);
|
|
778
877
|
textMessage.setMuid(String(getUnixTimestamp()));
|
|
779
878
|
parentMessageId && textMessage.setParentMessageId(parentMessageId as number);
|
|
780
879
|
|
|
880
|
+
allFormatters.current.forEach(item => {
|
|
881
|
+
textMessage = item.handlePreMessageSend(textMessage);
|
|
882
|
+
})
|
|
883
|
+
|
|
884
|
+
setMentionsSearchData([]);
|
|
885
|
+
plainTextInput.current = ""
|
|
886
|
+
|
|
781
887
|
onSendButtonPress && onSendButtonPress(textMessage);
|
|
782
|
-
if (
|
|
888
|
+
if (finalTextInput.trim().length == 0) {
|
|
783
889
|
return;
|
|
784
890
|
}
|
|
785
891
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
|
|
@@ -801,7 +907,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
801
907
|
})
|
|
802
908
|
.catch((error: any) => {
|
|
803
909
|
onError && onError(error);
|
|
804
|
-
textMessage.data.metaData = {error: true}
|
|
910
|
+
textMessage.data.metaData = { error: true }
|
|
805
911
|
CometChatUIEventHandler.emitMessageEvent(
|
|
806
912
|
MessageEvents.ccMessageSent,
|
|
807
913
|
{
|
|
@@ -817,7 +923,9 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
817
923
|
const editMessage = (message: any) => {
|
|
818
924
|
endTyping(null, null);
|
|
819
925
|
|
|
820
|
-
let
|
|
926
|
+
let finalTextInput = getRegexString(plainTextInput.current);
|
|
927
|
+
|
|
928
|
+
let messageText = finalTextInput.trim();
|
|
821
929
|
let textMessage = new CometChat.TextMessage(
|
|
822
930
|
chatWithId.current,
|
|
823
931
|
messageText,
|
|
@@ -826,6 +934,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
826
934
|
textMessage.setId(message.id);
|
|
827
935
|
parentMessageId && textMessage.setParentMessageId(parentMessageId as number);
|
|
828
936
|
|
|
937
|
+
inputValueRef.current = '';
|
|
829
938
|
setInputMessage('');
|
|
830
939
|
messageInputRef.current.textContent = '';
|
|
831
940
|
|
|
@@ -835,6 +944,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
835
944
|
|
|
836
945
|
CometChat.editMessage(textMessage)
|
|
837
946
|
.then((editedMessage: any) => {
|
|
947
|
+
inputValueRef.current = '';
|
|
838
948
|
setInputMessage('');
|
|
839
949
|
CometChatUIEventHandler.emitMessageEvent(
|
|
840
950
|
MessageEvents.ccMessageEdited,
|
|
@@ -936,7 +1046,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
936
1046
|
.catch((error: any) => {
|
|
937
1047
|
setShowRecordAudio(false);
|
|
938
1048
|
onError && onError(error);
|
|
939
|
-
localMessage.data.metaData = {error: true}
|
|
1049
|
+
localMessage.data.metaData = { error: true }
|
|
940
1050
|
CometChatUIEventHandler.emitMessageEvent(
|
|
941
1051
|
MessageEvents.ccMessageSent,
|
|
942
1052
|
{
|
|
@@ -1049,12 +1159,12 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1049
1159
|
imageStyle={[
|
|
1050
1160
|
Style.imageStyle,
|
|
1051
1161
|
{
|
|
1052
|
-
tintColor:
|
|
1162
|
+
tintColor: ((inputMessage as String).length === 0) ? theme.palette.getAccent400() :
|
|
1053
1163
|
messageComposerStyle.sendIconTint ||
|
|
1054
1164
|
theme.palette.getPrimary(),
|
|
1055
1165
|
},
|
|
1056
1166
|
]}
|
|
1057
|
-
disable={
|
|
1167
|
+
disable={((inputMessage as String).length === 0)}
|
|
1058
1168
|
onClick={sendTextMessage}
|
|
1059
1169
|
/>
|
|
1060
1170
|
);
|
|
@@ -1082,7 +1192,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1082
1192
|
);
|
|
1083
1193
|
};
|
|
1084
1194
|
const PrimaryButtonView = () => {
|
|
1085
|
-
return inputMessage.length || hideLiveReaction ? (
|
|
1195
|
+
return ((inputMessage as String).length !== 0) || hideLiveReaction ? (
|
|
1086
1196
|
<SendButtonViewElem />
|
|
1087
1197
|
) : (
|
|
1088
1198
|
<View>
|
|
@@ -1119,6 +1229,37 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1119
1229
|
//fetch logged in user
|
|
1120
1230
|
useEffect(() => {
|
|
1121
1231
|
CometChat.getLoggedinUser().then((user) => (loggedInUser.current = user));
|
|
1232
|
+
let _formatter = [...(textFormatters || [])] || [];
|
|
1233
|
+
|
|
1234
|
+
if (!disableMentions) {
|
|
1235
|
+
let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
|
|
1236
|
+
mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser);
|
|
1237
|
+
mentionsFormatter.setMentionsStyle(new MentionTextStyle({
|
|
1238
|
+
loggedInUserTextStyle: {
|
|
1239
|
+
color: theme.palette.getPrimary(),
|
|
1240
|
+
...theme.typography.title2,
|
|
1241
|
+
fontSize: 17
|
|
1242
|
+
},
|
|
1243
|
+
textStyle: {
|
|
1244
|
+
color: theme.palette.getPrimary(),
|
|
1245
|
+
...theme.typography.subtitle1,
|
|
1246
|
+
fontSize: 17
|
|
1247
|
+
}
|
|
1248
|
+
}));
|
|
1249
|
+
mentionsFormatter.setUser(user);
|
|
1250
|
+
mentionsFormatter.setGroup(group);
|
|
1251
|
+
|
|
1252
|
+
_formatter.push(mentionsFormatter)
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
_formatter.forEach((formatter) => {
|
|
1256
|
+
formatter.setComposerId(id);
|
|
1257
|
+
let trackingCharacter = formatter.getTrackingCharacter();
|
|
1258
|
+
trackingCharacters.current.push(trackingCharacter);
|
|
1259
|
+
|
|
1260
|
+
let newFormatter = CommonUtils.clone(formatter);
|
|
1261
|
+
allFormatters.current.set(trackingCharacter, newFormatter);
|
|
1262
|
+
})
|
|
1122
1263
|
}, []);
|
|
1123
1264
|
|
|
1124
1265
|
useEffect(() => {
|
|
@@ -1247,9 +1388,16 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1247
1388
|
setIsVisible(false);
|
|
1248
1389
|
bottomSheetRef.current?.togglePanel();
|
|
1249
1390
|
|
|
1391
|
+
inputValueRef.current = text?.text;
|
|
1250
1392
|
setInputMessage(text?.text)
|
|
1251
1393
|
|
|
1252
|
-
}
|
|
1394
|
+
},
|
|
1395
|
+
ccSuggestionData(item: { id: string | number, data: Array<SuggestionItem> }) {
|
|
1396
|
+
if (activeCharacter.current && id === item?.id) {
|
|
1397
|
+
setMentionsSearchData(item?.data);
|
|
1398
|
+
setSuggestionListLoader(false);
|
|
1399
|
+
}
|
|
1400
|
+
},
|
|
1253
1401
|
})
|
|
1254
1402
|
return () => {
|
|
1255
1403
|
CometChatUIEventHandler.removeMessageListener(editMessageListenerID);
|
|
@@ -1300,6 +1448,330 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1300
1448
|
console.log("Send Audio");
|
|
1301
1449
|
}
|
|
1302
1450
|
|
|
1451
|
+
function isCursorWithinMentionRange(mentionRanges, cursorPosition) {
|
|
1452
|
+
for (let [range, mention] of mentionRanges) {
|
|
1453
|
+
const [start, end] = range.split('_').map(Number);
|
|
1454
|
+
if (cursorPosition >= start && cursorPosition <= end) {
|
|
1455
|
+
return true; // Cursor is within the range of a mention
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
return false; // No mention found at the cursor position
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
function shouldOpenList(selection: {
|
|
1462
|
+
start: number;
|
|
1463
|
+
end: number;
|
|
1464
|
+
}, searchString: string, tracker: string) {
|
|
1465
|
+
return (selection.start === selection.end
|
|
1466
|
+
&& !isCursorWithinMentionRange(mentionMap.current, selection.start - searchString.length)
|
|
1467
|
+
&& trackingCharacters.current.includes(tracker)
|
|
1468
|
+
&& (searchString === "" ? ((plainTextInput.current[selection.start - 2]?.length === 1 && plainTextInput.current[selection.start - 2]?.trim()?.length === 0) || plainTextInput.current[selection.start - 2] === undefined) : true)
|
|
1469
|
+
&& ((plainTextInput.current[selection.start - 1]?.length === 1 && plainTextInput.current[selection.start - 1]?.trim()?.length === 0) ? searchString.length > 0 : true)
|
|
1470
|
+
)
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
let timeoutId;
|
|
1474
|
+
const openList = (selection: {
|
|
1475
|
+
start: number;
|
|
1476
|
+
end: number;
|
|
1477
|
+
}) => {
|
|
1478
|
+
clearTimeout(timeoutId);
|
|
1479
|
+
timeoutId = setTimeout(() => {
|
|
1480
|
+
let searchString = extractTextFromCursor(plainTextInput.current, selection.start);
|
|
1481
|
+
let tracker = searchString ? plainTextInput.current[selection.start - (searchString.length + 1)] : plainTextInput.current[selection.start - 1];
|
|
1482
|
+
|
|
1483
|
+
if (shouldOpenList(selection, searchString, tracker)) {
|
|
1484
|
+
activeCharacter.current = tracker;
|
|
1485
|
+
searchStringRef.current = searchString;
|
|
1486
|
+
setShowMentionList(true);
|
|
1487
|
+
|
|
1488
|
+
let formatter = allFormatters.current.get(tracker);
|
|
1489
|
+
formatter.search(searchString);
|
|
1490
|
+
|
|
1491
|
+
} else {
|
|
1492
|
+
activeCharacter.current = "";
|
|
1493
|
+
searchStringRef.current = "";
|
|
1494
|
+
setShowMentionList(false);
|
|
1495
|
+
setMentionsSearchData([]);
|
|
1496
|
+
}
|
|
1497
|
+
}, 100);
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
const getRegexString = (str: string) => {
|
|
1501
|
+
// Get an array of the entries in the map using the spread operator
|
|
1502
|
+
const entries = [...mentionMap.current.entries()].reverse();
|
|
1503
|
+
|
|
1504
|
+
let uidInput = str;
|
|
1505
|
+
|
|
1506
|
+
// Iterate over the array in reverse order
|
|
1507
|
+
entries.forEach(([key, value]) => {
|
|
1508
|
+
|
|
1509
|
+
let [start, end] = key.split("_").map(Number);
|
|
1510
|
+
|
|
1511
|
+
let pre = uidInput.substring(0, start);
|
|
1512
|
+
let post = uidInput.substring(end);
|
|
1513
|
+
|
|
1514
|
+
uidInput = pre + value.underlyingText + post;
|
|
1515
|
+
|
|
1516
|
+
});
|
|
1517
|
+
|
|
1518
|
+
return uidInput;
|
|
1519
|
+
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
const getPlainString = (str: string, edits: Array<{
|
|
1523
|
+
"endIndex": number,
|
|
1524
|
+
"replacement": string,
|
|
1525
|
+
"startIndex": number,
|
|
1526
|
+
"user": SuggestionItem
|
|
1527
|
+
}>) => {
|
|
1528
|
+
// Get an array of the entries in the map using the spread operator
|
|
1529
|
+
const entries = [...edits].reverse();
|
|
1530
|
+
|
|
1531
|
+
let _plainString = str;
|
|
1532
|
+
|
|
1533
|
+
// Iterate over the array in reverse order
|
|
1534
|
+
entries.forEach(({ endIndex, replacement, startIndex, user }) => {
|
|
1535
|
+
|
|
1536
|
+
let pre = _plainString.substring(0, startIndex);
|
|
1537
|
+
let post = _plainString.substring(endIndex);
|
|
1538
|
+
|
|
1539
|
+
_plainString = pre + replacement + post;
|
|
1540
|
+
|
|
1541
|
+
});
|
|
1542
|
+
|
|
1543
|
+
return _plainString;
|
|
1544
|
+
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
const textChangeHandler = (txt: string) => {
|
|
1548
|
+
let removing = plainTextInput.current.length > txt.length;
|
|
1549
|
+
let adding = plainTextInput.current.length < txt.length;
|
|
1550
|
+
let textDiff = txt.length - plainTextInput.current.length;
|
|
1551
|
+
let notAtLast = (selectionPosition.start + textDiff) < txt.length;
|
|
1552
|
+
|
|
1553
|
+
plainTextInput.current = txt;
|
|
1554
|
+
onChangeText && onChangeText(txt);
|
|
1555
|
+
startTyping();
|
|
1556
|
+
|
|
1557
|
+
let decr = 0;
|
|
1558
|
+
|
|
1559
|
+
let newMentionMap = new Map(mentionMap.current);
|
|
1560
|
+
|
|
1561
|
+
mentionMap.current.forEach((value, key) => {
|
|
1562
|
+
let position = { start: parseInt(key.split("_")[0]), end: parseInt(key.split("_")[1]) };
|
|
1563
|
+
|
|
1564
|
+
//Runs when cursor before the mention and before the last position
|
|
1565
|
+
|
|
1566
|
+
if (notAtLast && (((selectionPosition.start - 1) <= position.start)
|
|
1567
|
+
|| ((selectionPosition.start - textDiff) <= position.start)
|
|
1568
|
+
)) {
|
|
1569
|
+
if (removing) {
|
|
1570
|
+
decr = ((selectionPosition.end) - selectionPosition.start) - (textDiff);
|
|
1571
|
+
position = { start: position.start - decr, end: position.end - decr };
|
|
1572
|
+
} else if (adding) {
|
|
1573
|
+
decr = ((selectionPosition.end) - selectionPosition.start) + (textDiff);
|
|
1574
|
+
position = { start: position.start + decr, end: position.end + decr };
|
|
1575
|
+
}
|
|
1576
|
+
if (removing || adding) {
|
|
1577
|
+
let newKey = `${position.start}_${position.end}`;
|
|
1578
|
+
position.start >= 0 && newMentionMap.set(newKey, value);
|
|
1579
|
+
newMentionMap.delete(key);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// Code to delete mention from hashmap 👇
|
|
1584
|
+
let expctedMentionPos = plainTextInput.current.substring(position.start, position.end);
|
|
1585
|
+
|
|
1586
|
+
if (expctedMentionPos !== `${value.promptText}`) {
|
|
1587
|
+
let newKey = `${position.start}_${position.end}`;
|
|
1588
|
+
newMentionMap.delete(newKey);
|
|
1589
|
+
|
|
1590
|
+
if (!ifIdExists(value.id, newMentionMap)) {
|
|
1591
|
+
let targetedFormatter = allFormatters.current.get(value.trackingCharacter);
|
|
1592
|
+
let existingCCUsers = [...targetedFormatter.getSuggestionItems()];
|
|
1593
|
+
let userPosition = existingCCUsers.findIndex((item: SuggestionItem) => item.id === value.id);
|
|
1594
|
+
if (userPosition !== -1) {
|
|
1595
|
+
existingCCUsers.splice(userPosition, 1);
|
|
1596
|
+
(targetedFormatter as CometChatMentionsFormatter).setSuggestionItems(existingCCUsers)
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
mentionMap.current = newMentionMap;
|
|
1605
|
+
|
|
1606
|
+
setFormattedInputMessage();
|
|
1607
|
+
|
|
1608
|
+
};
|
|
1609
|
+
|
|
1610
|
+
const onMentionPress = (item: SuggestionItem) => {
|
|
1611
|
+
setShowMentionList(false);
|
|
1612
|
+
setMentionsSearchData([]);
|
|
1613
|
+
|
|
1614
|
+
let notAtLast = selectionPosition.start < plainTextInput.current.length;
|
|
1615
|
+
|
|
1616
|
+
let textDiff = (plainTextInput.current.length + item.promptText.length - searchStringRef.current.length) - plainTextInput.current.length;
|
|
1617
|
+
|
|
1618
|
+
let incr = 0;
|
|
1619
|
+
let mentionPos = 0;
|
|
1620
|
+
|
|
1621
|
+
let newMentionMap = new Map(mentionMap.current);
|
|
1622
|
+
|
|
1623
|
+
let targetedFormatter = allFormatters.current.get(activeCharacter.current);
|
|
1624
|
+
|
|
1625
|
+
let existingCCUsers = [...targetedFormatter.getSuggestionItems()];
|
|
1626
|
+
let userAlreadyExists = existingCCUsers.find((existingUser: SuggestionItem) => existingUser.id === item.id);
|
|
1627
|
+
if (!userAlreadyExists) {
|
|
1628
|
+
let cometchatUIUserArray: Array<SuggestionItem> = [...existingCCUsers];
|
|
1629
|
+
cometchatUIUserArray.push(item);
|
|
1630
|
+
(targetedFormatter as CometChatMentionsFormatter).setSuggestionItems(cometchatUIUserArray)
|
|
1631
|
+
}
|
|
1632
|
+
mentionMap.current.forEach((value, key) => {
|
|
1633
|
+
let position = { start: parseInt(key.split("_")[0]), end: parseInt(key.split("_")[1]) };
|
|
1634
|
+
|
|
1635
|
+
if (!(selectionPosition.start <= position.start)) {
|
|
1636
|
+
mentionPos += 1;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
// Code to delete mention from hashmap 👇
|
|
1640
|
+
if (position.end === selectionPosition.end || (selectionPosition.start > position.start && selectionPosition.end <= position.end)) {
|
|
1641
|
+
let newKey = `${position.start}_${position.end}`;
|
|
1642
|
+
newMentionMap.delete(newKey);
|
|
1643
|
+
mentionPos -= 1
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
if (notAtLast && ((selectionPosition.start - 1) <= position.start)) {
|
|
1647
|
+
incr = (selectionPosition.end - selectionPosition.start) + (textDiff);
|
|
1648
|
+
let newKey = `${(position.start + incr)}_${(position.end + incr)}`;
|
|
1649
|
+
newMentionMap.set(newKey, value);
|
|
1650
|
+
newMentionMap.delete(key);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
});
|
|
1654
|
+
mentionMap.current = newMentionMap;
|
|
1655
|
+
|
|
1656
|
+
// When updating the input text, just get the latest plain text input and replace the selected text with the new mention
|
|
1657
|
+
const updatedPlainTextInput = `${plainTextInput.current.substring(0, (selectionPosition.start - (1 + searchStringRef.current.length)))}${item.promptText + " "}${plainTextInput.current.substring(
|
|
1658
|
+
(selectionPosition.end),
|
|
1659
|
+
plainTextInput.current.length
|
|
1660
|
+
)}`;
|
|
1661
|
+
plainTextInput.current = updatedPlainTextInput;
|
|
1662
|
+
|
|
1663
|
+
let key = (selectionPosition.start - (1 + searchStringRef.current.length)) + "_" + ((selectionPosition.start - (searchStringRef.current.length + 1)) + item.promptText.length);
|
|
1664
|
+
|
|
1665
|
+
let updatedMap = insertMentionAt(mentionMap.current, mentionPos, key, { ...item, trackingCharacter: activeCharacter.current });
|
|
1666
|
+
mentionMap.current = updatedMap;
|
|
1667
|
+
|
|
1668
|
+
setFormattedInputMessage()
|
|
1669
|
+
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
const setFormattedInputMessage = () => {
|
|
1673
|
+
let textComponents = getRegexString(plainTextInput.current);
|
|
1674
|
+
|
|
1675
|
+
allFormatters.current.forEach((formatter: CometChatMentionsFormatter, key) => {
|
|
1676
|
+
let resp = formatter.getFormattedText(textComponents);
|
|
1677
|
+
textComponents = resp;
|
|
1678
|
+
})
|
|
1679
|
+
|
|
1680
|
+
inputValueRef.current = textComponents;
|
|
1681
|
+
setInputMessage(textComponents);
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
function escapeRegExp(string: string) {
|
|
1685
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
function extractTextFromCursor(inputText: string, cursorPosition: number) {
|
|
1689
|
+
const leftText = inputText.substring(0, cursorPosition);
|
|
1690
|
+
|
|
1691
|
+
// Escape the mentionPrefixes to safely use them in a regex pattern
|
|
1692
|
+
const escapedPrefixes = trackingCharacters.current.map(escapeRegExp).join('|');
|
|
1693
|
+
|
|
1694
|
+
// Build a dynamic regex pattern that matches any of the mention prefixes.
|
|
1695
|
+
// This pattern will match a prefix followed by any combination of word characters
|
|
1696
|
+
// and spaces, including a trailing space.
|
|
1697
|
+
const mentionRegex = new RegExp(`(?:^|\\s)(${escapedPrefixes})([^${escapedPrefixes}\\s][^${escapedPrefixes}]*)$`);
|
|
1698
|
+
const match = leftText.match(mentionRegex);
|
|
1699
|
+
|
|
1700
|
+
// If a match is found, return the first capturing group, which is the username
|
|
1701
|
+
return match && substringUpToNthSpace(match[2], 4) || "";
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
function substringUpToNthSpace(str: string, n: number) {
|
|
1705
|
+
// Split the string by spaces, slice to the (n-1) elements, and then rejoin with spaces
|
|
1706
|
+
return str.split(' ', n).join(' ');
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
const insertMentionAt = (mentionMap: Map<string, SuggestionItem>, insertAt: number, key: string, value: SuggestionItem): Map<string, SuggestionItem> => {
|
|
1710
|
+
// Convert the hashmap to an array of [key, value] pairs
|
|
1711
|
+
let mentionsArray = Array.from(mentionMap);
|
|
1712
|
+
|
|
1713
|
+
// Insert the new mention into the array at the calculated index
|
|
1714
|
+
mentionsArray.splice(insertAt, 0, [key, value]);
|
|
1715
|
+
|
|
1716
|
+
return new Map(mentionsArray);
|
|
1717
|
+
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
/**
|
|
1721
|
+
* Function to check if the id exists in the mentionMap
|
|
1722
|
+
*/
|
|
1723
|
+
const ifIdExists = (id: string, hashmap: Map<string, SuggestionItem>) => {
|
|
1724
|
+
let exists = false;
|
|
1725
|
+
hashmap.forEach((value, key) => {
|
|
1726
|
+
if (value.id === id) {
|
|
1727
|
+
exists = true;
|
|
1728
|
+
}
|
|
1729
|
+
});
|
|
1730
|
+
return exists;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
const onSuggestionListEndReached = () => {
|
|
1734
|
+
let targetedFormatter = allFormatters.current.get(activeCharacter.current);
|
|
1735
|
+
if (!targetedFormatter) return;
|
|
1736
|
+
let fetchingNext = targetedFormatter.fetchNext();
|
|
1737
|
+
fetchingNext !== null && setSuggestionListLoader(true);
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
const getMentionLimitView = () => {
|
|
1741
|
+
let targetedFormatter = allFormatters.current.get(activeCharacter.current);
|
|
1742
|
+
let shouldWarn;
|
|
1743
|
+
let limit;
|
|
1744
|
+
if (targetedFormatter?.getLimit && targetedFormatter?.getLimit()) {
|
|
1745
|
+
limit = targetedFormatter?.getLimit();
|
|
1746
|
+
if (targetedFormatter.getUniqueUsersList && targetedFormatter.getUniqueUsersList()?.size >= limit) {
|
|
1747
|
+
shouldWarn = true;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
if (!shouldWarn) return null;
|
|
1751
|
+
let errorString = targetedFormatter?.getErrorString ? targetedFormatter?.getErrorString() : `${localize("MENTION_UPTO")} ${limit} ${limit === 1 ? localize("TIME") : localize("TIMES")} ${localize("AT_A_TIME")}.`;
|
|
1752
|
+
return (
|
|
1753
|
+
<View style={{
|
|
1754
|
+
flexDirection: "row",
|
|
1755
|
+
alignItems: "center",
|
|
1756
|
+
paddingTop: 5,
|
|
1757
|
+
paddingLeft: 5,
|
|
1758
|
+
borderTopWidth: 1,
|
|
1759
|
+
borderTopColor: theme.palette.getAccent300()
|
|
1760
|
+
}}>
|
|
1761
|
+
<Image style={{
|
|
1762
|
+
tintColor: theme.palette.getAccent500(),
|
|
1763
|
+
height: 20,
|
|
1764
|
+
width: 20
|
|
1765
|
+
}} source={ICONS.INFO} />
|
|
1766
|
+
<Text style={{
|
|
1767
|
+
marginLeft: 5,
|
|
1768
|
+
color: theme.palette.getAccent500(),
|
|
1769
|
+
...theme.typography.text1
|
|
1770
|
+
}}>{errorString}</Text>
|
|
1771
|
+
</View>
|
|
1772
|
+
)
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1303
1775
|
return (
|
|
1304
1776
|
<>
|
|
1305
1777
|
{!isVisible && typeof CustomView === "function" && <CustomView />}
|
|
@@ -1316,7 +1788,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1316
1788
|
<KeyboardAvoidingView
|
|
1317
1789
|
key={id}
|
|
1318
1790
|
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
1319
|
-
keyboardVerticalOffset={Platform.select({ios:
|
|
1791
|
+
keyboardVerticalOffset={Platform.select({ios: kbOffset})}
|
|
1320
1792
|
{...keyboardAvoidingViewProps}
|
|
1321
1793
|
>
|
|
1322
1794
|
<View
|
|
@@ -1333,11 +1805,12 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1333
1805
|
shouldShow={showEmojiboard}
|
|
1334
1806
|
onClose={() => setShowEmojiboard(false)}
|
|
1335
1807
|
emojiSelection={(emoji: any) => {
|
|
1336
|
-
let pre =
|
|
1337
|
-
let post =
|
|
1808
|
+
let pre = plainTextInput.current.substring(0, selectionPosition.start);
|
|
1809
|
+
let post = plainTextInput.current.substring(
|
|
1338
1810
|
selectionPosition.end,
|
|
1339
|
-
|
|
1811
|
+
plainTextInput.current.length
|
|
1340
1812
|
);
|
|
1813
|
+
inputValueRef.current = selectionPosition.start && selectionPosition.end ? `${pre}${emoji}${post}` : `${inputValueRef.current}${emoji}`;
|
|
1341
1814
|
setInputMessage((prev) =>
|
|
1342
1815
|
selectionPosition.start && selectionPosition.end
|
|
1343
1816
|
? `${pre}${emoji}${post}`
|
|
@@ -1359,10 +1832,10 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1359
1832
|
messageComposerStyle.actionSheetSeparatorTint,
|
|
1360
1833
|
}
|
|
1361
1834
|
: {}),
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1835
|
+
layoutModeIconTint: messageComposerStyle.actionSheetLayoutModeIconTint,
|
|
1836
|
+
titleColor: messageComposerStyle.actionSheetTitleColor,
|
|
1837
|
+
listItemIconTint: messageComposerStyle.attachIconTint,
|
|
1838
|
+
listItemTitleFont: messageComposerStyle.actionSheetTitleFont
|
|
1366
1839
|
}}
|
|
1367
1840
|
cometChatBottomSheetStyle={
|
|
1368
1841
|
messageComposerStyle.actionSheetCancelButtonIconTint
|
|
@@ -1406,6 +1879,33 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1406
1879
|
aiOptions={AIOptionItems}
|
|
1407
1880
|
aiStyle={AIStyles}
|
|
1408
1881
|
/>
|
|
1882
|
+
|
|
1883
|
+
{
|
|
1884
|
+
(mentionsSearchData.length > 0 && plainTextInput.current.length > 0)
|
|
1885
|
+
&& <View style={{
|
|
1886
|
+
borderTopWidth: 1, borderColor: theme.palette.getAccent300(),
|
|
1887
|
+
paddingVertical: 5, paddingHorizontal: 0,
|
|
1888
|
+
maxHeight: Dimensions.get("window").height * .22, justifyContent: "flex-end",
|
|
1889
|
+
paddingBottom: messagePreview !== null ? 60 : undefined,
|
|
1890
|
+
zIndex: 1
|
|
1891
|
+
}}>
|
|
1892
|
+
<CometChatSuggestionList
|
|
1893
|
+
data={mentionsSearchData}
|
|
1894
|
+
avatarStyle={{
|
|
1895
|
+
height: 33, width: 33,
|
|
1896
|
+
}}
|
|
1897
|
+
listItemStyle={{
|
|
1898
|
+
height: 50,
|
|
1899
|
+
}}
|
|
1900
|
+
separatorColor={theme.palette.getAccent100()}
|
|
1901
|
+
onPress={onMentionPress}
|
|
1902
|
+
onEndReached={onSuggestionListEndReached}
|
|
1903
|
+
loading={suggestionListLoader}
|
|
1904
|
+
/>
|
|
1905
|
+
{getMentionLimitView()}
|
|
1906
|
+
</View>
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1409
1909
|
{HeaderView ? (
|
|
1410
1910
|
<HeaderView />
|
|
1411
1911
|
) : (
|
|
@@ -1420,11 +1920,13 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1420
1920
|
</View >
|
|
1421
1921
|
<CometChatMessageInput
|
|
1422
1922
|
messageInputRef={messageInputRef}
|
|
1423
|
-
text={inputMessage}
|
|
1923
|
+
text={inputMessage as string}
|
|
1424
1924
|
placeHolderText={placeHolderText}
|
|
1425
1925
|
style={messageComposerStyle}
|
|
1426
|
-
onSelectionChange={({ nativeEvent: { selection } }) =>
|
|
1926
|
+
onSelectionChange={({ nativeEvent: { selection } }) => {
|
|
1427
1927
|
setSelectionPosition(selection)
|
|
1928
|
+
openList(selection)
|
|
1929
|
+
}
|
|
1428
1930
|
}
|
|
1429
1931
|
maxHeight={maxHeight ?? null}
|
|
1430
1932
|
onChangeText={textChangeHandler}
|