@cometchat/chat-uikit-react-native 5.5.1 → 5.5.3
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/build.gradle +35 -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 +235 -4
- package/ios/FileManager.m +77 -3
- package/ios/RichTextEditorView.swift +234 -24
- package/package.json +7 -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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mention markup a user TYPED or PASTED, as opposed to a mention picked from the suggestion list.
|
|
3
|
+
*
|
|
4
|
+
* `<@uid:…>` / `<@all:…>` in a message's text is the only signal that a mention is real — there
|
|
5
|
+
* is no other metadata for `@all`. So text a user typed that happens to look like a token was
|
|
6
|
+
* sent verbatim and every platform rendered it as a live mention: `<@all:everyone> hi` became an
|
|
7
|
+
* @everyone chip. The cross-platform contract (shared with the React UI Kit) is to store a typed
|
|
8
|
+
* token's `<` as `<` — `<@all:everyone> hi` — and to show that as `<@all:everyone> hi`
|
|
9
|
+
* only after mentions have been resolved, so it can never turn back into a chip.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import React from "react";
|
|
13
|
+
|
|
14
|
+
const TYPED_TOKEN_REGEX = /<(@(?:uid|all):)/g;
|
|
15
|
+
const ESCAPED_TOKEN_REGEX = /<(@(?:uid|all):)/g;
|
|
16
|
+
|
|
17
|
+
/** Escapes token-looking text a user typed: `<@all:x>` → `<@all:x>`. */
|
|
18
|
+
export const escapeTypedMentionTokens = (text: string): string =>
|
|
19
|
+
text.indexOf("<@") < 0 ? text : text.replace(TYPED_TOKEN_REGEX, "<$1");
|
|
20
|
+
|
|
21
|
+
/** Display form of an escaped typed token: `<@all:x>` → `<@all:x>`. Run AFTER mention parsing. */
|
|
22
|
+
export const unescapeTypedMentionTokens = (text: string): string =>
|
|
23
|
+
text.indexOf("<@") < 0 ? text : text.replace(ESCAPED_TOKEN_REGEX, "<$1");
|
|
24
|
+
|
|
25
|
+
const hasEscapedToken = (node: any): boolean => {
|
|
26
|
+
if (typeof node === "string") return node.indexOf("<@") >= 0;
|
|
27
|
+
if (Array.isArray(node)) return node.some(hasEscapedToken);
|
|
28
|
+
if (React.isValidElement(node)) return hasEscapedToken((node as React.ReactElement<any>).props.children);
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const unescapeTree = (node: any): any => {
|
|
33
|
+
if (typeof node === "string") return unescapeTypedMentionTokens(node);
|
|
34
|
+
if (Array.isArray(node)) return node.map(unescapeTree);
|
|
35
|
+
if (React.isValidElement(node) && hasEscapedToken(node)) {
|
|
36
|
+
const children = (node as React.ReactElement<any>).props.children;
|
|
37
|
+
return React.cloneElement(node as React.ReactElement<any>, {
|
|
38
|
+
children: Array.isArray(children) ? children.map(unescapeTree) : unescapeTree(children),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return node;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* {@link unescapeTypedMentionTokens} over every string of a rendered tree. Only the branches
|
|
46
|
+
* holding an escaped token are rebuilt; any other tree — nearly every message — is returned as
|
|
47
|
+
* the same object, so rendering it costs nothing and changes nothing.
|
|
48
|
+
*/
|
|
49
|
+
export const unescapeTypedMentionTokensInTree = (node: any): any =>
|
|
50
|
+
hasEscapedToken(node) ? unescapeTree(node) : node;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Builds the text to send: real mentions (character ranges `"start_end"` in `text`, from the
|
|
54
|
+
* composer's mention map) become their tokens, and everything the user typed between them is
|
|
55
|
+
* escaped. Ranges are applied in position order, whatever order the map holds them in.
|
|
56
|
+
*/
|
|
57
|
+
export const insertMentionTokens = (
|
|
58
|
+
text: string,
|
|
59
|
+
mentions: Iterable<[string, { underlyingText: string }]>
|
|
60
|
+
): string => {
|
|
61
|
+
const ranges = [...mentions]
|
|
62
|
+
.map(([key, value]) => {
|
|
63
|
+
const [start, end] = key.split("_").map(Number);
|
|
64
|
+
return { start, end, token: value.underlyingText };
|
|
65
|
+
})
|
|
66
|
+
.filter((r) => Number.isFinite(r.start) && Number.isFinite(r.end))
|
|
67
|
+
.sort((a, b) => a.start - b.start);
|
|
68
|
+
|
|
69
|
+
let out = "";
|
|
70
|
+
let last = 0;
|
|
71
|
+
for (const { start, end, token } of ranges) {
|
|
72
|
+
if (start < last) continue; // overlapping range — skip it rather than corrupt the text
|
|
73
|
+
out += escapeTypedMentionTokens(text.substring(last, start)) + token;
|
|
74
|
+
last = end;
|
|
75
|
+
}
|
|
76
|
+
return out + escapeTypedMentionTokens(text.substring(last));
|
|
77
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stand-in for `InteractionManager.runAfterInteractions`, which React Native 0.87 removed
|
|
5
|
+
* (touching it throws in dev and is `undefined` in release).
|
|
6
|
+
*
|
|
7
|
+
* - RN < 0.82: `InteractionManager` still waits for running animations and navigation
|
|
8
|
+
* transitions, so it is used as before and apps on older RN keep the exact old timing.
|
|
9
|
+
* - RN >= 0.82: it had already stopped honouring interaction handles, so all it did was
|
|
10
|
+
* defer the callback past the current JS turn. That is what `setTimeout(task, 0)` does,
|
|
11
|
+
* without touching the removed module. `requestIdleCallback` is deliberately not used: it
|
|
12
|
+
* can hold the callback back for a long time, and these call sites move the caret or clear
|
|
13
|
+
* the input right after an edit.
|
|
14
|
+
*/
|
|
15
|
+
const rnVersion = Platform.constants?.reactNativeVersion;
|
|
16
|
+
const hasLegacyInteractionManager =
|
|
17
|
+
!!rnVersion && rnVersion.major === 0 && rnVersion.minor < 82;
|
|
18
|
+
|
|
19
|
+
export function runAfterInteractions(task: () => void): void {
|
|
20
|
+
if (hasLegacyInteractionManager) {
|
|
21
|
+
// Required lazily: on RN 0.87 even reading this export throws.
|
|
22
|
+
require("react-native").InteractionManager.runAfterInteractions(task);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setTimeout(task, 0);
|
|
26
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* as "make a <product>" or "5 < 10" is preserved.
|
|
8
8
|
*/
|
|
9
9
|
import { stripColorTags } from "../formatters/richTextWireFormat";
|
|
10
|
+
import { markdownLinkPattern } from "../constants/textPatterns";
|
|
10
11
|
|
|
11
12
|
export const stripRichText = (input?: string | null): string => {
|
|
12
13
|
if (!input) return "";
|
|
@@ -41,7 +42,7 @@ export const stripRichText = (input?: string | null): string => {
|
|
|
41
42
|
.replace(/(^|[^A-Za-z0-9_])_\s*(.+?)\s*_(?![A-Za-z0-9_])/g, "$1$2") // _italic_
|
|
42
43
|
.replace(/~~(.+?)~~/g, "$1") // ~~strikethrough~~
|
|
43
44
|
.replace(/`([^`]+)`/g, "$1") // `inline code`
|
|
44
|
-
.replace(
|
|
45
|
+
.replace(new RegExp(markdownLinkPattern, "g"), "$1"); // [label](url) -> label
|
|
45
46
|
|
|
46
47
|
// 3. Collapse leftover whitespace into a single clean line.
|
|
47
48
|
return text.replace(/\s+/g, " ").trim();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GestureResponderEvent } from 'react-native';
|
|
2
|
+
|
|
3
|
+
// Same tolerances as React Native's Pressability: a touch is still a tap within 10pt of where it started.
|
|
4
|
+
export const TAP_SLOP = 10;
|
|
5
|
+
// A longer hold is a long-press (the bubble's message options), not a tap.
|
|
6
|
+
export const TAP_MAX_MS = 500;
|
|
7
|
+
|
|
8
|
+
export interface TouchStart {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
at: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const touchStartOf = (e: GestureResponderEvent, now = Date.now()): TouchStart => ({
|
|
15
|
+
x: e.nativeEvent.pageX,
|
|
16
|
+
y: e.nativeEvent.pageY,
|
|
17
|
+
at: now,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const movedBeyondSlop = (start: TouchStart, e: GestureResponderEvent): boolean =>
|
|
21
|
+
Math.abs(e.nativeEvent.pageX - start.x) > TAP_SLOP || Math.abs(e.nativeEvent.pageY - start.y) > TAP_SLOP;
|
|
22
|
+
|
|
23
|
+
export const isTapDuration = (start: TouchStart, now = Date.now()): boolean => now - start.at < TAP_MAX_MS;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { NativeModules } from 'react-native';
|
|
3
|
+
|
|
4
|
+
const { FileManager } = NativeModules;
|
|
5
|
+
|
|
6
|
+
// Long edge of the generated JPEG — tray tiles and grid cells are at most ~200pt, so this stays sharp
|
|
7
|
+
// on 3x screens while keeping each file a few KB.
|
|
8
|
+
const THUMBNAIL_MAX_SIZE = 480;
|
|
9
|
+
|
|
10
|
+
// Local video uri → its thumbnail (in flight or done), so the tray tile and the bubble share one native call.
|
|
11
|
+
const byLocalUri = new Map<string, Promise<string | null>>();
|
|
12
|
+
// Resolved thumbnails, so a component can render the thumbnail on its first frame instead of after a tick.
|
|
13
|
+
const resolved = new Map<string, string>();
|
|
14
|
+
// Uploaded video url (without the signed query string) → the local file it came from.
|
|
15
|
+
const localUriByRemoteUrl = new Map<string, string>();
|
|
16
|
+
|
|
17
|
+
const withoutQuery = (url: string) => url.split('?')[0];
|
|
18
|
+
|
|
19
|
+
/** First-frame JPEG of a LOCAL video file, generated natively. Resolves null when unavailable. */
|
|
20
|
+
export function getLocalVideoThumbnail(localUri: string): Promise<string | null> {
|
|
21
|
+
const cached = byLocalUri.get(localUri);
|
|
22
|
+
if (cached) return cached;
|
|
23
|
+
const pending: Promise<string | null> = typeof FileManager?.getVideoThumbnail === 'function'
|
|
24
|
+
? FileManager.getVideoThumbnail(localUri, THUMBNAIL_MAX_SIZE)
|
|
25
|
+
.then((thumbnailUri: string) => {
|
|
26
|
+
resolved.set(localUri, thumbnailUri);
|
|
27
|
+
return thumbnailUri;
|
|
28
|
+
})
|
|
29
|
+
.catch(() => null)
|
|
30
|
+
: Promise.resolve(null);
|
|
31
|
+
byLocalUri.set(localUri, pending);
|
|
32
|
+
return pending;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Remembers which local file an uploaded video came from, so the sender's bubble (which only knows the
|
|
37
|
+
* uploaded url) can show the local thumbnail straight away. Also starts generating it.
|
|
38
|
+
*/
|
|
39
|
+
export function linkUploadedVideo(remoteUrl: string | undefined, localUri: string | undefined): void {
|
|
40
|
+
if (!remoteUrl || !localUri) return;
|
|
41
|
+
localUriByRemoteUrl.set(withoutQuery(remoteUrl), localUri);
|
|
42
|
+
getLocalVideoThumbnail(localUri);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function localUriFor(source: { localUri?: string; remoteUrl?: string }): string | undefined {
|
|
46
|
+
if (source.localUri) return source.localUri;
|
|
47
|
+
return source.remoteUrl ? localUriByRemoteUrl.get(withoutQuery(source.remoteUrl)) : undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Local first-frame thumbnail for a video, by its local file uri (tray) or its uploaded url (a bubble
|
|
52
|
+
* this device sent). `undefined` while generating, `null` when there is none — no local file (e.g. a
|
|
53
|
+
* video received from someone else), generation failed, or the native method isn't available.
|
|
54
|
+
*/
|
|
55
|
+
export function useLocalVideoThumbnail(source: { localUri?: string; remoteUrl?: string }): string | null | undefined {
|
|
56
|
+
const localUri = localUriFor(source);
|
|
57
|
+
const [thumbnail, setThumbnail] = useState<string | null | undefined>(() =>
|
|
58
|
+
localUri ? resolved.get(localUri) : null
|
|
59
|
+
);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!localUri) {
|
|
62
|
+
setThumbnail(null);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
let active = true;
|
|
66
|
+
getLocalVideoThumbnail(localUri).then((uri) => {
|
|
67
|
+
if (active) setThumbnail(uri);
|
|
68
|
+
});
|
|
69
|
+
return () => {
|
|
70
|
+
active = false;
|
|
71
|
+
};
|
|
72
|
+
}, [localUri]);
|
|
73
|
+
return thumbnail;
|
|
74
|
+
}
|
|
@@ -22,6 +22,7 @@ import { deepMerge } from '../../helper/helperFunctions';
|
|
|
22
22
|
import { SelectedAttachment } from '../../modals/SelectedAttachment';
|
|
23
23
|
import { Icon } from '../../icons/Icon';
|
|
24
24
|
import { getFileTypeIcon } from '../../constants/UIKitConstants';
|
|
25
|
+
import { useLocalVideoThumbnail } from '../../utils/videoThumbnail';
|
|
25
26
|
|
|
26
27
|
const { SoundPlayer } = NativeModules;
|
|
27
28
|
|
|
@@ -459,6 +460,8 @@ export const CometChatAttachmentTile = ({
|
|
|
459
460
|
style ?? {}
|
|
460
461
|
);
|
|
461
462
|
const { fileId, file, uploadState, uploadProgress } = attachment;
|
|
463
|
+
const isVideo = file.type.startsWith('video/');
|
|
464
|
+
const videoThumbnail = useLocalVideoThumbnail({ localUri: isVideo ? file.uri : undefined });
|
|
462
465
|
|
|
463
466
|
// Audio (audio/*) renders as a player card (play/pause + seek + time), not the file card.
|
|
464
467
|
if (file.type.startsWith('audio/')) {
|
|
@@ -670,24 +673,29 @@ export const CometChatAttachmentTile = ({
|
|
|
670
673
|
borderColor: theme.color.error,
|
|
671
674
|
}, s.mediaTileStyle]}
|
|
672
675
|
>
|
|
673
|
-
{
|
|
674
|
-
// A local video file can't render as an <Image
|
|
675
|
-
//
|
|
676
|
-
//
|
|
676
|
+
{isVideo ? (
|
|
677
|
+
// A local video file can't render as an <Image>: show its natively generated first-frame
|
|
678
|
+
// JPEG. Only if that isn't available, fall back to a paused, muted react-native-video
|
|
679
|
+
// (a full player per tile — heavy with several videos). The dark scrim sits behind so
|
|
680
|
+
// the tile reads as a video before either appears.
|
|
677
681
|
<>
|
|
678
682
|
<View
|
|
679
683
|
pointerEvents="none"
|
|
680
684
|
style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaScrim }}
|
|
681
685
|
/>
|
|
682
|
-
|
|
683
|
-
source={{ uri:
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
686
|
+
{videoThumbnail ? (
|
|
687
|
+
<Image source={{ uri: videoThumbnail }} style={styles.fill} resizeMode="cover" />
|
|
688
|
+
) : videoThumbnail === null ? (
|
|
689
|
+
<Video
|
|
690
|
+
source={{ uri: file.uri }}
|
|
691
|
+
paused
|
|
692
|
+
muted
|
|
693
|
+
repeat={false}
|
|
694
|
+
controls={false}
|
|
695
|
+
resizeMode="cover"
|
|
696
|
+
style={styles.fill}
|
|
697
|
+
/>
|
|
698
|
+
) : null}
|
|
691
699
|
</>
|
|
692
700
|
) : (
|
|
693
701
|
<Image
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { JSX, useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import {
|
|
3
3
|
EmitterSubscription,
|
|
4
|
+
GestureResponderEvent,
|
|
4
5
|
ImageSourcePropType,
|
|
5
6
|
ImageStyle,
|
|
6
7
|
NativeEventEmitter,
|
|
7
8
|
NativeModules,
|
|
8
|
-
Platform,
|
|
9
9
|
StyleProp,
|
|
10
10
|
Text,
|
|
11
11
|
TextStyle,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import { Icon } from "../../icons/Icon";
|
|
16
16
|
import { AnimatedAudioWaves } from "./AnimatedAudioWaves";
|
|
17
17
|
import { audioPlaybackCoordinator } from "../../utils/audioPlaybackCoordinator";
|
|
18
|
+
import { TouchStart, isTapDuration, movedBeyondSlop, touchStartOf } from "../../utils/tapGesture";
|
|
18
19
|
|
|
19
20
|
const { SoundPlayer } = NativeModules;
|
|
20
21
|
const eventEmitter = new NativeEventEmitter(SoundPlayer);
|
|
@@ -128,7 +129,8 @@ export const CometChatAudioBubble = ({
|
|
|
128
129
|
// Native fires soundPlayStatus on natural completion AND when a new play() replaces this clip.
|
|
129
130
|
// Interrupt echo (we were interrupted) → ignore; genuine finish → reset to idle.
|
|
130
131
|
useEffect(() => {
|
|
131
|
-
subRef.current = eventEmitter.addListener("soundPlayStatus", (
|
|
132
|
+
subRef.current = eventEmitter.addListener("soundPlayStatus", (event) => {
|
|
133
|
+
const data = event as { url?: string };
|
|
132
134
|
if (audioUrl !== data.url) return;
|
|
133
135
|
if (wasInterruptedRef.current) return;
|
|
134
136
|
setStatus("");
|
|
@@ -173,25 +175,21 @@ export const CometChatAudioBubble = ({
|
|
|
173
175
|
if (audioUrl) play(currentTimeRef.current || 0);
|
|
174
176
|
};
|
|
175
177
|
|
|
176
|
-
|
|
178
|
+
// Raw touches (not a Touchable) so the bubble's long-press and the list's scroll keep working.
|
|
179
|
+
// A finger always moves a little during a tap: only a move past the slop cancels it (a scroll).
|
|
180
|
+
const press = useRef<TouchStart | null>(null);
|
|
177
181
|
|
|
178
|
-
const handleTouchStart = () => {
|
|
179
|
-
|
|
182
|
+
const handleTouchStart = (e: GestureResponderEvent) => {
|
|
183
|
+
press.current = touchStartOf(e);
|
|
180
184
|
};
|
|
181
185
|
|
|
182
186
|
const handleTouchEnd = () => {
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
const pressDuration = endTime - (pressTime.current ?? 0);
|
|
186
|
-
if (pressDuration < 500) {
|
|
187
|
-
playPauseAudio();
|
|
188
|
-
}
|
|
187
|
+
if (press.current && isTapDuration(press.current)) playPauseAudio();
|
|
188
|
+
press.current = null;
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
-
const onTouchMove = () => {
|
|
192
|
-
if (
|
|
193
|
-
pressTime.current = null;
|
|
194
|
-
}
|
|
191
|
+
const onTouchMove = (e: GestureResponderEvent) => {
|
|
192
|
+
if (press.current && movedBeyondSlop(press.current, e)) press.current = null;
|
|
195
193
|
};
|
|
196
194
|
|
|
197
195
|
const displayDuration = useCallback(
|
|
@@ -279,7 +279,7 @@ const CometChatEmojiKeyboard: React.FC<CometChatEmojiKeyboardProps> = ({
|
|
|
279
279
|
showsVerticalScrollIndicator={false}
|
|
280
280
|
style={styles.flatList}
|
|
281
281
|
initialNumToRender={80}
|
|
282
|
-
removeClippedSubviews={
|
|
282
|
+
removeClippedSubviews={Platform.OS !== 'android'} // ENG-40210: clipping crashes Fabric on Android
|
|
283
283
|
/>
|
|
284
284
|
);
|
|
285
285
|
};
|
|
@@ -87,7 +87,8 @@ export const CometChatFileBubble = ({
|
|
|
87
87
|
if (Platform.OS == "android") {
|
|
88
88
|
listener = eventEmitter.addListener(
|
|
89
89
|
"downloadComplete",
|
|
90
|
-
(
|
|
90
|
+
(event) => {
|
|
91
|
+
const data = event as { downloadId: number };
|
|
91
92
|
if (data.downloadId && downloadIdRef.current && data.downloadId == downloadIdRef.current) {
|
|
92
93
|
setProcessing(false);
|
|
93
94
|
setFileExists(true);
|
|
@@ -83,7 +83,8 @@ export function CometChatFilesBubble({
|
|
|
83
83
|
const pendingOpensRef = useRef<Record<string, { url: string; name: string; key: string }>>({});
|
|
84
84
|
useEffect(() => {
|
|
85
85
|
if (Platform.OS !== 'android') return;
|
|
86
|
-
const sub = fileEventEmitter.addListener('downloadComplete', (
|
|
86
|
+
const sub = fileEventEmitter.addListener('downloadComplete', (event) => {
|
|
87
|
+
const data = event as { downloadId: number };
|
|
87
88
|
const pending = pendingOpensRef.current[String(data?.downloadId)];
|
|
88
89
|
if (pending) {
|
|
89
90
|
FileManager?.openFile?.(pending.url, pending.name, () => {});
|
|
@@ -6,7 +6,6 @@ import { useTheme } from '../../../theme';
|
|
|
6
6
|
import { useCompTheme } from '../../../theme/hook';
|
|
7
7
|
import { deepMerge } from '../../helper/helperFunctions';
|
|
8
8
|
import { CometChatUIKit } from '../../CometChatUiKit';
|
|
9
|
-
import { CometChatMessageEvents } from '../../events/CometChatMessageEvents';
|
|
10
9
|
import { CometChatMediaViewer } from '../CometChatMediaViewer';
|
|
11
10
|
import { CometChatCaptionText } from '../CometChatCaptionText';
|
|
12
11
|
import { Icon } from '../../icons/Icon';
|
|
@@ -81,14 +80,14 @@ const ImageCell = ({
|
|
|
81
80
|
{showPlaceholder ? (
|
|
82
81
|
<View
|
|
83
82
|
testID="grid-cell-nopreview"
|
|
84
|
-
style={[StyleSheet.
|
|
83
|
+
style={[StyleSheet.absoluteFill, borderStyle, { backgroundColor: theme.color.neutral200, justifyContent: 'center', alignItems: 'center' }]}
|
|
85
84
|
>
|
|
86
85
|
<Icon name="unknown-file-type" size={theme.spacing.spacing.s12} />
|
|
87
86
|
</View>
|
|
88
87
|
) : (
|
|
89
88
|
<Image
|
|
90
89
|
source={{ uri: attachment.getUrl() }}
|
|
91
|
-
style={[StyleSheet.
|
|
90
|
+
style={[StyleSheet.absoluteFill, borderStyle]}
|
|
92
91
|
resizeMode="cover"
|
|
93
92
|
onError={() => setFailed(true)}
|
|
94
93
|
/>
|
|
@@ -98,7 +97,7 @@ const ImageCell = ({
|
|
|
98
97
|
<View
|
|
99
98
|
testID="grid-overflow"
|
|
100
99
|
pointerEvents="none"
|
|
101
|
-
style={[StyleSheet.
|
|
100
|
+
style={[StyleSheet.absoluteFill, { backgroundColor: theme.color.mediaOverlay, justifyContent: 'center', alignItems: 'center' }, overflowOverlayStyle]}
|
|
102
101
|
>
|
|
103
102
|
{/* heading1.bold = { fontSize: 24, fontWeight: '700' }; letterSpacing -0.5 is a micro-adjust. */}
|
|
104
103
|
<Text style={[{ ...theme.typography.heading1.bold, color: theme.color.staticWhite, letterSpacing: -0.5 }, overflowTextStyle]}>{`+${overflowCount}`}</Text>
|
|
@@ -244,28 +243,6 @@ export function CometChatImagesBubble({
|
|
|
244
243
|
const caption = message.getCaption() ?? '';
|
|
245
244
|
const isSentByMe = message.getSender()?.getUid() === CometChatUIKit.loggedInUser?.getUid();
|
|
246
245
|
|
|
247
|
-
// §8.7 — refresh the local copy when the server edits the message in.
|
|
248
|
-
useEffect(() => {
|
|
249
|
-
const listenerId = `ImagesBubble_${message.getId?.() ?? message.getMuid?.() ?? Date.now()}`;
|
|
250
|
-
CometChatMessageEvents.addListener(
|
|
251
|
-
CometChatMessageEvents.messageEdited,
|
|
252
|
-
listenerId,
|
|
253
|
-
(edited: CometChat.BaseMessage) => {
|
|
254
|
-
const editedId = edited.getId?.();
|
|
255
|
-
const editedMuid = edited.getMuid?.();
|
|
256
|
-
const myId = message.getId?.();
|
|
257
|
-
const myMuid = message.getMuid?.();
|
|
258
|
-
if (
|
|
259
|
-
edited instanceof CometChat.MediaMessage &&
|
|
260
|
-
((myId && editedId && myId === editedId) || (myMuid && editedMuid && myMuid === editedMuid))
|
|
261
|
-
) {
|
|
262
|
-
setMessage(edited);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
);
|
|
266
|
-
return () => CometChatMessageEvents.removeListener(CometChatMessageEvents.messageEdited, listenerId);
|
|
267
|
-
}, []);
|
|
268
|
-
|
|
269
246
|
useEffect(() => {
|
|
270
247
|
setMessage(initialMessage);
|
|
271
248
|
}, [initialMessage]);
|
|
@@ -322,7 +322,8 @@ export function useAudioRecorder(): UseAudioRecorderReturn {
|
|
|
322
322
|
|
|
323
323
|
if (reducerState.state === 'recording') {
|
|
324
324
|
// Listen for native amplitude events
|
|
325
|
-
subscription = FileManagerEmitter.addListener('audioAmplitude', (
|
|
325
|
+
subscription = FileManagerEmitter.addListener('audioAmplitude', (data) => {
|
|
326
|
+
const event = data as { amplitude: number };
|
|
326
327
|
const amplitude = event.amplitude;
|
|
327
328
|
|
|
328
329
|
// WhatsApp-style amplitude processing:
|
|
@@ -371,7 +372,8 @@ export function useAudioRecorder(): UseAudioRecorderReturn {
|
|
|
371
372
|
|
|
372
373
|
if (reducerState.state === 'playing') {
|
|
373
374
|
// Listen for playback complete event from native
|
|
374
|
-
statusSubscription = FileManagerEmitter.addListener('status', (
|
|
375
|
+
statusSubscription = FileManagerEmitter.addListener('status', (data) => {
|
|
376
|
+
const event = data as { state: string };
|
|
375
377
|
// Ignore playback complete during seeking - it might be stale
|
|
376
378
|
if (event.state === 'playbackComplete' && !isSeekingRef.current) {
|
|
377
379
|
dispatch({ type: 'PLAYBACK_COMPLETE' });
|
|
@@ -176,7 +176,7 @@ export default function Header({
|
|
|
176
176
|
}: HeaderProps) {
|
|
177
177
|
const theme = useTheme();
|
|
178
178
|
const { t } = useCometChatTranslation();
|
|
179
|
-
const inputRef = useRef<TextInput
|
|
179
|
+
const inputRef = useRef<React.ComponentRef<typeof TextInput>>(null);
|
|
180
180
|
// Callers that pass nothing used to get a hardcoded English "Search", which
|
|
181
181
|
// is why the conversation list's search box stayed English in every locale.
|
|
182
182
|
const searchPlaceholder = searchPlaceholderText ?? t("SEARCH");
|
package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx
CHANGED
|
@@ -80,7 +80,8 @@ export const CometChatAudioPreview = ({
|
|
|
80
80
|
}, [audioUrl]);
|
|
81
81
|
|
|
82
82
|
useEffect(() => {
|
|
83
|
-
listener = eventEmitter.addListener("soundPlayStatus", (
|
|
83
|
+
listener = eventEmitter.addListener("soundPlayStatus", (event) => {
|
|
84
|
+
const data = event as { url?: string };
|
|
84
85
|
if (audioUrl === data.url) {
|
|
85
86
|
// playback ended for this url — reset to idle, clear interval and reset time
|
|
86
87
|
setStatus("");
|