@robono/messaging-react-native 0.13.0 → 0.15.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +26 -0
  3. package/SBOM.spdx.json +638 -230
  4. package/dist/attachment-preview.d.ts +18 -0
  5. package/dist/attachment-preview.js +27 -0
  6. package/dist/composer-input.d.ts +5 -0
  7. package/dist/composer-input.js +13 -0
  8. package/dist/contact-directory.d.ts +26 -0
  9. package/dist/contact-directory.js +16 -0
  10. package/dist/conversation-selector.d.ts +9 -0
  11. package/dist/conversation-selector.js +19 -0
  12. package/dist/expo-document.d.ts +7 -0
  13. package/dist/expo-document.js +50 -0
  14. package/dist/expo-media.js +5 -1
  15. package/dist/expo-messenger.d.ts +4 -1
  16. package/dist/expo-messenger.js +1 -1
  17. package/dist/expo-screen.d.ts +5 -1
  18. package/dist/expo-screen.js +67 -31
  19. package/dist/expo-thumbnails.d.ts +3 -1
  20. package/dist/expo-thumbnails.js +3 -1
  21. package/dist/expo.d.ts +1 -0
  22. package/dist/inbox-search.d.ts +2 -1
  23. package/dist/inbox-search.js +2 -2
  24. package/dist/inbox.d.ts +3 -2
  25. package/dist/inbox.js +52 -3
  26. package/dist/index.d.ts +23 -4
  27. package/dist/index.js +88 -41
  28. package/dist/keyboard-container.d.ts +10 -0
  29. package/dist/keyboard-container.js +18 -0
  30. package/dist/media-controller.d.ts +1 -0
  31. package/dist/media-controller.js +3 -2
  32. package/dist/media-ui.d.ts +4 -1
  33. package/dist/media-ui.js +5 -5
  34. package/dist/pdf-preview.d.ts +2 -0
  35. package/dist/pdf-preview.js +7 -0
  36. package/dist/pdf-renderer.generated.d.ts +1 -0
  37. package/dist/pdf-renderer.generated.js +2 -0
  38. package/dist/preview-cache.d.ts +1 -0
  39. package/dist/preview-cache.js +2 -0
  40. package/dist/translation-settings.js +5 -3
  41. package/licenses/pdfjs-LICENSE +177 -0
  42. 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,26 @@
1
+ import React from 'react';
2
+ import type { ConversationSummary, MessagingAppearance } from '@robono/messaging';
3
+ /** An authorized address-book entry, not a message or a grant of chat access. */
4
+ export interface MessagingDirectoryContact {
5
+ id: string;
6
+ contactId?: string;
7
+ conversationId?: string;
8
+ name: string;
9
+ avatarUrl?: string;
10
+ status: string;
11
+ detail: string;
12
+ /** False keeps the entry visible with its explanation and no composer. */
13
+ available: boolean;
14
+ }
15
+ export interface MessagingDirectoryOptions {
16
+ directory?: readonly MessagingDirectoryContact[];
17
+ /** Recheck permission on your server and return the authorized conversation.
18
+ * Honor cancellation when the account, directory entry or screen changes. */
19
+ onOpenDirectoryContact?: (contact: MessagingDirectoryContact, signal: AbortSignal) => Promise<ConversationSummary>;
20
+ }
21
+ export declare function directoryWithoutChats(directory: readonly MessagingDirectoryContact[], chats: readonly ConversationSummary[], query?: string): MessagingDirectoryContact[];
22
+ export declare function MessagingDirectoryRow({ contact, appearance, onPress }: {
23
+ contact: MessagingDirectoryContact;
24
+ appearance: MessagingAppearance;
25
+ onPress: () => void;
26
+ }): React.JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Image, Pressable, View } from 'react-native';
3
+ import { Text } from './typography.js';
4
+ export function directoryWithoutChats(directory, chats, query = '') {
5
+ const ids = new Set(chats.map(c => c.id)), people = new Set(chats.filter(c => c.kind !== 'group').map(c => c.contactId)), seen = new Set(), term = query.trim().toLocaleLowerCase();
6
+ return directory.filter(c => {
7
+ if (!c.id || seen.has(c.id) || c.conversationId && ids.has(c.conversationId) || c.contactId && people.has(c.contactId))
8
+ return false;
9
+ seen.add(c.id);
10
+ return !term || `${c.name} ${c.status}`.toLocaleLowerCase().includes(term);
11
+ });
12
+ }
13
+ export function MessagingDirectoryRow({ contact, appearance, onPress }) {
14
+ const c = appearance.colors;
15
+ return _jsxs(Pressable, { testID: 'messaging-directory-' + contact.id, accessibilityRole: "button", accessibilityLabel: contact.name + ', ' + contact.status, onPress: onPress, style: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingHorizontal: 12, paddingVertical: 10, minHeight: 68 }, children: [contact.avatarUrl ? _jsx(Image, { source: { uri: contact.avatarUrl }, style: { width: 40, height: 40, borderRadius: 20 } }) : _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, backgroundColor: c.accent + '20', alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 18, fontWeight: '700' }, children: contact.name.slice(0, 1).toUpperCase() }) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { color: c.foreground, fontSize: 16, fontWeight: '700' }, children: contact.name }), _jsx(Text, { numberOfLines: 1, style: { color: c.secondary, marginTop: 3, fontSize: 14 }, children: contact.status })] })] });
16
+ }
@@ -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
+ }
@@ -384,7 +384,11 @@ export function createExpoMessagingStorage(options) {
384
384
  },
385
385
  async thumbnail(message, context) {
386
386
  check(context.signal);
387
- const plan = await request('thumbnail', { conversationId: message.conversationId, messageId: message.id }, context.signal);
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;
@@ -1,3 +1,4 @@
1
+ import type { MessagingDirectoryOptions } from './contact-directory.js';
1
2
  import { createExpoMessengerCalling } from './expo-connected-calling.js';
2
3
  import type { LocationWorkspace } from '@robono/location';
3
4
  import React from 'react';
@@ -10,6 +11,8 @@ export declare function createExpoMessenger(options: {
10
11
  userId: string;
11
12
  getAccessToken: () => Promise<string>;
12
13
  fetch?: typeof fetch;
14
+ /** Host-authorized transcription/translation, including any credit checks. */
15
+ transformRequest?: import('@robono/messaging').MessagingRequest;
13
16
  availability?: false;
14
17
  notifications?: false;
15
18
  extras?: false;
@@ -111,7 +114,7 @@ export declare function createHostedExpoMessenger(options: Omit<Parameters<typeo
111
114
  availability: MessagingAvailabilityClient | undefined;
112
115
  maps: LocationWorkspace | undefined;
113
116
  }>;
114
- export interface ExpoMessengerProps extends Omit<ExpoMessagingScreenProps, 'contact' | 'renderConversation' | 'onBack'> {
117
+ export interface ExpoMessengerProps extends Omit<ExpoMessagingScreenProps, 'contact' | 'renderConversation' | 'onBack'>, MessagingDirectoryOptions {
115
118
  calling?: ReturnType<typeof createExpoMessengerCalling>;
116
119
  maps?: LocationWorkspace;
117
120
  notifications?: {
@@ -175,5 +175,5 @@ function ExpoMessengerContent({ inbox, contacts = {}, initialConversation, selec
175
175
  const notificationAccount = notifications ? { name: props.account?.name ?? 'Your account', ...props.account, onEnableNotifications: () => notifications.enable() } : props.account;
176
176
  const account = calling?.deviceCheck ? { name: 'Your account', ...notificationAccount, deviceCheck: calling.deviceCheck, renderCallPreview: (stream) => renderNativeCallVideo({ stream, local: true, style: { width: '100%', height: '100%' } }) } : notificationAccount;
177
177
  const contact = selected?.contactId === props.userId ? { name: 'Notes to self' } : selected?.kind === 'group' ? { name: selected.name ?? 'Group' } : contacts[selected?.contactId ?? ''] ?? { name: selected?.contactId ?? 'Chat' };
178
- return _jsxs(View, { style: { flex: 1, minHeight: 0 }, children: [_jsx(MessengerMapsNotice, { error: mapConnection.error, retry: mapConnection.retry }), showMaps && maps ? _jsx(RobonoMaps, { interfaceLocale: mapsLocale, workspace: maps, contacts: contacts, onClose: () => setShowMaps(false) }) : _jsx(ExpoMessagingScreen, { ...props, account: account, contact: contact, participants: props.participants ?? contacts, extras: selected ? props.extras : undefined, callActions: selected && selected.contactId !== props.userId ? { ...autoCalls, ...props.callActions, phoneNumber: contacts[selected.contactId ?? '']?.phoneNumber ?? props.callActions?.phoneNumber } : undefined, onBack: () => { props.client.stop(); setSelected(null); void inbox.refresh().catch(() => { }); }, renderConversation: screen => selected ? _jsx(MessagingCallingScreen, { ...screen, onCall: screen.callActions?.voice, onVideoCall: screen.callActions?.video, callLabel: "Internet call", unansweredCallId: callState.unanswered?.conversationId === selected.id ? callState.unanswered.id : undefined, onDismissCallMessage: calling?.dismissUnanswered }) : _jsxs(MessagingProvider, { ...screen, children: [_jsx(MessagingInbox, { viewMemory: inboxMemory, client: inbox, userId: props.userId, contacts: contacts, companyName: props.companyName, appearance: props.appearance, active: props.active !== false, headerActions: _jsx(MessagingAccountMenu, { onNewConversation: props.onNewConversation, onPublicRooms: inboxState.publicRoomsAvailable ? () => setPublicRooms(true) : undefined, onMaps: mapsAvailable ? () => setShowMaps(true) : undefined, onNewGroup: inboxState.groupCreationAvailable ? () => setNewGroup(true) : undefined }), onSelect: open, onDeleted: id => props.client.forgetConversation(id) }), publicRooms && _jsx(MessagingPublicRooms, { inbox: inbox, accent: (props.appearance ?? inboxState.appearance ?? defaultMessagingSettings().appearance).colors.accent, createRequestId: () => props.client.createForwardId(), onClose: () => setPublicRooms(false), onJoined: (id, name) => { setPublicRooms(false); open(inbox.getSnapshot().conversations.find(c => c.id === id) ?? { id, kind: 'group', name, contactId: null, lastMessage: null, unreadCount: 0, canSend: true }); } }), newGroup && _jsx(MessagingGroupEditor, { client: props.client, inbox: inbox, userId: props.userId, contacts: contacts, groups: inboxState.groups, accent: (props.appearance ?? inboxState.appearance ?? defaultMessagingSettings().appearance).colors.accent, onClose: () => setNewGroup(false), onSaved: (id, name) => { setNewGroup(false); const row = inbox.getSnapshot().conversations.find(c => c.id === id) ?? { id, kind: 'group', name, contactId: null, lastMessage: null, unreadCount: 0, canSend: true }; open(row); } }), props.inboxOverlay] }) }), _jsx(ExpoMessengerCalls, { calling: calling, state: callState })] });
178
+ return _jsxs(View, { style: { flex: 1, minHeight: 0 }, children: [_jsx(MessengerMapsNotice, { error: mapConnection.error, retry: mapConnection.retry }), showMaps && maps ? _jsx(RobonoMaps, { interfaceLocale: mapsLocale, workspace: maps, contacts: contacts, onClose: () => setShowMaps(false) }) : _jsx(ExpoMessagingScreen, { ...props, account: account, contact: contact, participants: props.participants ?? contacts, extras: selected ? props.extras : undefined, callActions: selected && selected.contactId !== props.userId ? { ...autoCalls, ...props.callActions, phoneNumber: contacts[selected.contactId ?? '']?.phoneNumber ?? props.callActions?.phoneNumber } : undefined, onBack: () => { props.client.stop(); setSelected(null); void inbox.refresh().catch(() => { }); }, renderConversation: screen => selected ? _jsx(MessagingCallingScreen, { ...screen, onCall: screen.callActions?.voice, onVideoCall: screen.callActions?.video, callLabel: "Internet call", unansweredCallId: callState.unanswered?.conversationId === selected.id ? callState.unanswered.id : undefined, onDismissCallMessage: calling?.dismissUnanswered }) : _jsxs(MessagingProvider, { ...screen, children: [_jsx(MessagingInbox, { directory: props.directory, onOpenDirectoryContact: props.onOpenDirectoryContact, viewMemory: inboxMemory, client: inbox, userId: props.userId, contacts: contacts, companyName: props.companyName, appearance: props.appearance, active: props.active !== false, headerActions: _jsx(MessagingAccountMenu, { onNewConversation: props.onNewConversation, onPublicRooms: inboxState.publicRoomsAvailable ? () => setPublicRooms(true) : undefined, onMaps: mapsAvailable ? () => setShowMaps(true) : undefined, onNewGroup: inboxState.groupCreationAvailable ? () => setNewGroup(true) : undefined }), onSelect: open, onDeleted: id => props.client.forgetConversation(id) }), publicRooms && _jsx(MessagingPublicRooms, { inbox: inbox, accent: (props.appearance ?? inboxState.appearance ?? defaultMessagingSettings().appearance).colors.accent, createRequestId: () => props.client.createForwardId(), onClose: () => setPublicRooms(false), onJoined: (id, name) => { setPublicRooms(false); open(inbox.getSnapshot().conversations.find(c => c.id === id) ?? { id, kind: 'group', name, contactId: null, lastMessage: null, unreadCount: 0, canSend: true }); } }), newGroup && _jsx(MessagingGroupEditor, { client: props.client, inbox: inbox, userId: props.userId, contacts: contacts, groups: inboxState.groups, accent: (props.appearance ?? inboxState.appearance ?? defaultMessagingSettings().appearance).colors.accent, onClose: () => setNewGroup(false), onSaved: (id, name) => { setNewGroup(false); const row = inbox.getSnapshot().conversations.find(c => c.id === id) ?? { id, kind: 'group', name, contactId: null, lastMessage: null, unreadCount: 0, canSend: true }; open(row); } }), props.inboxOverlay] }) }), _jsx(ExpoMessengerCalls, { calling: calling, state: callState })] });
179
179
  }
@@ -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: {
@@ -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, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
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 viewer = state.file && (review || state.phase === 'viewing') ? _jsx(MediaViewer, { expanded: expanded, onExpandedChange: setExpanded, 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, ...(!review ? viewerActions?.() : {}), downloading: downloading, onDownload: !review && appearance.showDownloadButton === true && ['image', 'video', 'document'].includes(state.kind) ? () => { if (saving.current || !state.file)
350
- return; saving.current = true; setDownloading(true); setFileError(''); void controller.exportFile(async (file, context) => { if (onDownloadAttachment) {
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: false }; 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')
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 = true; try {
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, { onDownloadAttachment: props.onDownloadAttachment, onDismiss: viewerDismissed, viewerActions: () => {
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) => Promise<{}>;
6
+ preview: (message: MessagingMessage, options?: {
7
+ refresh?: boolean;
8
+ }) => Promise<{}>;
7
9
  clear: () => void;
8
10
  };
@@ -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/expo.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './expo-screen.js';
2
2
  export { ExpoMessenger, createExpoMessenger, createHostedExpoMessenger, type ExpoMessengerProps } from './expo-messenger.js';
3
3
  export { MessagingPopup } from './popup.js';
4
4
  export { MessagingConnectionState, type MessagingConnectionStateProps, MessagingSignIn, MessagingPhoneInput, MessagingChoicePicker, type MessagingSignInProps, type MessagingPhoneInputProps, type MessagingChoice, type MessagingChoicePickerProps } from './sign-in.js';
5
+ export type { MessagingDirectoryContact, MessagingDirectoryOptions } from './contact-directory.js';
@@ -2,7 +2,8 @@ import { type InboxViewMemory } from './inbox-view.js';
2
2
  import React from 'react';
3
3
  import type { ConversationSummary, MessagingInboxClient, MessagingAppearance } from '@robono/messaging';
4
4
  /** Main-screen search covers retained messages beyond the current inbox page. */
5
- export declare function InboxMessageSearch({ client, query, appearance, name, chats, onSelect, viewMemory }: {
5
+ export declare function InboxMessageSearch({ client, query, appearance, name, chats, onSelect, viewMemory, directoryHeader }: {
6
+ directoryHeader?: React.ReactNode;
6
7
  viewMemory: InboxViewMemory;
7
8
  client: MessagingInboxClient;
8
9
  query: string;
@@ -5,7 +5,7 @@ import { useRobonoLocale } from './localization.js';
5
5
  import { useEffect, useRef, useState } from 'react';
6
6
  import { ActivityIndicator, FlatList, Pressable, View } from 'react-native';
7
7
  /** Main-screen search covers retained messages beyond the current inbox page. */
8
- export function InboxMessageSearch({ client, query, appearance, name, chats, onSelect, viewMemory }) {
8
+ export function InboxMessageSearch({ client, query, appearance, name, chats, onSelect, viewMemory, directoryHeader }) {
9
9
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
10
10
  const c = appearance.colors, [rows, setRows] = useState([]), [next, setNext] = useState(null), [busy, setBusy] = useState(true), [error, setError] = useState('');
11
11
  const scroll = useInboxScroll(viewMemory, 'search:' + query, rows.length > 0 && !busy, !next);
@@ -61,5 +61,5 @@ export function InboxMessageSearch({ client, query, appearance, name, chats, onS
61
61
  const timer = setTimeout(() => void search(), 300);
62
62
  return () => { clearTimeout(timer); ++generation.current; controller.current?.abort(); };
63
63
  }, [client, query]);
64
- return _jsx(FlatList, { ...scroll, testID: "messaging-inbox-search-results", style: { flex: 1 }, data: rows, keyExtractor: row => row.message.conversationId + ':' + row.message.id, keyboardShouldPersistTaps: "handled", ListHeaderComponent: _jsxs(View, { children: [chats.length > 0 && _jsxs(_Fragment, { children: [_jsx(Text, { style: { paddingHorizontal: 16, paddingVertical: 8, color: c.secondary, fontSize: 14, fontWeight: '600' }, children: uiText("Chats") }), chats.map(chat => _jsx(Pressable, { accessibilityRole: "button", onPress: () => onSelect(chat), style: { minHeight: 48, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: name(chat) }) }, chat.id))] }), _jsx(Text, { style: { paddingHorizontal: 16, paddingVertical: 12, color: c.secondary, fontSize: 14, fontWeight: '600' }, children: uiText("Messages") })] }), ListEmptyComponent: !busy && !error ? _jsx(Text, { style: { padding: 16, color: c.secondary }, children: uiText("No matching messages.") }) : null, renderItem: ({ item }) => _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Message in {value1}: {value2}", { value1: name(item.conversation), value2: item.message.text ?? '' }), onPress: () => onSelect(item.conversation, item.message.id), style: { paddingHorizontal: 16, paddingVertical: 12, gap: 5, borderBottomWidth: 1, borderBottomColor: c.foreground + '16' }, children: [_jsxs(View, { style: { flexDirection: 'row', gap: 8 }, children: [_jsx(Text, { numberOfLines: 1, style: { flex: 1, fontSize: 16, fontWeight: '600', color: c.foreground }, children: name(item.conversation) }), _jsx(Text, { style: { fontSize: 12, color: c.secondary }, children: new Date(item.message.createdAt).toLocaleDateString(uiLocale) })] }), _jsx(Text, { numberOfLines: 3, style: { fontSize: 15, lineHeight: 21, color: c.secondary }, children: item.message.text })] }), ListFooterComponent: _jsxs(View, { children: [busy && _jsx(ActivityIndicator, { accessibilityLabel: uiText("Searching all messages"), color: c.accent, style: { padding: 16 } }), !!error && _jsxs(_Fragment, { children: [_jsx(Text, { accessibilityRole: "alert", style: { padding: 16, color: c.foreground }, children: error }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => void search(rows.length > 0 && !!next), style: { minHeight: 44, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("Try again") }) })] }), next && !busy && !error && _jsx(Pressable, { accessibilityRole: "button", onPress: () => void search(true), style: { minHeight: 48, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("More results") }) })] }) });
64
+ return _jsx(FlatList, { ...scroll, testID: "messaging-inbox-search-results", style: { flex: 1 }, data: rows, keyExtractor: row => row.message.conversationId + ':' + row.message.id, keyboardShouldPersistTaps: "handled", ListHeaderComponent: _jsxs(View, { children: [directoryHeader, chats.length > 0 && _jsxs(_Fragment, { children: [_jsx(Text, { style: { paddingHorizontal: 16, paddingVertical: 8, color: c.secondary, fontSize: 14, fontWeight: '600' }, children: uiText("Chats") }), chats.map(chat => _jsx(Pressable, { accessibilityRole: "button", onPress: () => onSelect(chat), style: { minHeight: 48, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: name(chat) }) }, chat.id))] }), _jsx(Text, { style: { paddingHorizontal: 16, paddingVertical: 12, color: c.secondary, fontSize: 14, fontWeight: '600' }, children: uiText("Messages") })] }), ListEmptyComponent: !busy && !error ? _jsx(Text, { style: { padding: 16, color: c.secondary }, children: uiText("No matching messages.") }) : null, renderItem: ({ item }) => _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Message in {value1}: {value2}", { value1: name(item.conversation), value2: item.message.text ?? '' }), onPress: () => onSelect(item.conversation, item.message.id), style: { paddingHorizontal: 16, paddingVertical: 12, gap: 5, borderBottomWidth: 1, borderBottomColor: c.foreground + '16' }, children: [_jsxs(View, { style: { flexDirection: 'row', gap: 8 }, children: [_jsx(Text, { numberOfLines: 1, style: { flex: 1, fontSize: 16, fontWeight: '600', color: c.foreground }, children: name(item.conversation) }), _jsx(Text, { style: { fontSize: 12, color: c.secondary }, children: new Date(item.message.createdAt).toLocaleDateString(uiLocale) })] }), _jsx(Text, { numberOfLines: 3, style: { fontSize: 15, lineHeight: 21, color: c.secondary }, children: item.message.text })] }), ListFooterComponent: _jsxs(View, { children: [busy && _jsx(ActivityIndicator, { accessibilityLabel: uiText("Searching all messages"), color: c.accent, style: { padding: 16 } }), !!error && _jsxs(_Fragment, { children: [_jsx(Text, { accessibilityRole: "alert", style: { padding: 16, color: c.foreground }, children: error }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => void search(rows.length > 0 && !!next), style: { minHeight: 44, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("Try again") }) })] }), next && !busy && !error && _jsx(Pressable, { accessibilityRole: "button", onPress: () => void search(true), style: { minHeight: 48, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("More results") }) })] }) });
65
65
  }
package/dist/inbox.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import { type MessagingDirectoryOptions } from './contact-directory.js';
1
2
  import { type InboxViewMemory } from './inbox-view.js';
2
3
  import React from 'react';
3
4
  import { type MessagingAppearance, type MessagingInboxClient, type ConversationSummary } from '@robono/messaging';
4
- export interface MessagingInboxProps {
5
+ export interface MessagingInboxProps extends MessagingDirectoryOptions {
5
6
  client: MessagingInboxClient;
6
7
  userId: string;
7
8
  contacts?: Record<string, {
@@ -22,4 +23,4 @@ export interface MessagingInboxProps {
22
23
  onDeleted?: (conversationId: string) => Promise<void> | void;
23
24
  }
24
25
  /** Compact Messenger chat rows: avatar, name, last message, time and unread badge. */
25
- export declare function MessagingInbox({ client, userId, contacts, appearance, active, onSelect, onDeleted, companyName, headerActions, searchText, selectedId, query: controlledQuery, onSearchChange, viewMemory }: MessagingInboxProps): React.JSX.Element;
26
+ export declare function MessagingInbox({ client, userId, contacts, appearance, active, onSelect, onDeleted, companyName, headerActions, searchText, selectedId, query: controlledQuery, onSearchChange, viewMemory, directory, onOpenDirectoryContact }: MessagingInboxProps): React.JSX.Element;