@robono/messaging-react-native 0.26.2 → 0.27.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 (75) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +18 -1
  3. package/SBOM.spdx.json +1698 -618
  4. package/app.plugin.cjs +4 -0
  5. package/dist/bubble-design.d.ts +1 -0
  6. package/dist/bubble-design.js +1 -0
  7. package/dist/call-message-decoration.d.ts +15 -0
  8. package/dist/call-message-decoration.js +23 -0
  9. package/dist/calling-timeline.d.ts +40 -0
  10. package/dist/calling-timeline.js +79 -0
  11. package/dist/calling.d.ts +4 -1
  12. package/dist/calling.js +8 -5
  13. package/dist/expo-connected-calling.d.ts +4 -0
  14. package/dist/expo-connected-calling.js +3 -1
  15. package/dist/expo-messenger.d.ts +10 -0
  16. package/dist/expo-messenger.js +7 -1
  17. package/dist/expo-reviews.js +1 -1
  18. package/dist/expo-screen.d.ts +32 -0
  19. package/dist/expo-screen.js +93 -49
  20. package/dist/expo-thumbnails.js +2 -2
  21. package/dist/expo-video-orientation.d.ts +7 -0
  22. package/dist/expo-video-orientation.js +14 -0
  23. package/dist/expo-video-thumbnail.d.ts +6 -0
  24. package/dist/expo-video-thumbnail.js +30 -0
  25. package/dist/expo-voicemail-recorder.d.ts +18 -0
  26. package/dist/expo-voicemail-recorder.js +214 -0
  27. package/dist/expo-voicemail-storage.d.ts +10 -0
  28. package/dist/expo-voicemail-storage.js +81 -0
  29. package/dist/expo-voicemail-video.d.ts +15 -0
  30. package/dist/expo-voicemail-video.js +44 -0
  31. package/dist/expo-voicemail.d.ts +34 -0
  32. package/dist/expo-voicemail.js +110 -0
  33. package/dist/expo.d.ts +3 -0
  34. package/dist/expo.js +3 -0
  35. package/dist/header-action-group.d.ts +11 -0
  36. package/dist/header-action-group.js +7 -0
  37. package/dist/header-calls.js +2 -1
  38. package/dist/history-anchor.d.ts +29 -0
  39. package/dist/history-anchor.js +74 -0
  40. package/dist/history-follow.d.ts +18 -0
  41. package/dist/history-follow.js +35 -0
  42. package/dist/index.d.ts +14 -1
  43. package/dist/index.js +105 -63
  44. package/dist/message-time.d.ts +7 -0
  45. package/dist/message-time.js +17 -0
  46. package/dist/messenger-video-view.d.ts +4 -1
  47. package/dist/messenger-video-view.js +15 -4
  48. package/dist/recording-notice.d.ts +5 -0
  49. package/dist/recording-notice.js +13 -0
  50. package/dist/use-quote-gesture.d.ts +1 -0
  51. package/dist/use-quote-gesture.js +1 -0
  52. package/dist/video-message-badge.d.ts +7 -0
  53. package/dist/video-message-badge.js +8 -0
  54. package/dist/video-orientation.d.ts +13 -0
  55. package/dist/video-orientation.js +58 -0
  56. package/dist/voice-composer.d.ts +3 -1
  57. package/dist/voice-composer.js +7 -6
  58. package/dist/voicemail-flow.d.ts +60 -0
  59. package/dist/voicemail-flow.js +156 -0
  60. package/dist/voicemail-media.d.ts +19 -0
  61. package/dist/voicemail-media.js +45 -0
  62. package/dist/voicemail-message.d.ts +41 -0
  63. package/dist/voicemail-message.js +48 -0
  64. package/dist/voicemail-prompts.d.ts +4 -0
  65. package/dist/voicemail-prompts.js +3 -0
  66. package/dist/voicemail-recording.d.ts +15 -0
  67. package/dist/voicemail-recording.js +46 -0
  68. package/dist/voicemail-session.d.ts +19 -0
  69. package/dist/voicemail-session.js +48 -0
  70. package/dist/voicemail.d.ts +179 -0
  71. package/dist/voicemail.js +234 -0
  72. package/package.json +9 -5
  73. package/plugin/prepare-native.cjs +1 -0
  74. package/plugin/video-display-mirror.cjs +66 -0
  75. package/setup.plugin.cjs +1 -0
package/dist/index.js CHANGED
@@ -1,4 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { HistoryScrollAnchor } from './history-anchor.js';
3
+ import { HistoryFollow } from './history-follow.js';
4
+ export { HistoryFollow } from './history-follow.js';
5
+ import { MessagingHeaderActionGroup } from './header-action-group.js';
6
+ export { MessagingHeaderActionGroup, messagingHeaderActionStyle } from './header-action-group.js';
7
+ import { VideoMessageBadge } from './video-message-badge.js';
8
+ import { MessagingTimeFormatProvider } from './message-time.js';
9
+ export { MessagingTimeFormatProvider } from './message-time.js';
10
+ export { VoicemailMessageBubble } from './voicemail-message.js';
11
+ export { VoicemailFlow } from './voicemail-flow.js';
12
+ export { MessengerCallHistoryItem, CallingTimelineProvider, useCallingConversationHistory } from './calling-timeline.js';
13
+ import { CallingTimeline } from './calling-timeline.js';
14
+ export { useCallingVoicemail } from './voicemail-session.js';
15
+ export { VoicemailComposer, VoicemailInbox, VoicemailMailbox, useConversationVoicemail } from './voicemail.js';
2
16
  import { resolveMessagingVoice } from '@robono/messaging';
3
17
  export { MessagingLinkedAppsScreen } from './linked-apps.js';
4
18
  import { MessagingAccountPageScreen, messagingAccountPages, messagingAccountPageLabels } from './account-pages.js';
@@ -10,7 +24,7 @@ export { messagingHeaderColors } from './header-colors.js';
10
24
  export { MessagingReviewInbox } from './reviews.js';
11
25
  import { messageParts, selectMessagePart, composeMessageItems } from '@robono/messaging';
12
26
  import { DeliveryBar } from './delivery-bar.js';
13
- import { bubbleCorners, bubbleDelivery } from './bubble-design.js';
27
+ import { bubbleCorners, bubbleDelivery, messageSpacing } from './bubble-design.js';
14
28
  import { compareMessageOrder, isMessageIdentity } from '@robono/messaging';
15
29
  import { messagingScreenAppearance } from '@robono/messaging';
16
30
  import { messagingHeaderOrder } from '@robono/messaging';
@@ -202,14 +216,14 @@ function MessagingProviderContent({ children, ...props }) {
202
216
  setEditing, setForwarding, setDeleting, selection: selected, setSelection, saved, saving, toggleSaved, setSavedOpen,
203
217
  design,
204
218
  };
205
- return _jsx(Context.Provider, { value: value, children: _jsx(MessagingTypography, { appearance: value.design, screen: styleScreen, children: _jsxs(MessagingPopupHost, { children: [children, discussion && _jsx(GroupDiscussion, { threadRoot: discussion.threadRoot, onClose: () => setDiscussion(null) }), forwarding.length > 0 && _jsx(MessagingForward, { messages: forwarding, client: props.client, appearance: value.design, participants: props.participants, userId: props.userId, onClose: () => setForwarding([]) }), _jsx(MessageDeletion, { messages: deleting, onClose: () => setDeleting([]) }), savedOpen && _jsx(SavedMessagesPopup, { records: saved, appearance: value.design, onClose: () => setSavedOpen(false), onOpen: async (record) => { setSavedOpen(false); try {
206
- if (!props.openSavedAttachment)
207
- throw Error('Saved attachments cannot be opened here.');
208
- await props.openSavedAttachment(record);
209
- }
210
- catch (e) {
211
- setSavedError(e instanceof Error ? e.message : uiText("This saved attachment could not be opened."));
212
- } }, onRemove: async (key) => { await props.client.removeSavedMessage(key); setSaved(await props.client.savedMessages()); } }), !!savedError && _jsxs(MessagingPopup, { compact: true, contentWidth: 640, title: uiText("Saved"), foreground: value.design.colors.foreground, background: value.design.colors.background, onClose: () => setSavedError(''), children: [_jsx(Text, { accessibilityRole: "alert", style: { color: messagingPopupColors.foreground }, children: savedError }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => setSavedError(''), style: { minHeight: 44, alignSelf: 'flex-end', justifyContent: 'center' }, children: _jsx(Text, { style: { color: value.design.colors.accent }, children: uiText("OK") }) })] })] }) }) });
219
+ return _jsx(Context.Provider, { value: value, children: _jsx(MessagingTimeFormatProvider, { format: formatMessageTime, children: _jsx(MessagingTypography, { appearance: value.design, screen: styleScreen, children: _jsxs(MessagingPopupHost, { children: [children, discussion && _jsx(GroupDiscussion, { threadRoot: discussion.threadRoot, onClose: () => setDiscussion(null) }), forwarding.length > 0 && _jsx(MessagingForward, { messages: forwarding, client: props.client, appearance: value.design, participants: props.participants, userId: props.userId, onClose: () => setForwarding([]) }), _jsx(MessageDeletion, { messages: deleting, onClose: () => setDeleting([]) }), savedOpen && _jsx(SavedMessagesPopup, { records: saved, appearance: value.design, onClose: () => setSavedOpen(false), onOpen: async (record) => { setSavedOpen(false); try {
220
+ if (!props.openSavedAttachment)
221
+ throw Error('Saved attachments cannot be opened here.');
222
+ await props.openSavedAttachment(record);
223
+ }
224
+ catch (e) {
225
+ setSavedError(e instanceof Error ? e.message : uiText("This saved attachment could not be opened."));
226
+ } }, onRemove: async (key) => { await props.client.removeSavedMessage(key); setSaved(await props.client.savedMessages()); } }), !!savedError && _jsxs(MessagingPopup, { compact: true, contentWidth: 640, title: uiText("Saved"), foreground: value.design.colors.foreground, background: value.design.colors.background, onClose: () => setSavedError(''), children: [_jsx(Text, { accessibilityRole: "alert", style: { color: messagingPopupColors.foreground }, children: savedError }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => setSavedError(''), style: { minHeight: 44, alignSelf: 'flex-end', justifyContent: 'center' }, children: _jsx(Text, { style: { color: value.design.colors.accent }, children: uiText("OK") }) })] })] }) }) }) });
213
227
  }
214
228
  export function GroupDiscussion({ threadRoot, onClose }) {
215
229
  const messagingPopupColors = useMessagingPopupColors(undefined, threadRoot ? 'replies' : 'pins');
@@ -328,7 +342,7 @@ export function MessagingHeader({ children } = {}) {
328
342
  backgroundColor: c.incoming,
329
343
  alignItems: "center",
330
344
  justifyContent: "center",
331
- }, children: _jsx(Text, { style: { color: c.incomingText }, children: state.conversation?.kind === 'group' ? (state.conversation.name ?? 'Group').slice(0, 1) : contact.name.slice(0, 1) }) }))), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { color: header.foreground, fontSize: chatDesign?.titleSize ?? 18, lineHeight: Math.ceil((chatDesign?.titleSize ?? 18) * 1.25), textAlign: chatDesign?.titleAlign ?? 'left', fontWeight: "800" }, children: state.conversation?.kind === 'group' ? state.conversation.name : contact.name }), _jsx(MessagingActivity, { ink: header.foreground })] })] }), messagingHeaderOrder(design).map(action => _jsx(React.Fragment, { children: action === 'switcher' ? chatDesign?.showSwitcher !== false && _jsx(ConversationSelector, { options: headerOptions, selectedId: state.conversationId, color: header.foreground, background: header.background }) : action === 'close' ? chatDesign?.showClose !== false && headerOptions?.onClose && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Close conversation"), onPress: headerOptions.onClose, style: { width: 44, height: 44, alignItems: "center", justifyContent: "center" }, children: _jsx(MessageIcon, { name: "close", color: header.foreground, size: 24 }) }) : action === 'calls' ? _jsxs(_Fragment, { children: [children, components?.HeaderActions && _jsx(components.HeaderActions, { conversationId: state.conversationId, contact: contact, appearance: design }), state.conversation?.canSend !== false && _jsx(MessagingHeaderCalls, { actions: callActions ? { ...callActions, ...(chatDesign?.showVoiceCall === false ? { voice: undefined, phoneNumber: undefined } : {}), ...(chatDesign?.showVideoCall === false ? { video: undefined } : {}) } : undefined, name: state.conversation?.kind === 'group' ? (state.conversation.name ?? 'Group') : contact.name, group: state.conversation?.kind === 'group', color: header.foreground }, state.conversationId)] }) : action === 'privacy' ? null : _jsx(View, { style: { width: 44, height: 44 }, children: (onContactOptions || extrasState?.available.privacyLens || extrasState?.privacyLens || conversationActions || state.settings?.enabled || state.conversation?.safety || state.searchAvailable || state.scheduledMessagesAvailable || translationAvailable) && (_jsx(Pressable, { accessibilityRole: "button", testID: "messaging-contact-options", accessibilityLabel: uiText("Contact options"), ref: menuButton, accessibilityState: { expanded: safetyOpen }, onPress: onContactOptions ?? openContactMenu, style: { width: 44, height: 44, alignItems: "center", justifyContent: "center" }, children: _jsx(MessageIcon, { name: "more", color: header.foreground, size: 25 }) })) }) }, action)), safetyOpen && _jsx(MessagingSafety, { onMedia: state.sharedMediaAvailable ? () => { setSafetyOpen(false); setDetailsTab('media'); setDetailsOpen(true); } : undefined, onOptions: state.presence?.visibilityAvailable || conversationActions || extrasState?.available.privacyLens || extrasState?.privacyLens ? () => { setSafetyOpen(false); setOptionsOpen(true); } : undefined, onScheduled: state.scheduledMessagesAvailable ? () => { setSafetyOpen(false); setScheduledOpen(true); } : undefined, onDetails: state.settings?.enabled ? () => { setSafetyOpen(false); setDetailsTab('profile'); setDetailsOpen(true); } : undefined, onPins: state.discussionAvailable ? () => { setSafetyOpen(false); openDiscussion(); } : undefined, menuAnchor: menuAnchor, client: client, state: state, appearance: design, name: state.conversation?.kind === 'group' ? (state.conversation.name ?? 'Conversation') : contact.name, onSearch: state.searchAvailable && state.settings?.enabled ? () => { setSafetyOpen(false); setSearchOpen(true); } : undefined, onClose: () => setSafetyOpen(false), children: translationAvailable && _jsx(TranslationSettings, { client: client, appearance: design, preference: state.translationPreference, language: languageTools?.preferredLanguage ?? language, sourceLanguage: contact.language, defaults: state.settings?.languageDefaults, preferredVoice: languageTools?.preferredVoice, VoiceSample: components?.TranslationVoice, sampleBaseUrl: languageTools?.voiceSampleBaseUrl, voiceAvailable: languageTools?.voiceOutput !== false && !!components?.TranslationVoice, onSaved: () => setSafetyOpen(false) }, state.conversationId) })] }), scheduledOpen && _jsx(ScheduledMessages, { client: client, accent: c.accent, onClose: () => setScheduledOpen(false) }, state.conversationId), groupOpen && _jsx(MessagingGroupEditor, { client: client, userId: userId, contacts: participants ?? {}, conversation: state.conversation, groups: state.settings?.groups, accent: c.accent, onClose: () => setGroupOpen(false), onSaved: () => setGroupOpen(false) }), moderationOpen && _jsx(MessagingRoomModeration, { client: client, userId: userId, participants: participants, accent: c.accent, onClose: () => setModerationOpen(false) }), optionsOpen && _jsx(ChatOptions, { online: state.presence?.visibilityAvailable ? { hidden: state.presence.hidden === true, set: hidden => client.setOnlineStatusHidden(hidden) } : undefined, actions: conversationActions, accent: c.accent, onClose: () => setOptionsOpen(false), privacy: extras && extrasState && (extrasState.available.privacyLens || extrasState.privacyLens) ? { enabled: extrasState.privacyLens, set: enabled => extras.setPrivacy(enabled) } : undefined }), detailsOpen && _jsx(ConversationDetails, { initialTab: detailsTab, onOptions: state.presence?.visibilityAvailable || conversationActions ? () => setOptionsOpen(true) : undefined, onModerate: () => setModerationOpen(true), onEditGroup: () => setGroupOpen(true), onLeft: onBack, client: client, state: state, userId: userId, contact: contact, participants: participants, accent: c.accent, onClose: () => setDetailsOpen(false), attachmentPreview: attachmentPreview, openAttachment: openAttachment }), searchOpen && state.searchAvailable && state.settings?.enabled && _jsx(MessagingSearch, { client: client, appearance: design, onClose: () => setSearchOpen(false), resolveName: id => id === userId ? 'You' : participants?.[id]?.name ?? (state.conversation?.kind === 'direct' ? contact.name : 'Chat member') }, state.conversationId)] }));
345
+ }, children: _jsx(Text, { style: { color: c.incomingText }, children: state.conversation?.kind === 'group' ? (state.conversation.name ?? 'Group').slice(0, 1) : contact.name.slice(0, 1) }) }))), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { color: header.foreground, fontSize: chatDesign?.titleSize ?? 18, lineHeight: Math.ceil((chatDesign?.titleSize ?? 18) * 1.25), textAlign: chatDesign?.titleAlign ?? 'left', fontWeight: "800" }, children: state.conversation?.kind === 'group' ? state.conversation.name : contact.name }), _jsx(MessagingActivity, { ink: header.foreground })] })] }), messagingHeaderOrder(design).map(action => _jsx(React.Fragment, { children: action === 'switcher' ? chatDesign?.showSwitcher !== false && _jsx(ConversationSelector, { options: headerOptions, selectedId: state.conversationId, color: header.foreground, background: header.background }) : action === 'close' ? chatDesign?.showClose !== false && headerOptions?.onClose && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Close conversation"), onPress: headerOptions.onClose, style: { width: 44, height: 44, alignItems: "center", justifyContent: "center" }, children: _jsx(MessageIcon, { name: "close", color: header.foreground, size: 24 }) }) : action === 'calls' ? _jsxs(MessagingHeaderActionGroup, { children: [children, components?.HeaderActions && _jsx(components.HeaderActions, { conversationId: state.conversationId, contact: contact, appearance: design }), state.conversation?.canSend !== false && _jsx(MessagingHeaderCalls, { actions: callActions ? { ...callActions, ...(chatDesign?.showVoiceCall === false ? { voice: undefined, phoneNumber: undefined } : {}), ...(chatDesign?.showVideoCall === false ? { video: undefined } : {}) } : undefined, name: state.conversation?.kind === 'group' ? (state.conversation.name ?? 'Group') : contact.name, group: state.conversation?.kind === 'group', color: header.foreground }, state.conversationId)] }) : action === 'privacy' ? null : _jsx(View, { style: { width: 44, height: 44 }, children: (onContactOptions || extrasState?.available.privacyLens || extrasState?.privacyLens || conversationActions || state.settings?.enabled || state.conversation?.safety || state.searchAvailable || state.scheduledMessagesAvailable || translationAvailable) && (_jsx(Pressable, { accessibilityRole: "button", testID: "messaging-contact-options", accessibilityLabel: uiText("Contact options"), ref: menuButton, accessibilityState: { expanded: safetyOpen }, onPress: onContactOptions ?? openContactMenu, style: { width: 44, height: 44, alignItems: "center", justifyContent: "center" }, children: _jsx(MessageIcon, { name: "more", color: header.foreground, size: 25 }) })) }) }, action)), safetyOpen && _jsx(MessagingSafety, { onMedia: state.sharedMediaAvailable ? () => { setSafetyOpen(false); setDetailsTab('media'); setDetailsOpen(true); } : undefined, onOptions: state.presence?.visibilityAvailable || conversationActions || extrasState?.available.privacyLens || extrasState?.privacyLens ? () => { setSafetyOpen(false); setOptionsOpen(true); } : undefined, onScheduled: state.scheduledMessagesAvailable ? () => { setSafetyOpen(false); setScheduledOpen(true); } : undefined, onDetails: state.settings?.enabled ? () => { setSafetyOpen(false); setDetailsTab('profile'); setDetailsOpen(true); } : undefined, onPins: state.discussionAvailable ? () => { setSafetyOpen(false); openDiscussion(); } : undefined, menuAnchor: menuAnchor, client: client, state: state, appearance: design, name: state.conversation?.kind === 'group' ? (state.conversation.name ?? 'Conversation') : contact.name, onSearch: state.searchAvailable && state.settings?.enabled ? () => { setSafetyOpen(false); setSearchOpen(true); } : undefined, onClose: () => setSafetyOpen(false), children: translationAvailable && _jsx(TranslationSettings, { client: client, appearance: design, preference: state.translationPreference, language: languageTools?.preferredLanguage ?? language, sourceLanguage: contact.language, defaults: state.settings?.languageDefaults, preferredVoice: languageTools?.preferredVoice, VoiceSample: components?.TranslationVoice, sampleBaseUrl: languageTools?.voiceSampleBaseUrl, voiceAvailable: languageTools?.voiceOutput !== false && !!components?.TranslationVoice, onSaved: () => setSafetyOpen(false) }, state.conversationId) })] }), scheduledOpen && _jsx(ScheduledMessages, { client: client, accent: c.accent, onClose: () => setScheduledOpen(false) }, state.conversationId), groupOpen && _jsx(MessagingGroupEditor, { client: client, userId: userId, contacts: participants ?? {}, conversation: state.conversation, groups: state.settings?.groups, accent: c.accent, onClose: () => setGroupOpen(false), onSaved: () => setGroupOpen(false) }), moderationOpen && _jsx(MessagingRoomModeration, { client: client, userId: userId, participants: participants, accent: c.accent, onClose: () => setModerationOpen(false) }), optionsOpen && _jsx(ChatOptions, { online: state.presence?.visibilityAvailable ? { hidden: state.presence.hidden === true, set: hidden => client.setOnlineStatusHidden(hidden) } : undefined, actions: conversationActions, accent: c.accent, onClose: () => setOptionsOpen(false), privacy: extras && extrasState && (extrasState.available.privacyLens || extrasState.privacyLens) ? { enabled: extrasState.privacyLens, set: enabled => extras.setPrivacy(enabled) } : undefined }), detailsOpen && _jsx(ConversationDetails, { initialTab: detailsTab, onOptions: state.presence?.visibilityAvailable || conversationActions ? () => setOptionsOpen(true) : undefined, onModerate: () => setModerationOpen(true), onEditGroup: () => setGroupOpen(true), onLeft: onBack, client: client, state: state, userId: userId, contact: contact, participants: participants, accent: c.accent, onClose: () => setDetailsOpen(false), attachmentPreview: attachmentPreview, openAttachment: openAttachment }), searchOpen && state.searchAvailable && state.settings?.enabled && _jsx(MessagingSearch, { client: client, appearance: design, onClose: () => setSearchOpen(false), resolveName: id => id === userId ? 'You' : participants?.[id]?.name ?? (state.conversation?.kind === 'direct' ? contact.name : 'Chat member') }, state.conversationId)] }));
332
346
  }
333
347
  const mediaNames = {
334
348
  voice: "Voice message",
@@ -409,7 +423,7 @@ function MediaContent({ message, ink, footer, onOpen, onLongPress, sendRetry })
409
423
  const width = source?.width ?? target?.naturalWidth, height = source?.height ?? target?.naturalHeight;
410
424
  if (width && height && preview.uri)
411
425
  decodedSize(preview.uri, width, height);
412
- }, onError: onImageError, style: { width: '100%', height: '100%' } }) : _jsx(MessageIcon, { name: message.kind, color: ink, size: 36 }), failed && !preview.uri && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Retry preview'), onPress: event => { event.stopPropagation(); retry(); }, style: { position: 'absolute', bottom: 6, right: 6, minHeight: 44, paddingHorizontal: 12, justifyContent: 'center', backgroundColor: design.colors.incoming, borderRadius: 18 }, children: _jsx(Text, { style: { color: design.colors.accent }, children: uiText('Retry preview') }) }), sendRetry && _jsx(View, { testID: "media-send-retry", style: { position: 'absolute', backgroundColor: design.colors.incoming, borderRadius: 18, paddingHorizontal: 12 }, children: sendRetry }), message.kind === 'video' && !sendRetry && _jsxs(_Fragment, { children: [_jsx(View, { style: { position: 'absolute', borderRadius: 24, padding: 10, backgroundColor: '#00000099' }, children: _jsx(MessageIcon, { name: "play", color: "#ffffff" }) }), _jsx(Text, { style: { position: 'absolute', left: 8, bottom: 8, color: '#ffffff', backgroundColor: '#000000aa', borderRadius: 4, paddingHorizontal: 5, fontSize: 12 }, children: duration(message.media?.durationMs) })] })] }) });
426
+ }, onError: onImageError, style: { width: '100%', height: '100%' } }) : _jsx(MessageIcon, { name: message.kind, color: ink, size: 36 }), failed && !preview.uri && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Retry preview'), onPress: event => { event.stopPropagation(); retry(); }, style: { position: 'absolute', bottom: 6, right: 6, minHeight: 44, paddingHorizontal: 12, justifyContent: 'center', backgroundColor: design.colors.incoming, borderRadius: 18 }, children: _jsx(Text, { style: { color: design.colors.accent }, children: uiText('Retry preview') }) }), sendRetry && _jsx(View, { testID: "media-send-retry", style: { position: 'absolute', backgroundColor: design.colors.incoming, borderRadius: 18, paddingHorizontal: 12 }, children: sendRetry }), message.kind === 'video' && !sendRetry && _jsxs(_Fragment, { children: [_jsx(View, { style: { position: 'absolute', borderRadius: 24, padding: 10, backgroundColor: '#00000099' }, children: _jsx(MessageIcon, { name: "play", color: "#ffffff" }) }), _jsx(VideoMessageBadge, { durationMs: message.media?.durationMs })] })] }) });
413
427
  return _jsxs(View, { testID: "file-message-content", style: { flexDirection: 'row', alignItems: 'center', gap: 10, width: 220, maxWidth: '100%', minHeight: 56, paddingHorizontal: 12, paddingVertical: 6, ...bubbleCorners(design, message.senderId === userId), ...(message.senderId === userId && design.messageStatus?.style === 'circle' ? { paddingRight: 28 } : {}) }, children: [_jsx(MessageIcon, { name: "document", color: design.colors.accent, size: 24 }), _jsxs(View, { style: { flex: 1, gap: 2 }, children: [_jsx(Text, { numberOfLines: 2, style: { color: ink, fontSize: 14, fontWeight: '600' }, children: message.media?.fileName ?? uiText("File") }), _jsxs(Text, { style: { color: ink, fontSize: 12, opacity: 0.75 }, children: [message.media?.fileName?.split('.').pop()?.toUpperCase(), " \u00B7 ", fileSize(message.media?.byteSize)] }), sendRetry] })] });
414
428
  }
415
429
  function messageTimeLabel(message, format, text) { return (message.editedAt && !message.deleted ? text('edited') + ' · ' : '') + format(message.createdAt); }
@@ -466,7 +480,7 @@ const MessagingBubbleView = React.memo(function MessagingBubbleView({ message, p
466
480
  const circleStatus = mine && status.style === 'circle';
467
481
  const timePosition = design.messageTime?.position ?? 'slide', circlePosition = design.messageStatus?.position ?? 'inside';
468
482
  const statusLabel = uiText(notice.text ?? (status.phase === 'failed' ? 'Message not sent' : status.phase === 'sent' ? 'Sending message' : status.phase === 'consumed' ? (message.kind === 'voice' ? 'Heard' : message.kind === 'video' ? 'Watched' : 'Seen') : 'Delivered'));
469
- const messageGap = design.presentation?.messageSpacing === 'compact' ? 4 : design.presentation?.messageSpacing === 'relaxed' ? 12 : 8;
483
+ const messageGap = messageSpacing(design);
470
484
  const visual = message.kind === 'image' || message.kind === 'video', voice = message.kind === 'voice';
471
485
  const grouped = ui.grouped;
472
486
  const [error, setError] = useState(''), [busy, setBusy] = useState(false), [actions, setActions] = useState(false), [reportOpen, setReportOpen] = useState(false), [roomRemoval, setRoomRemoval] = useState(false);
@@ -644,7 +658,7 @@ const MessagingHistoryRow = React.memo(function MessagingHistoryRow({ item, prev
644
658
  const date = new Date(item.createdAt), start = !previous || date.toDateString() !== new Date(previous.createdAt).toDateString();
645
659
  const checked = selection.some(m => m.id === item.id), selectable = selection.length > 0 && !item.pendingStatus && !item.deleted;
646
660
  const toggle = () => setSelection(checked ? selection.filter(m => m.id !== item.id) : [...selection, item]);
647
- return _jsxs(View, { testID: highlighted ? 'focused-message' : undefined, style: highlighted || checked ? { backgroundColor: design.colors.accent + '20', borderRadius: 8 } : undefined, children: [start && design.screens?.chat?.showDates !== false && _jsx(Text, { testID: "messaging-date-separator", style: { alignSelf: 'center', fontSize: design.screens?.chat?.dateSize ?? 12, color: design.screens?.chat?.dateText ?? design.colors.secondary, backgroundColor: design.screens?.chat?.dateBackground ?? chatSurface(design.colors.background), borderRadius: 7, paddingHorizontal: 12, paddingVertical: 5, marginTop: 4, marginBottom: 10 }, children: date.toDateString() === new Date().toDateString() ? uiText("Today") : date.toLocaleDateString(uiLocale, { month: 'short', day: 'numeric' }) }), _jsx(View, { style: { paddingLeft: selection.length ? 32 : 0 }, pointerEvents: selection.length ? 'none' : 'auto', accessibilityElementsHidden: selection.length > 0, importantForAccessibility: selection.length ? 'no-hide-descendants' : 'auto', ...(Platform.OS === 'web' && selection.length ? { 'aria-hidden': true } : {}), children: Message ? _jsx(Message, { message: item }) : _jsx(MessagingBubbleItems, { message: item, pendingStatus: item.pendingStatus, ui: bubbleUI }) }), selectable && _jsx(Pressable, { accessibilityRole: "checkbox", accessibilityLabel: uiText('Select message: {message}', { message: item.text || item.media?.fileName || uiText(mediaNames[item.kind] || 'Message') }), accessibilityState: { checked }, onPress: toggle, style: { position: 'absolute', inset: 0, justifyContent: 'center' }, children: _jsx(View, { style: { width: 24, height: 24, borderRadius: 12, borderWidth: 1, borderColor: design.colors.accent, backgroundColor: checked ? design.colors.accent : design.colors.background, alignItems: 'center', justifyContent: 'center' }, children: checked && _jsx(MessageIcon, { name: "check", size: 16, color: "#ffffff" }) }) })] });
661
+ return _jsxs(View, { ...(Platform.OS === 'web' ? { dataSet: { historyKey: item.senderId + ':' + item.clientMessageId } } : {}), testID: highlighted ? 'focused-message' : undefined, style: highlighted || checked ? { backgroundColor: design.colors.accent + '20', borderRadius: 8 } : undefined, children: [start && design.screens?.chat?.showDates !== false && _jsx(Text, { testID: "messaging-date-separator", style: { alignSelf: 'center', fontSize: design.screens?.chat?.dateSize ?? 12, color: design.screens?.chat?.dateText ?? design.colors.secondary, backgroundColor: design.screens?.chat?.dateBackground ?? chatSurface(design.colors.background), borderRadius: 7, paddingHorizontal: 12, paddingVertical: 5, marginTop: 4, marginBottom: 10 }, children: date.toDateString() === new Date().toDateString() ? uiText("Today") : date.toLocaleDateString(uiLocale, { month: 'short', day: 'numeric' }) }), _jsx(View, { style: { paddingLeft: selection.length ? 32 : 0 }, pointerEvents: selection.length ? 'none' : 'auto', accessibilityElementsHidden: selection.length > 0, importantForAccessibility: selection.length ? 'no-hide-descendants' : 'auto', ...(Platform.OS === 'web' && selection.length ? { 'aria-hidden': true } : {}), children: Message ? _jsx(Message, { message: item }) : _jsx(MessagingBubbleItems, { message: item, pendingStatus: item.pendingStatus, ui: bubbleUI }) }), selectable && _jsx(Pressable, { accessibilityRole: "checkbox", accessibilityLabel: uiText('Select message: {message}', { message: item.text || item.media?.fileName || uiText(mediaNames[item.kind] || 'Message') }), accessibilityState: { checked }, onPress: toggle, style: { position: 'absolute', inset: 0, justifyContent: 'center' }, children: _jsx(View, { style: { width: 24, height: 24, borderRadius: 12, borderWidth: 1, borderColor: design.colors.accent, backgroundColor: checked ? design.colors.accent : design.colors.background, alignItems: 'center', justifyContent: 'center' }, children: checked && _jsx(MessageIcon, { name: "check", size: 16, color: "#ffffff" }) }) })] });
648
662
  });
649
663
  const conversationReadingPositions = new WeakMap();
650
664
  export function MessagingList() {
@@ -652,15 +666,26 @@ export function MessagingList() {
652
666
  const context = useMessagingUI();
653
667
  const { state, client, components, design, userId, selection, setSelection } = context;
654
668
  const Privacy = components?.PrivacyLayer ?? MessagingPrivacyLayer;
655
- const items = useMemo(() => orderChatMessages([...state.messages, ...state.pending.map(p => ({
669
+ const callTimeline = useContext(CallingTimeline);
670
+ const items = useMemo(() => orderChatMessages([...callTimeline.map(row => ({ id: 'call:' + row.id, clientMessageId: 'call:' + row.id, conversationId: state.conversationId, senderId: 'calling', kind: 'text', text: '', createdAt: new Date(row.createdAt).toISOString(), readAt: null, callingContent: row.content })), ...state.messages, ...state.pending.map(p => ({
656
671
  ...p.content, id: 'pending:' + p.clientMessageId, clientMessageId: p.clientMessageId, conversationId: state.conversationId, senderId: userId,
657
672
  createdAt: p.createdAt ?? new Date().toISOString(), readAt: null, pendingStatus: p.status,
658
- }))]).reverse(), [state.messages, state.pending, state.conversationId, userId]);
673
+ }))]).reverse(), [state.messages, state.pending, state.conversationId, userId, callTimeline]);
659
674
  const list = useRef(null);
660
675
  const historyInteraction = useRef({ conversationId: state.conversationId, dragged: false });
661
676
  if (historyInteraction.current.conversationId !== state.conversationId)
662
677
  historyInteraction.current = { conversationId: state.conversationId, dragged: false };
663
- const nearLatest = useRef(true), lastNewest = useRef(''), lastPending = useRef('');
678
+ const nearLatest = useRef(new HistoryFollow()).current, lastNewest = useRef(''), lastPending = useRef('');
679
+ const latestOffset = useRef(0);
680
+ const cancelLatestScroll = () => nearLatest.cancelLayout();
681
+ const followLatestLayout = () => {
682
+ if (state.historyWindow || scrollTarget.current)
683
+ return;
684
+ nearLatest.layout(() => { if (!scrollTarget.current)
685
+ list.current?.scrollToOffset({ offset: 0, animated: false }); });
686
+ };
687
+ const interruptLatestScroll = () => { nearLatest.begin(); historyInteraction.current.dragged = true; scrollTarget.current = null; };
688
+ useLayoutEffect(() => () => cancelLatestScroll(), [state.conversationId]);
664
689
  const [away, setAway] = useState(false), [newMessages, setNewMessages] = useState(false);
665
690
  const [historyHeight, setHistoryHeight] = useState(0);
666
691
  const [scrolling, setScrolling] = useState(false);
@@ -670,16 +695,17 @@ export function MessagingList() {
670
695
  const scrollingStarted = () => { if (scrollIdle.current)
671
696
  clearTimeout(scrollIdle.current); setScrolling(true); };
672
697
  const scrollingSettled = () => { if (scrollIdle.current)
673
- clearTimeout(scrollIdle.current); scrollIdle.current = setTimeout(() => { scrollIdle.current = null; setScrolling(false); }, 600); };
698
+ clearTimeout(scrollIdle.current); scrollIdle.current = setTimeout(() => { scrollIdle.current = null; const dragged = nearLatest.end(latestOffset.current); setScrolling(false); if (dragged)
699
+ followLatestLayout(); }, 600); };
674
700
  useEffect(() => { if (Platform.OS === 'web')
675
701
  return; const animation = Animated.timing(latestOpacity, { toValue: showLatest ? 1 : 0, duration: 200, useNativeDriver: true }); animation.start(); return () => animation.stop(); }, [showLatest, latestOpacity]);
676
702
  useEffect(() => { setScrolling(false); return () => { if (scrollIdle.current)
677
703
  clearTimeout(scrollIdle.current); }; }, [state.conversationId]);
678
704
  const jumpToLatest = (animated = true) => { if (state.historyWindow) {
679
- void client.goToLatest().then(() => { list.current?.scrollToOffset({ offset: 0, animated }); nearLatest.current = true; setAway(false); setNewMessages(false); }).catch(() => { });
705
+ void client.goToLatest().then(() => { list.current?.scrollToOffset({ offset: 0, animated }); nearLatest.reset(); setAway(false); setNewMessages(false); }).catch(() => { });
680
706
  return;
681
- } list.current?.scrollToOffset({ offset: 0, animated }); nearLatest.current = true; setAway(false); setNewMessages(false); };
682
- useEffect(() => { nearLatest.current = true; lastNewest.current = ''; lastPending.current = ''; setAway(false); setNewMessages(false); list.current?.scrollToOffset({ offset: 0, animated: false }); }, [state.conversationId]);
707
+ } list.current?.scrollToOffset({ offset: 0, animated }); nearLatest.reset(); setAway(false); setNewMessages(false); };
708
+ useEffect(() => { nearLatest.reset(); lastNewest.current = ''; lastPending.current = ''; setAway(false); setNewMessages(false); list.current?.scrollToOffset({ offset: 0, animated: false }); }, [state.conversationId]);
683
709
  const [highlight, setHighlight] = useState(null);
684
710
  const scrollTarget = useRef(null);
685
711
  useEffect(() => {
@@ -688,7 +714,7 @@ export function MessagingList() {
688
714
  const index = items.findIndex(m => m.id === state.focus.messageId);
689
715
  if (index < 0)
690
716
  return;
691
- nearLatest.current = false;
717
+ nearLatest.pause();
692
718
  setAway(true);
693
719
  setHighlight(state.focus.messageId);
694
720
  scrollTarget.current = { index, attempts: 0 };
@@ -717,16 +743,20 @@ export function MessagingList() {
717
743
  restoredReading.current = readingKey;
718
744
  const anchor = conversationReadingPositions.get(client)?.get(readingKey);
719
745
  if (anchor) {
720
- nearLatest.current = false;
746
+ nearLatest.pause();
721
747
  setAway(true);
722
748
  void client.focusMessage(anchor).catch(() => { conversationReadingPositions.get(client)?.delete(readingKey); });
723
749
  }
724
750
  }, [client, readingKey, state.loading, state.settings?.enabled]);
725
751
  const newest = items[0]?.clientMessageId ?? '', outgoing = state.pending.at(-1)?.clientMessageId ?? '';
726
- useEffect(() => {
752
+ useLayoutEffect(() => {
727
753
  if (newest && newest !== lastNewest.current) {
728
- if (!state.historyWindow && nearLatest.current || (outgoing && outgoing !== lastPending.current))
729
- requestAnimationFrame(() => jumpToLatest(false));
754
+ if (outgoing && outgoing !== lastPending.current)
755
+ jumpToLatest(false);
756
+ // Arm before layout/anchoring scroll events; content-size callbacks repeat
757
+ // the follow after virtualized rows and delayed media actually lay out.
758
+ else if (!state.historyWindow && nearLatest.current)
759
+ followLatestLayout();
730
760
  else if (!state.historyWindow)
731
761
  setNewMessages(true);
732
762
  }
@@ -796,47 +826,55 @@ export function MessagingList() {
796
826
  if (!ids.has(key))
797
827
  rowUIs.current.delete(key); }, [items]);
798
828
  const renderHistoryItem = useCallback(({ item, index }) => {
799
- const previous = items[index + 1], next = items[index - 1], key = item.senderId + ':' + item.clientMessageId;
829
+ if (item.callingContent)
830
+ return _jsx(View, { ...(Platform.OS === 'web' ? { dataSet: { historyKey: item.clientMessageId } } : {}), style: { paddingVertical: 4 }, children: item.callingContent });
831
+ const previous = items[index + 1]?.callingContent ? undefined : items[index + 1], next = items[index - 1]?.callingContent ? undefined : items[index - 1], key = item.senderId + ':' + item.clientMessageId;
800
832
  const bubbleUI = selectBubbleUI(context, { message: item, previousMessage: previous, nextMessage: next }, rowUIs.current.get(key) ?? null);
801
833
  rowUIs.current.set(key, bubbleUI);
802
834
  return _jsx(MessagingHistoryRow, { item: item, previous: previous, next: next, highlighted: highlight === item.id, selection: selection, setSelection: setSelection, design: design, Message: components?.Message, bubbleUI: bubbleUI });
803
835
  }, [context, items, highlight, selection, setSelection, design, components?.Message]);
804
- return (_jsxs(View, { style: { flex: 1, minHeight: 0 }, children: [_jsx(Privacy, { enabled: !!context.extrasState?.privacyLens, background: design.colors.background, children: _jsx(FlatList, { ref: list, testID: "messaging-history", onLayout: event => { setHistoryHeight(event.nativeEvent.layout.height); const target = scrollTarget.current; if (target)
805
- requestAnimationFrame(() => { if (scrollTarget.current === target)
806
- list.current?.scrollToIndex({ index: target.index, viewPosition: .5, animated: false }); }); }, maintainVisibleContentPosition: highlight ? undefined : { minIndexForVisible: 0 }, onContentSizeChange: () => { const target = scrollTarget.current; if (target)
807
- requestAnimationFrame(() => { if (scrollTarget.current === target)
808
- list.current?.scrollToIndex({ index: target.index, viewPosition: .5, animated: false }); }); },
809
- // Keep nearby history ready without mounting most of a long conversation.
810
- // Smaller batches leave the JS thread available for incoming messages,
811
- // gestures and receipt updates while the user scrolls.
812
- initialNumToRender: 12, maxToRenderPerBatch: 8, windowSize: 5, onScrollToIndexFailed: info => {
813
- const target = scrollTarget.current;
814
- if (!target || target.retryTimer || target.attempts >= 20)
815
- return;
816
- target.attempts++;
817
- // A distant cell may need several native layout batches. Coalesce
818
- // layout callbacks so they cannot exhaust retries before those batches.
819
- target.retryTimer = setTimeout(() => { target.retryTimer = undefined; if (scrollTarget.current === target)
820
- list.current?.scrollToIndex({ index: target.index, viewPosition: .5, animated: false }); }, 150);
821
- list.current?.scrollToOffset({ offset: info.averageItemLength * info.index, animated: false });
822
- }, onScrollBeginDrag: () => { historyInteraction.current.dragged = true; scrollTarget.current = null; scrollingStarted(); }, ...(Platform.OS === 'web' ? {
823
- // Browser wheel/keyboard/scrollbar input does not emit native drag events.
824
- onWheel: () => { historyInteraction.current.dragged = true; },
825
- onPointerDown: () => { historyInteraction.current.dragged = true; },
826
- onKeyDown: (event) => { if (['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End', ' '].includes(event.key))
827
- historyInteraction.current.dragged = true; },
828
- } : {}), onScrollEndDrag: scrollingSettled, onMomentumScrollBegin: scrollingStarted, onMomentumScrollEnd: scrollingSettled, onScroll: event => { scrollingStarted(); scrollingSettled(); const near = event.nativeEvent.contentOffset.y < 80; nearLatest.current = near; setAway(!near); if (near)
829
- setNewMessages(false); }, scrollEventThrottle: 32, data: items, inverted: true, keyExtractor: (m) => m.senderId + ':' + m.clientMessageId, style: { flex: 1 }, keyboardShouldPersistTaps: "handled", contentContainerStyle: { paddingHorizontal: 12, paddingVertical: 10, paddingTop: context.extrasState?.privacyLens ? privacyReadingStripHeight + 10 : 10, flexGrow: 1, justifyContent: context.extrasState?.privacyLens ? "flex-start" : "flex-end" }, onViewableItemsChanged: onVisible, viewabilityConfig: {
830
- itemVisiblePercentThreshold: 50,
831
- minimumViewTime: 500,
832
- }, renderItem: renderHistoryItem, onEndReached: () => {
833
- // Native lists can report their end before the first content layout.
834
- // Do not load successive older pages while the opening screen settles.
835
- // Short histories still expose the explicit “Load earlier messages”.
836
- if (historyInteraction.current.dragged && state.hasMore && !state.loading && !state.historyError) {
837
- void client.loadOlder().catch(() => { });
838
- }
839
- }, onEndReachedThreshold: 0.2, ListHeaderComponent: _jsxs(_Fragment, { children: [(state.heldMessages ?? []).map(item => _jsxs(View, { testID: "held-message", style: { padding: 12, marginVertical: 4, borderWidth: 1, borderColor: design.colors.secondary, borderRadius: 8 }, children: [_jsx(Text, { style: { color: design.colors.foreground }, children: item.content.text ?? item.content.media?.fileName ?? 'Message' }), _jsx(Text, { accessibilityLiveRegion: "polite", style: { color: design.colors.secondary, fontSize: 12, marginTop: 4 }, children: uiText(item.state === 'pending' ? 'Waiting for review — not delivered' : item.state === 'approved' ? 'Approved — waiting for delivery' : item.state === 'rejected' ? 'Not approved — not delivered' : 'Review expired — not delivered') })] }, item.id)), state.historyWindow && state.hasNewer ? _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Load newer messages"), disabled: state.loading, onPress: () => void client.loadNewer().catch(() => { }), style: { padding: 10, minHeight: 44, alignItems: 'center' }, children: _jsx(Text, { style: { color: design.colors.accent }, children: uiText("Load newer messages") }) }) : null] }), ListFooterComponent: _jsxs(_Fragment, { children: [state.messages.length > 0 && (state.loading || state.historyError || state.hasMore) ? _jsx(View, { style: { padding: 10, minHeight: 64, justifyContent: 'center', alignItems: 'center' }, children: state.loading ? _jsx(ActivityIndicator, { accessibilityLabel: uiText("Loading earlier messages"), color: design.colors.accent }) : _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: state.historyError ? uiText("Retry earlier messages") : uiText("Load earlier messages"), onPress: () => void client.loadOlder().catch(() => { }), style: { minHeight: 44, justifyContent: 'center' }, children: _jsx(Text, { style: { color: design.colors.accent }, children: state.historyError ? uiText("Earlier messages could not load. Retry") : uiText("Load earlier messages") }) }) }) : null, context.extrasState?.privacyLens && _jsx(View, { testID: "privacy-history-spacer", style: { height: Math.max(0, historyHeight - privacyReadingStripHeight) } })] }), ListEmptyComponent: state.loading ? _jsx(MessagingLoadingMessages, { color: design.colors.secondary }, state.conversationId) : state.error ? null : _jsx(Text, { style: { color: design.colors.secondary }, children: design.labels.empty }) }, state.conversationId + (context.extrasState?.privacyLens ? "privacy-reading" : "regular-history")) }), (away || state.historyWindow) && _jsx(Animated.View, { testID: "latest-message-control", pointerEvents: showLatest ? 'auto' : 'none', accessibilityElementsHidden: !showLatest, importantForAccessibility: showLatest ? 'auto' : 'no-hide-descendants', ...(Platform.OS === 'web' ? { 'aria-hidden': !showLatest } : {}), style: { position: 'absolute', left: '50%', marginLeft: -22, bottom: 8, opacity: Platform.OS === 'web' ? (showLatest ? 1 : 0) : latestOpacity, ...(Platform.OS === 'web' ? { transitionProperty: 'opacity', transitionDuration: '200ms' } : {}) }, children: _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: newMessages ? uiText("New messages. Go to latest") : uiText("Go to latest message"), disabled: !showLatest, onPress: () => jumpToLatest(), style: { width: 44, height: 44, borderRadius: 22, borderWidth: 1.5, borderColor: design.colors.accent, backgroundColor: chatSurface(design.colors.background), justifyContent: 'center', alignItems: 'center' }, children: _jsx(MessageIcon, { name: "arrow-down", color: design.colors.accent, size: 26 }) }) }), _jsx(MessageSelection, {})] }));
836
+ return (_jsxs(View, { style: { flex: 1, minHeight: 0 }, children: [_jsx(Privacy, { enabled: !!context.extrasState?.privacyLens, background: design.colors.background, children: _jsx(HistoryScrollAnchor, { historyKey: state.conversationId + ':' + (state.focus?.messageId ?? ''), following: nearLatest, node: () => Platform.OS === 'web' ? list.current?.getScrollableNode() ?? null : null, children: _jsx(FlatList, { ref: list, testID: "messaging-history", onLayout: event => { setHistoryHeight(event.nativeEvent.layout.height); const target = scrollTarget.current; if (target)
837
+ requestAnimationFrame(() => { if (scrollTarget.current === target)
838
+ list.current?.scrollToIndex({ index: target.index, viewPosition: .5, animated: false }); }); }, maintainVisibleContentPosition: highlight ? undefined : { minIndexForVisible: 0, ...(!state.historyWindow ? { autoscrollToTopThreshold: 80 } : {}) }, onContentSizeChange: () => { const target = scrollTarget.current; if (target)
839
+ requestAnimationFrame(() => { if (scrollTarget.current === target)
840
+ list.current?.scrollToIndex({ index: target.index, viewPosition: .5, animated: false }); });
841
+ else
842
+ followLatestLayout(); },
843
+ // Keep nearby history ready without mounting most of a long conversation.
844
+ // Smaller batches leave the JS thread available for incoming messages,
845
+ // gestures and receipt updates while the user scrolls.
846
+ initialNumToRender: 12, maxToRenderPerBatch: 8, windowSize: 5, onScrollToIndexFailed: info => {
847
+ const target = scrollTarget.current;
848
+ if (!target || target.retryTimer || target.attempts >= 20)
849
+ return;
850
+ target.attempts++;
851
+ // A distant cell may need several native layout batches. Coalesce
852
+ // layout callbacks so they cannot exhaust retries before those batches.
853
+ target.retryTimer = setTimeout(() => { target.retryTimer = undefined; if (scrollTarget.current === target)
854
+ list.current?.scrollToIndex({ index: target.index, viewPosition: .5, animated: false }); }, 150);
855
+ list.current?.scrollToOffset({ offset: info.averageItemLength * info.index, animated: false });
856
+ }, onScrollBeginDrag: () => { interruptLatestScroll(); scrollingStarted(); }, ...(Platform.OS === 'web' ? {
857
+ // Browser wheel/keyboard/scrollbar input does not emit native drag events.
858
+ onWheel: () => { interruptLatestScroll(); scrollingSettled(); },
859
+ onPointerDown: interruptLatestScroll,
860
+ onPointerUp: scrollingSettled,
861
+ onPointerCancel: scrollingSettled,
862
+ onKeyDown: (event) => { if (['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End', ' '].includes(event.key)) {
863
+ interruptLatestScroll();
864
+ scrollingSettled();
865
+ } },
866
+ } : {}), onScrollEndDrag: scrollingSettled, onMomentumScrollBegin: () => { nearLatest.begin(); scrollingStarted(); }, onMomentumScrollEnd: scrollingSettled, onScroll: event => { scrollingStarted(); scrollingSettled(); latestOffset.current = event.nativeEvent.contentOffset.y; const near = nearLatest.observe(latestOffset.current); setAway(!near); if (near)
867
+ setNewMessages(false); }, scrollEventThrottle: 32, data: items, inverted: true, keyExtractor: (m) => m.senderId + ':' + m.clientMessageId, style: { flex: 1 }, keyboardShouldPersistTaps: "handled", contentContainerStyle: { paddingHorizontal: 12, paddingVertical: 10, paddingTop: context.extrasState?.privacyLens ? privacyReadingStripHeight + 10 : 10, flexGrow: 1, justifyContent: context.extrasState?.privacyLens ? "flex-start" : "flex-end" }, onViewableItemsChanged: onVisible, viewabilityConfig: {
868
+ itemVisiblePercentThreshold: 50,
869
+ minimumViewTime: 500,
870
+ }, renderItem: renderHistoryItem, onEndReached: () => {
871
+ // Native lists can report their end before the first content layout.
872
+ // Do not load successive older pages while the opening screen settles.
873
+ // Short histories still expose the explicit “Load earlier messages”.
874
+ if (historyInteraction.current.dragged && state.hasMore && !state.loading && !state.historyError) {
875
+ void client.loadOlder().catch(() => { });
876
+ }
877
+ }, onEndReachedThreshold: 0.2, ListHeaderComponent: _jsxs(_Fragment, { children: [(state.heldMessages ?? []).map(item => _jsxs(View, { testID: "held-message", style: { padding: 12, marginVertical: 4, borderWidth: 1, borderColor: design.colors.secondary, borderRadius: 8 }, children: [_jsx(Text, { style: { color: design.colors.foreground }, children: item.content.text ?? item.content.media?.fileName ?? 'Message' }), _jsx(Text, { accessibilityLiveRegion: "polite", style: { color: design.colors.secondary, fontSize: 12, marginTop: 4 }, children: uiText(item.state === 'pending' ? 'Waiting for review — not delivered' : item.state === 'approved' ? 'Approved — waiting for delivery' : item.state === 'rejected' ? 'Not approved — not delivered' : 'Review expired — not delivered') })] }, item.id)), state.historyWindow && state.hasNewer ? _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Load newer messages"), disabled: state.loading, onPress: () => void client.loadNewer().catch(() => { }), style: { padding: 10, minHeight: 44, alignItems: 'center' }, children: _jsx(Text, { style: { color: design.colors.accent }, children: uiText("Load newer messages") }) }) : null] }), ListFooterComponent: _jsxs(_Fragment, { children: [state.messages.length > 0 && (state.loading || state.historyError || state.hasMore) ? _jsx(View, { style: { padding: 10, minHeight: 64, justifyContent: 'center', alignItems: 'center' }, children: state.loading ? _jsx(ActivityIndicator, { accessibilityLabel: uiText("Loading earlier messages"), color: design.colors.accent }) : _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: state.historyError ? uiText("Retry earlier messages") : uiText("Load earlier messages"), onPress: () => void client.loadOlder().catch(() => { }), style: { minHeight: 44, justifyContent: 'center' }, children: _jsx(Text, { style: { color: design.colors.accent }, children: state.historyError ? uiText("Earlier messages could not load. Retry") : uiText("Load earlier messages") }) }) }) : null, context.extrasState?.privacyLens && _jsx(View, { testID: "privacy-history-spacer", style: { height: Math.max(0, historyHeight - privacyReadingStripHeight) } })] }), ListEmptyComponent: state.loading ? _jsx(MessagingLoadingMessages, { color: design.colors.secondary }, state.conversationId) : state.error ? null : _jsx(Text, { style: { color: design.colors.secondary }, children: design.labels.empty }) }, state.conversationId + (context.extrasState?.privacyLens ? "privacy-reading" : "regular-history")) }) }), (away || state.historyWindow) && _jsx(Animated.View, { testID: "latest-message-control", pointerEvents: showLatest ? 'auto' : 'none', accessibilityElementsHidden: !showLatest, importantForAccessibility: showLatest ? 'auto' : 'no-hide-descendants', ...(Platform.OS === 'web' ? { 'aria-hidden': !showLatest } : {}), style: { position: 'absolute', left: '50%', marginLeft: -22, bottom: 8, opacity: Platform.OS === 'web' ? (showLatest ? 1 : 0) : latestOpacity, ...(Platform.OS === 'web' ? { transitionProperty: 'opacity', transitionDuration: '200ms' } : {}) }, children: _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: newMessages ? uiText("New messages. Go to latest") : uiText("Go to latest message"), disabled: !showLatest, onPress: () => jumpToLatest(), style: { width: 44, height: 44, borderRadius: 22, borderWidth: 1.5, borderColor: design.colors.accent, backgroundColor: chatSurface(design.colors.background), justifyContent: 'center', alignItems: 'center' }, children: _jsx(MessageIcon, { name: "arrow-down", color: design.colors.accent, size: 26 }) }) }), _jsx(MessageSelection, {})] }));
840
878
  }
841
879
  /** One horizontal media row on phones and in the browser preview. */
842
880
  function AttachmentStrip({ children, label, height, recent = false }) {
@@ -1204,7 +1242,7 @@ export function MessagingComposer() {
1204
1242
  return (_jsxs(View, { testID: "messaging-composer", style: { paddingStart: 8, paddingEnd: 0, paddingVertical: 4, gap: 8, backgroundColor: design.composer?.background ?? c.background }, children: [mentionSuggestions.length > 0 && _jsx(ScrollView, { keyboardShouldPersistTaps: "handled", style: { maxHeight: 144 }, children: mentionSuggestions.map(id => _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Mention {name}', { name: participants[id].name }), onPress: () => chooseMention(id), style: { minHeight: 44, paddingHorizontal: 12, justifyContent: 'center', borderBottomWidth: .5, borderBottomColor: c.secondary + '30' }, children: _jsxs(Text, { style: { color: c.accent, fontSize: 16 }, children: ["@", participants[id].name] }) }, id)) }), mentionQuery !== undefined && !!mentionError && _jsx(Text, { style: { color: c.secondary, fontSize: 13 }, children: mentionError }), editing && _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8 }, children: [_jsxs(Text, { numberOfLines: 1, style: { flex: 1, color: c.secondary }, children: [uiText("Editing:"), editing.text || editing.media?.fileName] }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Cancel editing"), disabled: busy, onPress: () => setEditing(null), style: { minHeight: 36, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("Cancel") }) })] }), !editing && reply && (_jsxs(View, { testID: "composer-quote", style: { flexDirection: "row", gap: 8 }, children: [_jsx(View, { style: { flex: 1 }, children: _jsx(QuotedPreview, { message: reply, ink: c.secondary }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Cancel quote"), onPress: () => setReply(null), children: _jsx(Text, { style: { color: c.foreground }, children: uiText("Cancel") }) })] })), state.settings?.history?.mode === 'last_two' && _jsx(Text, { style: { color: c.secondary, fontSize: 11, textAlign: 'center' }, children: uiText("Only the latest two messages are kept.") }), editing ? _jsxs(_Fragment, { children: [renderAttachments(), renderTextComposer()] }) : features?.voice ? _jsx(VoiceComposer, { appearance: design, maxSeconds: state.settings?.voice?.maxDurationSeconds ?? 60, busy: busy, onRecord: () => { Keyboard.dismiss(); void pick('voice'); }, renderAttachments: renderAttachments, renderTextComposer: features?.text || selected.length ? renderTextComposer : undefined, actions: _jsx(_Fragment, { children: (camera || library.image || library.video || library.document || !editing && (features?.poll || weatherAllowed)) && _jsx(Pressable, { ref: attachmentButton, accessibilityRole: "button", accessibilityLabel: uiText("Attach"), accessibilityState: { expanded: attachmentsOpen }, disabled: busy, onPress: () => setAttachmentsOpen(!attachmentsOpen), style: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: attachmentsOpen ? 'close' : 'plus', color: c.foreground, size: 25 }) }) }) }) : _jsxs(_Fragment, { children: [renderAttachments(), renderTextComposer()] }), attachmentsOpen && _jsx(AttachmentMenu, { anchor: attachmentButton, accent: c.accent, onClose: () => setAttachmentsOpen(false), actions: attachmentActions }), scheduleOpen && _jsx(ScheduleTimePicker, { initial: scheduleAttempt.current?.time, retryAt: scheduleError ? scheduleAttempt.current?.time : undefined, accent: c.accent, busy: busy, error: scheduleError, onSave: time => void schedule(time), onClose: () => setScheduleOpen(false) }), pollOpen && features?.poll && _jsx(PollComposer, { yesNo: state.conversation?.kind !== 'group', appearance: design, onSend: poll => submit({ kind: 'poll', poll }), onCancel: () => setPollOpen(false) }), error && (_jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground }, children: error }))] }));
1205
1243
  }
1206
1244
  /** Account navigation. Mount in the inbox/app toolbar, never in a contact menu. */
1207
- export function MessagingAccountMenu({ inbox, onNewGroup, onMaps, onPublicRooms } = {}) {
1245
+ export function MessagingAccountMenu({ inbox, onNewGroup, onMaps, onPublicRooms, onVoicemail } = {}) {
1208
1246
  const { text } = useRobonoLocale(), { client, design, setSavedOpen, account, companyName } = useMessagingUI();
1209
1247
  const [open, setOpen] = useState(false), [accountOpen, setAccountOpen] = useState(false), [page, setPage] = useState(null), pending = useRef(null);
1210
1248
  const menu = messagingMenuColors(design, 'friends'), items = design.menus?.friends?.items, layout = messagingMenuLayout(design.menus?.friends);
@@ -1218,6 +1256,8 @@ export function MessagingAccountMenu({ inbox, onNewGroup, onMaps, onPublicRooms
1218
1256
  if (key === 'language' && client.hasSavedMessages() && items?.saved !== false)
1219
1257
  rows.push({ key: 'saved', label: 'Saved', icon: 'bookmark-outline' });
1220
1258
  }
1259
+ if (onVoicemail)
1260
+ rows.push({ key: 'voicemail', label: 'Voicemail', icon: 'mic-outline' });
1221
1261
  if (onMaps && items?.maps !== false)
1222
1262
  rows.push({ key: 'maps', label: 'Maps', icon: 'location' });
1223
1263
  if (onPublicRooms && items?.publicGroups !== false)
@@ -1236,6 +1276,8 @@ export function MessagingAccountMenu({ inbox, onNewGroup, onMaps, onPublicRooms
1236
1276
  onMaps?.();
1237
1277
  else if (next === 'rooms')
1238
1278
  onPublicRooms?.();
1279
+ else if (next === 'voicemail')
1280
+ onVoicemail?.();
1239
1281
  else if (next === 'account')
1240
1282
  setAccountOpen(true);
1241
1283
  else if (next === 'linkedApps' && account?.onLinkedApps)
@@ -0,0 +1,7 @@
1
+ import React, { type ReactNode } from 'react';
2
+ /** Use the same formatter as the surrounding Messenger, including host locale. */
3
+ export declare function MessagingTimeFormatProvider({ format, children }: {
4
+ format: (value: string) => string;
5
+ children: ReactNode;
6
+ }): React.JSX.Element;
7
+ export declare function useMessagingTimeFormat(): (value: string) => string;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo } from 'react';
3
+ import { useRobonoLocale } from './localization.js';
4
+ const TimeFormat = createContext(null);
5
+ const formatters = new Map();
6
+ /** Use the same formatter as the surrounding Messenger, including host locale. */
7
+ export function MessagingTimeFormatProvider({ format, children }) { return _jsx(TimeFormat.Provider, { value: format, children: children }); }
8
+ export function useMessagingTimeFormat() {
9
+ const inherited = useContext(TimeFormat), { locale } = useRobonoLocale();
10
+ const fallback = useMemo(() => (value) => { const date = new Date(value), key = locale + ':' + date.getTimezoneOffset(); let formatter = formatters.get(key); if (!formatter) {
11
+ formatter = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: '2-digit' });
12
+ if (formatters.size >= 8)
13
+ formatters.clear();
14
+ formatters.set(key, formatter);
15
+ } return formatter.format(date); }, [locale]);
16
+ return inherited ?? fallback;
17
+ }
@@ -2,7 +2,10 @@ import React from 'react';
2
2
  import { type VideoViewProps, type VideoPlayer } from 'expo-video';
3
3
  /** Shared by Robono Messenger and the SDK. A decoded frame includes the camera's
4
4
  * rotation; the encoded track's natural width/height does not necessarily do so. */
5
- export declare function MessengerVideoView({ player, posterUri, ...props }: Omit<VideoViewProps, 'player' | 'contentFit' | 'fullscreenOptions'> & {
5
+ export declare function MessengerVideoView({ player, sourceUri, posterUri, allowFullscreen, onDimensions, ...props }: Omit<VideoViewProps, 'player' | 'contentFit' | 'fullscreenOptions'> & {
6
6
  player: VideoPlayer;
7
+ sourceUri?: string;
7
8
  posterUri?: string | null;
9
+ allowFullscreen?: boolean;
10
+ onDimensions?: (width: number, height: number) => void;
8
11
  }): React.JSX.Element;
@@ -1,16 +1,27 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from 'react';
3
- import { Image } from 'react-native';
3
+ import { Image, Platform } from 'react-native';
4
+ import { readLocalVideoOrientation } from './expo-video-orientation.js';
4
5
  import { VideoView } from 'expo-video';
5
6
  /** Shared by Robono Messenger and the SDK. A decoded frame includes the camera's
6
7
  * rotation; the encoded track's natural width/height does not necessarily do so. */
7
- export function MessengerVideoView({ player, posterUri, ...props }) {
8
+ export function MessengerVideoView({ player, sourceUri, posterUri, allowFullscreen = true, onDimensions, ...props }) {
9
+ const [mirrorVideoSurface, setMirrorVideoSurface] = useState(false);
10
+ useEffect(() => {
11
+ let alive = true;
12
+ setMirrorVideoSurface(false);
13
+ if (Platform.OS === 'android' && sourceUri)
14
+ void readLocalVideoOrientation(sourceUri).then(track => { if (alive)
15
+ setMirrorVideoSurface(!!track?.mirrored); }).catch(() => { });
16
+ return () => { alive = false; };
17
+ }, [sourceUri]);
18
+ const displayProps = Platform.OS === 'android' ? { mirrorVideoSurface } : {};
8
19
  const [orientation, setOrientation] = useState('default');
9
20
  useEffect(() => {
10
21
  let alive = true, pending = false, resolved = false;
11
22
  setOrientation('default');
12
23
  const accept = (width, height) => { if (!alive || width <= 0 || height <= 0)
13
- return; resolved = true; setOrientation(width > height ? 'landscape' : 'portrait'); };
24
+ return; resolved = true; onDimensions?.(width, height); setOrientation(width > height ? 'landscape' : 'portrait'); };
14
25
  const decode = async () => {
15
26
  if (!alive || pending || resolved || player.status !== 'readyToPlay' || typeof player.generateThumbnailsAsync !== 'function')
16
27
  return;
@@ -42,5 +53,5 @@ export function MessengerVideoView({ player, posterUri, ...props }) {
42
53
  void decode(); });
43
54
  return () => { alive = false; status.remove(); source.remove(); };
44
55
  }, [player, posterUri]);
45
- return _jsx(VideoView, { nativeControls: true, ...props, player: player, contentFit: "contain", fullscreenOptions: { enable: true, orientation } });
56
+ return _jsx(VideoView, { nativeControls: true, ...props, ...displayProps, player: player, surfaceType: !allowFullscreen || Platform.OS === 'android' && mirrorVideoSurface ? 'textureView' : props.surfaceType, style: [!allowFullscreen && { overflow: 'hidden' }, props.style], contentFit: "contain", fullscreenOptions: { enable: allowFullscreen, orientation } });
46
57
  }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ /** Transient recording feedback never participates in composer measurement. */
3
+ export declare function RecordingNotice({ message }: {
4
+ message?: string | null;
5
+ }): React.JSX.Element | null;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { View } from 'react-native';
4
+ import { Text } from './typography.js';
5
+ /** Transient recording feedback never participates in composer measurement. */
6
+ export function RecordingNotice({ message }) {
7
+ const [visible, setVisible] = useState(false);
8
+ useEffect(() => { setVisible(!!message); if (!message)
9
+ return; const timer = setTimeout(() => setVisible(false), 3000); return () => clearTimeout(timer); }, [message]);
10
+ if (!visible || !message)
11
+ return null;
12
+ return _jsx(View, { pointerEvents: "none", testID: "recording-notice", style: { position: 'absolute', bottom: '100%', left: 8, right: 8, marginBottom: 8, zIndex: 100, elevation: 12, alignItems: 'center' }, children: _jsx(View, { style: { maxWidth: 420, borderRadius: 10, backgroundColor: '#202124', paddingHorizontal: 14, paddingVertical: 10 }, children: _jsx(Text, { accessibilityRole: "alert", accessibilityLiveRegion: "polite", style: { color: '#fff', fontSize: 13, textAlign: 'center' }, children: message }) }) });
13
+ }
@@ -25,5 +25,6 @@ export declare function useQuoteGesture(enabled: boolean, outgoing: boolean, quo
25
25
  transitionTimingFunction?: undefined;
26
26
  };
27
27
  handlers: import("react-native").GestureResponderHandlers;
28
+ cancel: () => void;
28
29
  suppressPress: () => boolean;
29
30
  };
@@ -155,5 +155,6 @@ export function useQuoteGesture(enabled, outgoing, quote, details, onQuoteReady)
155
155
  revealWebStyle: Platform.OS === 'web' ? { transitionProperty: 'opacity', transitionDuration: webDragging ? '0ms' : '150ms' } : {},
156
156
  webStyle: Platform.OS === 'web' ? { transitionProperty: 'transform', transitionDuration: webDragging ? '0ms' : '150ms', transitionTimingFunction: 'cubic-bezier(0.215,0.61,0.355,1)' } : {},
157
157
  handlers: Platform.OS === 'web' ? {} : responder.panHandlers,
158
+ cancel: () => { pointer.current = null; quoteReady.current = false; suppressUntil.current = Date.now() + 400; reset(); },
158
159
  suppressPress: () => Date.now() < suppressUntil.current };
159
160
  }
@@ -0,0 +1,7 @@
1
+ import React, { type ReactNode } from 'react';
2
+ /** Metadata stays inside the thumbnail, shared by regular and voicemail video. */
3
+ export declare function VideoMessageBadge({ durationMs, label, time }: {
4
+ durationMs?: number | null;
5
+ label?: ReactNode;
6
+ time?: ReactNode;
7
+ }): React.JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { View } from 'react-native';
3
+ import { Text } from './typography.js';
4
+ import { duration } from './icons.js';
5
+ /** Metadata stays inside the thumbnail, shared by regular and voicemail video. */
6
+ export function VideoMessageBadge({ durationMs, label, time }) {
7
+ return _jsxs(View, { pointerEvents: "none", testID: "video-message-badge", style: { position: 'absolute', left: 6, right: 6, bottom: 6, alignItems: 'flex-end', gap: 2 }, children: [time, _jsxs(View, { style: { maxWidth: '100%', flexDirection: 'row', alignItems: 'center', gap: 6, borderRadius: 4, paddingHorizontal: 5, paddingVertical: 2, backgroundColor: '#0009' }, children: [label, _jsx(Text, { testID: "video-message-duration", style: { color: '#fff', fontSize: 11, fontVariant: ['tabular-nums'] }, children: duration(durationMs ?? 0) })] })] });
8
+ }
@@ -0,0 +1,13 @@
1
+ /** Read only ISO-BMFF headers, skipping media payloads. Matrix belongs to the
2
+ * video track; audio tracks have zero display dimensions. */
3
+ export declare function readVideoOrientation(read: (offset: number, length: number) => Promise<Uint8Array>, length: number): Promise<{
4
+ rotation: number;
5
+ width: number;
6
+ height: number;
7
+ mirrored: boolean;
8
+ } | undefined>;
9
+ export declare function thumbnailRotation(track: {
10
+ rotation: number;
11
+ width: number;
12
+ height: number;
13
+ } | undefined, width: number, height: number): 0 | 90 | 270;
@@ -0,0 +1,58 @@
1
+ /** Read only ISO-BMFF headers, skipping media payloads. Matrix belongs to the
2
+ * video track; audio tracks have zero display dimensions. */
3
+ export async function readVideoOrientation(read, length) {
4
+ let visited = 0;
5
+ const scan = async (start, end, depth) => {
6
+ if (depth > 3)
7
+ return;
8
+ for (let offset = start; offset + 8 <= end && visited++ < 256;) {
9
+ const header = await read(offset, 16);
10
+ if (header.length < 8)
11
+ return;
12
+ const h = new DataView(header.buffer, header.byteOffset, header.byteLength);
13
+ let size = h.getUint32(0), head = 8;
14
+ const type = String.fromCharCode(...header.slice(4, 8));
15
+ if (size === 1) {
16
+ if (header.length < 16)
17
+ return;
18
+ size = h.getUint32(8) * 4294967296 + h.getUint32(12);
19
+ head = 16;
20
+ }
21
+ else if (size === 0)
22
+ size = end - offset;
23
+ if (!Number.isSafeInteger(size) || size < head || offset + size > end)
24
+ return;
25
+ if (type === 'moov' || type === 'trak') {
26
+ const result = await scan(offset + head, offset + size, depth + 1);
27
+ if (result)
28
+ return result;
29
+ }
30
+ if (type === 'tkhd') {
31
+ const bytes = await read(offset + head, Math.min(100, size - head));
32
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), matrix = bytes[0] === 1 ? 52 : 40;
33
+ if (bytes.length >= matrix + 44) {
34
+ const width = view.getUint32(matrix + 36) / 65536, height = view.getUint32(matrix + 40) / 65536;
35
+ if (width > 0 && height > 0) {
36
+ const a = view.getInt32(matrix) / 65536, b = view.getInt32(matrix + 4) / 65536;
37
+ const c = view.getInt32(matrix + 12) / 65536, d = view.getInt32(matrix + 16) / 65536;
38
+ const mirrored = a * d - b * c < 0;
39
+ const rotation = (Math.round(Math.atan2(b, mirrored ? d : a) * 180 / Math.PI) + 360) % 360;
40
+ return { rotation, width, height, mirrored };
41
+ }
42
+ }
43
+ }
44
+ offset += size;
45
+ }
46
+ };
47
+ return scan(0, length, 0);
48
+ }
49
+ export function thumbnailRotation(track, width, height) {
50
+ if (!track || !width || !height)
51
+ return 0;
52
+ const r = track.rotation;
53
+ if (r !== 90 && r !== 270)
54
+ return 0;
55
+ const raw = track.width / track.height, actual = width / height;
56
+ // Some decoders apply the matrix already. Never rotate those frames twice.
57
+ return Math.abs(actual - raw) < Math.abs(actual - 1 / raw) ? r : 0;
58
+ }