@robono/messaging-react-native 0.20.3 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/README.md +36 -0
- package/SBOM.spdx.json +294 -198
- package/dist/disk-cache.d.ts +14 -0
- package/dist/disk-cache.js +15 -0
- package/dist/expo-cache.d.ts +20 -0
- package/dist/expo-cache.js +111 -0
- package/dist/expo-media.js +7 -22
- package/dist/expo-screen.js +15 -7
- package/dist/expo-thumbnails.d.ts +4 -0
- package/dist/expo-thumbnails.js +3 -2
- package/dist/expo.d.ts +1 -0
- package/dist/expo.js +1 -0
- package/dist/index.js +8 -5
- package/dist/media-controller.d.ts +2 -1
- package/dist/media-controller.js +8 -8
- package/dist/media-ui.d.ts +4 -2
- package/dist/media-ui.js +13 -13
- package/dist/preview-cache.d.ts +1 -0
- package/dist/preview-cache.js +2 -0
- package/dist/voice-composer.js +2 -1
- package/dist/voice-waveform.d.ts +2 -0
- package/dist/voice-waveform.js +9 -0
- package/package.json +2 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Only disposable, SDK-owned entries belong here. Documents/drafts are excluded. */
|
|
2
|
+
export interface MessagingDiskCacheEntry {
|
|
3
|
+
key: string;
|
|
4
|
+
bytes: number;
|
|
5
|
+
modifiedAt: number;
|
|
6
|
+
protected: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface MessagingDiskCacheLimits {
|
|
9
|
+
maxBytes: number;
|
|
10
|
+
maxAgeMs: number;
|
|
11
|
+
minFreeBytes: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const defaultMessagingDiskCacheLimits: MessagingDiskCacheLimits;
|
|
14
|
+
export declare function messagingDiskEvictions(entries: MessagingDiskCacheEntry[], limits: MessagingDiskCacheLimits, freeBytes: number, now: number, requiredBytes?: number): string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const defaultMessagingDiskCacheLimits = { maxBytes: 150 * 1024 * 1024, maxAgeMs: 24 * 3600000, minFreeBytes: 100 * 1024 * 1024 };
|
|
2
|
+
export function messagingDiskEvictions(entries, limits, freeBytes, now, requiredBytes = 0) {
|
|
3
|
+
let bytes = entries.reduce((n, e) => n + e.bytes, 0), available = freeBytes;
|
|
4
|
+
const remove = [];
|
|
5
|
+
for (const entry of [...entries].sort((a, b) => a.modifiedAt - b.modifiedAt)) {
|
|
6
|
+
if (entry.protected)
|
|
7
|
+
continue;
|
|
8
|
+
if (now - entry.modifiedAt >= limits.maxAgeMs || bytes > limits.maxBytes || available < limits.minFreeBytes + requiredBytes) {
|
|
9
|
+
remove.push(entry.key);
|
|
10
|
+
bytes -= entry.bytes;
|
|
11
|
+
available += entry.bytes;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return remove;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type MessagingDiskCacheLimits } from './disk-cache.js';
|
|
2
|
+
export type { MessagingDiskCacheLimits } from './disk-cache.js';
|
|
3
|
+
export interface MessagingCacheMaintenanceResult {
|
|
4
|
+
bytesBefore: number;
|
|
5
|
+
bytesAfter: number;
|
|
6
|
+
protectedBytes: number;
|
|
7
|
+
removedFiles: number;
|
|
8
|
+
freeBytes: number;
|
|
9
|
+
limitReached: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function configureExpoMessagingCache(options: Partial<MessagingDiskCacheLimits>): void;
|
|
12
|
+
export declare const messagingCacheRoot: () => string;
|
|
13
|
+
/** May run while Messenger is open. Active files are never eviction candidates.
|
|
14
|
+
* This does not erase saved messages, persistent drafts, host files or libraries. */
|
|
15
|
+
export declare function maintainExpoMessagingCache(options?: {
|
|
16
|
+
requiredBytes?: number;
|
|
17
|
+
clearUnused?: boolean;
|
|
18
|
+
}): Promise<MessagingCacheMaintenanceResult>;
|
|
19
|
+
export declare function allocateMessagingCache(requiredBytes?: number, draft?: boolean): Promise<string>;
|
|
20
|
+
export declare function removeMessagingCacheUri(uri: string): Promise<void>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as FS from 'expo-file-system/legacy';
|
|
2
|
+
import * as Crypto from 'expo-crypto';
|
|
3
|
+
import { defaultMessagingDiskCacheLimits, messagingDiskEvictions } from './disk-cache.js';
|
|
4
|
+
let limits = { ...defaultMessagingDiskCacheLimits };
|
|
5
|
+
// Allocations are leased before any await. Existing viewers, queued sends and
|
|
6
|
+
// selected attachments stay protected until their existing remove() lifecycle.
|
|
7
|
+
const active = new Set();
|
|
8
|
+
let maintenance, started = false, lastMaintenance = 0;
|
|
9
|
+
export function configureExpoMessagingCache(options) {
|
|
10
|
+
for (const [key, value] of Object.entries(options))
|
|
11
|
+
if (!Object.prototype.hasOwnProperty.call(limits, key) || !Number.isSafeInteger(value) || value < 0)
|
|
12
|
+
throw Error('Cache limits must be non-negative whole numbers.');
|
|
13
|
+
limits = { ...limits, ...options };
|
|
14
|
+
}
|
|
15
|
+
export const messagingCacheRoot = () => { if (!FS.cacheDirectory)
|
|
16
|
+
throw Error('Private device storage is unavailable.'); return FS.cacheDirectory + 'robono-messaging/'; };
|
|
17
|
+
const owned = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
18
|
+
/** May run while Messenger is open. Active files are never eviction candidates.
|
|
19
|
+
* This does not erase saved messages, persistent drafts, host files or libraries. */
|
|
20
|
+
export async function maintainExpoMessagingCache(options = {}) {
|
|
21
|
+
const required = options.requiredBytes ?? 0;
|
|
22
|
+
if (!Number.isSafeInteger(required) || required < 0)
|
|
23
|
+
throw Error('Invalid required storage.');
|
|
24
|
+
if (maintenance) {
|
|
25
|
+
await maintenance;
|
|
26
|
+
return maintainExpoMessagingCache(options);
|
|
27
|
+
}
|
|
28
|
+
const run = async () => {
|
|
29
|
+
const root = messagingCacheRoot(), entries = [];
|
|
30
|
+
if ((await FS.getInfoAsync(root)).exists)
|
|
31
|
+
for (const name of await FS.readDirectoryAsync(root)) {
|
|
32
|
+
if (!owned.test(name))
|
|
33
|
+
continue;
|
|
34
|
+
const dir = root + name + '/';
|
|
35
|
+
const info = await FS.getInfoAsync(dir);
|
|
36
|
+
if (!info.exists || !info.isDirectory)
|
|
37
|
+
continue;
|
|
38
|
+
let bytes = 0, modifiedAt = info.modificationTime * 1000, valid = true, draft = false;
|
|
39
|
+
for (const file of await FS.readDirectoryAsync(dir)) {
|
|
40
|
+
if (file === '__draft__')
|
|
41
|
+
draft = true;
|
|
42
|
+
const item = await FS.getInfoAsync(dir + file);
|
|
43
|
+
if (!item.exists)
|
|
44
|
+
continue;
|
|
45
|
+
if (item.isDirectory) {
|
|
46
|
+
valid = false;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
bytes += item.size;
|
|
50
|
+
modifiedAt = Math.max(modifiedAt, item.modificationTime * 1000);
|
|
51
|
+
}
|
|
52
|
+
if (valid)
|
|
53
|
+
entries.push({ key: dir, bytes, modifiedAt, protected: draft || active.has(dir) });
|
|
54
|
+
}
|
|
55
|
+
const free = await FS.getFreeDiskStorageAsync();
|
|
56
|
+
const selected = messagingDiskEvictions(entries, options.clearUnused ? { ...limits, maxBytes: 0, maxAgeMs: 0 } : limits, free, Date.now(), required);
|
|
57
|
+
let removedBytes = 0, removedFiles = 0;
|
|
58
|
+
for (const dir of selected) {
|
|
59
|
+
// Recheck immediately before deleting: no await may acquire this directory
|
|
60
|
+
// between this check and starting deletion. Allocations always get new UUIDs.
|
|
61
|
+
if (active.has(dir))
|
|
62
|
+
continue;
|
|
63
|
+
try {
|
|
64
|
+
await FS.deleteAsync(dir, { idempotent: true });
|
|
65
|
+
removedBytes += entries.find(e => e.key === dir).bytes;
|
|
66
|
+
removedFiles++;
|
|
67
|
+
}
|
|
68
|
+
catch { /* retry on next maintenance */ }
|
|
69
|
+
}
|
|
70
|
+
const bytesBefore = entries.reduce((n, e) => n + e.bytes, 0), bytesAfter = bytesBefore - removedBytes;
|
|
71
|
+
return { bytesBefore, bytesAfter, protectedBytes: entries.filter(e => e.protected || active.has(e.key)).reduce((n, e) => n + e.bytes, 0), removedFiles, freeBytes: await FS.getFreeDiskStorageAsync(), limitReached: bytesAfter > limits.maxBytes };
|
|
72
|
+
};
|
|
73
|
+
maintenance = run();
|
|
74
|
+
try {
|
|
75
|
+
return await maintenance;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
maintenance = undefined;
|
|
79
|
+
lastMaintenance = Date.now();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export async function allocateMessagingCache(requiredBytes = 0, draft = false) {
|
|
83
|
+
const low = requiredBytes > 0 && (await FS.getFreeDiskStorageAsync()) < limits.minFreeBytes + requiredBytes;
|
|
84
|
+
if (!started || low || Date.now() - lastMaintenance > 60000) {
|
|
85
|
+
await maintainExpoMessagingCache({ requiredBytes });
|
|
86
|
+
started = true;
|
|
87
|
+
}
|
|
88
|
+
const dir = messagingCacheRoot() + Crypto.randomUUID() + '/';
|
|
89
|
+
active.add(dir);
|
|
90
|
+
try {
|
|
91
|
+
await FS.makeDirectoryAsync(dir, { intermediates: true });
|
|
92
|
+
if (draft)
|
|
93
|
+
await FS.writeAsStringAsync(dir + '__draft__', '');
|
|
94
|
+
return dir;
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
active.delete(dir);
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export async function removeMessagingCacheUri(uri) {
|
|
102
|
+
const root = messagingCacheRoot();
|
|
103
|
+
if (!uri.startsWith(root))
|
|
104
|
+
return;
|
|
105
|
+
const relative = uri.slice(root.length), parts = relative.split('/');
|
|
106
|
+
if (parts.length !== 2 || !owned.test(parts[0]) || !parts[1] || parts[1] === '.' || parts[1] === '..')
|
|
107
|
+
return;
|
|
108
|
+
const dir = root + parts[0] + '/';
|
|
109
|
+
await FS.deleteAsync(dir, { idempotent: true });
|
|
110
|
+
active.delete(dir);
|
|
111
|
+
}
|
package/dist/expo-media.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { allocateMessagingCache, removeMessagingCacheUri } from './expo-cache.js';
|
|
1
2
|
import { MessagingError } from '@robono/messaging';
|
|
2
3
|
import { MessagingMediaAccess } from './media-access.js';
|
|
3
4
|
import { awaitMediaScreening } from './media-screening';
|
|
@@ -7,7 +8,6 @@ import { AudioModule, RecordingPresets, createAudioPlayer, setAudioModeAsync } f
|
|
|
7
8
|
import * as Picker from 'expo-image-picker';
|
|
8
9
|
import * as Documents from 'expo-document-picker';
|
|
9
10
|
import * as FS from 'expo-file-system/legacy';
|
|
10
|
-
import * as Crypto from 'expo-crypto';
|
|
11
11
|
import { defaultAttachmentLimits } from '@robono/messaging';
|
|
12
12
|
let audioOwner = false;
|
|
13
13
|
/** Pass your app's call-state guard and restore mode, or supply your existing audio-session coordinator. */
|
|
@@ -47,25 +47,10 @@ export function createExpoMessagingAudioSession(options = {}) {
|
|
|
47
47
|
}
|
|
48
48
|
function check(signal) { if (signal.aborted)
|
|
49
49
|
throw Error('Cancelled.'); }
|
|
50
|
-
const
|
|
51
|
-
throw Error('Private device storage is unavailable.'); return FS.cacheDirectory + 'robono-messaging/'; };
|
|
52
|
-
const ownedDirectories = new Set();
|
|
53
|
-
async function cacheDirectory() { const dir = cacheRoot() + Crypto.randomUUID() + '/'; await FS.makeDirectoryAsync(dir, { intermediates: true }); ownedDirectories.add(dir); return dir; }
|
|
50
|
+
const cacheDirectory = allocateMessagingCache;
|
|
54
51
|
const cacheName = (name) => name.replace(/[^a-zA-Z0-9._-]/g, '_').slice(-90) || 'Attachment';
|
|
55
|
-
async function cachePath(name) { return (await cacheDirectory()) + cacheName(name); }
|
|
56
|
-
|
|
57
|
-
if (!uri.startsWith(cacheRoot()))
|
|
58
|
-
return;
|
|
59
|
-
const dir = uri.slice(0, uri.lastIndexOf('/') + 1);
|
|
60
|
-
// Each owned directory contains exactly one private copy. Remove it in one
|
|
61
|
-
// native operation rather than making the next open wait for two deletions.
|
|
62
|
-
if (ownedDirectories.has(dir)) {
|
|
63
|
-
await FS.deleteAsync(dir, { idempotent: true });
|
|
64
|
-
ownedDirectories.delete(dir);
|
|
65
|
-
}
|
|
66
|
-
else
|
|
67
|
-
await FS.deleteAsync(uri, { idempotent: true });
|
|
68
|
-
}
|
|
52
|
+
async function cachePath(name, bytes = 0) { return (await cacheDirectory(bytes)) + cacheName(name); }
|
|
53
|
+
const removeUri = removeMessagingCacheUri;
|
|
69
54
|
async function remove(file) { await removeUri(file.uri); }
|
|
70
55
|
async function pickedCopy(uri, fileName, mimeType, durationMs) {
|
|
71
56
|
try {
|
|
@@ -78,7 +63,7 @@ async function pickedCopy(uri, fileName, mimeType, durationMs) {
|
|
|
78
63
|
}
|
|
79
64
|
export async function copyMessagingCache(file) { return copied(file.uri, file.fileName, file.mimeType, file.durationMs); }
|
|
80
65
|
async function copied(uri, fileName, mimeType, durationMs) {
|
|
81
|
-
const target = await
|
|
66
|
+
const target = (await allocateMessagingCache(0, true)) + cacheName(fileName).replace(/^__draft__$/, 'Attachment');
|
|
82
67
|
try {
|
|
83
68
|
await FS.copyAsync({ from: uri, to: target });
|
|
84
69
|
const info = await FS.getInfoAsync(target);
|
|
@@ -397,7 +382,7 @@ export function createExpoMessagingStorage(options) {
|
|
|
397
382
|
throw Error('Invalid attachment preview.');
|
|
398
383
|
check(context.signal);
|
|
399
384
|
access.remember(message, plan.attachmentDownload);
|
|
400
|
-
const path = await cachePath('preview.jpg');
|
|
385
|
+
const path = await cachePath('preview.jpg', media.byteSize);
|
|
401
386
|
try {
|
|
402
387
|
const task = FS.createDownloadResumable(https(plan.url), path, { headers: plan.headers ?? {}, sessionType: FS.FileSystemSessionType.FOREGROUND }, progress => { if (progress.totalBytesWritten > media.byteSize)
|
|
403
388
|
void task.cancelAsync().catch(() => { }); });
|
|
@@ -420,7 +405,7 @@ export function createExpoMessagingStorage(options) {
|
|
|
420
405
|
// authorization, but never start the transfer until both have succeeded.
|
|
421
406
|
const [authorized, prepared] = await Promise.allSettled([
|
|
422
407
|
playbackPlan(message, context.signal, context.reauthorize),
|
|
423
|
-
cacheDirectory(),
|
|
408
|
+
cacheDirectory(message.media?.byteSize ?? 0),
|
|
424
409
|
]);
|
|
425
410
|
const dir = prepared.status === 'fulfilled' ? prepared.value : null;
|
|
426
411
|
let path = null;
|
package/dist/expo-screen.js
CHANGED
|
@@ -142,7 +142,15 @@ function VoicePlayer({ file, audio, design, inline, draft, autoPlay = false }) {
|
|
|
142
142
|
setLoaded(player.isLoaded);
|
|
143
143
|
restorePaused();
|
|
144
144
|
const subscription = player.addListener('playbackStatusUpdate', status => { if (!scope.alive)
|
|
145
|
-
return; setLoaded(status.isLoaded); if (
|
|
145
|
+
return; setLoaded(status.isLoaded); if (status.didJustFinish) {
|
|
146
|
+
playIntent.current = false;
|
|
147
|
+
lastPosition.current = 0;
|
|
148
|
+
setPosition(0);
|
|
149
|
+
setPlaying(false);
|
|
150
|
+
void player.seekTo(0).catch(() => { });
|
|
151
|
+
void releaseVoice(scope);
|
|
152
|
+
return;
|
|
153
|
+
} if ('error' in status && status.error) {
|
|
146
154
|
if (!recoverStream())
|
|
147
155
|
fail(Error('The recording could not be played. Try again.'));
|
|
148
156
|
return;
|
|
@@ -240,13 +248,13 @@ function VoicePlayer({ file, audio, design, inline, draft, autoPlay = false }) {
|
|
|
240
248
|
return _jsx(VoicePlayback, { message: inline?.message, mine: inline?.mine, heard: inline?.heard, onPlayed: inline?.onPlayed, background: inline?.background, ink: inline?.ink ?? c.foreground, accent: inline?.accent ?? c.accent, waveform: inline?.waveform, showWaveform: inline?.showWaveform, footer: inline?.footer, onLongPress: inline?.onLongPress, durationMs: duration, positionMs: position, playing: playing, loading: !!file.stream && !loaded && !error, error: error, onToggle: () => void toggle(), onSeek: ms => { lastPosition.current = Math.max(0, Math.min(duration, ms)); void player.seekTo(lastPosition.current / 1000).catch(() => { if (!recoverStream())
|
|
241
249
|
setError(uiText("Could not seek. Try again.")); }); } });
|
|
242
250
|
}
|
|
243
|
-
function VideoPlayer({ file, audio }) {
|
|
251
|
+
function VideoPlayer({ file, audio, posterUri }) {
|
|
244
252
|
const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
|
|
245
253
|
const mediaReady = useContext(MediaReadiness), recover = useContext(StreamRecovery);
|
|
246
254
|
const source = useMemo(() => file.stream ? { uri: file.uri, headers: file.stream.headers, contentType: 'progressive', useCaching: false } : file.uri, [file]);
|
|
247
255
|
const player = useVideoPlayer(source, p => { p.loop = false; p.audioMixingMode = 'mixWithOthers'; if (file.stream)
|
|
248
256
|
p.bufferOptions = { preferredForwardBufferDuration: 5, minBufferForPlayback: 0.5 }; });
|
|
249
|
-
const [ready, setReady] = useState(false), [error, setError] = useState('');
|
|
257
|
+
const [ready, setReady] = useState(false), [error, setError] = useState(''), [frameReady, setFrameReady] = useState(false);
|
|
250
258
|
const desired = useRef(file.autoPlay ?? true), lastPosition = useRef(file.resumeAtMs ?? 0);
|
|
251
259
|
useEffect(() => {
|
|
252
260
|
let alive = true, recovered = false, audioReady = false, resumed = false, release;
|
|
@@ -313,7 +321,7 @@ function VideoPlayer({ file, audio }) {
|
|
|
313
321
|
}
|
|
314
322
|
catch { } void release?.().catch(() => { }); };
|
|
315
323
|
}, [player, audio]);
|
|
316
|
-
return _jsxs(View, { style: { flex: 1, minHeight: 0 }, children: [_jsx(MessengerVideoView, { testID: "messenger-video-player", onFirstFrameRender: () => mediaReady('video-frame', file.uri), player: player, nativeControls: ready, style: { height: '100%', width: '100%' } }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { position: 'absolute', bottom: 12, left: 12, right: 12, color: '#fff', backgroundColor: '#000c', padding: 12 }, children: error })] });
|
|
324
|
+
return _jsxs(View, { style: { flex: 1, minHeight: 0 }, children: [_jsx(MessengerVideoView, { posterUri: posterUri, testID: "messenger-video-player", onFirstFrameRender: () => { setFrameReady(true); mediaReady('video-frame', file.uri); }, player: player, nativeControls: ready, style: { height: '100%', width: '100%' } }), posterUri && !frameReady && _jsx(View, { pointerEvents: "none", style: { position: 'absolute', width: '100%', height: '100%' }, children: _jsx(Image, { testID: "video-loading-preview", source: { uri: posterUri }, resizeMode: "contain", style: { width: '100%', height: '100%' } }) }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { position: 'absolute', bottom: 12, left: 12, right: 12, color: '#fff', backgroundColor: '#000c', padding: 12 }, children: error })] });
|
|
317
325
|
}
|
|
318
326
|
function FileViewer({ file, kind, audio, design }) {
|
|
319
327
|
const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
|
|
@@ -387,7 +395,7 @@ export function MessagingMediaOverlay({ controller, audio, appearance, inlineVoi
|
|
|
387
395
|
if ((typeof inlineVoice === 'function' ? inlineVoice() : inlineVoice) && state.kind === 'voice' && ['opening', 'viewing', 'failed'].includes(state.phase) && !review)
|
|
388
396
|
return null;
|
|
389
397
|
const actions = !review ? viewerActions?.() : undefined;
|
|
390
|
-
const viewer = (state.file && (review || state.phase === 'viewing') || ['opening', 'failed'].includes(state.phase) && ['image', 'video', 'document'].includes(state.kind)) ? _jsx(MediaViewer, { showDelete: !review && enabled('delete'), showForward: !review && enabled('forward'), loading: state.phase === 'opening', 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, children: !state.file ? null : 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;
|
|
398
|
+
const viewer = (state.file && (review || state.phase === 'viewing') || ['opening', 'failed'].includes(state.phase) && ['image', 'video', 'document'].includes(state.kind)) ? _jsx(MediaViewer, { showDelete: !review && enabled('delete'), showForward: !review && enabled('forward'), loading: state.phase === 'opening', expanded: expanded, onExpandedChange: setExpanded, keepControlsVisible: mediaViewer?.keepControlsVisible ?? appearance.mediaViewer?.keepControlsVisible, status: status, kind: state.kind, previewUri: state.previewUri, 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, children: !state.file ? null : state.kind === 'document' ? _jsx(ExpoDocumentPreview, { file: state.file, onOpenLink: onDocumentLink }) : state.kind === 'video' ? _jsx(VideoPlayer, { posterUri: state.previewUri, 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;
|
|
391
399
|
// Present immediately: an iOS fade can still be dismissing when another attachment
|
|
392
400
|
// opens, leaving the next native modal invisible. Safe area belongs to this window.
|
|
393
401
|
return _jsx(Modal, { transparent: true, visible: state.phase !== 'idle' && state.phase !== 'choosing', onDismiss: onDismiss, animationType: "none", onRequestClose: () => { if (expanded)
|
|
@@ -555,8 +563,8 @@ function ExpoMessagingScreenContent({ storage, audioSession, renderConversation,
|
|
|
555
563
|
return undefined;
|
|
556
564
|
const draft = m.media && m.kind !== 'text' && m.kind !== 'poll' ? await restore(m.media, m.kind) : undefined;
|
|
557
565
|
return draft ? copyMessagingCache(draft) : undefined;
|
|
558
|
-
});
|
|
559
|
-
}, [restore, controller]);
|
|
566
|
+
}, thumbnails.peek(m)?.uri);
|
|
567
|
+
}, [restore, controller, thumbnails]);
|
|
560
568
|
const screenProps = { ...props, requestedMessageAction,
|
|
561
569
|
onQuoteReady: props.onQuoteReady ?? defaultQuoteReady,
|
|
562
570
|
copyText: props.copyText ?? defaultCopyText,
|
package/dist/expo-thumbnails.js
CHANGED
|
@@ -7,6 +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
|
+
const keyFor = (message) => JSON.stringify([message.conversationId, message.media?.assetId, message.revision, message.media]);
|
|
10
11
|
function preview(message, options) {
|
|
11
12
|
const media = message.media;
|
|
12
13
|
if (!media || message.deleted)
|
|
@@ -15,7 +16,7 @@ export function createExpoThumbnails(storage, local, remove) {
|
|
|
15
16
|
return Promise.resolve({ waveform: media.waveform });
|
|
16
17
|
if (!['image', 'video'].includes(message.kind))
|
|
17
18
|
return Promise.resolve({});
|
|
18
|
-
const id = media.assetId, key =
|
|
19
|
+
const id = media.assetId, key = keyFor(message);
|
|
19
20
|
if (options?.refresh)
|
|
20
21
|
cache.invalidate(key);
|
|
21
22
|
return cache.get(key, async (signal) => {
|
|
@@ -57,5 +58,5 @@ export function createExpoThumbnails(storage, local, remove) {
|
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
// Uploaded IDs get their own authorized preview; never alias access between assets.
|
|
60
|
-
return { preview, clear };
|
|
61
|
+
return { preview, clear, peek: (message) => message.deleted ? undefined : cache.peek(keyFor(message)) };
|
|
61
62
|
}
|
package/dist/expo.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ 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
5
|
export type { MessagingDirectoryContact, MessagingDirectoryOptions } from './contact-directory.js';
|
|
6
6
|
export { createExpoBridgeMessenger } from './expo-bridge.js';
|
|
7
|
+
export { configureExpoMessagingCache, maintainExpoMessagingCache, type MessagingDiskCacheLimits, type MessagingCacheMaintenanceResult } from './expo-cache.js';
|
package/dist/expo.js
CHANGED
|
@@ -3,3 +3,4 @@ export { ExpoMessenger, createExpoMessenger, createHostedExpoMessenger } from '.
|
|
|
3
3
|
export { MessagingPopup } from './popup.js';
|
|
4
4
|
export { MessagingConnectionState, MessagingSignIn, MessagingPhoneInput, MessagingChoicePicker } from './sign-in.js';
|
|
5
5
|
export { createExpoBridgeMessenger } from './expo-bridge.js';
|
|
6
|
+
export { configureExpoMessagingCache, maintainExpoMessagingCache } from './expo-cache.js';
|
package/dist/index.js
CHANGED
|
@@ -522,18 +522,21 @@ const MessagingBubbleView = React.memo(function MessagingBubbleView({ message, p
|
|
|
522
522
|
const showingTransform = !!transformed && !showOriginal && (transformed.kind === 'transcript' || canTranslate);
|
|
523
523
|
const languageActions = (canTranscript || canTranslate || transformed) && _jsxs(View, { testID: "message-language-actions", style: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: voice && !showingTransform ? 'flex-end' : 'flex-start', columnGap: 8, rowGap: 0 }, children: [transforming && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Cancel"), onPress: () => { transformAbort.current?.abort(); transformGeneration.current++; setTransforming(false); }, hitSlop: 8, children: _jsx(Text, { style: { color: c.accent, fontSize: 11, lineHeight: 15 }, children: uiText("Cancel") }) }), transformed && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: showOriginal ? (transformed.kind === 'transcript' ? 'Show transcript' : 'Show translation') : uiText("Show original"), onPress: () => { setTranslationAutoPlay(false); setShowOriginal(v => !v); }, hitSlop: 8, style: { minHeight: 17, paddingVertical: 1, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 11, lineHeight: 15 }, children: showOriginal ? (transformed.kind === 'transcript' ? 'Show transcript' : 'Show translation') : uiText("Show original") }) }), canTranscript && !transformed && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Read transcript"), disabled: transforming, onPress: () => void transform('transcript'), hitSlop: 8, style: { minHeight: 17, paddingVertical: 1, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 11, lineHeight: 15 }, children: transforming ? uiText("Transcribing…") : uiText("Transcript") }) }), canTranslate && transformed?.kind !== 'translation' && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: translation.mode === 'voice' && languageTools?.voiceOutput !== false ? uiText("Play translation") : uiText("Translate message"), disabled: transforming, onPress: () => void transform('translation', translation.mode === 'voice' && languageTools?.voiceOutput !== false ? 'voice' : 'text'), hitSlop: 8, style: { minHeight: 17, paddingVertical: 1, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 11, lineHeight: 15 }, children: translation.mode === 'voice' && languageTools?.voiceOutput !== false ? uiText("Play Translation") : uiText("Translate") }) })] });
|
|
524
524
|
const fallbackContent = _jsx(View, { testID: "message-original-text", children: _jsx(Text, { selectable: true, style: { color: ink, fontSize: 16, lineHeight: 22 }, children: renderText(message.text ?? '') }) });
|
|
525
|
-
const originalContent = message.custom && !message.deleted ? _jsxs(Pressable, { onLongPress: menu, children: [_jsx(CustomMessage, { message: message, mine: mine, appearance: design, pendingStatus: pendingStatus, components: components, enabled: canInteract, children: fallbackContent }), pendingStatus && footer] }) : extra?.weather || extra?.call ? extraCard : message.kind === 'poll' ? _jsx(PollMessage, { onLongPress: menu, message: message, userId: userId, ink: ink, accent: c.accent, background: c.background, foreground: c.foreground, resolveVoterName: id => id === userId ? 'You' : participants?.[id]?.name ?? (state.conversation?.kind === 'direct' ? contextContactName : 'Chat member'), enabled: canInteract && !!state.settings?.features.poll, onVote: options => client.vote(message.id, options), onClose: () => client.closePoll(message.id) }) : message.kind === 'text' ? _jsxs(View, { testID: "message-original-text", children: [_jsx(Text, { selectable: true, style: { color: ink, fontSize: bigEmoji ? 48 : 16, lineHeight: bigEmoji ? 58 : 22 }, children: renderText(message.text ?? '') }), pendingStatus && footer] }) : _jsx(MediaContent, { message: message, ink: ink, accent: c.accent, footer: voice ? languageActions : undefined, onOpen: () => void open(), onLongPress: menu });
|
|
526
|
-
const content = showingTransform ? _jsxs(View, { children: [_jsx(Text, { style: { color: ink, fontSize: 11, opacity: .65, marginBottom: 2 }, children: transformed.kind === 'transcript' ? uiText("Transcript") : 'Translated · ' + supportedLanguageLabel(translationLanguage) }), transformed.audio && TranslationVoice ? _jsx(View, { testID: "message-translated-voice", children: _jsx(TranslationVoice, { transform: transformed, ink: ink, accent: c.accent, showWaveform: design.showWaveform !== false, autoPlay: translationAutoPlay }) }) : _jsx(Text, { testID: "message-language-result", selectable: true, style: { color: ink, fontSize: 16, lineHeight: 22 }, children: transformed.text }), !voice && footer] }) : originalContent;
|
|
525
|
+
const originalContent = message.custom && !message.deleted ? _jsxs(Pressable, { onLongPress: menu, children: [_jsx(CustomMessage, { message: message, mine: mine, appearance: design, pendingStatus: pendingStatus, components: components, enabled: canInteract, children: fallbackContent }), pendingStatus && footer] }) : extra?.weather || extra?.call ? extraCard : message.kind === 'poll' ? _jsx(PollMessage, { onLongPress: menu, message: message, userId: userId, ink: ink, accent: c.accent, background: c.background, foreground: c.foreground, resolveVoterName: id => id === userId ? 'You' : participants?.[id]?.name ?? (state.conversation?.kind === 'direct' ? contextContactName : 'Chat member'), enabled: canInteract && !!state.settings?.features.poll, onVote: options => client.vote(message.id, options), onClose: () => client.closePoll(message.id) }) : message.kind === 'text' ? _jsxs(View, { testID: "message-original-text", children: [_jsx(Text, { selectable: true, style: { color: ink, fontSize: bigEmoji ? 48 : 16, lineHeight: bigEmoji ? 58 : 22, textAlign: mine ? 'right' : 'left' }, children: renderText(message.text ?? '') }), pendingStatus && footer] }) : _jsx(MediaContent, { message: message, ink: ink, accent: c.accent, footer: voice ? languageActions : undefined, onOpen: () => void open(), onLongPress: menu });
|
|
526
|
+
const content = showingTransform ? _jsxs(View, { children: [_jsx(Text, { style: { color: ink, fontSize: 11, opacity: .65, marginBottom: 2 }, children: transformed.kind === 'transcript' ? uiText("Transcript") : 'Translated · ' + supportedLanguageLabel(translationLanguage) }), transformed.audio && TranslationVoice ? _jsx(View, { testID: "message-translated-voice", children: _jsx(TranslationVoice, { transform: transformed, ink: ink, accent: c.accent, showWaveform: design.showWaveform !== false, autoPlay: translationAutoPlay }) }) : _jsx(Text, { testID: "message-language-result", selectable: true, style: { color: ink, fontSize: 16, lineHeight: 22, textAlign: mine ? 'right' : 'left' }, children: transformed.text }), !voice && footer] }) : originalContent;
|
|
527
527
|
const regionProps = { message, mine, appearance: design, pendingStatus };
|
|
528
528
|
const bodyContent = components?.MessageBody && !message.deleted ? _jsx(components.MessageBody, { ...regionProps, children: content }) : content;
|
|
529
|
-
const
|
|
529
|
+
const statusTopRadius = voice && !showingTransform ? 24 : bubbleRadius, statusBottomRadius = voice && !message.text && !showingTransform ? 24 : bubbleRadius;
|
|
530
|
+
// Trim the arc ends without moving the indicator away from the bubble's contour.
|
|
531
|
+
const statusTopTrim = statusTopRadius / 2, statusBottomTrim = statusBottomRadius / 2;
|
|
532
|
+
const bubbleBody = _jsxs(_Fragment, { children: [!bigEmoji && (!mine || !deliveryStatus) && _jsx(View, { testID: mine ? (message.readAt && state.settings?.features.readReceipts ? 'message-status-read' : 'message-status-sent') : 'message-status-incoming', pointerEvents: "none", accessible: false, style: { position: 'absolute', top: joinsBefore ? -(messageGap + 2) / 2 : statusTopTrim, bottom: joinsAfter ? -(messageGap + 2) / 2 : statusBottomTrim, start: 0, end: 0, zIndex: 40, overflow: 'hidden' }, children: _jsx(View, { style: { position: 'absolute', top: joinsBefore ? 0 : -statusTopTrim, bottom: joinsAfter ? 0 : -statusBottomTrim, start: 0, end: 0, ...(mine ? { borderEndWidth: 2, borderEndColor: message.readAt && state.settings?.features.readReceipts ? c.accent : c.foreground, borderTopEndRadius: joinsBefore ? 0 : statusTopRadius, borderBottomEndRadius: joinsAfter ? 0 : statusBottomRadius } : { borderStartWidth: 2, borderStartColor: '#2B2B2B', borderTopStartRadius: joinsBefore ? 0 : statusTopRadius, borderBottomStartRadius: joinsAfter ? 0 : statusBottomRadius }) } }) }), message.replyTo && message.replyTo !== discussionRoot && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Go to quoted message"), onLongPress: menu, onPress: () => { void client.focusMessage(message.replyTo).catch(e => setError(e instanceof Error ? e.message : uiText("This message is unavailable."))); }, style: { alignSelf: 'flex-start', maxWidth: 220, minHeight: 44, borderRadius: 10, backgroundColor: chatSurface(c.background) === '#ffffff' ? '#f3f3f3' : '#242424', borderWidth: StyleSheet.hairlineWidth, borderColor: c.secondary + '55', paddingHorizontal: 8, paddingTop: 6, paddingBottom: 7, marginBottom: 4, overflow: 'hidden' }, children: _jsx(QuotedPreview, { message: ui.quoted, ink: c.foreground }) }), !mine && !grouped && state.conversation?.kind === 'group' && _jsx(Text, { style: { color: ink, fontSize: 12, fontWeight: '600', marginBottom: 5 }, children: message.deleted ? uiText("Former member") : participants?.[message.senderId]?.name ?? uiText("Member") }), message.custom || extra?.address || extra?.weather || extra?.call || voice || message.kind === 'poll' ? bodyContent : _jsx(Pressable, { accessibilityRole: message.kind === 'text' ? undefined : 'button', accessibilityLabel: message.kind === 'text' ? undefined : uiText('{kind}: {name}', { kind: uiText(mediaNames[message.kind]), name: message.media?.fileName ?? uiText('Open attachment') }), disabled: busy, onLongPress: menu, onPress: message.kind === 'text' ? () => { if (quoteGesture.suppressPress())
|
|
530
533
|
return; if (extra?.address)
|
|
531
534
|
extraRef.current?.open();
|
|
532
535
|
else
|
|
533
|
-
socialRef.current?.open(); } : () => void open(), children: bodyContent }), !discussionPreview && state.discussionAvailable && !!message.replyCount && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: message.replyCount + ' ' + (message.replyCount === 1 ? 'reply' : 'replies'), onPress: () => openDiscussion(message.id), style: { minHeight: 32, justifyContent: 'center' }, children: _jsxs(Text, { style: { color: c.accent, fontSize: 12, fontWeight: '600' }, children: [message.replyCount, " ", message.replyCount === 1 ? uiText("reply") : uiText("replies")] }) }), message.kind !== 'text' && !!message.text && _jsx(Text, { testID: "attachment-caption", selectable: true, onLongPress: menu, style: { color: ink, fontSize: 16, lineHeight: 22, marginTop: 2, textAlign: 'right', alignSelf: 'stretch', paddingHorizontal: voice || message.kind === 'document' ? 8 : 2, paddingBottom: 2 }, children: renderText(message.text) }), deliveryStatus && message.kind !== 'text' && message.kind !== 'poll' && !voice && !visual && _jsx(View, { style: { marginTop: 4, alignSelf: 'flex-end' }, children: footer }), (!voice || showingTransform) && languageActions, components?.MessageFooter && !message.deleted && _jsx(components.MessageFooter, { ...regionProps }), transforming && !voice && _jsx(Text, { accessibilityLiveRegion: "polite", style: { color: ink, fontSize: 11 }, children: uiText("Converting…") }), !!error && _jsxs(MessagingPopup, { screen: "alerts", compact: true, contentWidth: 640, title: uiText("Message"), foreground: c.foreground, background: chatSurface(c.background), onClose: () => setError(''), children: [_jsx(Text, { accessibilityRole: "alert", style: { color: messagingPopupColors.foreground, fontSize: 15, lineHeight: 21, marginTop: 8 }, children: error }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Close message alert"), onPress: () => setError(''), style: { alignSelf: 'flex-end', minHeight: 44, justifyContent: 'center', paddingHorizontal: 8, marginTop: 8 }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("OK") }) })] }), deliveryStatus === 'failed' && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Retry sending message"), onPress: () => void client.retry(message.clientMessageId).catch(() => { }), style: { minHeight: 32, justifyContent: 'center', alignSelf: 'flex-end' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 12 }, children: design.labels.retry }) }), Platform.OS === 'web' && !mine && canInteract && state.settings?.features.reactions && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("React to message"), onFocus: () => setHovered(true), onBlur: () => setHovered(false), onPress: openMenu, style: { opacity: hovered || actions ? 1 : 0, position: 'absolute', top: 6, ...(mine ? { left: -34 } : { right: -34 }), width: 32, height: 32, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "reaction", color: c.secondary, size: 20 }) }), !!message.reactions?.length && _jsx(View, { testID: "message-reaction-badge", pointerEvents: "none", accessibilityLabel: message.reactions.slice(-3).map(r => r.emoji).join(' '), style: { position: 'absolute', zIndex: 41, top: -16, ...(mine ? { end: -9 } : { start: -9 }), minWidth: 30, height: 20, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { fontSize: 16, lineHeight: 20 }, children: message.reactions.slice(-3).map(r => r.emoji).join(' ') }) }), _jsx(MessageMenu, { visible: actions, position: menuPosition, screenHeight: viewport.height, mine: mine, reactions: reactionPicker, onClose: () => setActions(false), onDismiss: menuDismissed, children: actions && _jsxs(_Fragment, { children: [quoting && _jsx(MessageMenuRow, { icon: "quote", label: uiText("Quote message"), onPress: () => { setActions(false); setReply(message); } }), !discussionPreview && state.discussionAvailable && !pendingStatus && !message.deleted && _jsx(MessageMenuRow, { icon: "quote", label: uiText("Replies"), onPress: () => leaveMenu(() => openDiscussion(message.threadRoot ?? message.id)) }), state.discussionAvailable && canInteract && state.conversation?.ownerId === userId && _jsx(MessageMenuRow, { icon: "bookmark", label: message.pinned ? uiText("Unpin for group") : uiText("Pin for group"), onPress: () => { setActions(false); void client.pinMessage(message.id, !message.pinned).catch(e => setError(e instanceof Error ? e.message : uiText("The pin could not change."))); } }), canCopy && _jsx(MessageMenuRow, { icon: "copy", label: uiText("Copy"), onPress: () => { setActions(false); void (copyText ? copyText(message.text) : navigator.clipboard.writeText(message.text)).catch(() => setError(uiText("The text could not be copied."))); } }), canInteract && client.canForward(message) && _jsx(MessageMenuRow, { icon: "redo", label: uiText("Forward"), onPress: () => leaveMenu(() => setForwarding([message])) }), !pendingStatus && !message.deleted && message.kind !== 'poll' && client.hasSavedMessages() && _jsx(MessageMenuRow, { icon: "bookmark", label: saved.some(r => r.key === savedMessageKey(message)) ? uiText("Remove from Saved") : uiText("Save"), disabled: saving, onPress: () => { setActions(false); void toggleSaved(message); } }), canChange && !message.custom && message.kind !== 'poll' && state.settings?.features[message.kind] && _jsx(MessageMenuRow, { icon: "edit", label: uiText("Edit"), onPress: () => { setActions(false); setEditing(message); } }), !mine && state.conversation?.safety?.canReport && _jsx(MessageMenuRow, { icon: "flag", label: uiText("Report"), danger: true, onPress: () => leaveMenu(() => setReportOpen(true)) }), !pendingStatus && !message.deleted && ['owner', 'moderator'].includes(state.conversation?.roomRole ?? '') && _jsx(MessageMenuRow, { icon: "trash", label: uiText('Remove from group'), danger: true, onPress: () => leaveMenu(() => setRoomRemoval(true)) }), canChange && _jsx(MessageMenuRow, { icon: "trash", label: uiText("Delete"), danger: true, onPress: () => leaveMenu(() => setDeleting([message])) }), (pendingStatus === 'failed' || pendingStatus === 'queued') && _jsx(MessageMenuRow, { icon: "trash", label: uiText("Remove unsent message"), danger: true, onPress: () => { setActions(false); void client.discardPending(message.clientMessageId).catch(() => setError(uiText("The unsent message could not be removed."))); } }), !pendingStatus && onMessageOptions && _jsx(MessageMenuRow, { icon: "more", label: uiText("More options"), onPress: () => leaveMenu(() => onMessageOptions(message)) }), !pendingStatus && !message.deleted && _jsx(MessageMenuRow, { icon: "check", label: uiText("Select Multiple"), divider: true, onPress: () => { setActions(false); setSelection([message]); Keyboard.dismiss(); } })] }) }), roomRemoval && _jsx(MessagingRoomRemoval, { client: client, message: message, accent: c.accent, onClose: () => setRoomRemoval(false) }), reportOpen && _jsx(MessagingSafety, { client: client, state: state, appearance: design, name: participants?.[message.senderId]?.name ?? 'Contact', messageId: message.id, onClose: () => setReportOpen(false) })] });
|
|
536
|
+
socialRef.current?.open(); } : () => void open(), children: bodyContent }), !discussionPreview && state.discussionAvailable && !!message.replyCount && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: message.replyCount + ' ' + (message.replyCount === 1 ? 'reply' : 'replies'), onPress: () => openDiscussion(message.id), style: { minHeight: 32, justifyContent: 'center' }, children: _jsxs(Text, { style: { color: c.accent, fontSize: 12, fontWeight: '600' }, children: [message.replyCount, " ", message.replyCount === 1 ? uiText("reply") : uiText("replies")] }) }), message.kind !== 'text' && !!message.text && _jsx(View, { testID: voice ? 'voice-message-caption' : undefined, style: voice && !showingTransform ? { maxWidth: 220, alignSelf: mine ? 'flex-end' : 'flex-start', marginTop: 1, paddingTop: 4, paddingBottom: 1, borderRadius: 14, ...(mine ? { borderBottomEndRadius: 3 } : { borderBottomStartRadius: 3 }), backgroundColor: mine ? c.outgoing : c.incoming } : undefined, children: _jsx(Text, { testID: "attachment-caption", selectable: true, onLongPress: menu, style: { color: ink, fontSize: 16, lineHeight: 22, marginTop: voice ? 0 : 2, textAlign: mine ? 'right' : 'left', alignSelf: 'stretch', paddingHorizontal: voice || message.kind === 'document' ? 8 : 2, paddingBottom: 2 }, children: renderText(message.text) }) }), deliveryStatus && message.kind !== 'text' && message.kind !== 'poll' && !voice && !visual && _jsx(View, { style: { marginTop: 4, alignSelf: 'flex-end' }, children: footer }), (!voice || showingTransform) && languageActions, components?.MessageFooter && !message.deleted && _jsx(components.MessageFooter, { ...regionProps }), transforming && !voice && _jsx(Text, { accessibilityLiveRegion: "polite", style: { color: ink, fontSize: 11 }, children: uiText("Converting…") }), !!error && _jsxs(MessagingPopup, { screen: "alerts", compact: true, contentWidth: 640, title: uiText("Message"), foreground: c.foreground, background: chatSurface(c.background), onClose: () => setError(''), children: [_jsx(Text, { accessibilityRole: "alert", style: { color: messagingPopupColors.foreground, fontSize: 15, lineHeight: 21, marginTop: 8 }, children: error }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Close message alert"), onPress: () => setError(''), style: { alignSelf: 'flex-end', minHeight: 44, justifyContent: 'center', paddingHorizontal: 8, marginTop: 8 }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("OK") }) })] }), deliveryStatus === 'failed' && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Retry sending message"), onPress: () => void client.retry(message.clientMessageId).catch(() => { }), style: { minHeight: 32, justifyContent: 'center', alignSelf: 'flex-end' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 12 }, children: design.labels.retry }) }), Platform.OS === 'web' && !mine && canInteract && state.settings?.features.reactions && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("React to message"), onFocus: () => setHovered(true), onBlur: () => setHovered(false), onPress: openMenu, style: { opacity: hovered || actions ? 1 : 0, position: 'absolute', top: 6, ...(mine ? { left: -34 } : { right: -34 }), width: 32, height: 32, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "reaction", color: c.secondary, size: 20 }) }), !!message.reactions?.length && _jsx(View, { testID: "message-reaction-badge", pointerEvents: "none", accessibilityLabel: message.reactions.slice(-3).map(r => r.emoji).join(' '), style: { position: 'absolute', zIndex: 41, top: -16, ...(mine ? { end: -9 } : { start: -9 }), minWidth: 30, height: 20, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { fontSize: 16, lineHeight: 20 }, children: message.reactions.slice(-3).map(r => r.emoji).join(' ') }) }), _jsx(MessageMenu, { visible: actions, position: menuPosition, screenHeight: viewport.height, mine: mine, reactions: reactionPicker, onClose: () => setActions(false), onDismiss: menuDismissed, children: actions && _jsxs(_Fragment, { children: [quoting && _jsx(MessageMenuRow, { icon: "quote", label: uiText("Quote message"), onPress: () => { setActions(false); setReply(message); } }), !discussionPreview && state.discussionAvailable && !pendingStatus && !message.deleted && _jsx(MessageMenuRow, { icon: "quote", label: uiText("Replies"), onPress: () => leaveMenu(() => openDiscussion(message.threadRoot ?? message.id)) }), state.discussionAvailable && canInteract && state.conversation?.ownerId === userId && _jsx(MessageMenuRow, { icon: "bookmark", label: message.pinned ? uiText("Unpin for group") : uiText("Pin for group"), onPress: () => { setActions(false); void client.pinMessage(message.id, !message.pinned).catch(e => setError(e instanceof Error ? e.message : uiText("The pin could not change."))); } }), canCopy && _jsx(MessageMenuRow, { icon: "copy", label: uiText("Copy"), onPress: () => { setActions(false); void (copyText ? copyText(message.text) : navigator.clipboard.writeText(message.text)).catch(() => setError(uiText("The text could not be copied."))); } }), canInteract && client.canForward(message) && _jsx(MessageMenuRow, { icon: "redo", label: uiText("Forward"), onPress: () => leaveMenu(() => setForwarding([message])) }), !pendingStatus && !message.deleted && message.kind !== 'poll' && client.hasSavedMessages() && _jsx(MessageMenuRow, { icon: "bookmark", label: saved.some(r => r.key === savedMessageKey(message)) ? uiText("Remove from Saved") : uiText("Save"), disabled: saving, onPress: () => { setActions(false); void toggleSaved(message); } }), canChange && !message.custom && message.kind !== 'poll' && state.settings?.features[message.kind] && _jsx(MessageMenuRow, { icon: "edit", label: uiText("Edit"), onPress: () => { setActions(false); setEditing(message); } }), !mine && state.conversation?.safety?.canReport && _jsx(MessageMenuRow, { icon: "flag", label: uiText("Report"), danger: true, onPress: () => leaveMenu(() => setReportOpen(true)) }), !pendingStatus && !message.deleted && ['owner', 'moderator'].includes(state.conversation?.roomRole ?? '') && _jsx(MessageMenuRow, { icon: "trash", label: uiText('Remove from group'), danger: true, onPress: () => leaveMenu(() => setRoomRemoval(true)) }), canChange && _jsx(MessageMenuRow, { icon: "trash", label: uiText("Delete"), danger: true, onPress: () => leaveMenu(() => setDeleting([message])) }), (pendingStatus === 'failed' || pendingStatus === 'queued') && _jsx(MessageMenuRow, { icon: "trash", label: uiText("Remove unsent message"), danger: true, onPress: () => { setActions(false); void client.discardPending(message.clientMessageId).catch(() => setError(uiText("The unsent message could not be removed."))); } }), !pendingStatus && onMessageOptions && _jsx(MessageMenuRow, { icon: "more", label: uiText("More options"), onPress: () => leaveMenu(() => onMessageOptions(message)) }), !pendingStatus && !message.deleted && _jsx(MessageMenuRow, { icon: "check", label: uiText("Select Multiple"), divider: true, onPress: () => { setActions(false); setSelection([message]); Keyboard.dismiss(); } })] }) }), roomRemoval && _jsx(MessagingRoomRemoval, { client: client, message: message, accent: c.accent, onClose: () => setRoomRemoval(false) }), reportOpen && _jsx(MessagingSafety, { client: client, state: state, appearance: design, name: participants?.[message.senderId]?.name ?? 'Contact', messageId: message.id, onClose: () => setReportOpen(false) })] });
|
|
534
537
|
return _jsxs(View, { ...(Platform.OS === 'web' ? { onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), onContextMenu: (event) => { event.preventDefault(); menu(); } } : {}), style: { width: '100%', position: 'relative', marginTop: messageGap + (message.reactions?.length ? 16 : 0), marginBottom: 0 }, children: [quoteGesture.infoLoaded && _jsxs(Animated.View, { pointerEvents: "none", testID: "message-info-reveal", accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: { ...quoteGesture.revealWebStyle, position: 'absolute', top: '50%', marginTop: -26, minHeight: 52, width: messageInfoRevealWidth, justifyContent: 'center', ...(mine ? { start: 0, alignItems: 'flex-start' } : { end: 0, alignItems: 'flex-end' }), opacity: quoteGesture.infoOpacity }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'baseline', gap: 4 }, children: [_jsx(Text, { style: { color: c.secondary, fontSize: 8, lineHeight: 11, fontWeight: '900' }, children: uiText("SENT:") }), _jsx(Text, { style: { color: c.foreground, fontSize: 10, lineHeight: 12, fontWeight: '800' }, children: messageTimeLabel(message, ui.formatMessageTime, uiText) })] }), mine && state.settings?.features.readReceipts && _jsxs(View, { style: { flexDirection: 'row', alignItems: 'baseline', gap: 4 }, children: [_jsx(Text, { style: { color: c.secondary, fontSize: 8, lineHeight: 11, fontWeight: '900' }, children: uiText("READ:") }), _jsx(Text, { style: { color: message.readAt ? c.foreground : c.secondary, fontSize: 10, lineHeight: 12, fontWeight: '800' }, children: message.readAt ? ui.formatMessageTime(message.readAt) : uiText("Not yet") })] })] }), quoting && _jsxs(Animated.View, { pointerEvents: "none", ...(Platform.OS === 'web' ? { 'aria-hidden': true } : { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' }), testID: `quote-reveal-${mine ? 'outgoing' : 'incoming'}`, style: { ...quoteGesture.revealWebStyle, position: 'absolute', top: '50%', marginTop: -26, ...(mine ? { end: 0 } : { start: 0 }), width: messageReplyRevealWidth, minHeight: 52, gap: 3, alignItems: 'center', justifyContent: 'center', opacity: quoteGesture.revealOpacity }, children: [_jsx(View, { style: { width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center', backgroundColor: chatSurface(c.background), borderWidth: 1.5, borderColor: c.secondary + '40' }, children: _jsx(MessageIcon, { name: "quote", color: c.accent, size: 30 }) }), _jsx(Text, { style: { color: c.secondary, fontSize: 10, fontWeight: '900' }, children: uiText("QUOTE MESSAGE") })] }), _jsx(Animated.View, { ref: node => { anchor.current = node; if (quoteGesture.webRef)
|
|
535
538
|
quoteGesture.webRef.current = node; }, ...quoteGesture.handlers, accessibilityActions: quoting ? [{ name: "quote", label: uiText("Quote message") }] : undefined, onAccessibilityAction: event => { if (quoting && event.nativeEvent.actionName === "quote")
|
|
536
|
-
setReply(message); }, testID: `message-${message.kind}-${mine ? 'outgoing' : 'incoming'}`, style: { ...quoteGesture.webStyle, transform: [{ translateX: quoteGesture.offset }], ...(Platform.OS === "web" && !pendingStatus ? { touchAction: "pan-y", userSelect: "none" } : {}), alignSelf: mine ? 'flex-end' : 'flex-start', maxWidth: `${design.screens?.chat?.messageWidth ?? 88}%`, backgroundColor: mine ? c.outgoing : c.incoming, borderRadius: bubbleRadius, padding: visual ? 3 : 6, paddingBottom: visual || canTranscript || canTranslate ? 3 : 6, boxShadow: bigEmoji ? undefined : '0 1px 1px #00000010', ...((voice || message.kind === 'document') && !showingTransform ? { padding: 0, paddingBottom: 0, boxShadow: undefined, ...(
|
|
539
|
+
setReply(message); }, testID: `message-${message.kind}-${mine ? 'outgoing' : 'incoming'}`, style: { ...quoteGesture.webStyle, transform: [{ translateX: quoteGesture.offset }], ...(Platform.OS === "web" && !pendingStatus ? { touchAction: "pan-y", userSelect: "none" } : {}), alignSelf: mine ? 'flex-end' : 'flex-start', maxWidth: `${design.screens?.chat?.messageWidth ?? 88}%`, backgroundColor: mine ? c.outgoing : c.incoming, borderRadius: bubbleRadius, padding: visual ? 3 : 6, paddingBottom: visual || canTranscript || canTranslate ? 3 : 6, boxShadow: bigEmoji ? undefined : '0 1px 1px #00000010', ...((voice || message.kind === 'document') && !showingTransform ? { padding: 0, paddingBottom: 0, boxShadow: undefined, ...(voice ? { backgroundColor: 'transparent' } : {}) } : {}), ...(message.kind === 'poll' ? { backgroundColor: chatSurface(c.background), borderWidth: 1, borderColor: c.accent + '60', paddingHorizontal: 8, paddingTop: 4, paddingBottom: 2 } : {}), ...(bigEmoji ? { backgroundColor: 'transparent', paddingHorizontal: 4, paddingTop: 0, paddingBottom: 0 } : {}), ...(extra?.address || socialReady ? { flexDirection: mine ? 'row-reverse' : 'row', alignItems: 'center', gap: 8, padding: 0, paddingBottom: 0, backgroundColor: 'transparent', boxShadow: undefined } : {}) }, children: extra?.address ? extraCard : socialReady ? socialCard : bubbleBody })] });
|
|
537
540
|
});
|
|
538
541
|
export function MessageDeletion({ messages, onClose }) {
|
|
539
542
|
const messagingPopupColors = useMessagingPopupColors(undefined, 'alerts');
|
|
@@ -48,6 +48,7 @@ export interface MessagingMediaDevice {
|
|
|
48
48
|
}
|
|
49
49
|
export interface MessagingMediaState {
|
|
50
50
|
phase: 'idle' | 'choosing' | 'preparing' | 'recording' | 'review' | 'uploading' | 'opening' | 'viewing' | 'failed';
|
|
51
|
+
previewUri?: string;
|
|
51
52
|
kind: MediaKind;
|
|
52
53
|
file: LocalMessagingMedia | null;
|
|
53
54
|
elapsedMs: number;
|
|
@@ -110,7 +111,7 @@ export declare class MessagingMediaController {
|
|
|
110
111
|
send(): Promise<void>;
|
|
111
112
|
/** View an owned cache copy of a draft. Closing never removes the original draft. */
|
|
112
113
|
previewLocal(file: LocalMessagingMedia, kind: MediaKind, message?: MessagingMessage): Promise<void>;
|
|
113
|
-
open(message: MessagingMessage, local?: () => Promise<LocalMessagingMedia | undefined
|
|
114
|
+
open(message: MessagingMessage, local?: () => Promise<LocalMessagingMedia | undefined>, previewUri?: string): Promise<void>;
|
|
114
115
|
/** Save/share a local copy of a playing stream without replacing its playback source. */
|
|
115
116
|
exportFile<T>(save: (file: LocalMessagingMedia, context: {
|
|
116
117
|
message: MessagingMessage | null;
|
package/dist/media-controller.js
CHANGED
|
@@ -154,7 +154,7 @@ export class MessagingMediaController {
|
|
|
154
154
|
this.resolve = null;
|
|
155
155
|
this.uploadId = '';
|
|
156
156
|
this.abort = null;
|
|
157
|
-
this.update({ phase: 'idle', file: null, error: null });
|
|
157
|
+
this.update({ phase: 'idle', previewUri: undefined, file: null, error: null });
|
|
158
158
|
resolve?.(media);
|
|
159
159
|
}
|
|
160
160
|
else if (selectionIntent === 'send' && !source)
|
|
@@ -265,7 +265,7 @@ export class MessagingMediaController {
|
|
|
265
265
|
this.resolve = null;
|
|
266
266
|
this.uploadId = '';
|
|
267
267
|
this.abort = null;
|
|
268
|
-
this.update({ phase: 'idle', file: null, error: null });
|
|
268
|
+
this.update({ phase: 'idle', previewUri: undefined, file: null, error: null });
|
|
269
269
|
resolve?.(media);
|
|
270
270
|
return;
|
|
271
271
|
}
|
|
@@ -288,7 +288,7 @@ export class MessagingMediaController {
|
|
|
288
288
|
this.abort = null;
|
|
289
289
|
if (this.stageRecording)
|
|
290
290
|
this.prepared.set(media.assetId, file);
|
|
291
|
-
this.update({ phase: 'idle', file: null, error: null });
|
|
291
|
+
this.update({ phase: 'idle', previewUri: undefined, file: null, error: null });
|
|
292
292
|
resolve?.(media);
|
|
293
293
|
if (!this.stageRecording)
|
|
294
294
|
await this.options.device.remove(file).catch(() => { });
|
|
@@ -311,7 +311,7 @@ export class MessagingMediaController {
|
|
|
311
311
|
this.abort = new AbortController();
|
|
312
312
|
this.update({ phase: 'viewing', kind, file, error: null, progress: 0 });
|
|
313
313
|
}
|
|
314
|
-
open(message, local) { return this.openMedia(message, undefined, local); }
|
|
314
|
+
open(message, local, previewUri) { return this.openMedia(message, undefined, local, previewUri); }
|
|
315
315
|
/** Save/share a local copy of a playing stream without replacing its playback source. */
|
|
316
316
|
async exportFile(save, options = {}) {
|
|
317
317
|
const file = this.state.file, generation = this.generation, message = this.openedMessage, conversationId = this.conversationId;
|
|
@@ -341,9 +341,9 @@ export class MessagingMediaController {
|
|
|
341
341
|
fallbackStream(uri, positionMs, autoPlay) {
|
|
342
342
|
if (!this.state.file?.stream || this.state.file.uri !== uri || !this.openedMessage)
|
|
343
343
|
return Promise.resolve();
|
|
344
|
-
return this.openMedia({ ...this.openedMessage, attachmentDownload: undefined }, { download: true, positionMs, autoPlay });
|
|
344
|
+
return this.openMedia({ ...this.openedMessage, attachmentDownload: undefined }, { download: true, positionMs, autoPlay }, undefined, this.state.previewUri);
|
|
345
345
|
}
|
|
346
|
-
async openMedia(message, recovery, local) {
|
|
346
|
+
async openMedia(message, recovery, local, previewUri) {
|
|
347
347
|
const intent = ++this.intent;
|
|
348
348
|
await this.closeCurrent();
|
|
349
349
|
if (intent !== this.intent)
|
|
@@ -355,7 +355,7 @@ export class MessagingMediaController {
|
|
|
355
355
|
const g = ++this.generation, abort = this.abort = new AbortController();
|
|
356
356
|
this.conversationId = message.conversationId;
|
|
357
357
|
this.openedMessage = message;
|
|
358
|
-
this.update({ phase: 'opening', kind: message.kind, file: null, error: null, progress: 0 });
|
|
358
|
+
this.update({ phase: 'opening', previewUri, kind: message.kind, file: null, error: null, progress: 0 });
|
|
359
359
|
try {
|
|
360
360
|
const context = { signal: abort.signal, onProgress: f => { if (this.isCurrent(g))
|
|
361
361
|
this.update({ progress: Math.max(0, Math.min(1, f)) }); } };
|
|
@@ -397,7 +397,7 @@ export class MessagingMediaController {
|
|
|
397
397
|
this.uploadId = '';
|
|
398
398
|
clearInterval(this.timer);
|
|
399
399
|
this.timer = undefined;
|
|
400
|
-
this.update({ phase: 'idle', file: null, error: null });
|
|
400
|
+
this.update({ phase: 'idle', previewUri: undefined, file: null, error: null });
|
|
401
401
|
resolve?.(null);
|
|
402
402
|
const work = (async () => {
|
|
403
403
|
if (stopping)
|
package/dist/media-ui.d.ts
CHANGED
|
@@ -44,13 +44,14 @@ export declare function MediaPlaybackControls({ playing, loading, positionMs, du
|
|
|
44
44
|
fullscreen?: boolean;
|
|
45
45
|
}): React.JSX.Element;
|
|
46
46
|
/** A full-size photo surface. The same tap-to-hide-controls, pinch and pan handling runs in the preview and native app. */
|
|
47
|
-
export declare function ZoomablePhoto({ uri, label, onTap, expanded }: {
|
|
47
|
+
export declare function ZoomablePhoto({ uri, previewUri, label, onTap, expanded }: {
|
|
48
48
|
uri: string;
|
|
49
|
+
previewUri?: string;
|
|
49
50
|
label?: string;
|
|
50
51
|
onTap?: () => void;
|
|
51
52
|
expanded?: boolean;
|
|
52
53
|
}): React.JSX.Element;
|
|
53
|
-
export declare function MediaViewer({ title, subtitle, kind, uri, fileName, byteSize, children, loading, error, onClose, onFileAction, reviewAction, onReview, onDownload, onShare, onForward, onDelete, showDelete, showForward, downloading, expanded, onExpandedChange, keepControlsVisible, status, transferProgress }: {
|
|
54
|
+
export declare function MediaViewer({ title, subtitle, kind, uri, previewUri, fileName, byteSize, children, loading, error, onClose, onFileAction, reviewAction, onReview, onDownload, onShare, onForward, onDelete, showDelete, showForward, downloading, expanded, onExpandedChange, keepControlsVisible, status, transferProgress }: {
|
|
54
55
|
showDelete?: boolean;
|
|
55
56
|
showForward?: boolean;
|
|
56
57
|
transferProgress?: number;
|
|
@@ -67,6 +68,7 @@ export declare function MediaViewer({ title, subtitle, kind, uri, fileName, byte
|
|
|
67
68
|
subtitle?: string;
|
|
68
69
|
kind: 'image' | 'video' | 'document' | 'voice';
|
|
69
70
|
uri?: string;
|
|
71
|
+
previewUri?: string;
|
|
70
72
|
fileName?: string;
|
|
71
73
|
byteSize?: number;
|
|
72
74
|
children?: ReactNode;
|