@cometchat/chat-uikit-react-native 4.3.20 → 4.3.22-t1
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/package.json +1 -1
- package/src/AI/AIConversationSummary/AIConversationSummaryView.tsx +171 -167
- package/src/AI/CardView.tsx +55 -53
- package/src/CometChatCreateGroup/CometChatCreateGroup.tsx +8 -13
- package/src/CometChatGroups/CometChatGroups.tsx +545 -514
- package/src/CometChatJoinProtectedGroup/CometChatJoinProtectedGroup.tsx +5 -8
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +544 -378
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +103 -78
- package/src/CometChatThreadedMessages/CometChatThreadedMessages.tsx +3 -8
- package/src/CometChatTransferOwnership/CometChatTransferOwnership.tsx +11 -13
- package/src/CometChatUsers/CometChatUsers.tsx +24 -23
- package/src/extensions/CollaborativeBubble/CometChatCollaborativeBubble.tsx +24 -25
- package/src/extensions/Polls/Polls.tsx +8 -16
- package/src/extensions/Polls/PollsBubble.tsx +5 -10
- package/src/extensions/SmartReplies/SmartRepliesView.tsx +16 -22
- package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +51 -51
- package/src/shared/libs/datePickerModal/DateTimePickerModal.android.js +1 -7
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.js +38 -46
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +19 -19
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +8 -20
- package/src/shared/views/CometChatBadge/CometChatBadge.tsx +8 -14
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +141 -140
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +47 -51
- package/src/shared/views/CometChatDate/CometChatDate.tsx +18 -17
- package/src/shared/views/CometChatDateTimePicker/CometChatDateTimePicker.tsx +65 -51
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +76 -72
- package/src/shared/views/CometChatFormBubble/CometChatFormBubble.tsx +3 -8
- package/src/shared/views/CometChatList/CometChatList.tsx +133 -134
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +65 -64
- package/src/shared/views/CometChatMediaRecorder/CometChatMediaRecorder.tsx +20 -10
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +3 -8
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +24 -23
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +107 -53
- package/src/shared/views/CometChatReceipt/CometChatReceipt.tsx +22 -14
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +15 -8
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +2 -6
- package/src/shared/views/SwipeRow/SwipeRow.tsx +6 -14
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.4/executionHistory/executionHistory.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/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
|
@@ -63,7 +63,10 @@ import { MessageEvents } from '../shared/events';
|
|
|
63
63
|
import { CometChatContextType } from '../shared/base/Types';
|
|
64
64
|
import { CometChatUIEventHandler } from '../shared/events/CometChatUIEventHandler/CometChatUIEventHandler';
|
|
65
65
|
import { CometChatMessageComposerActionInterface } from '../shared/helper/types';
|
|
66
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
CometChatMediaRecorder,
|
|
68
|
+
MediaRecorderStyle,
|
|
69
|
+
} from '../shared/views/CometChatMediaRecorder';
|
|
67
70
|
import { AIOptionsStyle } from '../AI/AIOptionsStyle';
|
|
68
71
|
import { CommonUtils } from '../shared/utils/CommonUtils';
|
|
69
72
|
import { permissionUtil } from '../shared/utils/PermissionUtil';
|
|
@@ -74,10 +77,12 @@ const uiEventListenerShow = 'uiEvent_show_' + new Date().getTime();
|
|
|
74
77
|
const uiEventListenerHide = 'uiEvent_hide_' + new Date().getTime();
|
|
75
78
|
|
|
76
79
|
const MessagePreviewTray = (props: any) => {
|
|
77
|
-
const { shouldShow = false, text = '', onClose = () => {
|
|
80
|
+
const { shouldShow = false, text = '', onClose = () => {} } = props;
|
|
78
81
|
return shouldShow ? (
|
|
79
82
|
<CometChatMessagePreview
|
|
80
|
-
style={
|
|
83
|
+
style={
|
|
84
|
+
new MessagePreviewStyle({ width: '95%', backgroundColor: 'white' })
|
|
85
|
+
}
|
|
81
86
|
messagePreviewTitle={localize('EDIT_MESSAGE')}
|
|
82
87
|
messagePreviewSubtitle={text}
|
|
83
88
|
closeIconURL={ICONS.CLOSE}
|
|
@@ -89,14 +94,18 @@ const MessagePreviewTray = (props: any) => {
|
|
|
89
94
|
const ImageButton = (props: any) => {
|
|
90
95
|
const { image, onClick, buttonStyle, imageStyle, disable } = props;
|
|
91
96
|
return (
|
|
92
|
-
<TouchableOpacity
|
|
97
|
+
<TouchableOpacity
|
|
98
|
+
activeOpacity={disable ? 1 : undefined}
|
|
99
|
+
onPress={disable ? () => {} : onClick}
|
|
100
|
+
style={buttonStyle}
|
|
101
|
+
>
|
|
93
102
|
<Image source={image} style={[{ height: 24, width: 24 }, imageStyle]} />
|
|
94
103
|
</TouchableOpacity>
|
|
95
104
|
);
|
|
96
105
|
};
|
|
97
106
|
|
|
98
107
|
const AttachIconButton = (props: any) => {
|
|
99
|
-
const { icon, show = false, onClick = () => {
|
|
108
|
+
const { icon, show = false, onClick = () => {}, style, theme } = props;
|
|
100
109
|
if (show) {
|
|
101
110
|
return (
|
|
102
111
|
<ImageButton
|
|
@@ -113,8 +122,8 @@ const AttachIconButton = (props: any) => {
|
|
|
113
122
|
const EmojiBoard = (props: any) => {
|
|
114
123
|
const {
|
|
115
124
|
shouldShow = false,
|
|
116
|
-
onClose = () => {
|
|
117
|
-
emojiSelection = (emoji?: any) => {
|
|
125
|
+
onClose = () => {},
|
|
126
|
+
emojiSelection = (emoji?: any) => {},
|
|
118
127
|
...otherProps
|
|
119
128
|
} = props;
|
|
120
129
|
return shouldShow ? (
|
|
@@ -127,7 +136,7 @@ const EmojiBoard = (props: any) => {
|
|
|
127
136
|
const ActionSheetBoard = (props: any) => {
|
|
128
137
|
const {
|
|
129
138
|
shouldShow = false,
|
|
130
|
-
onClose = () => {
|
|
139
|
+
onClose = () => {},
|
|
131
140
|
options = [],
|
|
132
141
|
cometChatBottomSheetStyle = {},
|
|
133
142
|
sheetRef,
|
|
@@ -151,15 +160,15 @@ const ActionSheetBoard = (props: any) => {
|
|
|
151
160
|
const RecordAudio = (props: any) => {
|
|
152
161
|
const {
|
|
153
162
|
shouldShow = false,
|
|
154
|
-
onClose = () => {
|
|
163
|
+
onClose = () => {},
|
|
155
164
|
options = [],
|
|
156
165
|
cometChatBottomSheetStyle = {},
|
|
157
166
|
sheetRef,
|
|
158
|
-
onPause = () => {
|
|
159
|
-
onPlay = () => {
|
|
160
|
-
onSend = (recordedFile: String) => {
|
|
161
|
-
onStop = (recordedFile: String) => {
|
|
162
|
-
onStart = () => {
|
|
167
|
+
onPause = () => {},
|
|
168
|
+
onPlay = () => {},
|
|
169
|
+
onSend = (recordedFile: String) => {},
|
|
170
|
+
onStop = (recordedFile: String) => {},
|
|
171
|
+
onStart = () => {},
|
|
163
172
|
mediaRecorderStyle,
|
|
164
173
|
pauseIconUrl,
|
|
165
174
|
playIconUrl,
|
|
@@ -192,14 +201,17 @@ const RecordAudio = (props: any) => {
|
|
|
192
201
|
/>
|
|
193
202
|
</CometChatBottomSheet>
|
|
194
203
|
) : null;
|
|
195
|
-
}
|
|
204
|
+
};
|
|
196
205
|
|
|
197
206
|
const AIOptions = (props: any) => {
|
|
198
207
|
const {
|
|
199
208
|
aiStyle,
|
|
200
209
|
shouldShow = false,
|
|
201
|
-
onClose = () => {
|
|
202
|
-
cometChatBottomSheetStyle = {
|
|
210
|
+
onClose = () => {},
|
|
211
|
+
cometChatBottomSheetStyle = {
|
|
212
|
+
backgroundColor: aiStyle.backgroundColor,
|
|
213
|
+
paddingHorizontal: 0,
|
|
214
|
+
},
|
|
203
215
|
sheetRef,
|
|
204
216
|
aiOptions,
|
|
205
217
|
...otherProps
|
|
@@ -211,7 +223,6 @@ const AIOptions = (props: any) => {
|
|
|
211
223
|
onClose={onClose}
|
|
212
224
|
style={cometChatBottomSheetStyle}
|
|
213
225
|
>
|
|
214
|
-
|
|
215
226
|
<CometChatActionSheet
|
|
216
227
|
actions={aiOptions}
|
|
217
228
|
style={{ ...aiStyle, paddingHorizontal: 0 }}
|
|
@@ -221,7 +232,7 @@ const AIOptions = (props: any) => {
|
|
|
221
232
|
/>
|
|
222
233
|
</CometChatBottomSheet>
|
|
223
234
|
) : null;
|
|
224
|
-
}
|
|
235
|
+
};
|
|
225
236
|
|
|
226
237
|
const LiveReaction = (props: any) => {
|
|
227
238
|
const { show = false, reaction } = props;
|
|
@@ -231,7 +242,8 @@ const LiveReaction = (props: any) => {
|
|
|
231
242
|
return null;
|
|
232
243
|
};
|
|
233
244
|
|
|
234
|
-
let recordedTime = 0,
|
|
245
|
+
let recordedTime = 0,
|
|
246
|
+
timerIntervalId = null;
|
|
235
247
|
|
|
236
248
|
export interface MessageComposerStyleInterface extends BaseStyle {
|
|
237
249
|
attachIconTint?: string;
|
|
@@ -251,11 +263,17 @@ export interface MessageComposerStyleInterface extends BaseStyle {
|
|
|
251
263
|
actionSheetLayoutModeIconTint?: string;
|
|
252
264
|
actionSheetCancelButtonIconTint?: string;
|
|
253
265
|
}
|
|
254
|
-
type Enumerate<
|
|
266
|
+
type Enumerate<
|
|
267
|
+
N extends number,
|
|
268
|
+
Acc extends number[] = []
|
|
269
|
+
> = Acc['length'] extends N
|
|
255
270
|
? Acc[number]
|
|
256
|
-
: Enumerate<N, [...Acc, Acc['length']]
|
|
271
|
+
: Enumerate<N, [...Acc, Acc['length']]>;
|
|
257
272
|
|
|
258
|
-
type IntRange<F extends number, T extends number> = Exclude<
|
|
273
|
+
type IntRange<F extends number, T extends number> = Exclude<
|
|
274
|
+
Enumerate<T>,
|
|
275
|
+
Enumerate<F>
|
|
276
|
+
>;
|
|
259
277
|
|
|
260
278
|
export interface CometChatMessageComposerInterface {
|
|
261
279
|
/**
|
|
@@ -520,28 +538,30 @@ export interface CometChatMessageComposerInterface {
|
|
|
520
538
|
*/
|
|
521
539
|
onError?: (error: any) => void;
|
|
522
540
|
/**
|
|
523
|
-
|
|
524
|
-
|
|
541
|
+
* AI Icon URL.
|
|
542
|
+
*/
|
|
525
543
|
AIIconURL?: string;
|
|
526
544
|
/**
|
|
527
545
|
* AI Options Style.
|
|
528
546
|
*/
|
|
529
547
|
aiOptionsStyle?: AIOptionsStyle;
|
|
530
548
|
/**
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
keyboardAvoidingViewProps?: KeyboardAvoidingViewProps
|
|
549
|
+
* To override keyboardAvoidingViewProps.
|
|
550
|
+
*/
|
|
551
|
+
keyboardAvoidingViewProps?: KeyboardAvoidingViewProps;
|
|
534
552
|
/**
|
|
535
553
|
* Collection of text formatter class
|
|
536
554
|
* @type {Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>}
|
|
537
|
-
|
|
538
|
-
textFormatters?: Array<
|
|
555
|
+
*/
|
|
556
|
+
textFormatters?: Array<
|
|
557
|
+
CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter
|
|
558
|
+
>;
|
|
539
559
|
disableMentions?: boolean;
|
|
540
560
|
/*
|
|
541
561
|
* To manually manage image quality taken from the camera (100 means no compression).
|
|
542
562
|
* @default 20
|
|
543
563
|
*/
|
|
544
|
-
imageQuality?: IntRange<1, 100
|
|
564
|
+
imageQuality?: IntRange<1, 100>;
|
|
545
565
|
}
|
|
546
566
|
export const CometChatMessageComposer = React.forwardRef(
|
|
547
567
|
(props: CometChatMessageComposerInterface, ref) => {
|
|
@@ -553,7 +573,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
553
573
|
id,
|
|
554
574
|
user,
|
|
555
575
|
group,
|
|
556
|
-
disableSoundForMessages,
|
|
557
576
|
customSoundForMessage,
|
|
558
577
|
disableTypingEvents,
|
|
559
578
|
text,
|
|
@@ -562,16 +581,12 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
562
581
|
FooterView,
|
|
563
582
|
onChangeText,
|
|
564
583
|
maxHeight,
|
|
565
|
-
attachmentIcon,
|
|
566
584
|
attachmentOptions,
|
|
567
585
|
SecondaryButtonView,
|
|
568
586
|
AuxiliaryButtonView,
|
|
569
587
|
auxiliaryButtonsAlignment,
|
|
570
588
|
SendButtonView,
|
|
571
589
|
parentMessageId,
|
|
572
|
-
hideLiveReaction,
|
|
573
|
-
liveReactionIcon,
|
|
574
|
-
messageComposerStyle,
|
|
575
590
|
onSendButtonPress,
|
|
576
591
|
onError,
|
|
577
592
|
hideVoiceRecording,
|
|
@@ -588,7 +603,13 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
588
603
|
keyboardAvoidingViewProps,
|
|
589
604
|
textFormatters,
|
|
590
605
|
disableMentions,
|
|
591
|
-
imageQuality = 20
|
|
606
|
+
imageQuality = 20,
|
|
607
|
+
|
|
608
|
+
attachmentIcon = ICONS.ADD,
|
|
609
|
+
liveReactionIcon = ICONS.HEART,
|
|
610
|
+
hideLiveReaction = true,
|
|
611
|
+
disableSoundForMessages = true,
|
|
612
|
+
messageComposerStyle = {},
|
|
592
613
|
} = props;
|
|
593
614
|
|
|
594
615
|
const defaultAttachmentOptions =
|
|
@@ -609,15 +630,19 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
609
630
|
const messageInputRef = React.useRef<any>(null);
|
|
610
631
|
const chatRef = React.useRef<any>(chatWith);
|
|
611
632
|
const inputValueRef = React.useRef<any>(null);
|
|
612
|
-
const plainTextInput = React.useRef<string>(text ??
|
|
633
|
+
const plainTextInput = React.useRef<string>(text ?? '');
|
|
613
634
|
let mentionMap = React.useRef<Map<string, SuggestionItem>>(new Map());
|
|
614
|
-
let trackingCharacters = React.useRef<string[]>([])
|
|
615
|
-
let allFormatters = React.useRef<
|
|
616
|
-
|
|
617
|
-
|
|
635
|
+
let trackingCharacters = React.useRef<string[]>([]);
|
|
636
|
+
let allFormatters = React.useRef<
|
|
637
|
+
Map<string, CometChatTextFormatter | CometChatMentionsFormatter>
|
|
638
|
+
>(new Map());
|
|
639
|
+
let activeCharacter = React.useRef('');
|
|
640
|
+
let searchStringRef = React.useRef('');
|
|
618
641
|
|
|
619
642
|
const [selectionPosition, setSelectionPosition] = React.useState<any>({});
|
|
620
|
-
const [inputMessage, setInputMessage] = React.useState<
|
|
643
|
+
const [inputMessage, setInputMessage] = React.useState<
|
|
644
|
+
string | JSX.Element
|
|
645
|
+
>(text || '');
|
|
621
646
|
const [showReaction, setShowReaction] = React.useState(false);
|
|
622
647
|
const [showEmojiboard, setShowEmojiboard] = React.useState(false);
|
|
623
648
|
const [showActionSheet, setShowActionSheet] = React.useState(false);
|
|
@@ -633,13 +658,16 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
633
658
|
const [isVisible, setIsVisible] = React.useState(false);
|
|
634
659
|
const [kbOffset, setKbOffset] = React.useState(59);
|
|
635
660
|
const [showMentionList, setShowMentionList] = React.useState(false);
|
|
636
|
-
const [mentionsSearchData, setMentionsSearchData] = React.useState<
|
|
637
|
-
|
|
661
|
+
const [mentionsSearchData, setMentionsSearchData] = React.useState<
|
|
662
|
+
Array<SuggestionItem>
|
|
663
|
+
>([]);
|
|
664
|
+
const [suggestionListLoader, setSuggestionListLoader] =
|
|
665
|
+
React.useState(false);
|
|
638
666
|
|
|
639
667
|
const bottomSheetRef = React.useRef<any>(null);
|
|
640
668
|
|
|
641
669
|
useLayoutEffect(() => {
|
|
642
|
-
if (Platform.OS ===
|
|
670
|
+
if (Platform.OS === 'ios') {
|
|
643
671
|
if (Number.isInteger(commonVars.safeAreaInsets.top)) {
|
|
644
672
|
setKbOffset(commonVars.safeAreaInsets.top as number);
|
|
645
673
|
return;
|
|
@@ -648,9 +676,9 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
648
676
|
if (Number.isInteger(res.top)) {
|
|
649
677
|
commonVars.safeAreaInsets.top = res.top;
|
|
650
678
|
commonVars.safeAreaInsets.bottom = res.bottom;
|
|
651
|
-
setKbOffset(res.top)
|
|
679
|
+
setKbOffset(res.top);
|
|
652
680
|
}
|
|
653
|
-
})
|
|
681
|
+
});
|
|
654
682
|
}
|
|
655
683
|
}, []);
|
|
656
684
|
|
|
@@ -664,7 +692,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
664
692
|
optionsSeparatorTint: theme.palette.getAccent200(),
|
|
665
693
|
borderRadius: 0,
|
|
666
694
|
...aiOptionsStyle,
|
|
667
|
-
})
|
|
695
|
+
});
|
|
668
696
|
|
|
669
697
|
let isTyping = useRef<any>(null);
|
|
670
698
|
|
|
@@ -677,7 +705,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
677
705
|
|
|
678
706
|
const previewMessage = ({ message, status }: any) => {
|
|
679
707
|
if (status === messageStatus.inprogress) {
|
|
680
|
-
|
|
681
708
|
let textComponents = message?.text;
|
|
682
709
|
|
|
683
710
|
let rawText = message?.text;
|
|
@@ -685,20 +712,24 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
685
712
|
let users: any = {};
|
|
686
713
|
let regexes: Array<RegExp> = [];
|
|
687
714
|
|
|
688
|
-
allFormatters.current.forEach(
|
|
689
|
-
formatter
|
|
690
|
-
|
|
691
|
-
regexes.
|
|
715
|
+
allFormatters.current.forEach(
|
|
716
|
+
(formatter: CometChatTextFormatter, key) => {
|
|
717
|
+
formatter.handleComposerPreview(message);
|
|
718
|
+
if (!regexes.includes(formatter.getRegexPattern())) {
|
|
719
|
+
regexes.push(formatter.getRegexPattern());
|
|
720
|
+
}
|
|
721
|
+
let suggestionUsers = formatter.getSuggestionItems();
|
|
722
|
+
suggestionUsers.forEach(
|
|
723
|
+
(item) => (users[item.underlyingText] = item)
|
|
724
|
+
);
|
|
725
|
+
let resp = formatter.getFormattedText(textComponents);
|
|
726
|
+
textComponents = resp;
|
|
692
727
|
}
|
|
693
|
-
|
|
694
|
-
suggestionUsers.forEach(item => users[item.underlyingText] = item);
|
|
695
|
-
let resp = formatter.getFormattedText(textComponents);
|
|
696
|
-
textComponents = resp;
|
|
697
|
-
})
|
|
728
|
+
);
|
|
698
729
|
|
|
699
730
|
let edits: any[] = [];
|
|
700
731
|
|
|
701
|
-
regexes.forEach(regex => {
|
|
732
|
+
regexes.forEach((regex) => {
|
|
702
733
|
let match;
|
|
703
734
|
while ((match = regex.exec(rawText)) !== null) {
|
|
704
735
|
const user = users[match[0]];
|
|
@@ -707,7 +738,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
707
738
|
startIndex: match.index,
|
|
708
739
|
endIndex: regex.lastIndex,
|
|
709
740
|
replacement: user.promptText,
|
|
710
|
-
user
|
|
741
|
+
user,
|
|
711
742
|
});
|
|
712
743
|
}
|
|
713
744
|
}
|
|
@@ -716,16 +747,21 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
716
747
|
// Sort edits by startIndex to apply them in order
|
|
717
748
|
edits.sort((a, b) => a.startIndex - b.startIndex);
|
|
718
749
|
|
|
719
|
-
plainTextInput.current = getPlainString(message?.text, edits)
|
|
750
|
+
plainTextInput.current = getPlainString(message?.text, edits);
|
|
720
751
|
|
|
721
752
|
const hashMap = new Map();
|
|
722
753
|
let offset = 0; // Tracks shift in position due to replacements
|
|
723
754
|
|
|
724
|
-
edits.forEach(edit => {
|
|
755
|
+
edits.forEach((edit) => {
|
|
725
756
|
const adjustedStartIndex = edit.startIndex + offset;
|
|
726
|
-
rawText =
|
|
757
|
+
rawText =
|
|
758
|
+
rawText.substring(0, adjustedStartIndex) +
|
|
759
|
+
edit.replacement +
|
|
760
|
+
rawText.substring(edit.endIndex);
|
|
727
761
|
offset += edit.replacement.length - (edit.endIndex - edit.startIndex);
|
|
728
|
-
const rangeKey = `${adjustedStartIndex}_${
|
|
762
|
+
const rangeKey = `${adjustedStartIndex}_${
|
|
763
|
+
adjustedStartIndex + edit.replacement.length
|
|
764
|
+
}`;
|
|
729
765
|
hashMap.set(rangeKey, edit.user);
|
|
730
766
|
});
|
|
731
767
|
|
|
@@ -758,32 +794,27 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
758
794
|
MessageTypeConstants.image,
|
|
759
795
|
chatWith.current
|
|
760
796
|
);
|
|
761
|
-
}
|
|
797
|
+
};
|
|
762
798
|
|
|
763
799
|
const fileInputHandler = async (fileType: string) => {
|
|
764
800
|
if (fileType === MessageTypeConstants.takePhoto) {
|
|
765
|
-
if (!(await permissionUtil.startResourceBasedTask([
|
|
801
|
+
if (!(await permissionUtil.startResourceBasedTask(['camera']))) {
|
|
766
802
|
return;
|
|
767
803
|
}
|
|
768
|
-
let quality = imageQuality
|
|
804
|
+
let quality = imageQuality;
|
|
769
805
|
if (isNaN(imageQuality) || imageQuality < 1 || imageQuality > 100) {
|
|
770
|
-
quality = 20
|
|
806
|
+
quality = 20;
|
|
771
807
|
}
|
|
772
|
-
if (Platform.OS ===
|
|
773
|
-
FileManager.openCamera(
|
|
774
|
-
fileType,
|
|
775
|
-
Math.round(quality),
|
|
776
|
-
cameraCallback
|
|
777
|
-
);
|
|
808
|
+
if (Platform.OS === 'android') {
|
|
809
|
+
FileManager.openCamera(fileType, Math.round(quality), cameraCallback);
|
|
778
810
|
} else {
|
|
779
|
-
FileManager.openCamera(
|
|
780
|
-
fileType,
|
|
781
|
-
cameraCallback
|
|
782
|
-
);
|
|
811
|
+
FileManager.openCamera(fileType, cameraCallback);
|
|
783
812
|
}
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
|
|
813
|
+
} else if (
|
|
814
|
+
Platform.OS === 'ios' &&
|
|
815
|
+
fileType === MessageTypeConstants.video
|
|
816
|
+
) {
|
|
817
|
+
NativeModules.VideoPickerModule.pickVideo((file: any) => {
|
|
787
818
|
if (file.uri)
|
|
788
819
|
sendMediaMessage(
|
|
789
820
|
chatWithId.current,
|
|
@@ -791,9 +822,8 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
791
822
|
MessageTypeConstants.video,
|
|
792
823
|
chatWith.current
|
|
793
824
|
);
|
|
794
|
-
})
|
|
795
|
-
}
|
|
796
|
-
else
|
|
825
|
+
});
|
|
826
|
+
} else
|
|
797
827
|
FileManager.openFileChooser(fileType, async (fileInfo: any) => {
|
|
798
828
|
if (CheckPropertyExists(fileInfo, 'error')) {
|
|
799
829
|
return;
|
|
@@ -862,7 +892,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
862
892
|
};
|
|
863
893
|
|
|
864
894
|
const sendTextMessage = () => {
|
|
865
|
-
|
|
866
895
|
//ignore sending new message
|
|
867
896
|
if (messagePreview != null) {
|
|
868
897
|
editMessage(messagePreview.message);
|
|
@@ -881,14 +910,15 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
881
910
|
textMessage.setReceiver(chatWith.current);
|
|
882
911
|
textMessage.setText(finalTextInput);
|
|
883
912
|
textMessage.setMuid(String(getUnixTimestampInMilliseconds()));
|
|
884
|
-
parentMessageId &&
|
|
913
|
+
parentMessageId &&
|
|
914
|
+
textMessage.setParentMessageId(parentMessageId as number);
|
|
885
915
|
|
|
886
|
-
allFormatters.current.forEach(item => {
|
|
916
|
+
allFormatters.current.forEach((item) => {
|
|
887
917
|
textMessage = item.handlePreMessageSend(textMessage);
|
|
888
|
-
})
|
|
918
|
+
});
|
|
889
919
|
|
|
890
920
|
setMentionsSearchData([]);
|
|
891
|
-
plainTextInput.current =
|
|
921
|
+
plainTextInput.current = '';
|
|
892
922
|
|
|
893
923
|
if (finalTextInput.trim().length == 0) {
|
|
894
924
|
return;
|
|
@@ -920,7 +950,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
920
950
|
})
|
|
921
951
|
.catch((error: any) => {
|
|
922
952
|
onError && onError(error);
|
|
923
|
-
textMessage.data.metaData = { error: true }
|
|
953
|
+
textMessage.data.metaData = { error: true };
|
|
924
954
|
CometChatUIEventHandler.emitMessageEvent(
|
|
925
955
|
MessageEvents.ccMessageSent,
|
|
926
956
|
{
|
|
@@ -945,7 +975,8 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
945
975
|
chatWith.current
|
|
946
976
|
);
|
|
947
977
|
textMessage.setId(message.id);
|
|
948
|
-
parentMessageId &&
|
|
978
|
+
parentMessageId &&
|
|
979
|
+
textMessage.setParentMessageId(parentMessageId as number);
|
|
949
980
|
|
|
950
981
|
inputValueRef.current = '';
|
|
951
982
|
setInputMessage('');
|
|
@@ -1004,7 +1035,8 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1004
1035
|
url: messageInput['uri'],
|
|
1005
1036
|
sender: loggedInUser.current,
|
|
1006
1037
|
});
|
|
1007
|
-
parentMessageId &&
|
|
1038
|
+
parentMessageId &&
|
|
1039
|
+
mediaMessage.setParentMessageId(parentMessageId as number);
|
|
1008
1040
|
|
|
1009
1041
|
let localMessage: any = new CometChat.MediaMessage(
|
|
1010
1042
|
receiverId,
|
|
@@ -1025,7 +1057,8 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1025
1057
|
url: messageInput['uri'],
|
|
1026
1058
|
sender: loggedInUser.current,
|
|
1027
1059
|
});
|
|
1028
|
-
parentMessageId &&
|
|
1060
|
+
parentMessageId &&
|
|
1061
|
+
localMessage.setParentMessageId(parentMessageId as number);
|
|
1029
1062
|
localMessage.setData({
|
|
1030
1063
|
type: messageType,
|
|
1031
1064
|
category: CometChat.CATEGORY_MESSAGE,
|
|
@@ -1044,19 +1077,19 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1044
1077
|
if (!disableSoundForMessages) playAudio();
|
|
1045
1078
|
CometChat.sendMediaMessage(mediaMessage)
|
|
1046
1079
|
.then((message: any) => {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1080
|
+
CometChatUIEventHandler.emitMessageEvent(
|
|
1081
|
+
MessageEvents.ccMessageSent,
|
|
1082
|
+
{
|
|
1083
|
+
message: message,
|
|
1084
|
+
status: messageStatus.success,
|
|
1085
|
+
}
|
|
1086
|
+
);
|
|
1087
|
+
setShowRecordAudio(false);
|
|
1055
1088
|
})
|
|
1056
1089
|
.catch((error: any) => {
|
|
1057
1090
|
setShowRecordAudio(false);
|
|
1058
1091
|
onError && onError(error);
|
|
1059
|
-
localMessage.data.metaData = { error: true }
|
|
1092
|
+
localMessage.data.metaData = { error: true };
|
|
1060
1093
|
CometChatUIEventHandler.emitMessageEvent(
|
|
1061
1094
|
MessageEvents.ccMessageSent,
|
|
1062
1095
|
{
|
|
@@ -1074,14 +1107,13 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1074
1107
|
return false;
|
|
1075
1108
|
}
|
|
1076
1109
|
|
|
1077
|
-
|
|
1078
1110
|
//if typing is in progress, clear the previous timeout and set new timeout
|
|
1079
1111
|
if (isTyping.current) {
|
|
1080
1112
|
clearTimeout(isTyping.current);
|
|
1081
1113
|
isTyping.current = null;
|
|
1082
1114
|
} else {
|
|
1083
1115
|
let metadata = typingMetadata || undefined;
|
|
1084
|
-
|
|
1116
|
+
|
|
1085
1117
|
let typingNotification = new CometChat.TypingIndicator(
|
|
1086
1118
|
chatWithId.current,
|
|
1087
1119
|
chatWith.current,
|
|
@@ -1090,7 +1122,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1090
1122
|
CometChat.startTyping(typingNotification);
|
|
1091
1123
|
}
|
|
1092
1124
|
|
|
1093
|
-
|
|
1094
1125
|
let typingInterval = endTypingTimeout || 500;
|
|
1095
1126
|
isTyping.current = setTimeout(() => {
|
|
1096
1127
|
endTyping(null, typingMetadata);
|
|
@@ -1133,7 +1164,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1133
1164
|
|
|
1134
1165
|
const shouldShowAIOptions = () => {
|
|
1135
1166
|
return !parentMessageId && AIOptionItems.length > 0;
|
|
1136
|
-
}
|
|
1167
|
+
};
|
|
1137
1168
|
|
|
1138
1169
|
const AuxiliaryButtonViewElem = () => {
|
|
1139
1170
|
if (AuxiliaryButtonView && id)
|
|
@@ -1141,11 +1172,13 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1141
1172
|
<AuxiliaryButtonView user={user} group={group} composerId={id} />
|
|
1142
1173
|
);
|
|
1143
1174
|
else if (defaultAuxiliaryButtonOptions)
|
|
1144
|
-
return
|
|
1145
|
-
{
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1175
|
+
return (
|
|
1176
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
1177
|
+
{defaultAuxiliaryButtonOptions}
|
|
1178
|
+
{shouldShowAIOptions() && <AIOptionsButtonView />}
|
|
1179
|
+
{!hideVoiceRecording && <RecordAudioButtonView />}
|
|
1180
|
+
</View>
|
|
1181
|
+
);
|
|
1149
1182
|
|
|
1150
1183
|
return hideVoiceRecording ? null : <RecordAudioButtonView />;
|
|
1151
1184
|
};
|
|
@@ -1159,12 +1192,14 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1159
1192
|
imageStyle={[
|
|
1160
1193
|
Style.imageStyle,
|
|
1161
1194
|
{
|
|
1162
|
-
tintColor:
|
|
1163
|
-
|
|
1164
|
-
|
|
1195
|
+
tintColor:
|
|
1196
|
+
(inputMessage as String).length === 0
|
|
1197
|
+
? theme.palette.getAccent400()
|
|
1198
|
+
: messageComposerStyle?.sendIconTint ||
|
|
1199
|
+
theme.palette.getPrimary(),
|
|
1165
1200
|
},
|
|
1166
1201
|
]}
|
|
1167
|
-
disable={(
|
|
1202
|
+
disable={(inputMessage as String).length === 0}
|
|
1168
1203
|
onClick={sendTextMessage}
|
|
1169
1204
|
/>
|
|
1170
1205
|
);
|
|
@@ -1192,7 +1227,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1192
1227
|
);
|
|
1193
1228
|
};
|
|
1194
1229
|
const PrimaryButtonView = () => {
|
|
1195
|
-
return (
|
|
1230
|
+
return (inputMessage as String).length !== 0 || hideLiveReaction ? (
|
|
1196
1231
|
<SendButtonViewElem />
|
|
1197
1232
|
) : (
|
|
1198
1233
|
<View>
|
|
@@ -1209,50 +1244,62 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1209
1244
|
};
|
|
1210
1245
|
|
|
1211
1246
|
const RecordAudioButtonView = () => {
|
|
1212
|
-
return
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1247
|
+
return (
|
|
1248
|
+
<ImageButton
|
|
1249
|
+
image={voiceRecordingIconURL || ICONS.MICROPHONE}
|
|
1250
|
+
imageStyle={[
|
|
1251
|
+
Style.imageStyle,
|
|
1252
|
+
messageComposerStyle?.voiceRecordingIconTint
|
|
1253
|
+
? { tintColor: messageComposerStyle?.voiceRecordingIconTint }
|
|
1254
|
+
: {},
|
|
1255
|
+
]}
|
|
1256
|
+
onClick={() => setShowRecordAudio(true)}
|
|
1257
|
+
/>
|
|
1258
|
+
);
|
|
1259
|
+
};
|
|
1221
1260
|
const AIOptionsButtonView = () => {
|
|
1222
|
-
return
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1261
|
+
return (
|
|
1262
|
+
<ImageButton
|
|
1263
|
+
image={AIIconURL || ICONS.AI}
|
|
1264
|
+
imageStyle={Style.imageStyle}
|
|
1265
|
+
onClick={() => {
|
|
1266
|
+
setShowAIOptions(true);
|
|
1267
|
+
setAIOptionItems(rootAIOptionItems);
|
|
1268
|
+
}}
|
|
1269
|
+
/>
|
|
1270
|
+
);
|
|
1271
|
+
};
|
|
1231
1272
|
|
|
1232
1273
|
//fetch logged in user
|
|
1233
1274
|
useEffect(() => {
|
|
1234
|
-
CometChat.getLoggedinUser().then(
|
|
1275
|
+
CometChat.getLoggedinUser().then(
|
|
1276
|
+
(user: any) => (loggedInUser.current = user)
|
|
1277
|
+
);
|
|
1235
1278
|
let _formatter = [...(textFormatters ?? [])];
|
|
1236
1279
|
|
|
1237
1280
|
if (!disableMentions) {
|
|
1238
|
-
let mentionsFormatter =
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1281
|
+
let mentionsFormatter =
|
|
1282
|
+
ChatConfigurator.getDataSource().getMentionsFormatter();
|
|
1283
|
+
CometChatUIKit.loggedInUser &&
|
|
1284
|
+
mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser);
|
|
1285
|
+
mentionsFormatter.setMentionsStyle(
|
|
1286
|
+
new MentionTextStyle({
|
|
1287
|
+
loggedInUserTextStyle: {
|
|
1288
|
+
color: theme.palette.getPrimary(),
|
|
1289
|
+
...theme.typography.title2,
|
|
1290
|
+
fontSize: 17,
|
|
1291
|
+
} as TextStyle,
|
|
1292
|
+
textStyle: {
|
|
1293
|
+
color: theme.palette.getPrimary(),
|
|
1294
|
+
...theme.typography.subtitle1,
|
|
1295
|
+
fontSize: 17,
|
|
1296
|
+
} as TextStyle,
|
|
1297
|
+
})
|
|
1298
|
+
);
|
|
1252
1299
|
user && mentionsFormatter.setUser(user);
|
|
1253
1300
|
group && mentionsFormatter.setGroup(group);
|
|
1254
1301
|
|
|
1255
|
-
_formatter.unshift(mentionsFormatter)
|
|
1302
|
+
_formatter.unshift(mentionsFormatter);
|
|
1256
1303
|
}
|
|
1257
1304
|
|
|
1258
1305
|
_formatter.forEach((formatter) => {
|
|
@@ -1264,7 +1311,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1264
1311
|
|
|
1265
1312
|
let newFormatter = CommonUtils.clone(formatter);
|
|
1266
1313
|
allFormatters.current.set(trackingCharacter, newFormatter);
|
|
1267
|
-
})
|
|
1314
|
+
});
|
|
1268
1315
|
}, []);
|
|
1269
1316
|
|
|
1270
1317
|
useEffect(() => {
|
|
@@ -1300,6 +1347,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1300
1347
|
}
|
|
1301
1348
|
);
|
|
1302
1349
|
bottomSheetRef.current?.togglePanel();
|
|
1350
|
+
setShowActionSheet(false);
|
|
1303
1351
|
setTimeout(() => {
|
|
1304
1352
|
setCustomView(() => view);
|
|
1305
1353
|
setIsVisible(true);
|
|
@@ -1308,72 +1356,87 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1308
1356
|
|
|
1309
1357
|
useEffect(() => {
|
|
1310
1358
|
const defaultAttachmentOptions =
|
|
1311
|
-
ChatConfigurator.dataSource.getAttachmentOptions(
|
|
1359
|
+
ChatConfigurator.dataSource.getAttachmentOptions(
|
|
1360
|
+
user,
|
|
1361
|
+
group,
|
|
1362
|
+
composerIdMap
|
|
1363
|
+
);
|
|
1312
1364
|
setActionSheetItems(() =>
|
|
1313
1365
|
attachmentOptions && typeof attachmentOptions === 'function'
|
|
1314
|
-
? attachmentOptions({ user, group, composerId: composerIdMap })?.map(
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1366
|
+
? attachmentOptions({ user, group, composerId: composerIdMap })?.map(
|
|
1367
|
+
(item) => {
|
|
1368
|
+
if (typeof item.CustomView === 'function')
|
|
1369
|
+
return {
|
|
1370
|
+
...item,
|
|
1371
|
+
onPress: () => handleOnClick(item.CustomView),
|
|
1372
|
+
};
|
|
1373
|
+
if (typeof item.onPress == 'function')
|
|
1374
|
+
return {
|
|
1375
|
+
...item,
|
|
1376
|
+
onPress: () => {
|
|
1377
|
+
setShowActionSheet(false);
|
|
1378
|
+
item.onPress?.(user, group);
|
|
1379
|
+
},
|
|
1380
|
+
};
|
|
1381
|
+
return {
|
|
1382
|
+
...item,
|
|
1383
|
+
onPress: () => fileInputHandler(item.id),
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
)
|
|
1334
1387
|
: defaultAttachmentOptions.map((item: any) => {
|
|
1335
|
-
|
|
1388
|
+
if (typeof item.CustomView === 'function')
|
|
1389
|
+
return {
|
|
1390
|
+
...item,
|
|
1391
|
+
onPress: () => handleOnClick(item.CustomView),
|
|
1392
|
+
};
|
|
1393
|
+
if (typeof item.onPress === 'function')
|
|
1394
|
+
return {
|
|
1395
|
+
...item,
|
|
1396
|
+
onPress: () => item.onPress(user, group),
|
|
1397
|
+
};
|
|
1336
1398
|
return {
|
|
1337
1399
|
...item,
|
|
1338
|
-
onPress: () =>
|
|
1400
|
+
onPress: () => fileInputHandler(item.id),
|
|
1339
1401
|
};
|
|
1340
|
-
|
|
1341
|
-
return {
|
|
1342
|
-
...item,
|
|
1343
|
-
onPress: () => item.onPress(user, group),
|
|
1344
|
-
};
|
|
1345
|
-
return {
|
|
1346
|
-
...item,
|
|
1347
|
-
onPress: () => fileInputHandler(item.id),
|
|
1348
|
-
};
|
|
1349
|
-
})
|
|
1402
|
+
})
|
|
1350
1403
|
);
|
|
1351
1404
|
|
|
1352
|
-
const aiOptions = ChatConfigurator.dataSource.getAIOptions(
|
|
1405
|
+
const aiOptions = ChatConfigurator.dataSource.getAIOptions(
|
|
1406
|
+
user as CometChat.User,
|
|
1407
|
+
group as CometChat.Group,
|
|
1408
|
+
theme,
|
|
1409
|
+
composerIdMap,
|
|
1410
|
+
AIStyles
|
|
1411
|
+
);
|
|
1353
1412
|
let newAiOptions: any = _getAIOptions(aiOptions);
|
|
1354
1413
|
setAIOptionItems(newAiOptions);
|
|
1355
1414
|
setRootAIOptionItems(newAiOptions);
|
|
1356
1415
|
}, [user, group, id, parentMessageId]);
|
|
1357
1416
|
|
|
1358
|
-
const _getAIOptions = (
|
|
1417
|
+
const _getAIOptions = (
|
|
1418
|
+
options: (
|
|
1419
|
+
| CometChatMessageOption
|
|
1420
|
+
| CometChatMessageComposerActionInterface
|
|
1421
|
+
)[]
|
|
1422
|
+
) => {
|
|
1359
1423
|
let newOptions = [...options];
|
|
1360
1424
|
let newAiOptions = newOptions.map((item: any) => {
|
|
1361
1425
|
if (typeof item.onPress === 'function')
|
|
1362
1426
|
return {
|
|
1363
1427
|
...item,
|
|
1364
1428
|
onPress: () => {
|
|
1365
|
-
setShowAIOptions(false)
|
|
1366
|
-
item?.onPress?.(user)
|
|
1429
|
+
setShowAIOptions(false);
|
|
1430
|
+
item?.onPress?.(user);
|
|
1367
1431
|
},
|
|
1368
1432
|
};
|
|
1369
1433
|
return {
|
|
1370
1434
|
...item,
|
|
1371
|
-
onPress: () => {
|
|
1435
|
+
onPress: () => {},
|
|
1372
1436
|
};
|
|
1373
|
-
})
|
|
1437
|
+
});
|
|
1374
1438
|
return newAiOptions;
|
|
1375
|
-
|
|
1376
|
-
}
|
|
1439
|
+
};
|
|
1377
1440
|
|
|
1378
1441
|
useEffect(() => {
|
|
1379
1442
|
CometChatUIEventHandler.addMessageListener(editMessageListenerID, {
|
|
@@ -1382,9 +1445,9 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1382
1445
|
CometChatUIEventHandler.addUIListener(UiEventListenerID, {
|
|
1383
1446
|
ccToggleBottomSheet: (item) => {
|
|
1384
1447
|
if (item?.bots) {
|
|
1385
|
-
let newAiOptions: any = _getAIOptions(item.bots)
|
|
1448
|
+
let newAiOptions: any = _getAIOptions(item.bots);
|
|
1386
1449
|
setAIOptionItems(newAiOptions);
|
|
1387
|
-
setShowAIOptions(true)
|
|
1450
|
+
setShowAIOptions(true);
|
|
1388
1451
|
return;
|
|
1389
1452
|
} else if (item?.botView) {
|
|
1390
1453
|
setCustomView(() => item.child);
|
|
@@ -1399,20 +1462,22 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1399
1462
|
|
|
1400
1463
|
inputValueRef.current = text?.text;
|
|
1401
1464
|
plainTextInput.current = text?.text;
|
|
1402
|
-
setInputMessage(text?.text)
|
|
1403
|
-
|
|
1465
|
+
setInputMessage(text?.text);
|
|
1404
1466
|
},
|
|
1405
|
-
ccSuggestionData(item: {
|
|
1467
|
+
ccSuggestionData(item: {
|
|
1468
|
+
id: string | number;
|
|
1469
|
+
data: Array<SuggestionItem>;
|
|
1470
|
+
}) {
|
|
1406
1471
|
if (activeCharacter.current && id === item?.id) {
|
|
1407
1472
|
setMentionsSearchData(item?.data);
|
|
1408
1473
|
setSuggestionListLoader(false);
|
|
1409
1474
|
}
|
|
1410
1475
|
},
|
|
1411
|
-
})
|
|
1476
|
+
});
|
|
1412
1477
|
return () => {
|
|
1413
1478
|
CometChatUIEventHandler.removeMessageListener(editMessageListenerID);
|
|
1414
1479
|
CometChatUIEventHandler.removeUIListener(UiEventListenerID);
|
|
1415
|
-
}
|
|
1480
|
+
};
|
|
1416
1481
|
}, []);
|
|
1417
1482
|
|
|
1418
1483
|
const handlePannel = (item: any) => {
|
|
@@ -1444,21 +1509,24 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1444
1509
|
|
|
1445
1510
|
const _sendRecordedAudio = (recordedFile: String) => {
|
|
1446
1511
|
let fileObj = {
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
}
|
|
1451
|
-
console.log(
|
|
1512
|
+
name: 'audio-recording' + recordedFile.split('/audio-recording')[1],
|
|
1513
|
+
type: 'audio/mp4',
|
|
1514
|
+
uri: recordedFile,
|
|
1515
|
+
};
|
|
1516
|
+
console.log('fileObj', fileObj);
|
|
1452
1517
|
sendMediaMessage(
|
|
1453
1518
|
chatWithId.current,
|
|
1454
1519
|
fileObj,
|
|
1455
1520
|
MessageTypeConstants.audio,
|
|
1456
1521
|
chatWith.current
|
|
1457
1522
|
);
|
|
1458
|
-
console.log(
|
|
1459
|
-
}
|
|
1523
|
+
console.log('Send Audio');
|
|
1524
|
+
};
|
|
1460
1525
|
|
|
1461
|
-
function isCursorWithinMentionRange(
|
|
1526
|
+
function isCursorWithinMentionRange(
|
|
1527
|
+
mentionRanges: any,
|
|
1528
|
+
cursorPosition: number
|
|
1529
|
+
) {
|
|
1462
1530
|
for (let [range, mention] of mentionRanges) {
|
|
1463
1531
|
const [start, end] = range.split('_').map(Number);
|
|
1464
1532
|
if (cursorPosition >= start && cursorPosition <= end) {
|
|
@@ -1468,27 +1536,45 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1468
1536
|
return false; // No mention found at the cursor position
|
|
1469
1537
|
}
|
|
1470
1538
|
|
|
1471
|
-
function shouldOpenList(
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1539
|
+
function shouldOpenList(
|
|
1540
|
+
selection: {
|
|
1541
|
+
start: number;
|
|
1542
|
+
end: number;
|
|
1543
|
+
},
|
|
1544
|
+
searchString: string,
|
|
1545
|
+
tracker: string
|
|
1546
|
+
) {
|
|
1547
|
+
return (
|
|
1548
|
+
selection.start === selection.end &&
|
|
1549
|
+
!isCursorWithinMentionRange(
|
|
1550
|
+
mentionMap.current,
|
|
1551
|
+
selection.start - searchString.length
|
|
1552
|
+
) &&
|
|
1553
|
+
trackingCharacters.current.includes(tracker) &&
|
|
1554
|
+
(searchString === ''
|
|
1555
|
+
? (plainTextInput.current[selection.start - 2]?.length === 1 &&
|
|
1556
|
+
plainTextInput.current[selection.start - 2]?.trim()?.length ===
|
|
1557
|
+
0) ||
|
|
1558
|
+
plainTextInput.current[selection.start - 2] === undefined
|
|
1559
|
+
: true) &&
|
|
1560
|
+
(plainTextInput.current[selection.start - 1]?.length === 1 &&
|
|
1561
|
+
plainTextInput.current[selection.start - 1]?.trim()?.length === 0
|
|
1562
|
+
? searchString.length > 0
|
|
1563
|
+
: true)
|
|
1564
|
+
);
|
|
1481
1565
|
}
|
|
1482
1566
|
|
|
1483
1567
|
let timeoutId: any;
|
|
1484
|
-
const openList = (selection: {
|
|
1485
|
-
start: number;
|
|
1486
|
-
end: number;
|
|
1487
|
-
}) => {
|
|
1568
|
+
const openList = (selection: { start: number; end: number }) => {
|
|
1488
1569
|
clearTimeout(timeoutId);
|
|
1489
1570
|
timeoutId = setTimeout(() => {
|
|
1490
|
-
let searchString = extractTextFromCursor(
|
|
1491
|
-
|
|
1571
|
+
let searchString = extractTextFromCursor(
|
|
1572
|
+
plainTextInput.current,
|
|
1573
|
+
selection.start
|
|
1574
|
+
);
|
|
1575
|
+
let tracker = searchString
|
|
1576
|
+
? plainTextInput.current[selection.start - (searchString.length + 1)]
|
|
1577
|
+
: plainTextInput.current[selection.start - 1];
|
|
1492
1578
|
|
|
1493
1579
|
if (shouldOpenList(selection, searchString, tracker)) {
|
|
1494
1580
|
activeCharacter.current = tracker;
|
|
@@ -1497,22 +1583,28 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1497
1583
|
|
|
1498
1584
|
let formatter = allFormatters.current.get(tracker);
|
|
1499
1585
|
if (formatter instanceof CometChatMentionsFormatter) {
|
|
1500
|
-
let shouldShowMentionList =
|
|
1586
|
+
let shouldShowMentionList =
|
|
1587
|
+
formatter.getVisibleIn() === MentionsVisibility.both ||
|
|
1588
|
+
(formatter.getVisibleIn() ===
|
|
1589
|
+
MentionsVisibility.usersConversationOnly &&
|
|
1590
|
+
user) ||
|
|
1591
|
+
(formatter.getVisibleIn() ===
|
|
1592
|
+
MentionsVisibility.groupsConversationOnly &&
|
|
1593
|
+
group);
|
|
1501
1594
|
if (shouldShowMentionList) {
|
|
1502
1595
|
formatter.search(searchString);
|
|
1503
1596
|
}
|
|
1504
1597
|
} else {
|
|
1505
1598
|
formatter?.search(searchString);
|
|
1506
1599
|
}
|
|
1507
|
-
|
|
1508
1600
|
} else {
|
|
1509
|
-
activeCharacter.current =
|
|
1510
|
-
searchStringRef.current =
|
|
1601
|
+
activeCharacter.current = '';
|
|
1602
|
+
searchStringRef.current = '';
|
|
1511
1603
|
setShowMentionList(false);
|
|
1512
1604
|
setMentionsSearchData([]);
|
|
1513
1605
|
}
|
|
1514
1606
|
}, 100);
|
|
1515
|
-
}
|
|
1607
|
+
};
|
|
1516
1608
|
|
|
1517
1609
|
const getRegexString = (str: string) => {
|
|
1518
1610
|
// Get an array of the entries in the map using the spread operator
|
|
@@ -1522,26 +1614,26 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1522
1614
|
|
|
1523
1615
|
// Iterate over the array in reverse order
|
|
1524
1616
|
entries.forEach(([key, value]) => {
|
|
1525
|
-
|
|
1526
|
-
let [start, end] = key.split("_").map(Number);
|
|
1617
|
+
let [start, end] = key.split('_').map(Number);
|
|
1527
1618
|
|
|
1528
1619
|
let pre = uidInput.substring(0, start);
|
|
1529
1620
|
let post = uidInput.substring(end);
|
|
1530
1621
|
|
|
1531
1622
|
uidInput = pre + value.underlyingText + post;
|
|
1532
|
-
|
|
1533
1623
|
});
|
|
1534
1624
|
|
|
1535
1625
|
return uidInput;
|
|
1626
|
+
};
|
|
1536
1627
|
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1628
|
+
const getPlainString = (
|
|
1629
|
+
str: string,
|
|
1630
|
+
edits: Array<{
|
|
1631
|
+
endIndex: number;
|
|
1632
|
+
replacement: string;
|
|
1633
|
+
startIndex: number;
|
|
1634
|
+
user: SuggestionItem;
|
|
1635
|
+
}>
|
|
1636
|
+
) => {
|
|
1545
1637
|
// Get an array of the entries in the map using the spread operator
|
|
1546
1638
|
const entries = [...edits].reverse();
|
|
1547
1639
|
|
|
@@ -1549,23 +1641,20 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1549
1641
|
|
|
1550
1642
|
// Iterate over the array in reverse order
|
|
1551
1643
|
entries.forEach(({ endIndex, replacement, startIndex, user }) => {
|
|
1552
|
-
|
|
1553
1644
|
let pre = _plainString.substring(0, startIndex);
|
|
1554
1645
|
let post = _plainString.substring(endIndex);
|
|
1555
1646
|
|
|
1556
1647
|
_plainString = pre + replacement + post;
|
|
1557
|
-
|
|
1558
1648
|
});
|
|
1559
1649
|
|
|
1560
1650
|
return _plainString;
|
|
1561
|
-
|
|
1562
|
-
}
|
|
1651
|
+
};
|
|
1563
1652
|
|
|
1564
1653
|
const textChangeHandler = (txt: string) => {
|
|
1565
1654
|
let removing = plainTextInput.current.length > txt.length;
|
|
1566
1655
|
let adding = plainTextInput.current.length < txt.length;
|
|
1567
1656
|
let textDiff = txt.length - plainTextInput.current.length;
|
|
1568
|
-
let notAtLast =
|
|
1657
|
+
let notAtLast = selectionPosition.start + textDiff < txt.length;
|
|
1569
1658
|
|
|
1570
1659
|
plainTextInput.current = txt;
|
|
1571
1660
|
onChangeText && onChangeText(txt);
|
|
@@ -1576,19 +1665,30 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1576
1665
|
let newMentionMap = new Map(mentionMap.current);
|
|
1577
1666
|
|
|
1578
1667
|
mentionMap.current.forEach((value, key) => {
|
|
1579
|
-
let position = {
|
|
1668
|
+
let position = {
|
|
1669
|
+
start: parseInt(key.split('_')[0]),
|
|
1670
|
+
end: parseInt(key.split('_')[1]),
|
|
1671
|
+
};
|
|
1580
1672
|
|
|
1581
1673
|
//Runs when cursor before the mention and before the last position
|
|
1582
1674
|
|
|
1583
|
-
if (
|
|
1584
|
-
|
|
1585
|
-
|
|
1675
|
+
if (
|
|
1676
|
+
notAtLast &&
|
|
1677
|
+
(selectionPosition.start - 1 <= position.start ||
|
|
1678
|
+
selectionPosition.start - textDiff <= position.start)
|
|
1679
|
+
) {
|
|
1586
1680
|
if (removing) {
|
|
1587
|
-
decr =
|
|
1588
|
-
position = {
|
|
1681
|
+
decr = selectionPosition.end - selectionPosition.start - textDiff;
|
|
1682
|
+
position = {
|
|
1683
|
+
start: position.start - decr,
|
|
1684
|
+
end: position.end - decr,
|
|
1685
|
+
};
|
|
1589
1686
|
} else if (adding) {
|
|
1590
|
-
decr =
|
|
1591
|
-
position = {
|
|
1687
|
+
decr = selectionPosition.end - selectionPosition.start + textDiff;
|
|
1688
|
+
position = {
|
|
1689
|
+
start: position.start + decr,
|
|
1690
|
+
end: position.end + decr,
|
|
1691
|
+
};
|
|
1592
1692
|
}
|
|
1593
1693
|
if (removing || adding) {
|
|
1594
1694
|
let newKey = `${position.start}_${position.end}`;
|
|
@@ -1598,30 +1698,36 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1598
1698
|
}
|
|
1599
1699
|
|
|
1600
1700
|
// Code to delete mention from hashmap 👇
|
|
1601
|
-
let expctedMentionPos = plainTextInput.current.substring(
|
|
1701
|
+
let expctedMentionPos = plainTextInput.current.substring(
|
|
1702
|
+
position.start,
|
|
1703
|
+
position.end
|
|
1704
|
+
);
|
|
1602
1705
|
|
|
1603
1706
|
if (expctedMentionPos !== `${value.promptText}`) {
|
|
1604
1707
|
let newKey = `${position.start}_${position.end}`;
|
|
1605
1708
|
newMentionMap.delete(newKey);
|
|
1606
1709
|
|
|
1607
1710
|
if (!ifIdExists(value.id, newMentionMap)) {
|
|
1608
|
-
let targetedFormatter: any = allFormatters.current.get(
|
|
1711
|
+
let targetedFormatter: any = allFormatters.current.get(
|
|
1712
|
+
value.trackingCharacter
|
|
1713
|
+
);
|
|
1609
1714
|
let existingCCUsers = [...targetedFormatter.getSuggestionItems()];
|
|
1610
|
-
let userPosition = existingCCUsers.findIndex(
|
|
1715
|
+
let userPosition = existingCCUsers.findIndex(
|
|
1716
|
+
(item: SuggestionItem) => item.id === value.id
|
|
1717
|
+
);
|
|
1611
1718
|
if (userPosition !== -1) {
|
|
1612
1719
|
existingCCUsers.splice(userPosition, 1);
|
|
1613
|
-
(
|
|
1720
|
+
(
|
|
1721
|
+
targetedFormatter as CometChatMentionsFormatter
|
|
1722
|
+
).setSuggestionItems(existingCCUsers);
|
|
1614
1723
|
}
|
|
1615
1724
|
}
|
|
1616
|
-
|
|
1617
1725
|
}
|
|
1618
|
-
|
|
1619
1726
|
});
|
|
1620
1727
|
|
|
1621
1728
|
mentionMap.current = newMentionMap;
|
|
1622
1729
|
|
|
1623
1730
|
setFormattedInputMessage();
|
|
1624
|
-
|
|
1625
1731
|
};
|
|
1626
1732
|
|
|
1627
1733
|
const onMentionPress = (item: SuggestionItem) => {
|
|
@@ -1630,61 +1736,88 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1630
1736
|
|
|
1631
1737
|
let notAtLast = selectionPosition.start < plainTextInput.current.length;
|
|
1632
1738
|
|
|
1633
|
-
let textDiff =
|
|
1739
|
+
let textDiff =
|
|
1740
|
+
plainTextInput.current.length +
|
|
1741
|
+
item.promptText.length -
|
|
1742
|
+
searchStringRef.current.length -
|
|
1743
|
+
plainTextInput.current.length;
|
|
1634
1744
|
|
|
1635
1745
|
let incr = 0;
|
|
1636
1746
|
let mentionPos = 0;
|
|
1637
1747
|
|
|
1638
1748
|
let newMentionMap = new Map(mentionMap.current);
|
|
1639
1749
|
|
|
1640
|
-
let targetedFormatter: any = allFormatters.current.get(
|
|
1750
|
+
let targetedFormatter: any = allFormatters.current.get(
|
|
1751
|
+
activeCharacter.current
|
|
1752
|
+
);
|
|
1641
1753
|
|
|
1642
1754
|
let existingCCUsers = [...targetedFormatter.getSuggestionItems()];
|
|
1643
|
-
let userAlreadyExists = existingCCUsers.find(
|
|
1755
|
+
let userAlreadyExists = existingCCUsers.find(
|
|
1756
|
+
(existingUser: SuggestionItem) => existingUser.id === item.id
|
|
1757
|
+
);
|
|
1644
1758
|
if (!userAlreadyExists) {
|
|
1645
1759
|
let cometchatUIUserArray: Array<SuggestionItem> = [...existingCCUsers];
|
|
1646
1760
|
cometchatUIUserArray.push(item);
|
|
1647
|
-
(targetedFormatter as CometChatMentionsFormatter).setSuggestionItems(
|
|
1761
|
+
(targetedFormatter as CometChatMentionsFormatter).setSuggestionItems(
|
|
1762
|
+
cometchatUIUserArray
|
|
1763
|
+
);
|
|
1648
1764
|
}
|
|
1649
1765
|
mentionMap.current.forEach((value, key) => {
|
|
1650
|
-
let position = {
|
|
1766
|
+
let position = {
|
|
1767
|
+
start: parseInt(key.split('_')[0]),
|
|
1768
|
+
end: parseInt(key.split('_')[1]),
|
|
1769
|
+
};
|
|
1651
1770
|
|
|
1652
1771
|
if (!(selectionPosition.start <= position.start)) {
|
|
1653
1772
|
mentionPos += 1;
|
|
1654
1773
|
}
|
|
1655
1774
|
|
|
1656
1775
|
// Code to delete mention from hashmap 👇
|
|
1657
|
-
if (
|
|
1776
|
+
if (
|
|
1777
|
+
position.end === selectionPosition.end ||
|
|
1778
|
+
(selectionPosition.start > position.start &&
|
|
1779
|
+
selectionPosition.end <= position.end)
|
|
1780
|
+
) {
|
|
1658
1781
|
let newKey = `${position.start}_${position.end}`;
|
|
1659
1782
|
newMentionMap.delete(newKey);
|
|
1660
|
-
mentionPos -= 1
|
|
1783
|
+
mentionPos -= 1;
|
|
1661
1784
|
}
|
|
1662
1785
|
|
|
1663
|
-
if (notAtLast &&
|
|
1664
|
-
incr =
|
|
1665
|
-
let newKey = `${
|
|
1786
|
+
if (notAtLast && selectionPosition.start - 1 <= position.start) {
|
|
1787
|
+
incr = selectionPosition.end - selectionPosition.start + textDiff;
|
|
1788
|
+
let newKey = `${position.start + incr}_${position.end + incr}`;
|
|
1666
1789
|
newMentionMap.set(newKey, value);
|
|
1667
1790
|
newMentionMap.delete(key);
|
|
1668
1791
|
}
|
|
1669
|
-
|
|
1670
1792
|
});
|
|
1671
1793
|
mentionMap.current = newMentionMap;
|
|
1672
1794
|
|
|
1673
1795
|
// When updating the input text, just get the latest plain text input and replace the selected text with the new mention
|
|
1674
|
-
const updatedPlainTextInput = `${plainTextInput.current.substring(
|
|
1675
|
-
|
|
1796
|
+
const updatedPlainTextInput = `${plainTextInput.current.substring(
|
|
1797
|
+
0,
|
|
1798
|
+
selectionPosition.start - (1 + searchStringRef.current.length)
|
|
1799
|
+
)}${item.promptText + ' '}${plainTextInput.current.substring(
|
|
1800
|
+
selectionPosition.end,
|
|
1676
1801
|
plainTextInput.current.length
|
|
1677
1802
|
)}`;
|
|
1678
1803
|
plainTextInput.current = updatedPlainTextInput;
|
|
1679
1804
|
|
|
1680
|
-
let key =
|
|
1681
|
-
|
|
1682
|
-
|
|
1805
|
+
let key =
|
|
1806
|
+
selectionPosition.start -
|
|
1807
|
+
(1 + searchStringRef.current.length) +
|
|
1808
|
+
'_' +
|
|
1809
|
+
(selectionPosition.start -
|
|
1810
|
+
(searchStringRef.current.length + 1) +
|
|
1811
|
+
item.promptText.length);
|
|
1812
|
+
|
|
1813
|
+
let updatedMap = insertMentionAt(mentionMap.current, mentionPos, key, {
|
|
1814
|
+
...item,
|
|
1815
|
+
trackingCharacter: activeCharacter.current,
|
|
1816
|
+
});
|
|
1683
1817
|
mentionMap.current = updatedMap;
|
|
1684
1818
|
|
|
1685
|
-
setFormattedInputMessage()
|
|
1686
|
-
|
|
1687
|
-
}
|
|
1819
|
+
setFormattedInputMessage();
|
|
1820
|
+
};
|
|
1688
1821
|
|
|
1689
1822
|
const setFormattedInputMessage = () => {
|
|
1690
1823
|
let textComponents: any = getRegexString(plainTextInput.current);
|
|
@@ -1692,11 +1825,11 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1692
1825
|
allFormatters.current.forEach((formatter, key) => {
|
|
1693
1826
|
let resp = formatter.getFormattedText(textComponents);
|
|
1694
1827
|
textComponents = resp;
|
|
1695
|
-
})
|
|
1828
|
+
});
|
|
1696
1829
|
|
|
1697
1830
|
inputValueRef.current = textComponents;
|
|
1698
1831
|
setInputMessage(textComponents);
|
|
1699
|
-
}
|
|
1832
|
+
};
|
|
1700
1833
|
|
|
1701
1834
|
function escapeRegExp(string: string) {
|
|
1702
1835
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -1706,16 +1839,20 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1706
1839
|
const leftText = inputText.substring(0, cursorPosition);
|
|
1707
1840
|
|
|
1708
1841
|
// Escape the mentionPrefixes to safely use them in a regex pattern
|
|
1709
|
-
const escapedPrefixes = trackingCharacters.current
|
|
1842
|
+
const escapedPrefixes = trackingCharacters.current
|
|
1843
|
+
.map(escapeRegExp)
|
|
1844
|
+
.join('|');
|
|
1710
1845
|
|
|
1711
1846
|
// Build a dynamic regex pattern that matches any of the mention prefixes.
|
|
1712
1847
|
// This pattern will match a prefix followed by any combination of word characters
|
|
1713
1848
|
// and spaces, including a trailing space.
|
|
1714
|
-
const mentionRegex = new RegExp(
|
|
1849
|
+
const mentionRegex = new RegExp(
|
|
1850
|
+
`(?:^|\\s)(${escapedPrefixes})([^${escapedPrefixes}\\s][^${escapedPrefixes}]*)$`
|
|
1851
|
+
);
|
|
1715
1852
|
const match = leftText.match(mentionRegex);
|
|
1716
1853
|
|
|
1717
1854
|
// If a match is found, return the first capturing group, which is the username
|
|
1718
|
-
return match && substringUpToNthSpace(match[2], 4) ||
|
|
1855
|
+
return (match && substringUpToNthSpace(match[2], 4)) || '';
|
|
1719
1856
|
}
|
|
1720
1857
|
|
|
1721
1858
|
function substringUpToNthSpace(str: string, n: number) {
|
|
@@ -1723,7 +1860,12 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1723
1860
|
return str.split(' ', n).join(' ');
|
|
1724
1861
|
}
|
|
1725
1862
|
|
|
1726
|
-
const insertMentionAt = (
|
|
1863
|
+
const insertMentionAt = (
|
|
1864
|
+
mentionMap: Map<string, SuggestionItem>,
|
|
1865
|
+
insertAt: number,
|
|
1866
|
+
key: string,
|
|
1867
|
+
value: SuggestionItem
|
|
1868
|
+
): Map<string, SuggestionItem> => {
|
|
1727
1869
|
// Convert the hashmap to an array of [key, value] pairs
|
|
1728
1870
|
let mentionsArray = Array.from(mentionMap);
|
|
1729
1871
|
|
|
@@ -1731,12 +1873,11 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1731
1873
|
mentionsArray.splice(insertAt, 0, [key, value]);
|
|
1732
1874
|
|
|
1733
1875
|
return new Map(mentionsArray);
|
|
1734
|
-
|
|
1735
|
-
}
|
|
1876
|
+
};
|
|
1736
1877
|
|
|
1737
1878
|
/**
|
|
1738
1879
|
* Function to check if the id exists in the mentionMap
|
|
1739
|
-
|
|
1880
|
+
*/
|
|
1740
1881
|
const ifIdExists = (id: string, hashmap: Map<string, SuggestionItem>) => {
|
|
1741
1882
|
let exists = false;
|
|
1742
1883
|
hashmap.forEach((value, key) => {
|
|
@@ -1745,53 +1886,75 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1745
1886
|
}
|
|
1746
1887
|
});
|
|
1747
1888
|
return exists;
|
|
1748
|
-
}
|
|
1889
|
+
};
|
|
1749
1890
|
|
|
1750
1891
|
const onSuggestionListEndReached = () => {
|
|
1751
|
-
let targetedFormatter = allFormatters.current.get(
|
|
1892
|
+
let targetedFormatter = allFormatters.current.get(
|
|
1893
|
+
activeCharacter.current
|
|
1894
|
+
);
|
|
1752
1895
|
if (!targetedFormatter) return;
|
|
1753
1896
|
let fetchingNext = targetedFormatter.fetchNext();
|
|
1754
1897
|
fetchingNext !== null && setSuggestionListLoader(true);
|
|
1755
|
-
}
|
|
1898
|
+
};
|
|
1756
1899
|
|
|
1757
1900
|
const getMentionLimitView = () => {
|
|
1758
|
-
let targetedFormatter: any = allFormatters.current.get(
|
|
1901
|
+
let targetedFormatter: any = allFormatters.current.get(
|
|
1902
|
+
activeCharacter.current
|
|
1903
|
+
);
|
|
1759
1904
|
let shouldWarn;
|
|
1760
1905
|
let limit;
|
|
1761
1906
|
if (targetedFormatter?.getLimit && targetedFormatter?.getLimit()) {
|
|
1762
1907
|
limit = targetedFormatter?.getLimit();
|
|
1763
|
-
if (
|
|
1908
|
+
if (
|
|
1909
|
+
targetedFormatter.getUniqueUsersList &&
|
|
1910
|
+
targetedFormatter.getUniqueUsersList()?.size >= limit
|
|
1911
|
+
) {
|
|
1764
1912
|
shouldWarn = true;
|
|
1765
1913
|
}
|
|
1766
1914
|
}
|
|
1767
1915
|
if (!shouldWarn) return null;
|
|
1768
|
-
let errorString = targetedFormatter?.getErrorString
|
|
1916
|
+
let errorString = targetedFormatter?.getErrorString
|
|
1917
|
+
? targetedFormatter?.getErrorString()
|
|
1918
|
+
: `${localize('MENTION_UPTO')} ${limit} ${
|
|
1919
|
+
limit === 1 ? localize('TIME') : localize('TIMES')
|
|
1920
|
+
} ${localize('AT_A_TIME')}.`;
|
|
1769
1921
|
return (
|
|
1770
|
-
<View
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1922
|
+
<View
|
|
1923
|
+
style={{
|
|
1924
|
+
flexDirection: 'row',
|
|
1925
|
+
alignItems: 'center',
|
|
1926
|
+
paddingTop: 5,
|
|
1927
|
+
paddingLeft: 5,
|
|
1928
|
+
borderTopWidth: 1,
|
|
1929
|
+
borderTopColor: theme.palette.getAccent300(),
|
|
1930
|
+
}}
|
|
1931
|
+
>
|
|
1932
|
+
<Image
|
|
1933
|
+
style={{
|
|
1934
|
+
tintColor: theme.palette.getAccent500(),
|
|
1935
|
+
height: 20,
|
|
1936
|
+
width: 20,
|
|
1937
|
+
}}
|
|
1938
|
+
source={ICONS.INFO}
|
|
1939
|
+
/>
|
|
1940
|
+
<Text
|
|
1941
|
+
style={
|
|
1942
|
+
{
|
|
1943
|
+
marginLeft: 5,
|
|
1944
|
+
color: theme.palette.getAccent500(),
|
|
1945
|
+
...theme.typography.text1,
|
|
1946
|
+
} as TextStyle
|
|
1947
|
+
}
|
|
1948
|
+
>
|
|
1949
|
+
{errorString}
|
|
1950
|
+
</Text>
|
|
1788
1951
|
</View>
|
|
1789
|
-
)
|
|
1790
|
-
}
|
|
1952
|
+
);
|
|
1953
|
+
};
|
|
1791
1954
|
|
|
1792
1955
|
return (
|
|
1793
1956
|
<>
|
|
1794
|
-
{!isVisible && typeof CustomView ===
|
|
1957
|
+
{!isVisible && typeof CustomView === 'function' && <CustomView />}
|
|
1795
1958
|
<Modal
|
|
1796
1959
|
animationType="slide"
|
|
1797
1960
|
visible={isVisible}
|
|
@@ -1809,25 +1972,33 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1809
1972
|
{...keyboardAvoidingViewProps}
|
|
1810
1973
|
>
|
|
1811
1974
|
<View
|
|
1812
|
-
style={
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1975
|
+
style={
|
|
1976
|
+
[
|
|
1977
|
+
Style.container,
|
|
1978
|
+
{
|
|
1979
|
+
paddingTop: CustomViewHeader ? 0 : 8,
|
|
1980
|
+
},
|
|
1981
|
+
messageComposerStyle,
|
|
1982
|
+
] as ViewProps
|
|
1983
|
+
}
|
|
1819
1984
|
>
|
|
1820
1985
|
<EmojiBoard
|
|
1821
1986
|
hideSearch={true}
|
|
1822
1987
|
shouldShow={showEmojiboard}
|
|
1823
1988
|
onClose={() => setShowEmojiboard(false)}
|
|
1824
1989
|
emojiSelection={(emoji: any) => {
|
|
1825
|
-
let pre = plainTextInput.current.substring(
|
|
1990
|
+
let pre = plainTextInput.current.substring(
|
|
1991
|
+
0,
|
|
1992
|
+
selectionPosition.start
|
|
1993
|
+
);
|
|
1826
1994
|
let post = plainTextInput.current.substring(
|
|
1827
1995
|
selectionPosition.end,
|
|
1828
1996
|
plainTextInput.current.length
|
|
1829
1997
|
);
|
|
1830
|
-
inputValueRef.current =
|
|
1998
|
+
inputValueRef.current =
|
|
1999
|
+
selectionPosition.start && selectionPosition.end
|
|
2000
|
+
? `${pre}${emoji}${post}`
|
|
2001
|
+
: `${inputValueRef.current}${emoji}`;
|
|
1831
2002
|
setInputMessage((prev) =>
|
|
1832
2003
|
selectionPosition.start && selectionPosition.end
|
|
1833
2004
|
? `${pre}${emoji}${post}`
|
|
@@ -1845,21 +2016,22 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1845
2016
|
// ...getActionSheetStyle(),
|
|
1846
2017
|
...(messageComposerStyle?.actionSheetSeparatorTint
|
|
1847
2018
|
? {
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
2019
|
+
actionSheetSeparatorTint:
|
|
2020
|
+
messageComposerStyle.actionSheetSeparatorTint,
|
|
2021
|
+
}
|
|
1851
2022
|
: {}),
|
|
1852
|
-
layoutModeIconTint:
|
|
2023
|
+
layoutModeIconTint:
|
|
2024
|
+
messageComposerStyle?.actionSheetLayoutModeIconTint,
|
|
1853
2025
|
titleColor: messageComposerStyle?.actionSheetTitleColor,
|
|
1854
2026
|
listItemIconTint: messageComposerStyle?.attachIconTint,
|
|
1855
|
-
listItemTitleFont: messageComposerStyle?.actionSheetTitleFont
|
|
2027
|
+
listItemTitleFont: messageComposerStyle?.actionSheetTitleFont,
|
|
1856
2028
|
}}
|
|
1857
2029
|
cometChatBottomSheetStyle={
|
|
1858
2030
|
messageComposerStyle?.actionSheetCancelButtonIconTint
|
|
1859
2031
|
? {
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
2032
|
+
lineColor:
|
|
2033
|
+
messageComposerStyle.actionSheetCancelButtonIconTint,
|
|
2034
|
+
}
|
|
1863
2035
|
: {}
|
|
1864
2036
|
}
|
|
1865
2037
|
/>
|
|
@@ -1868,15 +2040,15 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1868
2040
|
options={actionSheetItems}
|
|
1869
2041
|
shouldShow={showRecordAudio}
|
|
1870
2042
|
onClose={() => {
|
|
1871
|
-
setShowRecordAudio(false)
|
|
2043
|
+
setShowRecordAudio(false);
|
|
1872
2044
|
}}
|
|
1873
2045
|
onSend={_sendRecordedAudio}
|
|
1874
2046
|
cometChatBottomSheetStyle={
|
|
1875
2047
|
messageComposerStyle?.actionSheetCancelButtonIconTint
|
|
1876
2048
|
? {
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
2049
|
+
lineColor:
|
|
2050
|
+
messageComposerStyle.actionSheetCancelButtonIconTint,
|
|
2051
|
+
}
|
|
1880
2052
|
: {}
|
|
1881
2053
|
}
|
|
1882
2054
|
mediaRecorderStyle={mediaRecorderStyle}
|
|
@@ -1891,38 +2063,44 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1891
2063
|
sheetRef={bottomSheetRef}
|
|
1892
2064
|
shouldShow={showAIOptions}
|
|
1893
2065
|
onClose={() => {
|
|
1894
|
-
setShowAIOptions(false)
|
|
2066
|
+
setShowAIOptions(false);
|
|
1895
2067
|
}}
|
|
1896
2068
|
aiOptions={AIOptionItems}
|
|
1897
2069
|
aiStyle={AIStyles}
|
|
1898
2070
|
/>
|
|
1899
2071
|
|
|
1900
|
-
{
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
height: 33, width: 33,
|
|
1913
|
-
}}
|
|
1914
|
-
listItemStyle={{
|
|
1915
|
-
height: 50,
|
|
2072
|
+
{mentionsSearchData.length > 0 &&
|
|
2073
|
+
plainTextInput.current.length > 0 && (
|
|
2074
|
+
<View
|
|
2075
|
+
style={{
|
|
2076
|
+
borderTopWidth: 1,
|
|
2077
|
+
borderColor: theme.palette.getAccent300(),
|
|
2078
|
+
paddingVertical: 5,
|
|
2079
|
+
paddingHorizontal: 0,
|
|
2080
|
+
maxHeight: Dimensions.get('window').height * 0.22,
|
|
2081
|
+
justifyContent: 'flex-end',
|
|
2082
|
+
paddingBottom: messagePreview !== null ? 60 : undefined,
|
|
2083
|
+
zIndex: 1,
|
|
1916
2084
|
}}
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
2085
|
+
>
|
|
2086
|
+
<CometChatSuggestionList
|
|
2087
|
+
data={mentionsSearchData}
|
|
2088
|
+
avatarStyle={{
|
|
2089
|
+
height: 33,
|
|
2090
|
+
width: 33,
|
|
2091
|
+
}}
|
|
2092
|
+
listItemStyle={{
|
|
2093
|
+
height: 50,
|
|
2094
|
+
}}
|
|
2095
|
+
separatorColor={theme.palette.getAccent100()}
|
|
2096
|
+
onPress={onMentionPress}
|
|
2097
|
+
onEndReached={onSuggestionListEndReached}
|
|
2098
|
+
loading={suggestionListLoader}
|
|
2099
|
+
theme={theme}
|
|
2100
|
+
/>
|
|
2101
|
+
{getMentionLimitView()}
|
|
2102
|
+
</View>
|
|
2103
|
+
)}
|
|
1926
2104
|
|
|
1927
2105
|
{HeaderView ? (
|
|
1928
2106
|
<HeaderView />
|
|
@@ -1935,17 +2113,16 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1935
2113
|
text={messagePreview?.message?.text}
|
|
1936
2114
|
shouldShow={messagePreview != null}
|
|
1937
2115
|
/>
|
|
1938
|
-
</View
|
|
2116
|
+
</View>
|
|
1939
2117
|
<CometChatMessageInput
|
|
1940
2118
|
messageInputRef={messageInputRef}
|
|
1941
2119
|
text={inputMessage as string}
|
|
1942
2120
|
placeHolderText={placeHolderText}
|
|
1943
2121
|
style={messageComposerStyle}
|
|
1944
2122
|
onSelectionChange={({ nativeEvent: { selection } }) => {
|
|
1945
|
-
setSelectionPosition(selection)
|
|
1946
|
-
openList(selection)
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
2123
|
+
setSelectionPosition(selection);
|
|
2124
|
+
openList(selection);
|
|
2125
|
+
}}
|
|
1949
2126
|
maxHeight={maxHeight ?? undefined}
|
|
1950
2127
|
onChangeText={textChangeHandler}
|
|
1951
2128
|
SecondaryButtonView={SecondaryButtonViewElem}
|
|
@@ -1966,14 +2143,3 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1966
2143
|
);
|
|
1967
2144
|
}
|
|
1968
2145
|
);
|
|
1969
|
-
|
|
1970
|
-
CometChatMessageComposer.defaultProps = {
|
|
1971
|
-
user: undefined,
|
|
1972
|
-
group: undefined,
|
|
1973
|
-
// style: new MessageComposerStyle({}),
|
|
1974
|
-
attachmentIcon: ICONS.ADD,
|
|
1975
|
-
liveReactionIcon: ICONS.HEART,
|
|
1976
|
-
hideLiveReaction: true,
|
|
1977
|
-
disableSoundForMessages: true,
|
|
1978
|
-
messageComposerStyle: {},
|
|
1979
|
-
};
|