@robono/messaging-react-native 0.13.0 → 0.14.0
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/CHANGELOG.md +7 -1
- package/SBOM.spdx.json +577 -217
- package/dist/attachment-preview.d.ts +18 -0
- package/dist/attachment-preview.js +27 -0
- package/dist/composer-input.d.ts +5 -0
- package/dist/composer-input.js +13 -0
- package/dist/conversation-selector.d.ts +9 -0
- package/dist/conversation-selector.js +19 -0
- package/dist/expo-document.d.ts +7 -0
- package/dist/expo-document.js +50 -0
- package/dist/expo-media.js +5 -1
- package/dist/expo-messenger.d.ts +2 -0
- package/dist/expo-screen.d.ts +5 -1
- package/dist/expo-screen.js +67 -31
- package/dist/expo-thumbnails.d.ts +3 -1
- package/dist/expo-thumbnails.js +3 -1
- package/dist/index.d.ts +22 -4
- package/dist/index.js +88 -41
- package/dist/keyboard-container.d.ts +10 -0
- package/dist/keyboard-container.js +18 -0
- package/dist/media-controller.d.ts +1 -0
- package/dist/media-controller.js +3 -2
- package/dist/media-ui.d.ts +4 -1
- package/dist/media-ui.js +5 -5
- package/dist/pdf-preview.d.ts +2 -0
- package/dist/pdf-preview.js +7 -0
- package/dist/pdf-renderer.generated.d.ts +1 -0
- package/dist/pdf-renderer.generated.js +2 -0
- package/dist/preview-cache.d.ts +1 -0
- package/dist/preview-cache.js +2 -0
- package/dist/translation-settings.js +5 -3
- package/licenses/pdfjs-LICENSE +177 -0
- package/package.json +3 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MessagingMessage } from '@robono/messaging';
|
|
2
|
+
export type AttachmentPreviewLoader = (message: MessagingMessage, options?: {
|
|
3
|
+
refresh?: boolean;
|
|
4
|
+
}) => Promise<{
|
|
5
|
+
uri?: string;
|
|
6
|
+
waveform?: number[];
|
|
7
|
+
}>;
|
|
8
|
+
/** Retry a visible thumbnail a bounded number of times; never keep a failed
|
|
9
|
+
* effect dormant forever, and never publish a result from the previous chat. */
|
|
10
|
+
export declare function useAttachmentPreview(message: MessagingMessage, load: AttachmentPreviewLoader | undefined, active?: boolean): {
|
|
11
|
+
preview: {
|
|
12
|
+
uri?: string;
|
|
13
|
+
waveform?: number[];
|
|
14
|
+
};
|
|
15
|
+
failed: boolean;
|
|
16
|
+
retry: () => void;
|
|
17
|
+
onImageError: () => void;
|
|
18
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEffect, useState, useRef } from 'react';
|
|
2
|
+
import { AppState } from 'react-native';
|
|
3
|
+
/** Retry a visible thumbnail a bounded number of times; never keep a failed
|
|
4
|
+
* effect dormant forever, and never publish a result from the previous chat. */
|
|
5
|
+
export function useAttachmentPreview(message, load, active = true) {
|
|
6
|
+
const loader = useRef(load);
|
|
7
|
+
loader.current = load;
|
|
8
|
+
const [preview, setPreview] = useState({}), [attempt, setAttempt] = useState(0), [failed, setFailed] = useState(false);
|
|
9
|
+
const retry = () => setAttempt(n => n + 1);
|
|
10
|
+
useEffect(() => { setAttempt(0); setPreview({}); }, [message.id, message.conversationId, message.media?.assetId, message.revision]);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
let alive = true, timer;
|
|
13
|
+
if (!loader.current || !active || message.deleted)
|
|
14
|
+
return;
|
|
15
|
+
setFailed(false);
|
|
16
|
+
void loader.current(message, { refresh: attempt > 0 }).then(value => { if (!alive)
|
|
17
|
+
return; setPreview(value); if (!value.uri && ['image', 'video'].includes(message.kind))
|
|
18
|
+
missing(); }, () => { if (alive)
|
|
19
|
+
missing(); });
|
|
20
|
+
function missing() { setFailed(true); if (attempt < 2)
|
|
21
|
+
timer = setTimeout(retry, attempt === 0 ? 1000 : 3000); }
|
|
22
|
+
const subscription = AppState.addEventListener('change', state => { if (state === 'active' && alive)
|
|
23
|
+
setAttempt(n => n < 3 ? n + 1 : n); });
|
|
24
|
+
return () => { alive = false; clearTimeout(timer); subscription.remove(); };
|
|
25
|
+
}, [!!load, message.id, message.conversationId, message.media?.assetId, message.revision, message.deleted, attempt, active]);
|
|
26
|
+
return { preview, failed, retry, onImageError: () => { setPreview({}); setFailed(true); } };
|
|
27
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type TextInputProps } from 'react-native';
|
|
3
|
+
/** Native content-size callbacks can miss restored/programmatically changed
|
|
4
|
+
* drafts. Measure the same text so typing, paste and draft restore size alike. */
|
|
5
|
+
export declare const ComposerInput: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<import("react-native").TextInput>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState } from 'react';
|
|
3
|
+
import { Platform, View } from 'react-native';
|
|
4
|
+
import { Text, TextInput } from './typography.js';
|
|
5
|
+
/** Native content-size callbacks can miss restored/programmatically changed
|
|
6
|
+
* drafts. Measure the same text so typing, paste and draft restore size alike. */
|
|
7
|
+
export const ComposerInput = forwardRef(function ComposerInput({ style, value, onContentSizeChange, ...props }, ref) {
|
|
8
|
+
const [height, setHeight] = useState(44);
|
|
9
|
+
const resize = (next) => setHeight(Math.max(44, Math.min(120, Math.ceil(next))));
|
|
10
|
+
const layout = (event) => { const lines = event.nativeEvent.lines, last = lines[lines.length - 1]; resize(last ? last.y + last.height + 16 : 44); };
|
|
11
|
+
return _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [Platform.OS !== 'web' && _jsx(View, { pointerEvents: "none", accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: { position: 'absolute', top: 0, left: 4, right: 4, opacity: 0 }, children: _jsx(Text, { onTextLayout: layout, style: { fontSize: 16, lineHeight: 22 }, children: value || ' ' }) }), _jsx(TextInput, { ...props, value: value, ref: ref, multiline: true, scrollEnabled: height >= 120, onContentSizeChange: event => { if (Platform.OS === 'web')
|
|
12
|
+
resize(event.nativeEvent.contentSize.height); onContentSizeChange?.(event); }, style: [style, { flex: undefined, height, minHeight: 44, maxHeight: 120 }] })] });
|
|
13
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { MessagingHeaderOptions } from '@robono/messaging';
|
|
3
|
+
export type { MessagingHeaderOptions, MessagingConversationChoice } from '@robono/messaging';
|
|
4
|
+
export declare function ConversationSelector({ options, selectedId, color, background }: {
|
|
5
|
+
options?: MessagingHeaderOptions;
|
|
6
|
+
selectedId: string;
|
|
7
|
+
color: string;
|
|
8
|
+
background: string;
|
|
9
|
+
}): React.JSX.Element | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useEffect } from 'react';
|
|
3
|
+
import { View, Pressable, ScrollView, Image } from 'react-native';
|
|
4
|
+
import { Text } from './typography.js';
|
|
5
|
+
import { MessageIcon } from './icons.js';
|
|
6
|
+
import { MessagingMenuSurface } from './popup.js';
|
|
7
|
+
import { useRobonoLocale } from './localization.js';
|
|
8
|
+
export function ConversationSelector({ options, selectedId, color, background }) {
|
|
9
|
+
const { text } = useRobonoLocale(), anchor = useRef(null);
|
|
10
|
+
const [point, setPoint] = useState(null), [busy, setBusy] = useState(false), [error, setError] = useState('');
|
|
11
|
+
const generation = useRef(0), choiceIds = JSON.stringify(options?.conversations?.map(choice => choice.id));
|
|
12
|
+
useEffect(() => { generation.current++; setPoint(null); setBusy(false); setError(''); return () => { generation.current++; }; }, [selectedId, choiceIds]);
|
|
13
|
+
if (!options?.onSelectConversation || (options.conversations?.length ?? 0) < 2)
|
|
14
|
+
return null;
|
|
15
|
+
return _jsxs(_Fragment, { children: [_jsx(Pressable, { ref: anchor, accessibilityRole: "button", accessibilityLabel: text('Choose conversation'), onPress: () => anchor.current?.measureInWindow((x, y, w, h) => setPoint({ x, y: y + h })), style: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "chevron-down", color: color, size: 22 }) }), _jsx(MessagingMenuSurface, { visible: !!point, onClose: () => setPoint(null), children: rect => _jsxs(View, { style: { flex: 1 }, children: [_jsx(Pressable, { accessibilityLabel: text('Close conversation list'), onPress: () => setPoint(null), style: { position: 'absolute', inset: 0 } }), _jsxs(View, { accessibilityViewIsModal: true, style: { position: 'absolute', left: Math.max(8, Math.min((point?.x ?? 0) - rect.left, rect.width - 288)), top: Math.max(8, Math.min((point?.y ?? 0) - rect.top, rect.height - 160)), width: Math.min(280, rect.width - 16), maxHeight: Math.min(360, Math.max(120, rect.height - (point?.y ?? 0) + rect.top - 8)), backgroundColor: background, borderWidth: 1, borderColor: color + '44', borderRadius: 12, padding: 4 }, children: [_jsx(ScrollView, { keyboardShouldPersistTaps: "handled", children: options.conversations?.map(choice => _jsxs(Pressable, { accessibilityRole: "button", accessibilityState: { selected: choice.id === selectedId, disabled: busy }, disabled: busy, onPress: () => { const current = ++generation.current; setBusy(true); setError(''); void Promise.resolve().then(() => options.onSelectConversation(choice)).then(() => { if (current === generation.current)
|
|
16
|
+
setPoint(null); }, () => { if (current === generation.current)
|
|
17
|
+
setError(text('This conversation could not be opened. Try again.')); }).finally(() => { if (current === generation.current)
|
|
18
|
+
setBusy(false); }); }, style: { minHeight: 52, padding: 8, flexDirection: 'row', alignItems: 'center', gap: 10, borderRadius: 8, backgroundColor: choice.id === selectedId ? color + '18' : 'transparent' }, children: [choice.avatarUrl ? _jsx(Image, { source: { uri: choice.avatarUrl }, style: { width: 32, height: 32, borderRadius: 16 } }) : _jsx(View, { style: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: color + '18' }, children: _jsx(Text, { style: { color }, children: choice.name.slice(0, 1) }) }), _jsx(Text, { numberOfLines: 1, style: { flex: 1, color, fontSize: 16 }, children: choice.name }), !!choice.unreadCount && _jsx(Text, { accessibilityLabel: text('Unread messages'), style: { color, fontWeight: '700' }, children: choice.unreadCount > 99 ? '99+' : choice.unreadCount })] }, choice.id)) }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color, padding: 8 }, children: error })] })] }) })] });
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { LocalMessagingMedia } from './media-controller.js';
|
|
3
|
+
/** Text is rendered as text, never HTML or active document content. */
|
|
4
|
+
export declare function ExpoDocumentPreview({ file, onOpenLink }: {
|
|
5
|
+
file: LocalMessagingMedia;
|
|
6
|
+
onOpenLink?: (url: string) => void;
|
|
7
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { messageLinks } from './message-links.js';
|
|
3
|
+
import { WebView } from 'react-native-webview';
|
|
4
|
+
import { pdfDocumentHtml } from './pdf-preview.js';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { ScrollView, View, ActivityIndicator } from 'react-native';
|
|
7
|
+
import { Text } from './typography.js';
|
|
8
|
+
import * as FS from 'expo-file-system/legacy';
|
|
9
|
+
/** Text is rendered as text, never HTML or active document content. */
|
|
10
|
+
export function ExpoDocumentPreview({ file, onOpenLink }) {
|
|
11
|
+
const [documentStatus, setDocumentStatus] = useState('Opening PDF');
|
|
12
|
+
const [html, setHtml] = useState(null);
|
|
13
|
+
const [content, setContent] = useState(null), [error, setError] = useState('');
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
let live = true;
|
|
16
|
+
setContent(null);
|
|
17
|
+
setError('');
|
|
18
|
+
setHtml(null);
|
|
19
|
+
setDocumentStatus('Opening PDF');
|
|
20
|
+
if (file.mimeType === 'application/pdf') {
|
|
21
|
+
if (file.byteSize > 25 * 1024 * 1024) {
|
|
22
|
+
setError('This PDF is too large to preview.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
void FS.readAsStringAsync(file.uri, { encoding: FS.EncodingType.Base64 }).then(bytes => { if (live)
|
|
26
|
+
setHtml(pdfDocumentHtml(bytes, !!onOpenLink)); }).catch(() => { if (live)
|
|
27
|
+
setError('This PDF could not be opened. Try again.'); });
|
|
28
|
+
return () => { live = false; };
|
|
29
|
+
}
|
|
30
|
+
if (!/^(text\/(plain|csv)|application\/json)(;|$)/i.test(file.mimeType) || file.byteSize > 1024 * 1024) {
|
|
31
|
+
setError('A preview is not available for this file.');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
void FS.readAsStringAsync(file.uri).then(value => { if (live)
|
|
35
|
+
setContent(value); }, () => { if (live)
|
|
36
|
+
setError('This preview could not be opened. Close it and try again.'); });
|
|
37
|
+
return () => { live = false; };
|
|
38
|
+
}, [file.uri, file.mimeType, file.byteSize, !!onOpenLink]);
|
|
39
|
+
return html ? _jsx(WebView, { accessibilityLabel: documentStatus, source: { html }, onMessage: event => { try {
|
|
40
|
+
const value = JSON.parse(event.nativeEvent.data);
|
|
41
|
+
if (value.type === 'robono-document-status' && typeof value.status === 'string' && /^(Page \d+ of \d+|Preview unavailable)$/.test(value.status)) {
|
|
42
|
+
setDocumentStatus(value.status);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const url = new URL(value.url);
|
|
46
|
+
if (value.type === 'robono-document-link' && ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password)
|
|
47
|
+
onOpenLink?.(url.href);
|
|
48
|
+
}
|
|
49
|
+
catch { } }, originWhitelist: ['*'], onShouldStartLoadWithRequest: request => request.url === 'about:blank', allowFileAccess: false, allowFileAccessFromFileURLs: false, allowUniversalAccessFromFileURLs: false, mixedContentMode: "never", javaScriptCanOpenWindowsAutomatically: false, setSupportMultipleWindows: false, style: { flex: 1, backgroundColor: '#111' } }) : _jsx(View, { style: { flex: 1, padding: 16 }, children: error ? _jsx(Text, { accessibilityRole: "alert", style: { color: '#fff', fontSize: 17 }, children: error }) : content === null ? _jsx(ActivityIndicator, { color: "#fff" }) : _jsx(ScrollView, { children: _jsx(Text, { selectable: true, style: { color: '#fff', fontSize: 16, lineHeight: 23 }, children: messageLinks(content).map((part, index) => part.url && onOpenLink ? _jsx(Text, { accessibilityRole: "link", onPress: () => onOpenLink(part.url), style: { color: '#8ab4f8', textDecorationLine: 'underline' }, children: part.text }, index) : part.text) }) }) });
|
|
50
|
+
}
|
package/dist/expo-media.js
CHANGED
|
@@ -384,7 +384,11 @@ export function createExpoMessagingStorage(options) {
|
|
|
384
384
|
},
|
|
385
385
|
async thumbnail(message, context) {
|
|
386
386
|
check(context.signal);
|
|
387
|
-
|
|
387
|
+
if (message.deleted)
|
|
388
|
+
throw Error('This attachment is no longer available.');
|
|
389
|
+
const grant = message.attachmentPreview;
|
|
390
|
+
const fresh = grant && grant.messageId === message.id && grant.conversationId === message.conversationId && grant.assetId === message.media?.assetId && Number.isFinite(grant.expiresAt) && grant.expiresAt > Date.now() + 5000 && grant.expiresAt <= Date.now() + 60000 && Number.isSafeInteger(grant.byteSize) && grant.byteSize > 0 && grant.byteSize <= 131072;
|
|
391
|
+
const plan = fresh ? { url: grant.url, media: { assetId: grant.assetId, mimeType: 'image/jpeg', fileName: 'preview.jpg', byteSize: grant.byteSize } } : await request('thumbnail', { conversationId: message.conversationId, messageId: message.id }, context.signal);
|
|
388
392
|
if (!plan)
|
|
389
393
|
return null;
|
|
390
394
|
const media = plan.media;
|
package/dist/expo-messenger.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export declare function createExpoMessenger(options: {
|
|
|
10
10
|
userId: string;
|
|
11
11
|
getAccessToken: () => Promise<string>;
|
|
12
12
|
fetch?: typeof fetch;
|
|
13
|
+
/** Host-authorized transcription/translation, including any credit checks. */
|
|
14
|
+
transformRequest?: import('@robono/messaging').MessagingRequest;
|
|
13
15
|
availability?: false;
|
|
14
16
|
notifications?: false;
|
|
15
17
|
extras?: false;
|
package/dist/expo-screen.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MessagingViewerPolicy } from '@robono/messaging';
|
|
1
2
|
export { createExpoMessagingClient } from './expo-outbox.js';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import { type MessagingAppearance, type MessagingMessage } from '@robono/messaging';
|
|
@@ -14,7 +15,9 @@ export type MessagingAttachmentDownload = (input: {
|
|
|
14
15
|
file: LocalMessagingMedia;
|
|
15
16
|
signal: AbortSignal;
|
|
16
17
|
}) => Promise<void>;
|
|
17
|
-
export declare function MessagingMediaOverlay({ controller, audio, appearance, inlineVoice, inlineRecorder, viewerActions, onDismiss, onDownloadAttachment }: {
|
|
18
|
+
export declare function MessagingMediaOverlay({ controller, audio, appearance, inlineVoice, inlineRecorder, viewerActions, onDismiss, onDownloadAttachment, mediaViewer, onDocumentLink }: {
|
|
19
|
+
onDocumentLink?: (url: string) => void;
|
|
20
|
+
mediaViewer?: MessagingViewerPolicy<LocalMessagingMedia>;
|
|
18
21
|
onDownloadAttachment?: MessagingAttachmentDownload;
|
|
19
22
|
onDismiss?: () => void;
|
|
20
23
|
viewerActions?: () => {
|
|
@@ -31,6 +34,7 @@ export interface ExpoMessagingScreenProps extends Omit<MessagingScreenProps, 'pi
|
|
|
31
34
|
storage: MessagingMediaStorage;
|
|
32
35
|
audioSession: MessagingAudioSession;
|
|
33
36
|
/** Save an authorized private copy to your own destination. Copy it before resolving; Robono removes its temporary copy afterward. Respect signal when the viewer/account closes. */
|
|
37
|
+
mediaViewer?: MessagingViewerPolicy<LocalMessagingMedia>;
|
|
34
38
|
onDownloadAttachment?: MessagingAttachmentDownload;
|
|
35
39
|
/** Optional timing callback from native image/frame/playback readiness, measured from opening. */
|
|
36
40
|
onMediaReady?: (event: {
|
package/dist/expo-screen.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Linking } from 'react-native';
|
|
3
|
+
import { ExpoDocumentPreview } from './expo-document.js';
|
|
2
4
|
import { MessagingTypography } from './typography.js';
|
|
3
5
|
import { Text } from './typography.js';
|
|
4
6
|
import { RobonoLocaleProvider } from './localization.js';
|
|
@@ -332,37 +334,68 @@ function FileViewer({ file, kind, audio, design }) {
|
|
|
332
334
|
} })();
|
|
333
335
|
} }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: design.colors.foreground }, children: error })] });
|
|
334
336
|
}
|
|
335
|
-
export function MessagingMediaOverlay({ controller, audio, appearance, inlineVoice = false, inlineRecorder = false, viewerActions, onDismiss, onDownloadAttachment }) {
|
|
336
|
-
const { text: uiText
|
|
337
|
-
const state = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
|
|
338
|
-
const c = appearance.colors;
|
|
337
|
+
export function MessagingMediaOverlay({ controller, audio, appearance, inlineVoice = false, inlineRecorder = false, viewerActions, onDismiss, onDownloadAttachment, mediaViewer, onDocumentLink }) {
|
|
338
|
+
const { text: uiText } = useRobonoLocale();
|
|
339
|
+
const state = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot), c = appearance.colors;
|
|
339
340
|
const mediaReady = useContext(MediaReadiness);
|
|
340
|
-
const [fileError, setFileError] = useState(''), [downloading, setDownloading] = useState(false);
|
|
341
|
+
const [fileError, setFileError] = useState(''), [downloading, setDownloading] = useState(false), [status, setStatus] = useState('');
|
|
341
342
|
const saving = useRef(false);
|
|
343
|
+
const latest = useRef({ mediaViewer, appearance, onDownloadAttachment });
|
|
344
|
+
latest.current = { mediaViewer, appearance, onDownloadAttachment };
|
|
345
|
+
const enabled = (action) => action === 'download' ? latest.current.mediaViewer?.download !== false && latest.current.appearance.showDownloadButton === true : latest.current.mediaViewer?.[action] !== false && latest.current.appearance.mediaViewer?.[action] !== false;
|
|
346
|
+
const policyKey = JSON.stringify([mediaViewer?.revision, mediaViewer?.download, mediaViewer?.share, mediaViewer?.open, mediaViewer?.forward, mediaViewer?.delete, appearance.showDownloadButton, appearance.mediaViewer]);
|
|
347
|
+
useEffect(() => () => { void controller.cancel(); }, [controller, policyKey]);
|
|
342
348
|
const [expanded, setExpanded] = useState(false);
|
|
343
|
-
useEffect(() => setExpanded(false), [state.file?.uri, state.phase]);
|
|
349
|
+
useEffect(() => { setExpanded(false); setFileError(''); setStatus(''); }, [state.file?.uri, state.phase]);
|
|
344
350
|
const review = ['review', 'failed'].includes(state.phase) && !!state.file;
|
|
351
|
+
const perform = (action, callback) => {
|
|
352
|
+
if (saving.current || !enabled(action))
|
|
353
|
+
return;
|
|
354
|
+
saving.current = true;
|
|
355
|
+
setDownloading(true);
|
|
356
|
+
setFileError('');
|
|
357
|
+
setStatus('');
|
|
358
|
+
void controller.exportFile(async (file, context) => {
|
|
359
|
+
const message = context.message;
|
|
360
|
+
if (!message)
|
|
361
|
+
throw Error('The attachment is unavailable.');
|
|
362
|
+
const check = async () => { if (context.signal.aborted || !enabled(action))
|
|
363
|
+
throw Error('This action is no longer allowed.'); await latest.current.mediaViewer?.authorize?.({ action, message, signal: context.signal }); if (context.signal.aborted || !enabled(action))
|
|
364
|
+
throw Error('This action is no longer allowed.'); };
|
|
365
|
+
await check();
|
|
366
|
+
const input = { file, message, signal: context.signal };
|
|
367
|
+
if (callback)
|
|
368
|
+
callback();
|
|
369
|
+
else if (action === 'download') {
|
|
370
|
+
if (latest.current.onDownloadAttachment)
|
|
371
|
+
await latest.current.onDownloadAttachment(input);
|
|
372
|
+
else
|
|
373
|
+
await saveMessagingAttachment(file, state.kind);
|
|
374
|
+
}
|
|
375
|
+
else if (action === 'share' && latest.current.mediaViewer?.onShare)
|
|
376
|
+
await latest.current.mediaViewer.onShare(input);
|
|
377
|
+
else if (action === 'open' && latest.current.mediaViewer?.onOpen)
|
|
378
|
+
await latest.current.mediaViewer.onOpen(input);
|
|
379
|
+
else {
|
|
380
|
+
if (!await Sharing.isAvailableAsync())
|
|
381
|
+
throw Error('Sharing is unavailable on this device.');
|
|
382
|
+
await check();
|
|
383
|
+
await Sharing.shareAsync(file.uri, { mimeType: file.mimeType, dialogTitle: file.fileName });
|
|
384
|
+
}
|
|
385
|
+
if (!context.signal.aborted) {
|
|
386
|
+
mediaReady('file-opened', file.uri);
|
|
387
|
+
if (action === 'download')
|
|
388
|
+
setStatus(uiText('Downloaded'));
|
|
389
|
+
}
|
|
390
|
+
}, { reauthorize: !callback, requireLocalFile: !callback }).catch(e => { if (controller.getSnapshot().phase === 'viewing')
|
|
391
|
+
setFileError(e instanceof Error ? e.message : uiText('This action could not finish. Try again.')); }).finally(() => { saving.current = false; setDownloading(false); });
|
|
392
|
+
};
|
|
345
393
|
if (state.phase !== 'idle' && (typeof inlineRecorder === 'function' ? inlineRecorder() : inlineRecorder) && state.kind === 'voice')
|
|
346
394
|
return null;
|
|
347
395
|
if ((typeof inlineVoice === 'function' ? inlineVoice() : inlineVoice) && state.kind === 'voice' && ['opening', 'viewing', 'failed'].includes(state.phase) && !review)
|
|
348
396
|
return null;
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
if (!context.message)
|
|
352
|
-
throw Error('The attachment is unavailable.');
|
|
353
|
-
await onDownloadAttachment({ file, message: context.message, signal: context.signal });
|
|
354
|
-
}
|
|
355
|
-
else
|
|
356
|
-
await saveMessagingAttachment(file, state.kind); if (!context.signal.aborted)
|
|
357
|
-
mediaReady('file-opened', file.uri); }, { reauthorize: !!onDownloadAttachment }).catch(e => setFileError(e instanceof Error ? e.message : uiText("Could not save the attachment."))).finally(() => { saving.current = false; setDownloading(false); }); } : undefined, onShare: !review ? () => { void controller.exportFile(async (file) => { await Sharing.shareAsync(file.uri, { mimeType: file.mimeType, dialogTitle: file.fileName }); mediaReady('file-opened', state.file.uri); }).catch(() => setFileError(uiText("Could not share this attachment."))); } : undefined, onFileAction: () => { void (async () => { try {
|
|
358
|
-
if (!await Sharing.isAvailableAsync())
|
|
359
|
-
throw Error('File opening is unavailable.');
|
|
360
|
-
await Sharing.shareAsync(state.file.uri, { mimeType: state.file.mimeType, dialogTitle: state.file.fileName });
|
|
361
|
-
mediaReady('file-opened', state.file.uri);
|
|
362
|
-
}
|
|
363
|
-
catch (e) {
|
|
364
|
-
setFileError(e instanceof Error ? e.message : uiText("Could not open the file."));
|
|
365
|
-
} })(); }, children: state.kind === 'video' ? _jsx(VideoPlayer, { file: state.file, audio: audio, design: appearance }, state.file.uri) : state.kind === 'voice' ? _jsx(View, { style: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20 }, children: _jsx(VoicePlayer, { file: state.file, audio: audio, design: { ...appearance, colors: { ...appearance.colors, foreground: '#ffffff', accent: '#8ab4f8' } } }) }) : null }) : null;
|
|
397
|
+
const actions = !review ? viewerActions?.() : undefined;
|
|
398
|
+
const viewer = state.file && (review || state.phase === 'viewing') ? _jsx(MediaViewer, { expanded: expanded, onExpandedChange: setExpanded, keepControlsVisible: mediaViewer?.keepControlsVisible ?? appearance.mediaViewer?.keepControlsVisible, status: status, kind: state.kind, uri: state.file.uri, title: review ? uiText('Preview attachment') : state.kind === 'image' ? uiText('Photo') : state.kind === 'video' ? uiText('Video') : state.kind === 'voice' ? uiText('Voice message') : uiText('File'), subtitle: state.file.fileName, fileName: state.file.fileName, byteSize: state.file.byteSize, error: state.error ?? fileError, onClose: () => { setFileError(''); void controller.cancel(); }, reviewAction: review ? (state.phase === 'failed' ? 'Retry upload' : 'Add attachment') : undefined, onReview: review ? () => void controller.send() : undefined, downloading: downloading, transferProgress: downloading ? state.progress : undefined, onForward: actions?.onForward && enabled('forward') ? () => perform('forward', actions.onForward) : undefined, onDelete: actions?.onDelete && enabled('delete') ? () => perform('delete', actions.onDelete) : undefined, onDownload: !review && enabled('download') && ['image', 'video', 'document'].includes(state.kind) ? () => perform('download') : undefined, onShare: !review && enabled('share') ? () => perform('share') : undefined, onFileAction: !review && enabled('open') ? () => perform('open') : undefined, children: state.kind === 'document' ? _jsx(ExpoDocumentPreview, { file: state.file, onOpenLink: onDocumentLink }) : state.kind === 'video' ? _jsx(VideoPlayer, { file: state.file, audio: audio, design: appearance }, state.file.uri) : state.kind === 'voice' ? _jsx(View, { style: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20 }, children: _jsx(VoicePlayer, { file: state.file, audio: audio, design: { ...appearance, colors: { ...appearance.colors, foreground: '#ffffff', accent: '#8ab4f8' } } }) }) : null }) : null;
|
|
366
399
|
// A native modal has its own window; measure its safe area inside that window.
|
|
367
400
|
return _jsx(Modal, { transparent: true, visible: state.phase !== 'idle' && state.phase !== 'choosing', onDismiss: onDismiss, animationType: "fade", onRequestClose: () => { if (expanded)
|
|
368
401
|
setExpanded(false);
|
|
@@ -428,6 +461,8 @@ function ExpoMessagingScreenContent({ storage, audioSession, renderConversation,
|
|
|
428
461
|
const thumbnails = useMemo(() => createExpoThumbnails(recent.storage, id => controller.getPrepared(id) ?? recorder.getPrepared(id), createExpoMessagingDevice(audioSession).remove), [recent, controller, recorder, audioSession]);
|
|
429
462
|
const thumbnailAccess = JSON.stringify([state.settings?.enabled, state.settings?.features, state.conversation?.canSend, !!state.error]);
|
|
430
463
|
useEffect(() => () => thumbnails.clear(), [thumbnails, state.conversationId, thumbnailAccess, props.active]);
|
|
464
|
+
useEffect(() => { const sub = AppState.addEventListener('change', value => { if (value !== 'active')
|
|
465
|
+
thumbnails.clear(); }); return () => sub.remove(); }, [thumbnails]);
|
|
431
466
|
const cacheDisposal = useRef(new Map());
|
|
432
467
|
useEffect(() => {
|
|
433
468
|
clearTimeout(cacheDisposal.current.get(recent));
|
|
@@ -468,7 +503,7 @@ function ExpoMessagingScreenContent({ storage, audioSession, renderConversation,
|
|
|
468
503
|
const conversation = useRef(state.conversationId);
|
|
469
504
|
const disposal = useRef(new Map());
|
|
470
505
|
useEffect(() => {
|
|
471
|
-
if (conversation.current !== state.conversationId || props.active === false || !state.settings?.enabled || message.current && !state.messages.some(m => m.id === message.current.id && !m.deleted) && !controller.getPrepared(message.current.media?.assetId ?? '') && !recorder.getPrepared(message.current.media?.assetId ?? '')) {
|
|
506
|
+
if (conversation.current !== state.conversationId || props.active === false || !state.settings?.enabled || message.current && ![...state.messages, ...(state.latestVoices ?? [])].some(m => m.id === message.current.id && !m.deleted) && !controller.getPrepared(message.current.media?.assetId ?? '') && !recorder.getPrepared(message.current.media?.assetId ?? '')) {
|
|
472
507
|
++openingIntent.current;
|
|
473
508
|
afterViewer.current = undefined;
|
|
474
509
|
message.current = null;
|
|
@@ -507,8 +542,8 @@ function ExpoMessagingScreenContent({ storage, audioSession, renderConversation,
|
|
|
507
542
|
return ready ? _jsx(ExpoSocialPlayer, { ...ui }) : null;
|
|
508
543
|
}, [audioSession]);
|
|
509
544
|
useEffect(() => saved?.bindDownload(async (m) => { const device = createExpoMessagingDevice(audioSession), file = await storage.download(m, { signal: AbortSignal.timeout(120000), onProgress: () => { } }); return { file, release: () => device.remove(file) }; }), [saved, storage, audioSession]);
|
|
510
|
-
const attachmentPreview = useCallback(async (m) => { if (m.media && m.kind !== 'text' && m.kind !== 'poll')
|
|
511
|
-
await restore(m.media, m.kind); return thumbnails.preview(m); }, [restore, thumbnails]);
|
|
545
|
+
const attachmentPreview = useCallback(async (m, options) => { if (m.media && m.kind !== 'text' && m.kind !== 'poll')
|
|
546
|
+
await restore(m.media, m.kind); return thumbnails.preview(m, options); }, [restore, thumbnails]);
|
|
512
547
|
const screenProps = { ...props, requestedMessageAction,
|
|
513
548
|
onQuoteReady: props.onQuoteReady ?? (() => { if (Platform.OS === 'android')
|
|
514
549
|
Vibration.vibrate(8);
|
|
@@ -547,7 +582,7 @@ function ExpoMessagingScreenContent({ storage, audioSession, renderConversation,
|
|
|
547
582
|
return media;
|
|
548
583
|
},
|
|
549
584
|
openAttachment: async (m) => { const intent = ++openingIntent.current; await stopVoicePlayers(); if (intent !== openingIntent.current)
|
|
550
|
-
return; opened.current = { messageId: m.id, kind: m.kind, started: Date.now(), reported:
|
|
585
|
+
return; opened.current = { messageId: m.id, kind: m.kind, started: Date.now(), reported: new Set() }; message.current = m; const draft = m.media && m.kind !== 'text' && m.kind !== 'poll' ? await restore(m.media, m.kind) : undefined; if (draft && m.kind !== 'text' && m.kind !== 'poll')
|
|
551
586
|
await controller.previewLocal(await copyMessagingCache(draft), m.kind);
|
|
552
587
|
else
|
|
553
588
|
await controller.open(m); },
|
|
@@ -559,14 +594,15 @@ function ExpoMessagingScreenContent({ storage, audioSession, renderConversation,
|
|
|
559
594
|
};
|
|
560
595
|
const mediaReady = (stage, uri) => { const event = opened.current; if (!event || controller.getSnapshot().phase !== 'viewing' || controller.getSnapshot().file?.uri !== uri)
|
|
561
596
|
return; if (stage !== 'video-frame' && message.current?.conversationId === current.current.client.getSnapshot().conversationId)
|
|
562
|
-
void current.current.client.consumeMessage(event.messageId).catch(() => { }); if (event.reported)
|
|
563
|
-
return; event.reported
|
|
597
|
+
void current.current.client.consumeMessage(event.messageId).catch(() => { }); if (event.reported.has(stage))
|
|
598
|
+
return; event.reported.add(stage); try {
|
|
564
599
|
current.current.onMediaReady?.({ messageId: event.messageId, kind: event.kind, stage, elapsedMs: Date.now() - event.started });
|
|
565
600
|
}
|
|
566
601
|
catch { } };
|
|
567
|
-
return _jsx(MessagingTypography, { appearance: props.appearance ?? state.settings?.appearance ?? defaultMessagingSettings().appearance, children: _jsx(StreamRecovery.Provider, { value: (uri, position, playing) => { void controller.fallbackStream(uri, position, playing); }, children: _jsxs(MediaReadiness.Provider, { value: mediaReady, children: [renderConversation ? renderConversation(screenProps) : _jsx(MessagingScreen, { ...screenProps }), _jsx(MessagingMediaOverlay, {
|
|
602
|
+
return _jsx(MessagingTypography, { appearance: props.appearance ?? state.settings?.appearance ?? defaultMessagingSettings().appearance, children: _jsx(StreamRecovery.Provider, { value: (uri, position, playing) => { void controller.fallbackStream(uri, position, playing); }, children: _jsxs(MediaReadiness.Provider, { value: mediaReady, children: [renderConversation ? renderConversation(screenProps) : _jsx(MessagingScreen, { ...screenProps }), _jsx(MessagingMediaOverlay, { onDocumentLink: props.linkHandling?.webLinks === false || (props.appearance ?? state.settings?.appearance)?.linkHandling?.webLinks === false ? undefined : url => { const m = message.current, p = current.current; if (!m || controller.getSnapshot().phase !== 'viewing' || p.linkHandling?.webLinks === false)
|
|
603
|
+
return; void Promise.resolve().then(() => p.linkHandling?.openUrl ? p.linkHandling.openUrl(url, m) : Linking.openURL(url)).catch(() => { }); }, mediaViewer: props.mediaViewer, onDownloadAttachment: props.onDownloadAttachment, onDismiss: viewerDismissed, viewerActions: () => {
|
|
568
604
|
const m = message.current;
|
|
569
|
-
if (!m || !state.messages.some(row => row.id === m.id && !row.deleted))
|
|
605
|
+
if (!m || ![...state.messages, ...(state.latestVoices ?? [])].some(row => row.id === m.id && !row.deleted))
|
|
570
606
|
return {};
|
|
571
607
|
const action = (kind) => {
|
|
572
608
|
afterViewer.current = { kind, messageId: m.id, sequence: Date.now() };
|
|
@@ -3,6 +3,8 @@ import type { LocalMessagingMedia, MessagingMediaStorage } from './media-control
|
|
|
3
3
|
/** Small local previews, with bounded downloads and memory. Large originals stay
|
|
4
4
|
* tap-to-open until the storage service supplies a dedicated thumbnail. */
|
|
5
5
|
export declare function createExpoThumbnails(storage: MessagingMediaStorage, local: (id: string) => LocalMessagingMedia | undefined, remove: (file: LocalMessagingMedia) => Promise<void>): {
|
|
6
|
-
preview: (message: MessagingMessage
|
|
6
|
+
preview: (message: MessagingMessage, options?: {
|
|
7
|
+
refresh?: boolean;
|
|
8
|
+
}) => Promise<{}>;
|
|
7
9
|
clear: () => void;
|
|
8
10
|
};
|
package/dist/expo-thumbnails.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as FS from 'expo-file-system/legacy';
|
|
|
7
7
|
export function createExpoThumbnails(storage, local, remove) {
|
|
8
8
|
const cache = new MessagingPreviewCache();
|
|
9
9
|
const clear = () => cache.clear();
|
|
10
|
-
function preview(message) {
|
|
10
|
+
function preview(message, options) {
|
|
11
11
|
const media = message.media;
|
|
12
12
|
if (!media || message.deleted)
|
|
13
13
|
return Promise.resolve({});
|
|
@@ -16,6 +16,8 @@ export function createExpoThumbnails(storage, local, remove) {
|
|
|
16
16
|
if (!['image', 'video'].includes(message.kind))
|
|
17
17
|
return Promise.resolve({});
|
|
18
18
|
const id = media.assetId, key = JSON.stringify([message.conversationId, id, message.revision, media]);
|
|
19
|
+
if (options?.refresh)
|
|
20
|
+
cache.invalidate(key);
|
|
19
21
|
return cache.get(key, async (signal) => {
|
|
20
22
|
if (signal.aborted)
|
|
21
23
|
return {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { type MessagingHeaderOptions } from './conversation-selector.js';
|
|
2
|
+
export type { MessagingHeaderOptions, MessagingConversationChoice } from './conversation-selector.js';
|
|
3
|
+
import { type AttachmentPreviewLoader } from './attachment-preview.js';
|
|
1
4
|
export { MessagingConnectionState, type MessagingConnectionStateProps, MessagingSignIn, MessagingPhoneInput, MessagingChoicePicker, type MessagingSignInProps, type MessagingPhoneInputProps, type MessagingChoice, type MessagingChoicePickerProps } from './sign-in.js';
|
|
2
5
|
import type { MessagingCustomization } from './customization.js';
|
|
3
6
|
export { RobonoLocaleProvider, useRobonoLocale } from './localization.js';
|
|
@@ -61,6 +64,24 @@ export interface AttachmentChoice {
|
|
|
61
64
|
durationMs?: number;
|
|
62
65
|
}
|
|
63
66
|
export interface MessagingScreenProps {
|
|
67
|
+
/** Standard header configuration; no replacement Header component required. */
|
|
68
|
+
header?: MessagingHeaderOptions;
|
|
69
|
+
conversationMode?: "messenger" | "walkie-talkie";
|
|
70
|
+
/** The host owns safe-area insets. Set enabled:false if a parent already avoids the keyboard. */
|
|
71
|
+
keyboard?: {
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
behavior?: 'height' | 'position' | 'padding';
|
|
74
|
+
verticalOffset?: number;
|
|
75
|
+
bottomInset?: number;
|
|
76
|
+
};
|
|
77
|
+
/** Effective host permission. The transform request must still authorize on the server. */
|
|
78
|
+
languageTools?: {
|
|
79
|
+
translation?: boolean;
|
|
80
|
+
transcription?: boolean;
|
|
81
|
+
voiceOutput?: boolean;
|
|
82
|
+
preferredLanguage?: string;
|
|
83
|
+
revision?: string | number;
|
|
84
|
+
};
|
|
64
85
|
/** Disabled links render as plain text. Callbacks replace system navigation;
|
|
65
86
|
* providing openUrl also disables embedded social browsing. */
|
|
66
87
|
linkHandling?: {
|
|
@@ -136,10 +157,7 @@ export interface MessagingScreenProps {
|
|
|
136
157
|
prepareAttachment?: (kind: Exclude<MessageKind, 'text' | 'poll'>, media: MessageMedia) => Promise<MessageMedia>;
|
|
137
158
|
retainDraftAttachments?: boolean;
|
|
138
159
|
/** Resolve an authorized thumbnail and/or normalized waveform. Never put signed URLs in message data. */
|
|
139
|
-
attachmentPreview?:
|
|
140
|
-
uri?: string;
|
|
141
|
-
waveform?: number[];
|
|
142
|
-
}>;
|
|
160
|
+
attachmentPreview?: AttachmentPreviewLoader;
|
|
143
161
|
/** Authorize the asset and open it using your app's media player/viewer. */
|
|
144
162
|
openAttachment?: (message: MessagingMessage) => Promise<void>;
|
|
145
163
|
openSavedAttachment?: (record: SavedMessage) => Promise<void>;
|