@cometchat/chat-uikit-react-native 5.5.1 → 5.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +23 -89
- package/android/gradle.properties +5 -5
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatSoundModule.java +5 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +52 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +17 -4
- package/ios/FileManager.m +77 -3
- package/ios/RichTextEditorView.swift +9 -1
- package/package.json +4 -4
- package/react-native-cometchat-ui-kit.podspec +5 -19
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +31 -27
- package/src/CometChatConversations/CometChatConversations.tsx +4 -0
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +35 -28
- package/src/CometChatMessageList/CometChatMessageList.tsx +20 -18
- package/src/CometChatRichTextEditor/index.tsx +2 -1
- package/src/CometChatSearch/CometChatSearch.tsx +10 -5
- package/src/calls/CometChatOngoingCall/CometChatOngoingCall.tsx +56 -17
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +12 -9
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +13 -10
- package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +34 -27
- package/src/extensions/Polls/Polls.tsx +7 -7
- package/src/extensions/Polls/PollsBubble.tsx +2 -2
- package/src/globals.d.ts +6 -0
- package/src/shared/constants/textPatterns.ts +20 -2
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +22 -11
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +26 -14
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +8 -0
- package/src/shared/formatters/codeElements.ts +21 -0
- package/src/shared/helper/types/index.ts +5 -0
- package/src/shared/libs/ImageZoom/ReactNativeZoomableView.tsx +4 -4
- package/src/shared/libs/ImageZoom/types/index.ts +2 -0
- package/src/shared/resources/CometChatSoundManager/sound.js +2 -3
- package/src/shared/services/UploadQueueService.ts +7 -0
- package/src/shared/utils/CometChatMessageHelper/index.ts +3 -0
- package/src/shared/utils/MarkdownUtils.ts +11 -4
- package/src/shared/utils/MessageUtils.tsx +7 -5
- package/src/shared/utils/groupMemberAddedRows.ts +28 -0
- package/src/shared/utils/linkPreviewSelection.ts +109 -0
- package/src/shared/utils/mentionTokens.ts +77 -0
- package/src/shared/utils/runAfterInteractions.ts +26 -0
- package/src/shared/utils/stripRichText.ts +2 -1
- package/src/shared/utils/tapGesture.ts +23 -0
- package/src/shared/utils/videoThumbnail.ts +74 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +21 -13
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +13 -15
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +1 -1
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +2 -1
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +2 -1
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +3 -26
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +4 -2
- package/src/shared/views/CometChatList/Header.tsx +1 -1
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +2 -1
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +28 -8
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -4
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +36 -4
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +2 -1
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +57 -30
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
- package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +0 -313
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
|
@@ -16,11 +16,29 @@ export const wordBoundary = {
|
|
|
16
16
|
export const emailPattern =
|
|
17
17
|
wordBoundary.start + `[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}` + wordBoundary.end;
|
|
18
18
|
|
|
19
|
+
// A URL character, excluding parentheses — those only count in balanced pairs (below).
|
|
20
|
+
const urlChar = `[-\\w;/?:@&=+$\\|\\_.!~*\\|'\\[\\]%#,☺]`;
|
|
21
|
+
const urlParens = `\\(${urlChar}*\\)`;
|
|
22
|
+
// A URL path: ends on a word char, `/`, `#`, or a balanced `(…)`. A lone `)` could never be the
|
|
23
|
+
// last character, so https://en.wikipedia.org/wiki/Mercury_(planet) linked without its `)` and
|
|
24
|
+
// opened a page that does not exist — while "(see https://example.com/page)" must still leave
|
|
25
|
+
// the sentence's own `)` outside the link. Balanced pairs satisfy both.
|
|
26
|
+
const urlPath = `(?:${urlChar}|${urlParens})*(?:[\\w/#]|${urlParens})`;
|
|
27
|
+
|
|
19
28
|
export const urlPattern =
|
|
20
|
-
`((https?://|ftp://|www\\.|pic\\.)
|
|
21
|
-
`|[a-zA-Z][a-zA-Z0-9]*[-a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\\.[a-zA-Z]{2,}(?:[:/]
|
|
29
|
+
`((https?://|ftp://|www\\.|pic\\.)${urlPath}` +
|
|
30
|
+
`|[a-zA-Z][a-zA-Z0-9]*[-a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\\.[a-zA-Z]{2,}(?:[:/]${urlPath})?)` +
|
|
22
31
|
wordBoundary.end;
|
|
23
32
|
|
|
33
|
+
/**
|
|
34
|
+
* A markdown link `[label](address)`. Group 1 is the label, group 2 the address.
|
|
35
|
+
*
|
|
36
|
+
* The address may contain one level of balanced parentheses, so a Wikipedia-style
|
|
37
|
+
* `[Mercury](https://en.wikipedia.org/wiki/Mercury_(planet))` keeps its `(planet)` and only the
|
|
38
|
+
* final `)` closes the link. The old `[^)]+` stopped at the first `)`, opening `…Mercury_(planet`.
|
|
39
|
+
*/
|
|
40
|
+
export const markdownLinkPattern = `\\[([^\\]]+)\\]\\(((?:[^()]|\\([^()]*\\))+)\\)`;
|
|
41
|
+
|
|
24
42
|
export const phoneNumPattern =
|
|
25
43
|
wordBoundary.start +
|
|
26
44
|
`(?:\\+?(\\d{1,3}))?([-. (]*(\\d{3})[-. )]*)?((\\d{3})[-. ]*(\\d{2,4})(?:[-.x ]*(\\d+))?)` +
|
|
@@ -12,6 +12,7 @@ import { SuggestionItem } from "../../views/CometChatSuggestionList";
|
|
|
12
12
|
import { CometChatTextFormatter } from "../CometChatTextFormatter";
|
|
13
13
|
import { CometChatTheme } from "../../../theme/type";
|
|
14
14
|
import { deepMerge } from "../../helper/helperFunctions";
|
|
15
|
+
import { unescapeTypedMentionTokensInTree } from "../../utils/mentionTokens";
|
|
15
16
|
import { getCometChatTranslation } from "../../resources/CometChatLocalizeNew/LocalizationManager";
|
|
16
17
|
|
|
17
18
|
const t = getCometChatTranslation();
|
|
@@ -544,7 +545,8 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
|
|
|
544
545
|
return "";
|
|
545
546
|
}
|
|
546
547
|
let formattedText = this.addMentionsView(inputText, textStyle);
|
|
547
|
-
|
|
548
|
+
// Only now, with every real mention resolved, may escaped typed text read as `<@all:…>`.
|
|
549
|
+
return unescapeTypedMentionTokensInTree(formattedText);
|
|
548
550
|
}
|
|
549
551
|
|
|
550
552
|
temp!: Function;
|
|
@@ -604,8 +606,10 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
|
|
|
604
606
|
segments.push(inputText.slice(lastIndex, match.index));
|
|
605
607
|
}
|
|
606
608
|
|
|
607
|
-
// Add
|
|
608
|
-
|
|
609
|
+
// Add the whole token; it is resolved to its id below. Pushing only the id rendered an
|
|
610
|
+
// unresolved `<@uid:someone>` as just "someone", and let plain text that happened to
|
|
611
|
+
// equal a mentioned uid become a chip.
|
|
612
|
+
segments.push(match[0]);
|
|
609
613
|
|
|
610
614
|
// Update lastIndex
|
|
611
615
|
lastIndex = match.index + match[0].length;
|
|
@@ -618,12 +622,19 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
|
|
|
618
622
|
|
|
619
623
|
// Now create an array of JSX elements from the segments
|
|
620
624
|
const elements = segments.map((segment, index) => {
|
|
621
|
-
//
|
|
622
|
-
|
|
625
|
+
// A token segment resolves to its id; anything else is plain text.
|
|
626
|
+
const token = /^<@(?:uid|all):(.*?)>$/.exec(segment);
|
|
627
|
+
const id = token ? token[1] : undefined;
|
|
628
|
+
// `<@all:x>` resolves only to an @all alias and `<@uid:x>` only to a user.
|
|
629
|
+
if (
|
|
630
|
+
id !== undefined &&
|
|
631
|
+
userRegistry.hasOwnProperty(id) &&
|
|
632
|
+
aliasIdSet.has(id) === segment.startsWith("<@all:")
|
|
633
|
+
) {
|
|
623
634
|
let _loggedInUser = this.loggedInUser || CometChatUIKit.loggedInUser;
|
|
624
635
|
|
|
625
|
-
const isAlias = aliasIdSet.has(
|
|
626
|
-
const isSelf = isAlias || _loggedInUser?.getUid() ===
|
|
636
|
+
const isAlias = aliasIdSet.has(id);
|
|
637
|
+
const isSelf = isAlias || _loggedInUser?.getUid() === id;
|
|
627
638
|
|
|
628
639
|
const isOutgoing =
|
|
629
640
|
this.messageObject?.getSender()?.getUid() === _loggedInUser?.getUid();
|
|
@@ -636,7 +647,7 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
|
|
|
636
647
|
|
|
637
648
|
let onPressProp =
|
|
638
649
|
this.temp && !isAlias
|
|
639
|
-
? { onPress: (event: any) => this.onMentionClick(event,
|
|
650
|
+
? { onPress: (event: any) => this.onMentionClick(event, id) }
|
|
640
651
|
: {}; // still suppress click for alias
|
|
641
652
|
|
|
642
653
|
const mentionContainerStyle = backgroundColor ? {
|
|
@@ -648,20 +659,20 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
|
|
|
648
659
|
if (this.target === MentionsTargetElement.textbubble) {
|
|
649
660
|
return (
|
|
650
661
|
<Text suppressHighlighting={true} key={index} {...onPressProp} style={[textStyle, mentionContainerStyle]}>
|
|
651
|
-
{userRegistry[
|
|
662
|
+
{userRegistry[id]}
|
|
652
663
|
</Text>
|
|
653
664
|
);
|
|
654
665
|
}
|
|
655
666
|
|
|
656
667
|
return (
|
|
657
668
|
<Text suppressHighlighting={true} key={index} {...onPressProp} style={[textStyle, mentionContainerStyle]}>
|
|
658
|
-
{userRegistry[
|
|
669
|
+
{userRegistry[id]}
|
|
659
670
|
</Text>
|
|
660
671
|
);
|
|
661
672
|
} else {
|
|
662
673
|
// Handle group-wide alias formatting if present
|
|
663
674
|
const aliasItem = this.SuggestionItems.find(
|
|
664
|
-
(it) => it.underlyingText ===
|
|
675
|
+
(it) => token !== null && it.underlyingText === segment
|
|
665
676
|
);
|
|
666
677
|
if (aliasItem) {
|
|
667
678
|
const { textStyle: styleResolved, backgroundColor } = this.resolveStyle(true);
|
|
@@ -3,8 +3,9 @@ import React, { JSX } from "react";
|
|
|
3
3
|
import { Text, TextStyle, ViewStyle, Platform, Linking, View } from "react-native";
|
|
4
4
|
import { CometChatTextFormatter } from "../CometChatTextFormatter";
|
|
5
5
|
import { COLOR_OPEN_TAG, HEX_COLOR_REGEX, findColorTag, stripColorTags } from "../richTextWireFormat";
|
|
6
|
+
import { markCode } from "../codeElements";
|
|
6
7
|
import { isTextElement, isViewElement } from "../../utils/elementType";
|
|
7
|
-
import { urlPattern, emailPattern } from "../../constants/textPatterns";
|
|
8
|
+
import { urlPattern, emailPattern, markdownLinkPattern } from "../../constants/textPatterns";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Style configuration for rich text formatting
|
|
@@ -30,7 +31,9 @@ export interface RichTextStyle {
|
|
|
30
31
|
// Pre-compiled regex patterns — avoids recompilation on every call
|
|
31
32
|
const ORDERED_LIST_REGEX = /^(\d+)\.(?:\s(.*))?$/;
|
|
32
33
|
const ORDERED_LIST_DETECT_REGEX = /^\d+\.(\s|$)/;
|
|
33
|
-
const LINK_REGEX =
|
|
34
|
+
const LINK_REGEX = new RegExp(markdownLinkPattern);
|
|
35
|
+
// Global form, for stashing each half of every markdown link before URLs are stashed.
|
|
36
|
+
const LINK_REGEX_GLOBAL = new RegExp(markdownLinkPattern, "g");
|
|
34
37
|
const URL_PROTOCOL_REGEX = /^(https?|mailto|tel):/i;
|
|
35
38
|
// Patterns for detecting list items inside blockquote content (ENG-31998)
|
|
36
39
|
const QUOTE_BULLET_REGEX = /^- (.*)$/;
|
|
@@ -289,7 +292,7 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
289
292
|
style here — but it must never reach the reader as literal markup either.
|
|
290
293
|
Messages sent before the serializer fix still carry the token inside the
|
|
291
294
|
fence, so strip rather than render (ENG-38253). */}
|
|
292
|
-
<Text style={[this.style.codeBlockStyle]}>{stripColorTags(content)}</Text>
|
|
295
|
+
{markCode(<Text style={[this.style.codeBlockStyle]}>{stripColorTags(content)}</Text>)}
|
|
293
296
|
</View>
|
|
294
297
|
);
|
|
295
298
|
lineIndex++;
|
|
@@ -333,13 +336,15 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
333
336
|
this.style.codeBlockContainerStyle,
|
|
334
337
|
]}
|
|
335
338
|
>
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
339
|
+
{markCode(
|
|
340
|
+
<Text
|
|
341
|
+
style={[
|
|
342
|
+
this.style.codeBlockStyle,
|
|
343
|
+
]}
|
|
344
|
+
>
|
|
345
|
+
{stripColorTags(codeLines.join("\n"))}
|
|
346
|
+
</Text>
|
|
347
|
+
)}
|
|
343
348
|
</View>
|
|
344
349
|
);
|
|
345
350
|
if (lineIndex < lines.length) {
|
|
@@ -580,6 +585,13 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
580
585
|
};
|
|
581
586
|
let sanitized = text.replace(MENTION_PATTERN_REGEX, stash);
|
|
582
587
|
try {
|
|
588
|
+
// Markdown links first, one half at a time. The url pattern accepts `[ ] ( )`, so on a
|
|
589
|
+
// link whose label is itself an address — `[https://x/p](https://x/p)`, what a pasted or
|
|
590
|
+
// copied link is stored as — it matched `https://x/p](https://x/p` as ONE url. That hid
|
|
591
|
+
// the `](`, findLink never saw a link, and the bubble showed the raw markdown.
|
|
592
|
+
sanitized = sanitized.replace(LINK_REGEX_GLOBAL, (_m, label: string, url: string) =>
|
|
593
|
+
`[${label.replace(URL_PATTERN_REGEX, stash)}](${stash(url)})`
|
|
594
|
+
);
|
|
583
595
|
sanitized = sanitized.replace(EMAIL_PATTERN_REGEX, stash);
|
|
584
596
|
sanitized = sanitized.replace(URL_PATTERN_REGEX, stash);
|
|
585
597
|
} catch {
|
|
@@ -644,19 +656,19 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
644
656
|
// Use a single Text element (not View) so inline code stays on the
|
|
645
657
|
// same text baseline as surrounding content (mentions, plain text).
|
|
646
658
|
// Text supports backgroundColor, borderRadius, and padding in RN.
|
|
647
|
-
elements.push(
|
|
659
|
+
elements.push(markCode(
|
|
648
660
|
<Text key={`fmt-${keyCounter++}`} style={[this.style.inlineCodeContainerStyle, this.style.inlineCodeStyle]}>{innerContent}</Text>
|
|
649
|
-
);
|
|
661
|
+
));
|
|
650
662
|
} else if (match.type === "codeBlock") {
|
|
651
663
|
// Inline ```text``` — render identically to single-backtick inline code
|
|
652
664
|
// (compact pill with background, no block-level padding).
|
|
653
665
|
// Block-level code block rendering with View container is handled in renderMarkdown.
|
|
654
|
-
elements.push(
|
|
666
|
+
elements.push(markCode(
|
|
655
667
|
<Text
|
|
656
668
|
key={`fmt-${keyCounter++}`}
|
|
657
669
|
style={[this.style.inlineCodeContainerStyle, this.style.inlineCodeStyle]}
|
|
658
670
|
>{restoredContent}</Text>
|
|
659
|
-
);
|
|
671
|
+
));
|
|
660
672
|
} else if (match.type === "textColor" && match.color) {
|
|
661
673
|
// Re-validate at render time: the hex reaching here came off the wire, and an
|
|
662
674
|
// unparseable value must fall back to the base style rather than reach RN.
|
|
@@ -3,6 +3,7 @@ import React, { JSX } from "react";
|
|
|
3
3
|
import { ColorValue, Linking, Text, TextStyle } from "react-native";
|
|
4
4
|
import { emailPattern, phoneNumPattern, urlPattern } from "../../constants/UIKitConstants";
|
|
5
5
|
import { CometChatTextFormatter } from "../CometChatTextFormatter";
|
|
6
|
+
import { isCode } from "../codeElements";
|
|
6
7
|
|
|
7
8
|
export class CometChatUrlsFormatter extends CometChatTextFormatter {
|
|
8
9
|
protected style: {
|
|
@@ -117,6 +118,13 @@ export class CometChatUrlsFormatter extends CometChatTextFormatter {
|
|
|
117
118
|
return <Text>{str}</Text>;
|
|
118
119
|
} else if (React.isValidElement(str)) {
|
|
119
120
|
// str is a React element
|
|
121
|
+
if ((str as React.ReactElement<any>).props.onPress || isCode(str)) {
|
|
122
|
+
// Already a link (a markdown `[label](url)` from the rich-text formatter). Linkifying its
|
|
123
|
+
// label again nests a second link inside it, and the inner one wins the tap: the label
|
|
124
|
+
// of `[www.google.com](https://drive…)` opened google.com instead of the Drive address.
|
|
125
|
+
// Code is literal: an address inside `backticks` stays text.
|
|
126
|
+
return str;
|
|
127
|
+
}
|
|
120
128
|
if ((str as React.ReactElement<any>).props.children) {
|
|
121
129
|
// If the React element have children, we map over these children
|
|
122
130
|
// and call addMentionsSpan recursively for each child.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elements the rich-text formatter rendered as code (inline code and code blocks).
|
|
3
|
+
*
|
|
4
|
+
* Code is literal: `` `https://google.com` `` must stay monospace text, but the urls formatter,
|
|
5
|
+
* which runs after the rich-text formatter, walked into the code element and made the address
|
|
6
|
+
* a link anyway. The rich-text formatter marks what it renders as code; the urls formatter
|
|
7
|
+
* leaves marked elements alone.
|
|
8
|
+
*
|
|
9
|
+
* The mark is a prop, not a registry: it survives the `cloneElement` calls later formatters make,
|
|
10
|
+
* and it cannot be split across two copies of this module (a symlinked kit can be bundled twice).
|
|
11
|
+
* React Native only forwards a host component's known attributes, so the prop never reaches native.
|
|
12
|
+
*/
|
|
13
|
+
import React from "react";
|
|
14
|
+
|
|
15
|
+
const CODE_PROP = "ccRichTextCode";
|
|
16
|
+
|
|
17
|
+
export const markCode = (element: React.ReactElement<any>): React.ReactElement<any> =>
|
|
18
|
+
React.cloneElement(element, { [CODE_PROP]: true });
|
|
19
|
+
|
|
20
|
+
export const isCode = (element: unknown): boolean =>
|
|
21
|
+
React.isValidElement(element) && (element.props as any)?.[CODE_PROP] === true;
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
ImageSourcePropType,
|
|
6
6
|
ImageStyle,
|
|
7
7
|
ImageURISource,
|
|
8
|
+
StyleProp,
|
|
8
9
|
TextStyle,
|
|
9
10
|
ViewStyle,
|
|
10
11
|
} from "react-native";
|
|
@@ -38,6 +39,10 @@ type DoNotPartial =
|
|
|
38
39
|
| ViewStyle
|
|
39
40
|
| ImageURISource
|
|
40
41
|
| ImageStyle
|
|
42
|
+
// StyleProp is a recursive alias (ReadonlyArray<StyleProp<T>>); mapping over it never terminates
|
|
43
|
+
| StyleProp<TextStyle>
|
|
44
|
+
| StyleProp<ViewStyle>
|
|
45
|
+
| StyleProp<ImageStyle>
|
|
41
46
|
| ColorValue
|
|
42
47
|
| DimensionValue
|
|
43
48
|
| ImageSourcePropType
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
Animated,
|
|
4
4
|
Easing,
|
|
5
5
|
GestureResponderEvent,
|
|
6
|
-
InteractionManager,
|
|
7
6
|
PanResponder,
|
|
8
7
|
PanResponderGestureState,
|
|
9
8
|
StyleSheet,
|
|
@@ -18,6 +17,7 @@ import {
|
|
|
18
17
|
ZoomableViewEvent,
|
|
19
18
|
} from './types';
|
|
20
19
|
import { applyPanBoundariesToOffset, calcGestureTouchDistance, calcNewScaledOffsetForZoomCentering, getBoundaryCrossedAnim, getPanMomentumDecayAnim, getZoomToAnimation } from './helper';
|
|
20
|
+
import { runAfterInteractions } from "../../utils/runAfterInteractions";
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
const initialState = {
|
|
@@ -54,7 +54,7 @@ class ReactNativeZoomableView extends Component<
|
|
|
54
54
|
ReactNativeZoomableViewProps,
|
|
55
55
|
ReactNativeZoomableViewState
|
|
56
56
|
> {
|
|
57
|
-
zoomSubjectWrapperRef: RefObject<View | null>;
|
|
57
|
+
zoomSubjectWrapperRef: RefObject<React.ComponentRef<typeof View> | null>;
|
|
58
58
|
gestureHandlers: any;
|
|
59
59
|
doubleTapFirstTapReleaseTimestamp!: number | any;
|
|
60
60
|
|
|
@@ -152,7 +152,7 @@ class ReactNativeZoomableView extends Component<
|
|
|
152
152
|
this.props.onMoveShouldSetPanResponderCapture?.(evt, gestureState),
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
-
this.zoomSubjectWrapperRef = createRef<View
|
|
155
|
+
this.zoomSubjectWrapperRef = createRef<React.ComponentRef<typeof View>>();
|
|
156
156
|
|
|
157
157
|
if (this.props.zoomAnimatedValue)
|
|
158
158
|
this.zoomAnim = this.props.zoomAnimatedValue;
|
|
@@ -332,7 +332,7 @@ class ReactNativeZoomableView extends Component<
|
|
|
332
332
|
*/
|
|
333
333
|
private grabZoomSubjectOriginalMeasurements = () => {
|
|
334
334
|
// make sure we measure after animations are complete
|
|
335
|
-
|
|
335
|
+
runAfterInteractions(() => {
|
|
336
336
|
// this setTimeout is here to fix a weird issue on iOS where the measurements are all `0`
|
|
337
337
|
// when navigating back (react-navigation stack) from another view
|
|
338
338
|
// while closing the keyboard at the same time
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
1
2
|
import { Animated, GestureResponderEvent, PanResponderGestureState, ViewProps } from "react-native";
|
|
2
3
|
|
|
3
4
|
export enum SwipeDirection {
|
|
@@ -18,6 +19,7 @@ export interface ZoomableViewEvent {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export interface ReactNativeZoomableViewProps extends ViewProps {
|
|
22
|
+
children?: ReactNode;
|
|
21
23
|
// options
|
|
22
24
|
zoomEnabled?: boolean;
|
|
23
25
|
panEnabled?: boolean;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
1
|
+
import { Image, NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
2
|
const {CometChatSoundModule} = NativeModules ;
|
|
3
3
|
var IsAndroid = CometChatSoundModule.IsAndroid;
|
|
4
4
|
var IsWindows = CometChatSoundModule.IsWindows;
|
|
5
|
-
import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
|
|
6
5
|
var eventEmitter = new NativeEventEmitter(CometChatSoundModule);
|
|
7
6
|
|
|
8
7
|
var nextKey = 0;
|
|
@@ -36,7 +35,7 @@ function setAndroidVolumes(sound) {
|
|
|
36
35
|
|
|
37
36
|
class Sound {
|
|
38
37
|
constructor(filename, basePath, onError, options) {
|
|
39
|
-
var asset = resolveAssetSource(filename);
|
|
38
|
+
var asset = Image.resolveAssetSource(filename);
|
|
40
39
|
if (asset) {
|
|
41
40
|
this._filename = asset.uri;
|
|
42
41
|
onError = basePath;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CometChat } from '@cometchat/chat-sdk-react-native';
|
|
2
2
|
import { SelectedAttachment } from '../modals/SelectedAttachment';
|
|
3
|
+
import { linkUploadedVideo } from '../utils/videoThumbnail';
|
|
3
4
|
|
|
4
5
|
type CometChatException = InstanceType<typeof CometChat.CometChatException>;
|
|
5
6
|
|
|
@@ -52,6 +53,8 @@ export class UploadQueueService {
|
|
|
52
53
|
private request: CometChat.UploadFileRequest | null = null;
|
|
53
54
|
// Successes only — the set the send button reads. Keyed by tile id (== SDK fileId).
|
|
54
55
|
private completed = new Map<string, CometChat.Attachment>();
|
|
56
|
+
// Local uri of each enqueued VIDEO, so its upload can be linked to a local thumbnail.
|
|
57
|
+
private localVideoUris = new Map<string, string>();
|
|
55
58
|
|
|
56
59
|
// Kept for signature compatibility; the request API no longer exposes a presign buffer knob.
|
|
57
60
|
constructor(callbacks: UploadQueueCallbacks, _opts?: { presignBufferMs?: number }) {
|
|
@@ -63,6 +66,7 @@ export class UploadQueueService {
|
|
|
63
66
|
},
|
|
64
67
|
onFileUploaded: (fileId: string, att: CometChat.Attachment) => {
|
|
65
68
|
this.completed.set(fileId, att);
|
|
69
|
+
linkUploadedVideo(att?.getUrl?.(), this.localVideoUris.get(fileId));
|
|
66
70
|
this.callbacks.onFileComplete(fileId, att);
|
|
67
71
|
},
|
|
68
72
|
onFileFailure: (fileId: string, error: CometChatException) => {
|
|
@@ -94,6 +98,7 @@ export class UploadQueueService {
|
|
|
94
98
|
*/
|
|
95
99
|
enqueue(attachment: SelectedAttachment, target?: { receiver?: string; receiverType?: string }): void {
|
|
96
100
|
const { fileId, file } = attachment;
|
|
101
|
+
if (file.type?.startsWith('video/')) this.localVideoUris.set(fileId, file.uri);
|
|
97
102
|
if (!this.request) {
|
|
98
103
|
this.request = CometChat.createUploadFileRequest(target?.receiver ?? '', target?.receiverType ?? '');
|
|
99
104
|
this.request.setConcurrency(UPLOAD_CONCURRENCY);
|
|
@@ -111,6 +116,7 @@ export class UploadQueueService {
|
|
|
111
116
|
// Aborts an in-flight upload or drops an already-uploaded file — either way its slot frees.
|
|
112
117
|
this.request?.removeAttachment(tileId);
|
|
113
118
|
this.completed.delete(tileId);
|
|
119
|
+
this.localVideoUris.delete(tileId);
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
retry(tileId: string, file: SelectedAttachment): void {
|
|
@@ -127,6 +133,7 @@ export class UploadQueueService {
|
|
|
127
133
|
this.request?.clearAll();
|
|
128
134
|
this.request = null;
|
|
129
135
|
this.completed.clear();
|
|
136
|
+
this.localVideoUris.clear();
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
get completedAttachments(): CometChat.Attachment[] {
|
|
@@ -48,6 +48,9 @@ export const getUnixTimestampInMilliseconds = () => {
|
|
|
48
48
|
return Math.round(+new Date());
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
/** A muid that stays unique for messages created in the same second (or millisecond). */
|
|
52
|
+
export const uniqueMuid = () => `${getUnixTimestampInMilliseconds()}${ID()}`;
|
|
53
|
+
|
|
51
54
|
export const formatBytes = (bytes: number, decimals = 2) => {
|
|
52
55
|
if (bytes === 0) return "0 Bytes";
|
|
53
56
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Utility functions for markdown text processing.
|
|
3
3
|
*/
|
|
4
4
|
import { stripColorTags } from "../formatters/richTextWireFormat";
|
|
5
|
-
import { urlPattern, emailPattern } from "../constants/textPatterns";
|
|
5
|
+
import { urlPattern, emailPattern, markdownLinkPattern } from "../constants/textPatterns";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Strips markdown syntax characters from text, returning clean readable content.
|
|
@@ -39,9 +39,16 @@ export function stripMarkdown(text: string, keepColorTags = false): string {
|
|
|
39
39
|
protectedUrls.push(match);
|
|
40
40
|
return `\x00U${protectedUrls.length - 1}\x00`;
|
|
41
41
|
};
|
|
42
|
-
//
|
|
42
|
+
// Markdown links first, each half on its own — see CometChatRichTextFormatter. The url
|
|
43
|
+
// pattern accepts `[ ] ( )`, so `[https://x/p](https://x/p)` was stashed as ONE url and
|
|
44
|
+
// step 1.5 never saw a link: the conversation row showed the raw markdown.
|
|
45
|
+
const urlRegex = new RegExp(urlPattern, "gi");
|
|
46
|
+
staged = text.replace(new RegExp(markdownLinkPattern, "g"), (_m, label: string, url: string) =>
|
|
47
|
+
`[${label.replace(urlRegex, keep)}](${keep(url)})`
|
|
48
|
+
);
|
|
49
|
+
// Emails next — the url pattern matches only an address's domain, leaving the local
|
|
43
50
|
// part's underscores exposed to the markdown rules below.
|
|
44
|
-
staged =
|
|
51
|
+
staged = staged.replace(new RegExp(emailPattern, "gi"), keep);
|
|
45
52
|
staged = staged.replace(new RegExp(urlPattern, "gi"), keep);
|
|
46
53
|
} catch {
|
|
47
54
|
// A bad pattern must not cost the caller their text; fall back to stripping unprotected.
|
|
@@ -58,7 +65,7 @@ export function stripMarkdown(text: string, keepColorTags = false): string {
|
|
|
58
65
|
});
|
|
59
66
|
|
|
60
67
|
// 1.5. Convert markdown links [text](url) → text
|
|
61
|
-
result = result.replace(
|
|
68
|
+
result = result.replace(new RegExp(markdownLinkPattern, "g"), '$1');
|
|
62
69
|
|
|
63
70
|
// 2. Remove inline code backticks (normal and escaped)
|
|
64
71
|
result = result.replace(/\\`([^`]*?)\\`/g, '$1'); // escaped \`code\`
|
|
@@ -24,6 +24,7 @@ import { useCometChatTranslation } from "../resources/CometChatLocalizeNew";
|
|
|
24
24
|
import { getCometChatTranslation } from "../resources/CometChatLocalizeNew/LocalizationManager";
|
|
25
25
|
import { useTheme } from "../../theme";
|
|
26
26
|
import { isPinned, isSaved } from "./PinSaveHelper";
|
|
27
|
+
import { unescapeTypedMentionTokensInTree } from "./mentionTokens";
|
|
27
28
|
|
|
28
29
|
/** Module-scope translator — getStatusInfoView is a plain function, not a component. */
|
|
29
30
|
const translate = getCometChatTranslation();
|
|
@@ -75,9 +76,9 @@ const getOverridenBubbleStyles = (theme: CometChatTheme) => {
|
|
|
75
76
|
* copies of this map are a standing hazard.
|
|
76
77
|
*/
|
|
77
78
|
const fileIncoming = deepMerge(incomingBubbleStyles, incomingBubbleStyles.fileBubbleStyles ?? {});
|
|
78
|
-
if (fileIncoming.containerStyle) fileIncoming.containerStyle
|
|
79
|
+
if (fileIncoming.containerStyle) Object.assign(fileIncoming.containerStyle, { height: undefined });
|
|
79
80
|
const fileOutgoing = deepMerge(outgoingBubbleStyles, outgoingBubbleStyles.fileBubbleStyles ?? {});
|
|
80
|
-
if (fileOutgoing.containerStyle) fileOutgoing.containerStyle
|
|
81
|
+
if (fileOutgoing.containerStyle) Object.assign(fileOutgoing.containerStyle, { height: undefined });
|
|
81
82
|
|
|
82
83
|
styleCache.set(MessageTypeConstants.file, {
|
|
83
84
|
incoming: fileIncoming,
|
|
@@ -88,12 +89,12 @@ const getOverridenBubbleStyles = (theme: CometChatTheme) => {
|
|
|
88
89
|
incomingBubbleStyles,
|
|
89
90
|
incomingBubbleStyles.audioBubbleStyles ?? {}
|
|
90
91
|
);
|
|
91
|
-
if (audioIncoming.containerStyle) audioIncoming.containerStyle
|
|
92
|
+
if (audioIncoming.containerStyle) Object.assign(audioIncoming.containerStyle, { height: undefined });
|
|
92
93
|
const audioOutgoing = deepMerge(
|
|
93
94
|
outgoingBubbleStyles,
|
|
94
95
|
outgoingBubbleStyles.audioBubbleStyles ?? {}
|
|
95
96
|
);
|
|
96
|
-
if (audioOutgoing.containerStyle) audioOutgoing.containerStyle
|
|
97
|
+
if (audioOutgoing.containerStyle) Object.assign(audioOutgoing.containerStyle, { height: undefined });
|
|
97
98
|
|
|
98
99
|
styleCache.set(MessageTypeConstants.audio, {
|
|
99
100
|
incoming: audioIncoming,
|
|
@@ -480,7 +481,8 @@ export const applyMentionsFormatting = (
|
|
|
480
481
|
): string | JSX.Element => {
|
|
481
482
|
const containsAllAlias = /<@all:(.*?)>/.test(rawText);
|
|
482
483
|
if (!message.getMentionedUsers?.().length && !containsAllAlias) {
|
|
483
|
-
|
|
484
|
+
// No real mentions to resolve, but typed token text (stored escaped) still reads as typed.
|
|
485
|
+
return unescapeTypedMentionTokensInTree(content);
|
|
484
486
|
}
|
|
485
487
|
|
|
486
488
|
try {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CommonUtils } from './CommonUtils';
|
|
2
|
+
import { getUnixTimestamp, uniqueMuid } from './CometChatMessageHelper';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The "added X" rows to show for one ccGroupMemberAdded event: one copy per member, each with its own
|
|
6
|
+
* muid (members added in the same second shared a timestamp muid and were merged into one row).
|
|
7
|
+
* Accepts both shapes that reach the list: { message } from apps that emit once per member, and
|
|
8
|
+
* { messages } (one action per member) from CometChatUIKitHelper.onGroupMemberAdded.
|
|
9
|
+
*/
|
|
10
|
+
export function groupMemberAddedRows(
|
|
11
|
+
event: { message?: object; messages?: object[]; usersAdded?: any[] },
|
|
12
|
+
loggedInUserName: string | undefined
|
|
13
|
+
): any[] {
|
|
14
|
+
const users = event.usersAdded ?? [];
|
|
15
|
+
const rows: any[] = [];
|
|
16
|
+
users.forEach((user, i) => {
|
|
17
|
+
const base = event.messages?.[i] ?? event.message ?? event.messages?.[0];
|
|
18
|
+
if (!base) return;
|
|
19
|
+
const row: any = CommonUtils.clone(base);
|
|
20
|
+
row['message'] = `${loggedInUserName} added ${user.name}`;
|
|
21
|
+
row['muid'] = uniqueMuid();
|
|
22
|
+
row['sentAt'] = getUnixTimestamp();
|
|
23
|
+
row['actionOn'] = user;
|
|
24
|
+
row['action'] = 'added';
|
|
25
|
+
rows.push(row);
|
|
26
|
+
});
|
|
27
|
+
return rows;
|
|
28
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which of a message's link previews to show.
|
|
3
|
+
*
|
|
4
|
+
* The server scans the raw text and returns a preview for every address it finds, in order, with
|
|
5
|
+
* no idea what the text means. Taking `links[0]` therefore showed a card for an address the link
|
|
6
|
+
* never opens: `[www.google.com](https://drive…)` got a Google card although it opens Drive, and
|
|
7
|
+
* `` `https://google.com` `` — code, not a link — still got a card.
|
|
8
|
+
*
|
|
9
|
+
* A preview is shown for a DESTINATION: a markdown link's address, or a bare address outside code
|
|
10
|
+
* and outside a link label. Label and code addresses are never destinations. The server reports
|
|
11
|
+
* an address after redirects and can keep a stray `)` from markdown, so addresses are compared
|
|
12
|
+
* loosely, and a preview that matches nothing is still shown when the text has a destination (it
|
|
13
|
+
* is most likely that destination, redirected) — just never one known to be a label or code.
|
|
14
|
+
*/
|
|
15
|
+
import { markdownLinkPattern, urlPattern } from "../constants/textPatterns";
|
|
16
|
+
|
|
17
|
+
/** A link-preview entry as the extension delivers it (url, title, image, favicon, description…). */
|
|
18
|
+
type Preview = Record<string, any>;
|
|
19
|
+
|
|
20
|
+
const count = (s: string, ch: string) => s.split(ch).length - 1;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Drops trailing `)` that have no matching `(`. The server's scanner does not stop at markdown
|
|
24
|
+
* punctuation, so `[Mercury](…/Mercury_(planet))` comes back as `…/Mercury_(planet))` — a card
|
|
25
|
+
* that shows, and opens, an address that does not exist.
|
|
26
|
+
*/
|
|
27
|
+
export const trimStrayParens = (url: string): string => {
|
|
28
|
+
let u = (url || "").trim();
|
|
29
|
+
while (u.endsWith(")") && count(u, ")") > count(u, "(")) u = u.slice(0, -1);
|
|
30
|
+
return u;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Loose form for comparing addresses: no scheme, no `www.`, no trailing `/`, no stray `)`. */
|
|
34
|
+
export const normalizePreviewUrl = (url: string): string =>
|
|
35
|
+
trimStrayParens(url).toLowerCase().replace(/^[a-z][a-z0-9+.-]*:\/\//, "").replace(/^www\./, "").replace(/\/+$/, "");
|
|
36
|
+
|
|
37
|
+
const addressesIn = (text: string): string[] => text.match(new RegExp(urlPattern, "gi")) || [];
|
|
38
|
+
|
|
39
|
+
/** What the text links to (destinations) and addresses it only shows as a label or code (excluded). */
|
|
40
|
+
function classify(text: string | undefined | null) {
|
|
41
|
+
const destinations: string[] = [];
|
|
42
|
+
const notDestinations: string[] = [];
|
|
43
|
+
let rest = text || "";
|
|
44
|
+
|
|
45
|
+
rest = rest.replace(/```[\s\S]*?```|`[^`\n]*`/g, (code) => {
|
|
46
|
+
// The fences aren't word boundaries for urlPattern (`https://a.com` read as "https://a"): blank them.
|
|
47
|
+
notDestinations.push(...addressesIn(code.replace(/`/g, " ")));
|
|
48
|
+
return " ";
|
|
49
|
+
});
|
|
50
|
+
rest = rest.replace(new RegExp(markdownLinkPattern, "g"), (_m, label: string, address: string) => {
|
|
51
|
+
notDestinations.push(...addressesIn(label));
|
|
52
|
+
destinations.push(address);
|
|
53
|
+
return " ";
|
|
54
|
+
});
|
|
55
|
+
destinations.push(...addressesIn(rest));
|
|
56
|
+
|
|
57
|
+
const wanted = new Set(destinations.map(normalizePreviewUrl));
|
|
58
|
+
const excluded = new Set(notDestinations.map(normalizePreviewUrl).filter((u) => !wanted.has(u)));
|
|
59
|
+
return { wanted, excluded };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The single card to stand for a message (list row type, search thumbnail). */
|
|
63
|
+
export function selectLinkPreview<T extends Preview>(links: T[] | undefined | null, text: string | undefined | null): T | undefined {
|
|
64
|
+
if (!links || links.length === 0) return undefined;
|
|
65
|
+
const { wanted, excluded } = classify(text);
|
|
66
|
+
const exact = links.find((link) => link?.url && wanted.has(normalizePreviewUrl(link.url)));
|
|
67
|
+
if (exact) return exact;
|
|
68
|
+
|
|
69
|
+
// Nothing in the text is a destination, but some addresses are code or labels: no card.
|
|
70
|
+
if (wanted.size === 0 && excluded.size > 0) return undefined;
|
|
71
|
+
return links.find((link) => !link?.url || !excluded.has(normalizePreviewUrl(link.url)));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Every card the bubble shows: one per destination, in the server's order — like React UI Kit's
|
|
76
|
+
* selectDestinationPreviews. `https://www.google.com and https://www.facebook.com` gets both cards.
|
|
77
|
+
*/
|
|
78
|
+
export function selectLinkPreviews<T extends Preview>(links: T[] | undefined | null, text: string | undefined | null): T[] {
|
|
79
|
+
if (!links || links.length === 0) return [];
|
|
80
|
+
const { wanted, excluded } = classify(text);
|
|
81
|
+
if (wanted.size === 0 && excluded.size > 0) return [];
|
|
82
|
+
// One card per site: the server can return the same page twice (the label's
|
|
83
|
+
// http://www.x.com and the link's https://www.x.com). Keep one, in first-seen
|
|
84
|
+
// order, preferring https — the card opens its url.
|
|
85
|
+
const kept: T[] = [];
|
|
86
|
+
const slot = new Map<string, number>();
|
|
87
|
+
for (const link of links) {
|
|
88
|
+
if (!link?.url) { kept.push(link); continue; }
|
|
89
|
+
if (excluded.has(normalizePreviewUrl(link.url))) continue;
|
|
90
|
+
const key = siteKey(link.url);
|
|
91
|
+
const i = slot.get(key);
|
|
92
|
+
if (i === undefined) { slot.set(key, kept.length); kept.push(link); }
|
|
93
|
+
else if (/^https:/i.test(link.url) && !/^https:/i.test(kept[i].url)) kept[i] = link;
|
|
94
|
+
}
|
|
95
|
+
return kept;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Dedup key: scheme and `www.` dropped, host lowercased, path kept as is (paths are case-sensitive). */
|
|
99
|
+
function siteKey(url: string): string {
|
|
100
|
+
const u = trimStrayParens(url).replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").replace(/\/+$/, "");
|
|
101
|
+
const cut = u.search(/[/?#]/);
|
|
102
|
+
const host = (cut < 0 ? u : u.slice(0, cut)).toLowerCase().replace(/^www\./, "");
|
|
103
|
+
return host + (cut < 0 ? "" : u.slice(cut));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The card image: empty when the server sent none, or only the site's favicon. */
|
|
107
|
+
export function previewImage(image?: string | null, favicon?: string | null): string {
|
|
108
|
+
return !image || image === favicon ? "" : image;
|
|
109
|
+
}
|