@robono/messaging-react-native 0.20.2 → 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/BRIDGE-MESSENGER.md +7 -1
- package/CHANGELOG.md +12 -1
- package/README.md +36 -0
- package/SBOM.spdx.json +348 -204
- 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 +15 -27
- package/dist/expo-screen.js +18 -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-access.d.ts +18 -0
- package/dist/media-access.js +33 -0
- 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/message-menu.js +2 -2
- package/dist/preview-cache.d.ts +1 -0
- package/dist/preview-cache.js +2 -0
- package/dist/recent-media.d.ts +5 -0
- package/dist/recent-media.js +26 -1
- 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 +3 -3
|
@@ -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,4 +1,6 @@
|
|
|
1
|
+
import { allocateMessagingCache, removeMessagingCacheUri } from './expo-cache.js';
|
|
1
2
|
import { MessagingError } from '@robono/messaging';
|
|
3
|
+
import { MessagingMediaAccess } from './media-access.js';
|
|
2
4
|
import { awaitMediaScreening } from './media-screening';
|
|
3
5
|
import { AppState } from 'react-native';
|
|
4
6
|
import { prepareRecordingPermission } from './recording-permission.js';
|
|
@@ -6,7 +8,6 @@ import { AudioModule, RecordingPresets, createAudioPlayer, setAudioModeAsync } f
|
|
|
6
8
|
import * as Picker from 'expo-image-picker';
|
|
7
9
|
import * as Documents from 'expo-document-picker';
|
|
8
10
|
import * as FS from 'expo-file-system/legacy';
|
|
9
|
-
import * as Crypto from 'expo-crypto';
|
|
10
11
|
import { defaultAttachmentLimits } from '@robono/messaging';
|
|
11
12
|
let audioOwner = false;
|
|
12
13
|
/** Pass your app's call-state guard and restore mode, or supply your existing audio-session coordinator. */
|
|
@@ -46,25 +47,10 @@ export function createExpoMessagingAudioSession(options = {}) {
|
|
|
46
47
|
}
|
|
47
48
|
function check(signal) { if (signal.aborted)
|
|
48
49
|
throw Error('Cancelled.'); }
|
|
49
|
-
const
|
|
50
|
-
throw Error('Private device storage is unavailable.'); return FS.cacheDirectory + 'robono-messaging/'; };
|
|
51
|
-
const ownedDirectories = new Set();
|
|
52
|
-
async function cacheDirectory() { const dir = cacheRoot() + Crypto.randomUUID() + '/'; await FS.makeDirectoryAsync(dir, { intermediates: true }); ownedDirectories.add(dir); return dir; }
|
|
50
|
+
const cacheDirectory = allocateMessagingCache;
|
|
53
51
|
const cacheName = (name) => name.replace(/[^a-zA-Z0-9._-]/g, '_').slice(-90) || 'Attachment';
|
|
54
|
-
async function cachePath(name) { return (await cacheDirectory()) + cacheName(name); }
|
|
55
|
-
|
|
56
|
-
if (!uri.startsWith(cacheRoot()))
|
|
57
|
-
return;
|
|
58
|
-
const dir = uri.slice(0, uri.lastIndexOf('/') + 1);
|
|
59
|
-
// Each owned directory contains exactly one private copy. Remove it in one
|
|
60
|
-
// native operation rather than making the next open wait for two deletions.
|
|
61
|
-
if (ownedDirectories.has(dir)) {
|
|
62
|
-
await FS.deleteAsync(dir, { idempotent: true });
|
|
63
|
-
ownedDirectories.delete(dir);
|
|
64
|
-
}
|
|
65
|
-
else
|
|
66
|
-
await FS.deleteAsync(uri, { idempotent: true });
|
|
67
|
-
}
|
|
52
|
+
async function cachePath(name, bytes = 0) { return (await cacheDirectory(bytes)) + cacheName(name); }
|
|
53
|
+
const removeUri = removeMessagingCacheUri;
|
|
68
54
|
async function remove(file) { await removeUri(file.uri); }
|
|
69
55
|
async function pickedCopy(uri, fileName, mimeType, durationMs) {
|
|
70
56
|
try {
|
|
@@ -77,7 +63,7 @@ async function pickedCopy(uri, fileName, mimeType, durationMs) {
|
|
|
77
63
|
}
|
|
78
64
|
export async function copyMessagingCache(file) { return copied(file.uri, file.fileName, file.mimeType, file.durationMs); }
|
|
79
65
|
async function copied(uri, fileName, mimeType, durationMs) {
|
|
80
|
-
const target = await
|
|
66
|
+
const target = (await allocateMessagingCache(0, true)) + cacheName(fileName).replace(/^__draft__$/, 'Attachment');
|
|
81
67
|
try {
|
|
82
68
|
await FS.copyAsync({ from: uri, to: target });
|
|
83
69
|
const info = await FS.getInfoAsync(target);
|
|
@@ -264,6 +250,7 @@ function https(value) { const url = new URL(value); if (url.protocol !== 'https:
|
|
|
264
250
|
/** Private-storage transport. The endpoint is YOUR authenticated backend, never a Robono API key on the phone. */
|
|
265
251
|
export function createExpoMessagingStorage(options) {
|
|
266
252
|
const endpoint = https(options.url);
|
|
253
|
+
const access = new MessagingMediaAccess();
|
|
267
254
|
async function request(operation, input, signal) {
|
|
268
255
|
const token = await options.getAccessToken();
|
|
269
256
|
if (!token)
|
|
@@ -296,13 +283,12 @@ export function createExpoMessagingStorage(options) {
|
|
|
296
283
|
signal?.removeEventListener('abort', cancel);
|
|
297
284
|
}
|
|
298
285
|
}
|
|
299
|
-
async function playbackPlan(message, signal) {
|
|
286
|
+
async function playbackPlan(message, signal, reauthorize = false) {
|
|
300
287
|
check(signal);
|
|
301
288
|
if (message.deleted)
|
|
302
289
|
throw Error('This attachment is no longer available.');
|
|
303
|
-
const grant = message
|
|
304
|
-
const
|
|
305
|
-
const plan = granted ? { url: grant.url, media: message.media, headers: undefined } : await request('download', { conversationId: message.conversationId, messageId: message.id }, signal);
|
|
290
|
+
const grant = access.get(message, reauthorize);
|
|
291
|
+
const plan = grant ? { url: grant.url, media: message.media, headers: undefined } : await request('download', { conversationId: message.conversationId, messageId: message.id }, signal);
|
|
306
292
|
check(signal);
|
|
307
293
|
const media = plan.media;
|
|
308
294
|
if (!media || media.assetId !== message.media?.assetId || !Number.isSafeInteger(media.byteSize) || media.byteSize < 1 || media.byteSize > 104857600)
|
|
@@ -394,7 +380,9 @@ export function createExpoMessagingStorage(options) {
|
|
|
394
380
|
const media = plan.media;
|
|
395
381
|
if (media?.assetId !== message.media?.assetId || media?.mimeType !== 'image/jpeg' || !Number.isInteger(media.byteSize) || media.byteSize < 1 || media.byteSize > (message.media?.assetId.startsWith('bridge:') ? 204800 : 131072))
|
|
396
382
|
throw Error('Invalid attachment preview.');
|
|
397
|
-
|
|
383
|
+
check(context.signal);
|
|
384
|
+
access.remember(message, plan.attachmentDownload);
|
|
385
|
+
const path = await cachePath('preview.jpg', media.byteSize);
|
|
398
386
|
try {
|
|
399
387
|
const task = FS.createDownloadResumable(https(plan.url), path, { headers: plan.headers ?? {}, sessionType: FS.FileSystemSessionType.FOREGROUND }, progress => { if (progress.totalBytesWritten > media.byteSize)
|
|
400
388
|
void task.cancelAsync().catch(() => { }); });
|
|
@@ -416,8 +404,8 @@ export function createExpoMessagingStorage(options) {
|
|
|
416
404
|
// Local directory preparation needs no media access. Run it alongside
|
|
417
405
|
// authorization, but never start the transfer until both have succeeded.
|
|
418
406
|
const [authorized, prepared] = await Promise.allSettled([
|
|
419
|
-
playbackPlan(message, context.signal),
|
|
420
|
-
cacheDirectory(),
|
|
407
|
+
playbackPlan(message, context.signal, context.reauthorize),
|
|
408
|
+
cacheDirectory(message.media?.byteSize ?? 0),
|
|
421
409
|
]);
|
|
422
410
|
const dir = prepared.status === 'fulfilled' ? prepared.value : null;
|
|
423
411
|
let path = null;
|
package/dist/expo-screen.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Linking } from 'react-native';
|
|
3
|
+
import { isRemoteMessagingAsset } from './media-access.js';
|
|
3
4
|
import { ExpoDocumentPreview } from './expo-document.js';
|
|
4
5
|
import { MessagingTypography } from './typography.js';
|
|
5
6
|
import { Text } from './typography.js';
|
|
@@ -141,7 +142,15 @@ function VoicePlayer({ file, audio, design, inline, draft, autoPlay = false }) {
|
|
|
141
142
|
setLoaded(player.isLoaded);
|
|
142
143
|
restorePaused();
|
|
143
144
|
const subscription = player.addListener('playbackStatusUpdate', status => { if (!scope.alive)
|
|
144
|
-
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) {
|
|
145
154
|
if (!recoverStream())
|
|
146
155
|
fail(Error('The recording could not be played. Try again.'));
|
|
147
156
|
return;
|
|
@@ -239,13 +248,13 @@ function VoicePlayer({ file, audio, design, inline, draft, autoPlay = false }) {
|
|
|
239
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())
|
|
240
249
|
setError(uiText("Could not seek. Try again.")); }); } });
|
|
241
250
|
}
|
|
242
|
-
function VideoPlayer({ file, audio }) {
|
|
251
|
+
function VideoPlayer({ file, audio, posterUri }) {
|
|
243
252
|
const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
|
|
244
253
|
const mediaReady = useContext(MediaReadiness), recover = useContext(StreamRecovery);
|
|
245
254
|
const source = useMemo(() => file.stream ? { uri: file.uri, headers: file.stream.headers, contentType: 'progressive', useCaching: false } : file.uri, [file]);
|
|
246
255
|
const player = useVideoPlayer(source, p => { p.loop = false; p.audioMixingMode = 'mixWithOthers'; if (file.stream)
|
|
247
256
|
p.bufferOptions = { preferredForwardBufferDuration: 5, minBufferForPlayback: 0.5 }; });
|
|
248
|
-
const [ready, setReady] = useState(false), [error, setError] = useState('');
|
|
257
|
+
const [ready, setReady] = useState(false), [error, setError] = useState(''), [frameReady, setFrameReady] = useState(false);
|
|
249
258
|
const desired = useRef(file.autoPlay ?? true), lastPosition = useRef(file.resumeAtMs ?? 0);
|
|
250
259
|
useEffect(() => {
|
|
251
260
|
let alive = true, recovered = false, audioReady = false, resumed = false, release;
|
|
@@ -312,7 +321,7 @@ function VideoPlayer({ file, audio }) {
|
|
|
312
321
|
}
|
|
313
322
|
catch { } void release?.().catch(() => { }); };
|
|
314
323
|
}, [player, audio]);
|
|
315
|
-
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 })] });
|
|
316
325
|
}
|
|
317
326
|
function FileViewer({ file, kind, audio, design }) {
|
|
318
327
|
const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
|
|
@@ -386,7 +395,7 @@ export function MessagingMediaOverlay({ controller, audio, appearance, inlineVoi
|
|
|
386
395
|
if ((typeof inlineVoice === 'function' ? inlineVoice() : inlineVoice) && state.kind === 'voice' && ['opening', 'viewing', 'failed'].includes(state.phase) && !review)
|
|
387
396
|
return null;
|
|
388
397
|
const actions = !review ? viewerActions?.() : undefined;
|
|
389
|
-
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;
|
|
390
399
|
// Present immediately: an iOS fade can still be dismissing when another attachment
|
|
391
400
|
// opens, leaving the next native modal invisible. Safe area belongs to this window.
|
|
392
401
|
return _jsx(Modal, { transparent: true, visible: state.phase !== 'idle' && state.phase !== 'choosing', onDismiss: onDismiss, animationType: "none", onRequestClose: () => { if (expanded)
|
|
@@ -435,6 +444,8 @@ function ExpoMessagingScreenContent({ storage, audioSession, renderConversation,
|
|
|
435
444
|
const present = controller.getPrepared(media.assetId) ?? recorder.getPrepared(media.assetId);
|
|
436
445
|
if (present)
|
|
437
446
|
return present;
|
|
447
|
+
if (isRemoteMessagingAsset(media.assetId))
|
|
448
|
+
return undefined;
|
|
438
449
|
const conversationId = props.client.getSnapshot().conversationId, saved = await outbox?.file(conversationId, media.assetId);
|
|
439
450
|
if (!saved)
|
|
440
451
|
return undefined;
|
|
@@ -552,8 +563,8 @@ function ExpoMessagingScreenContent({ storage, audioSession, renderConversation,
|
|
|
552
563
|
return undefined;
|
|
553
564
|
const draft = m.media && m.kind !== 'text' && m.kind !== 'poll' ? await restore(m.media, m.kind) : undefined;
|
|
554
565
|
return draft ? copyMessagingCache(draft) : undefined;
|
|
555
|
-
});
|
|
556
|
-
}, [restore, controller]);
|
|
566
|
+
}, thumbnails.peek(m)?.uri);
|
|
567
|
+
}, [restore, controller, thumbnails]);
|
|
557
568
|
const screenProps = { ...props, requestedMessageAction,
|
|
558
569
|
onQuoteReady: props.onQuoteReady ?? defaultQuoteReady,
|
|
559
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');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MessagingMessage } from '@robono/messaging';
|
|
2
|
+
export declare const isRemoteMessagingAsset: (id: string) => boolean;
|
|
3
|
+
/** Access belongs to this authorized message object, never a global URL cache.
|
|
4
|
+
* Explicit exports still request fresh authorization. */
|
|
5
|
+
export declare class MessagingMediaAccess {
|
|
6
|
+
private now;
|
|
7
|
+
private grants;
|
|
8
|
+
constructor(now?: () => number);
|
|
9
|
+
private valid;
|
|
10
|
+
remember(message: MessagingMessage, grant: unknown): void;
|
|
11
|
+
get(message: MessagingMessage, reauthorize?: boolean): {
|
|
12
|
+
url: string;
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
messageId: string;
|
|
15
|
+
conversationId: string;
|
|
16
|
+
assetId: string;
|
|
17
|
+
} | undefined;
|
|
18
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const isRemoteMessagingAsset = (id) => id.startsWith('bridge:') || id.startsWith('robono-r2:');
|
|
2
|
+
/** Access belongs to this authorized message object, never a global URL cache.
|
|
3
|
+
* Explicit exports still request fresh authorization. */
|
|
4
|
+
export class MessagingMediaAccess {
|
|
5
|
+
now;
|
|
6
|
+
grants = new WeakMap();
|
|
7
|
+
constructor(now = Date.now) {
|
|
8
|
+
this.now = now;
|
|
9
|
+
}
|
|
10
|
+
valid(message, grant) {
|
|
11
|
+
if (message.deleted || !message.media || !grant || grant.messageId !== message.id || grant.conversationId !== message.conversationId || grant.assetId !== message.media.assetId || !Number.isFinite(grant.expiresAt) || grant.expiresAt <= this.now() + 5000 || grant.expiresAt > this.now() + 60000)
|
|
12
|
+
return false;
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(grant.url);
|
|
15
|
+
return url.protocol === 'https:' && !url.username && !url.password;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
remember(message, grant) { if (this.valid(message, grant))
|
|
22
|
+
this.grants.set(message, { ...grant }); }
|
|
23
|
+
get(message, reauthorize = false) {
|
|
24
|
+
if (reauthorize)
|
|
25
|
+
return undefined;
|
|
26
|
+
const grant = this.grants.get(message) ?? message.attachmentDownload;
|
|
27
|
+
if (!this.valid(message, grant)) {
|
|
28
|
+
this.grants.delete(message);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return grant;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -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;
|