@robono/messaging-react-native 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +75 -1
- package/RobonoMessagingRuntime.podspec +2 -0
- package/SBOM.spdx.json +1829 -557
- package/android/build.gradle +4 -1
- package/android/src/main/java/com/robono/messaging/RobonoBackupGoogle.java +76 -0
- package/android/src/main/java/com/robono/messaging/RobonoHistoryStore.java +173 -0
- package/android/src/main/java/com/robono/messaging/RobonoMessagingPackage.java +1 -1
- package/app.plugin.cjs +14 -1
- package/cloudkit/backup-schema.ckdb +13 -0
- package/dist/account-pages.d.ts +51 -0
- package/dist/account-pages.js +65 -0
- package/dist/account.d.ts +2 -1
- package/dist/account.js +6 -2
- package/dist/backup-background.d.ts +25 -0
- package/dist/backup-background.js +71 -0
- package/dist/backup-base64.d.ts +3 -0
- package/dist/backup-base64.js +41 -0
- package/dist/backup-google-authorization.d.ts +23 -0
- package/dist/backup-google-authorization.js +95 -0
- package/dist/backup.js +61 -16
- package/dist/bubble-design.d.ts +1 -1
- package/dist/cloudkit-backup.d.ts +14 -0
- package/dist/cloudkit-backup.js +193 -0
- package/dist/conversation-details.js +1 -1
- package/dist/customization.d.ts +1 -0
- package/dist/delivery-bar.d.ts +1 -1
- package/dist/delivery-bar.js +5 -2
- package/dist/delivery-notice.d.ts +9 -0
- package/dist/delivery-notice.js +15 -0
- package/dist/expo-backup-background.d.ts +17 -0
- package/dist/expo-backup-background.js +57 -0
- package/dist/expo-backup-cloudkit.d.ts +6 -0
- package/dist/expo-backup-cloudkit.js +11 -0
- package/dist/expo-backup-google.d.ts +7 -0
- package/dist/expo-backup-google.js +16 -0
- package/dist/expo-backup-network.d.ts +8 -0
- package/dist/expo-backup-network.js +18 -0
- package/dist/expo-backup-passkeys.d.ts +7 -0
- package/dist/expo-backup-passkeys.js +31 -7
- package/dist/expo-backup-settings.js +26 -8
- package/dist/expo-backup.d.ts +14 -0
- package/dist/expo-backup.js +22 -0
- package/dist/expo-bridge.d.ts +2 -0
- package/dist/expo-bridge.js +3 -1
- package/dist/expo-cache.js +20 -1
- package/dist/expo-device-history.d.ts +24 -0
- package/dist/expo-device-history.js +88 -0
- package/dist/expo-durable-history.d.ts +26 -0
- package/dist/expo-durable-history.js +56 -0
- package/dist/expo-history-backup.d.ts +3 -0
- package/dist/expo-history-backup.js +79 -0
- package/dist/expo-history-maintenance.d.ts +4 -0
- package/dist/expo-history-maintenance.js +23 -0
- package/dist/expo-history-previews.d.ts +5 -0
- package/dist/expo-history-previews.js +57 -0
- package/dist/expo-history.d.ts +1 -1
- package/dist/expo-history.js +2 -2
- package/dist/expo-media.d.ts +2 -0
- package/dist/expo-media.js +15 -21
- package/dist/expo-messenger.d.ts +8 -0
- package/dist/expo-messenger.js +18 -7
- package/dist/expo-notifications.d.ts +17 -1
- package/dist/expo-notifications.js +36 -16
- package/dist/expo-outbox.d.ts +2 -0
- package/dist/expo-outbox.js +1 -1
- package/dist/expo-oversight.d.ts +15 -0
- package/dist/expo-oversight.js +15 -0
- package/dist/expo-reviews.d.ts +4 -1
- package/dist/expo-reviews.js +122 -17
- package/dist/expo-screen.js +5 -4
- package/dist/expo-thumbnails.d.ts +2 -2
- package/dist/expo-thumbnails.js +48 -5
- package/dist/expo.d.ts +10 -0
- package/dist/expo.js +8 -0
- package/dist/header-calls.js +1 -1
- package/dist/inbox-search.d.ts +1 -1
- package/dist/inbox-search.js +7 -3
- package/dist/inbox.d.ts +1 -0
- package/dist/inbox.js +5 -5
- package/dist/index.d.ts +8 -3
- package/dist/index.js +138 -63
- package/dist/linked-apps.d.ts +45 -0
- package/dist/linked-apps.js +40 -0
- package/dist/loading-messages.d.ts +1 -1
- package/dist/loading-messages.js +1 -1
- package/dist/media-controller.d.ts +2 -0
- package/dist/native-history-authorization.d.ts +4 -0
- package/dist/native-history-authorization.js +69 -0
- package/dist/native-history-backup.d.ts +16 -0
- package/dist/native-history-backup.js +144 -0
- package/dist/native-history.d.ts +14 -0
- package/dist/native-history.js +186 -0
- package/dist/native-outbox.d.ts +2 -0
- package/dist/oversight-session.d.ts +4 -0
- package/dist/oversight-session.js +14 -0
- package/dist/preview-layout.d.ts +12 -0
- package/dist/preview-layout.js +102 -0
- package/dist/recent-media.js +2 -1
- package/dist/reviews.d.ts +8 -4
- package/dist/reviews.js +53 -26
- package/dist/scheduled.js +2 -2
- package/dist/search.js +18 -8
- package/ios/RobonoBackupCloudKit.m +96 -0
- package/ios/RobonoHistoryStore.m +170 -0
- package/package.json +22 -4
- package/plugin/backup-expiration.cjs +23 -0
- package/plugin/prepare-native.cjs +12 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
2
|
+
/** Bounded bridge encoding that does not depend on browser atob/btoa in Hermes. */
|
|
3
|
+
export function encodeBackupBase64(bytes) {
|
|
4
|
+
const chunks = [];
|
|
5
|
+
let chunk = '';
|
|
6
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
7
|
+
const a = bytes[i], b = bytes[i + 1] ?? 0, c = bytes[i + 2] ?? 0;
|
|
8
|
+
chunk += alphabet[a >>> 2] + alphabet[((a & 3) << 4) | (b >>> 4)] + (i + 1 < bytes.length ? alphabet[((b & 15) << 2) | (c >>> 6)] : '=') + (i + 2 < bytes.length ? alphabet[c & 63] : '=');
|
|
9
|
+
if (chunk.length >= 32768) {
|
|
10
|
+
chunks.push(chunk);
|
|
11
|
+
chunk = '';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
chunks.push(chunk);
|
|
15
|
+
return chunks.join('');
|
|
16
|
+
}
|
|
17
|
+
export function decodeBackupBase64(text, maximum) {
|
|
18
|
+
if (typeof text !== 'string' || text.length % 4 || text.length > Math.ceil(maximum / 3) * 4)
|
|
19
|
+
throw Error('Invalid backup encoding.');
|
|
20
|
+
const padding = text.endsWith('==') ? 2 : text.endsWith('=') ? 1 : 0, length = text.length / 4 * 3 - padding;
|
|
21
|
+
if (length < 0 || length > maximum)
|
|
22
|
+
throw Error('Invalid backup length.');
|
|
23
|
+
const bytes = new Uint8Array(length);
|
|
24
|
+
let offset = 0;
|
|
25
|
+
for (let i = 0; i < text.length; i += 4) {
|
|
26
|
+
let value = 0, last = 0;
|
|
27
|
+
for (let j = 0; j < 4; j++) {
|
|
28
|
+
const at = i + j, char = text[at], digit = at >= text.length - padding && char === '=' ? 0 : alphabet.indexOf(char);
|
|
29
|
+
if (digit < 0)
|
|
30
|
+
throw Error('Invalid backup encoding.');
|
|
31
|
+
value = (value << 6) | digit;
|
|
32
|
+
if (at === text.length - padding - 1)
|
|
33
|
+
last = digit;
|
|
34
|
+
}
|
|
35
|
+
if (i + 4 === text.length && ((padding === 2 && (last & 15)) || (padding === 1 && (last & 3))))
|
|
36
|
+
throw Error('Invalid backup padding.');
|
|
37
|
+
for (let shift = 16; shift >= 0 && offset < length; shift -= 8)
|
|
38
|
+
bytes[offset++] = (value >>> shift) & 255;
|
|
39
|
+
}
|
|
40
|
+
return bytes;
|
|
41
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface MessagingGoogleAuthorizationTransport {
|
|
2
|
+
authorize(requestId: string, interactive: boolean): Promise<{
|
|
3
|
+
accessToken: string;
|
|
4
|
+
} | null>;
|
|
5
|
+
cancel(requestId: string): void;
|
|
6
|
+
invalidateToken(accessToken: string): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** Modern Android authorization: consent is foreground-only; tokens are never
|
|
9
|
+
* persisted. Drive's stable permission ID identifies the selected cloud account. */
|
|
10
|
+
export declare function createMessagingGoogleBackupAuthorization(options: {
|
|
11
|
+
transport: MessagingGoogleAuthorizationTransport;
|
|
12
|
+
fetch: typeof fetch;
|
|
13
|
+
randomId: () => string;
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
}): {
|
|
16
|
+
getSession: (signal: AbortSignal) => Promise<{
|
|
17
|
+
accountId: string;
|
|
18
|
+
label: string;
|
|
19
|
+
accessToken: string;
|
|
20
|
+
} | null>;
|
|
21
|
+
invalidateSession(accessToken: string, signal: AbortSignal): Promise<void>;
|
|
22
|
+
connect(signal: AbortSignal): Promise<void>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { MessagingBackupError, withMessagingDeadline } from '@robono/messaging';
|
|
2
|
+
/** Modern Android authorization: consent is foreground-only; tokens are never
|
|
3
|
+
* persisted. Drive's stable permission ID identifies the selected cloud account. */
|
|
4
|
+
export function createMessagingGoogleBackupAuthorization(options) {
|
|
5
|
+
const timeoutMs = options.timeoutMs ?? 120000;
|
|
6
|
+
let cached = null;
|
|
7
|
+
const authorize = async (interactive, parent) => {
|
|
8
|
+
try {
|
|
9
|
+
return await withMessagingDeadline(async (signal) => {
|
|
10
|
+
const id = options.randomId(), cancel = () => { try {
|
|
11
|
+
options.transport.cancel(id);
|
|
12
|
+
}
|
|
13
|
+
catch { } };
|
|
14
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
15
|
+
try {
|
|
16
|
+
if (signal.aborted)
|
|
17
|
+
throw new MessagingBackupError('cancelled');
|
|
18
|
+
const result = await options.transport.authorize(id, interactive);
|
|
19
|
+
if (signal.aborted)
|
|
20
|
+
throw new MessagingBackupError('cancelled');
|
|
21
|
+
if (!result) {
|
|
22
|
+
cached = null;
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (typeof result.accessToken !== 'string' || !result.accessToken || result.accessToken.length > 16384)
|
|
26
|
+
throw new MessagingBackupError('connection');
|
|
27
|
+
if (cached?.accessToken === result.accessToken)
|
|
28
|
+
return { ...cached };
|
|
29
|
+
const response = await options.fetch('https://www.googleapis.com/drive/v3/about?fields=user(permissionId,emailAddress)', { signal, redirect: 'error', headers: { Authorization: 'Bearer ' + result.accessToken } });
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
void response.body?.cancel().catch(() => { });
|
|
32
|
+
throw new MessagingBackupError('connection');
|
|
33
|
+
}
|
|
34
|
+
const reader = response.body?.getReader();
|
|
35
|
+
if (!reader)
|
|
36
|
+
throw new MessagingBackupError('connection');
|
|
37
|
+
const chunks = [];
|
|
38
|
+
let size = 0, done = false;
|
|
39
|
+
const stop = () => { void reader.cancel().catch(() => { }); };
|
|
40
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
41
|
+
try {
|
|
42
|
+
for (;;) {
|
|
43
|
+
if (signal.aborted)
|
|
44
|
+
throw new MessagingBackupError('cancelled');
|
|
45
|
+
const part = await reader.read();
|
|
46
|
+
if (part.done) {
|
|
47
|
+
done = true;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
size += part.value.length;
|
|
51
|
+
if (size > 65536)
|
|
52
|
+
throw new MessagingBackupError('connection');
|
|
53
|
+
chunks.push(part.value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
signal.removeEventListener('abort', stop);
|
|
58
|
+
if (!done)
|
|
59
|
+
stop();
|
|
60
|
+
}
|
|
61
|
+
if (signal.aborted)
|
|
62
|
+
throw new MessagingBackupError('cancelled');
|
|
63
|
+
const bytes = new Uint8Array(size);
|
|
64
|
+
let offset = 0;
|
|
65
|
+
for (const chunk of chunks) {
|
|
66
|
+
bytes.set(chunk, offset);
|
|
67
|
+
offset += chunk.length;
|
|
68
|
+
}
|
|
69
|
+
const user = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)).user;
|
|
70
|
+
if (!user || typeof user.permissionId !== 'string' || !/^[a-zA-Z0-9_-]{1,256}$/.test(user.permissionId) || typeof user.emailAddress !== 'string' || !user.emailAddress || user.emailAddress.length > 320)
|
|
71
|
+
throw new MessagingBackupError('connection');
|
|
72
|
+
cached = { accountId: user.permissionId, label: user.emailAddress, accessToken: result.accessToken };
|
|
73
|
+
return { ...cached };
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
signal.removeEventListener('abort', cancel);
|
|
77
|
+
cancel();
|
|
78
|
+
}
|
|
79
|
+
}, { signal: parent, timeoutMs });
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
cached = null;
|
|
83
|
+
const code = parent.aborted || error?.code === 'cancelled' ? 'cancelled' : error?.code === 'unavailable' ? 'unavailable' : 'connection';
|
|
84
|
+
throw Object.assign(new MessagingBackupError(code), { cause: error });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
getSession: (signal) => authorize(false, signal),
|
|
89
|
+
async invalidateSession(accessToken, signal) { if (cached?.accessToken === accessToken)
|
|
90
|
+
cached = null; if (signal.aborted)
|
|
91
|
+
throw new MessagingBackupError('cancelled'); await options.transport.invalidateToken(accessToken); },
|
|
92
|
+
async connect(signal) { if (!await authorize(true, signal))
|
|
93
|
+
throw new MessagingBackupError('connection'); },
|
|
94
|
+
};
|
|
95
|
+
}
|
package/dist/backup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
-
import { AppState, Pressable, ScrollView, StyleSheet, View } from 'react-native';
|
|
3
|
+
import { ActivityIndicator, AppState, Platform, Pressable, ScrollView, StyleSheet, View } from 'react-native';
|
|
4
4
|
import { formatMessagingDateTime, messagingContrastInk } from '@robono/messaging';
|
|
5
5
|
import { Text, TextInput } from './typography.js';
|
|
6
6
|
import { useRobonoLocale } from './localization.js';
|
|
@@ -27,6 +27,9 @@ export function MessagingBackupPage({ client, onClose, active = true, render })
|
|
|
27
27
|
const [recovery, setRecovery] = useState(null), [saved, setSaved] = useState(false), [restore, setRestore] = useState(false), [key, setKey] = useState(''), [localError, setLocalError] = useState(''), [choosing, setChoosing] = useState(false);
|
|
28
28
|
const [protectionPage, setProtectionPage] = useState(null), [password, setPassword] = useState(''), [confirmPassword, setConfirmPassword] = useState(''), [restoreMethod, setRestoreMethod] = useState(null);
|
|
29
29
|
const pending = useRef(null), mounted = useRef(true);
|
|
30
|
+
const [pendingMethod, setPendingMethod] = useState(null);
|
|
31
|
+
const [visibleFields, setVisibleFields] = useState({});
|
|
32
|
+
useEffect(() => { setVisibleFields({}); }, [active, protectionPage, restore]);
|
|
30
33
|
useEffect(() => { mounted.current = active; if (active)
|
|
31
34
|
void client.refresh();
|
|
32
35
|
else {
|
|
@@ -43,7 +46,8 @@ export function MessagingBackupPage({ client, onClose, active = true, render })
|
|
|
43
46
|
setConfirmPassword('');
|
|
44
47
|
setRestoreMethod(null);
|
|
45
48
|
} return () => { mounted.current = false; void pending.current?.cancel(); pending.current = null; }; }, [client, active]);
|
|
46
|
-
useEffect(() => { const sub = AppState.addEventListener('change', value => { if (value
|
|
49
|
+
useEffect(() => { const sub = AppState.addEventListener('change', value => { if (value === 'background') {
|
|
50
|
+
setVisibleFields({});
|
|
47
51
|
setPassword('');
|
|
48
52
|
setConfirmPassword('');
|
|
49
53
|
void pending.current?.cancel();
|
|
@@ -55,16 +59,33 @@ export function MessagingBackupPage({ client, onClose, active = true, render })
|
|
|
55
59
|
const busy = state.phase !== 'idle', border = c.foreground + '14';
|
|
56
60
|
const card = (children) => _jsx(View, { style: [s.card, { backgroundColor: c.incoming, borderColor: border }], children: children });
|
|
57
61
|
const copy = (value) => _jsx(Text, { style: [s.copy, { color: c.secondary }], children: text(value) });
|
|
58
|
-
const button = (label, onPress, disabled = false, primary = false) =>
|
|
59
|
-
|
|
62
|
+
const button = (label, onPress, disabled = false, primary = false) => {
|
|
63
|
+
const loading = primary && busy, cancellable = loading && (state.phase === 'uploading' || state.phase === 'restoring'), ink = primary ? messagingContrastInk(c.accent) : c.foreground, blocked = disabled && !cancellable;
|
|
64
|
+
return _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: text(cancellable ? 'Cancel' : label), "aria-busy": loading, accessibilityState: { disabled: blocked, busy: loading }, disabled: blocked, onPress: cancellable ? () => client.cancel() : onPress, style: [s.button, { backgroundColor: primary ? c.accent : 'transparent', opacity: blocked && !loading ? 0.45 : 1 }], children: [_jsx(Text, { style: { color: ink, fontWeight: '700', fontSize: 14, opacity: loading ? 0 : 1 }, children: text(label) }), loading && _jsxs(View, { pointerEvents: "none", style: s.buttonActivity, children: [_jsx(ActivityIndicator, { accessibilityLabel: text(activity), color: ink }), cancellable && _jsxs(Text, { style: { color: ink, fontWeight: '700', fontSize: 14 }, children: [progress !== null ? `${progress}% · ` : '', text('Cancel')] })] })] });
|
|
65
|
+
};
|
|
66
|
+
const row = (label, detail, action) => {
|
|
67
|
+
const content = _jsxs(View, { style: s.rowText, children: [_jsx(Text, { style: [s.label, { color: c.foreground }], children: text(label) }), _jsx(Text, { style: [s.copy, { color: c.secondary }], children: detail })] });
|
|
68
|
+
const loading = busy && (pendingMethod === label || state.phase === 'connecting' && (label === 'Google Account' || label === 'Backup account'));
|
|
69
|
+
return action ? _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: text(label), disabled: busy, "aria-busy": loading, accessibilityState: { disabled: busy, busy: loading }, onPress: action, style: s.row, children: [content, _jsx(View, { style: { width: 20, height: 20, alignItems: 'center', justifyContent: 'center' }, children: loading ? _jsx(ActivityIndicator, { color: c.secondary }) : _jsx(MessageIcon, { name: "chevron-right", color: c.secondary, size: 18 }) })] }) : _jsx(View, { style: s.row, children: content });
|
|
70
|
+
};
|
|
60
71
|
// Same compact switch geometry as Chat options; the entire row is a touch target.
|
|
61
72
|
const toggle = (label, value, onChange) => _jsxs(Pressable, { accessibilityRole: "switch", "aria-checked": value, accessibilityLabel: text(label), accessibilityState: { checked: value, disabled: busy }, disabled: busy, onPress: () => onChange(!value), style: s.row, children: [_jsx(Text, { style: [s.label, { flex: 1, color: c.foreground }], children: text(label) }), _jsx(View, { style: { width: 44, height: 26, borderRadius: 14, padding: 3, backgroundColor: value ? c.accent : '#555', alignItems: value ? 'flex-end' : 'flex-start' }, children: _jsx(View, { style: { width: 20, height: 20, borderRadius: 10, backgroundColor: '#fff' } }) })] });
|
|
62
73
|
const divider = _jsx(View, { style: { height: StyleSheet.hairlineWidth, backgroundColor: border } });
|
|
63
|
-
const prepare = async () => { setLocalError('');
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
const prepare = async () => { setLocalError(''); setPendingMethod('Recovery key'); try {
|
|
75
|
+
const setup = await client.prepareRecovery();
|
|
76
|
+
if (!setup)
|
|
77
|
+
return;
|
|
78
|
+
if (!mounted.current) {
|
|
79
|
+
await setup.cancel();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
pending.current = setup;
|
|
83
|
+
setRecovery(setup);
|
|
84
|
+
setSaved(false);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
setPendingMethod(null);
|
|
88
|
+
} };
|
|
68
89
|
const close = () => { if (busy) {
|
|
69
90
|
client.cancel();
|
|
70
91
|
return;
|
|
@@ -107,9 +128,8 @@ export function MessagingBackupPage({ client, onClose, active = true, render })
|
|
|
107
128
|
return;
|
|
108
129
|
}
|
|
109
130
|
const value = password;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const result = await client.prepareProtection(method === 'password' ? { method, password: value } : { method });
|
|
131
|
+
setPendingMethod(method === 'passkey' ? 'Passkey' : 'Password');
|
|
132
|
+
const result = await client.prepareProtection(method === 'password' ? { method, password: value } : { method }).finally(() => setPendingMethod(null));
|
|
113
133
|
if (!result)
|
|
114
134
|
return;
|
|
115
135
|
if (!mounted.current) {
|
|
@@ -120,6 +140,8 @@ export function MessagingBackupPage({ client, onClose, active = true, render })
|
|
|
120
140
|
try {
|
|
121
141
|
await result.confirm();
|
|
122
142
|
pending.current = null;
|
|
143
|
+
setPassword('');
|
|
144
|
+
setConfirmPassword('');
|
|
123
145
|
setProtectionPage(null);
|
|
124
146
|
}
|
|
125
147
|
catch {
|
|
@@ -127,6 +149,24 @@ export function MessagingBackupPage({ client, onClose, active = true, render })
|
|
|
127
149
|
}
|
|
128
150
|
};
|
|
129
151
|
const openRestore = () => { setRestoreMethod(state.lastBackup?.protection ?? 'recovery-key'); setPassword(''); setKey(''); setRestore(true); };
|
|
152
|
+
const beginSetup = async () => {
|
|
153
|
+
setLocalError('');
|
|
154
|
+
// Account selection belongs to setup, including resuming an unfinished setup.
|
|
155
|
+
// iCloud uses the device's Apple account; other providers can show their picker.
|
|
156
|
+
if (!await client.connect() || !mounted.current)
|
|
157
|
+
return;
|
|
158
|
+
const connected = client.getSnapshot();
|
|
159
|
+
if (!connected.account || connected.encryptionReady)
|
|
160
|
+
return;
|
|
161
|
+
if (connected.lastBackup) {
|
|
162
|
+
setRestoreMethod(connected.lastBackup.protection ?? 'recovery-key');
|
|
163
|
+
setPassword('');
|
|
164
|
+
setKey('');
|
|
165
|
+
setRestore(true);
|
|
166
|
+
}
|
|
167
|
+
else
|
|
168
|
+
setProtectionPage('choose');
|
|
169
|
+
};
|
|
130
170
|
const method = restoreMethod ?? state.lastBackup?.protection ?? 'recovery-key';
|
|
131
171
|
const restoreBackup = () => {
|
|
132
172
|
const credential = method === 'password' ? { method, password } : method === 'passkey' ? { method } : { method, recoveryKey: key };
|
|
@@ -137,13 +177,17 @@ export function MessagingBackupPage({ client, onClose, active = true, render })
|
|
|
137
177
|
setRestoreMethod(null);
|
|
138
178
|
} });
|
|
139
179
|
};
|
|
140
|
-
const field = (label, value, change, newPassword = false) =>
|
|
180
|
+
const field = (label, value, change, newPassword = false) => {
|
|
181
|
+
const visible = !!visibleFields[label], action = label === 'Confirm password' ? (visible ? 'Hide confirmation password' : 'Show confirmation password') : label === 'Recovery key' ? (visible ? 'Hide recovery key' : 'Show recovery key') : (visible ? 'Hide password' : 'Show password');
|
|
182
|
+
return _jsxs(View, { children: [_jsx(TextInput, { accessibilityLabel: text(label), placeholder: text(label), placeholderTextColor: c.secondary, value: value, onChangeText: value => { change(value); setLocalError(''); }, secureTextEntry: !visible, clearTextOnFocus: false, selectTextOnFocus: false, autoCorrect: false, autoCapitalize: "none", maxLength: 1024, autoComplete: newPassword ? 'new-password' : 'current-password', editable: !busy, style: [s.input, { paddingRight: 48, color: c.foreground, backgroundColor: c.background, borderColor: border }] }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: text(action), disabled: busy, onPress: () => setVisibleFields(fields => ({ ...fields, [label]: !fields[label] })), style: { position: 'absolute', right: 2, top: 0, bottom: 0, width: 44, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: visible ? 'eye-off' : 'eye', size: 20, color: c.secondary }) })] });
|
|
183
|
+
};
|
|
141
184
|
const progress = state.progress?.total ? Math.min(100, Math.round(state.progress.completed / state.progress.total * 100)) : null;
|
|
142
185
|
const activity = state.phase === 'uploading' ? 'Backing up…' : state.phase === 'restoring' ? 'Restoring…' : state.phase === 'connecting' ? 'Connecting…' : 'Preparing…';
|
|
143
186
|
const provider = state.account?.provider === 'google' ? 'Google' : state.account?.provider === 'icloud' ? 'iCloud' : text('cloud');
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
187
|
+
const configured = !!state.account && state.encryptionReady;
|
|
188
|
+
const content = _jsxs(ScrollView, { keyboardShouldPersistTaps: "handled", contentContainerStyle: s.content, children: [recovery ? _jsxs(_Fragment, { children: [card(_jsxs(_Fragment, { children: [_jsx(Text, { selectable: true, accessibilityLabel: text('Recovery key'), style: { color: c.foreground, fontSize: 15, lineHeight: 24, fontFamily: 'monospace' }, children: recovery.recoveryKey.match(/.{1,8}/g)?.join(' ') }), divider, toggle('I saved my recovery key', saved, setSaved), button('Enable encrypted backups', () => void confirm(), busy || !saved, true)] })), copy('We cannot recover this key for you. Your backup account will not receive it.')] }) : protectionPage === 'choose' ? _jsx(_Fragment, { children: card(_jsxs(_Fragment, { children: [row('Passkey', text(available.includes('passkey') ? 'Use your fingerprint, face or screen lock.' : 'Not available here. Choose Password or Recovery key.'), available.includes('passkey') ? () => void setup('passkey') : undefined), divider, row('Password', text(available.includes('password') ? 'Use a password you can remember.' : 'Not available in this app yet.'), available.includes('password') ? () => setProtectionPage('password') : undefined), divider, row('Recovery key', text('Save a long code somewhere safe.'), () => void prepare())] })) }) : protectionPage === 'password' ? _jsxs(_Fragment, { children: [card(_jsxs(_Fragment, { children: [field('Password', password, setPassword, true), field('Confirm password', confirmPassword, setConfirmPassword, true), button('Save password', () => void setup('password'), busy || !password || !confirmPassword, true)] })), copy('Use at least 12 characters. A few memorable words work well.'), copy('You will need this password to restore your backup on another device. We cannot reset it for you.')] }) : restore ? _jsx(_Fragment, { children: card(_jsxs(_Fragment, { children: [method === 'password' ? field('Password', password, setPassword) : method === 'recovery-key' ? field('Recovery key', key, setKey) : copy('Use the passkey saved in your password manager.'), button(method === 'passkey' ? 'Restore with passkey' : 'Restore chats', restoreBackup, busy || !state.lastBackup || (!state.encryptionReady && (method === 'password' ? !password : method === 'recovery-key' ? !key : false)), true), method !== 'recovery-key' && button('Use recovery key', () => { setRestoreMethod('recovery-key'); setPassword(''); })] })) }) : _jsxs(_Fragment, { children: [card(_jsxs(_Fragment, { children: [state.account && state.lastBackup && _jsxs(View, { style: { gap: 6 }, children: [_jsx(Text, { style: [s.label, { color: c.foreground }], children: text('Last backup') }), _jsx(Text, { style: { fontSize: 15, lineHeight: 21, color: c.foreground }, children: formatMessagingDateTime(state.lastBackup.createdAt, { locale, relativeLabels: { today: text('Today'), yesterday: text('Yesterday') } }) }), _jsxs(Text, { style: [s.copy, { color: c.secondary }], children: [text('Size'), ": ", size(state.lastBackup.byteSize)] })] }), state.account && !state.encryptionReady && state.lastBackup ? button('Restore chats', () => void beginSetup(), busy, true) : !configured ? button('Set up backup', () => void beginSetup(), busy, true) : button('Back up now', () => void client.backUp(), busy, true)] })), state.lastBackup && state.encryptionReady && state.protectionMethod !== (state.lastBackup.protection ?? 'recovery-key') && copy('Your new protection will apply when you back up again.'), configured && state.account && card(_jsx(_Fragment, { children: state.account.provider === 'icloud' ? row('iCloud', text('Uses the Apple account on this device.')) : _jsxs(_Fragment, { children: [row(state.account.provider === 'google' ? 'Google Account' : 'Backup account', state.account.label, () => void client.connect()), configured && _jsxs(_Fragment, { children: [divider, row(text('Manage {provider} storage', { provider }), state.account.storageUsed !== undefined ? (state.account.storageTotal !== undefined ? text('{used} of {total} used', { used: size(state.account.storageUsed), total: size(state.account.storageTotal) }) : text('{used} used', { used: size(state.account.storageUsed) })) : text('Open your storage settings'), () => void client.manageStorage())] })] }) })), configured && card(_jsxs(_Fragment, { children: [_jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: text('Automatic backups'), accessibilityState: { expanded: choosing, disabled: busy || !state.encryptionReady }, disabled: busy || !state.encryptionReady, onPress: () => setChoosing(!choosing), style: s.row, children: [_jsx(Text, { style: [s.label, { flex: 1, color: c.foreground }], children: text('Automatic backups') }), _jsx(Text, { style: { fontSize: 14, color: c.secondary }, children: text(frequencies.find(([value]) => value === state.preferences.frequency)[1]) }), _jsx(MessageIcon, { name: choosing ? 'chevron-up' : 'chevron-down', color: c.secondary, size: 18 })] }), choosing && _jsx(View, { accessibilityRole: "radiogroup", children: frequencies.map(([value, label]) => _jsxs(Pressable, { accessibilityRole: "radio", accessibilityLabel: text(label), accessibilityState: { checked: state.preferences.frequency === value, disabled: busy }, disabled: busy, onPress: () => { void client.configure({ frequency: value }).then(ok => { if (ok)
|
|
189
|
+
setChoosing(false); }); }, style: [s.row, { paddingHorizontal: 8 }], children: [_jsx(Text, { style: { flex: 1, color: c.foreground, fontSize: 15 }, children: text(label) }), state.preferences.frequency === value && _jsx(MessageIcon, { name: "checkmark", size: 18, color: c.accent })] }, value)) }), divider, toggle('Back up over cellular', state.preferences.cellular, value => void client.configure({ cellular: value })), divider, toggle('Include videos in chats', state.preferences.includeVideos, value => void client.configure({ includeVideos: value }))] })), configured && card(_jsxs(_Fragment, { children: [row('End-to-end encrypted backup', text(state.protectionMethod === 'password' ? 'On · Password' : state.protectionMethod === 'passkey' ? 'On · Passkey' : 'On · Recovery key'), () => setProtectionPage('choose')), state.lastBackup && _jsxs(_Fragment, { children: [divider, row('Restore chats', text('Recover from your last successful backup'), openRestore)] })] }))] }), (state.error || localError) && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 14, lineHeight: 20 }, children: localError || text(state.error) }), _jsx(Text, { accessibilityLiveRegion: "polite", style: { position: 'absolute', width: 1, height: 1, opacity: 0, overflow: 'hidden' }, children: state.notice ? text(state.notice) : '' })] }, recovery ? 'recovery' : protectionPage ?? (restore ? 'restore' : 'backup'));
|
|
190
|
+
return render({ title: text(recovery ? 'Recovery key' : protectionPage === 'password' ? 'Create a password' : protectionPage ? 'Protect your backup' : restore ? 'Restore chats' : 'Chat backup'), description: text(protectionPage === 'password' ? 'Choose a password for your encrypted backup.' : !recovery && protectionPage ? 'Choose how you will unlock your backup on another device.' : recovery ? 'Save this recovery key away from this phone. You will need it to restore your chats on another device.' : restore ? 'Restore your last backup. Newer chats on this device will be kept.' : Platform.OS === 'android' ? 'Back up your chats and media to your own Google Drive.' : 'Back up your chats and media to your own cloud storage.'), form: restore || protectionPage === 'password', isRoot: !recovery && !restore && !protectionPage, onClose: close, content });
|
|
147
191
|
}
|
|
148
192
|
const s = StyleSheet.create({
|
|
149
193
|
content: { paddingBottom: 16, gap: 12 },
|
|
@@ -153,5 +197,6 @@ const s = StyleSheet.create({
|
|
|
153
197
|
label: { fontSize: 14, lineHeight: 20, fontWeight: '700' },
|
|
154
198
|
copy: { fontSize: 13, lineHeight: 18 },
|
|
155
199
|
button: { minHeight: 48, borderRadius: 8, paddingHorizontal: 16, alignItems: 'center', justifyContent: 'center' },
|
|
200
|
+
buttonActivity: { position: 'absolute', top: 0, right: 0, bottom: 0, left: 0, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 10 },
|
|
156
201
|
input: { minHeight: 48, borderWidth: 1, borderRadius: 8, paddingHorizontal: 12, fontSize: 16 },
|
|
157
202
|
});
|
package/dist/bubble-design.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare function bubbleCorners(appearance: MessagingAppearance, mine: boo
|
|
|
6
6
|
borderBottomRightRadius: number;
|
|
7
7
|
};
|
|
8
8
|
export declare function bubbleDelivery(message: MessagingMessage, pending: 'sending' | 'queued' | 'failed' | undefined, receipts: boolean, appearance: MessagingAppearance): {
|
|
9
|
-
readonly phase: "
|
|
9
|
+
readonly phase: "sent" | "failed" | "consumed" | "delivered";
|
|
10
10
|
readonly color: string;
|
|
11
11
|
readonly style: "circle" | "bar";
|
|
12
12
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MessagingBackupCloud } from '@robono/messaging';
|
|
2
|
+
export interface MessagingCloudKitTransport {
|
|
3
|
+
request(id: string, input: Record<string, unknown>): Promise<any>;
|
|
4
|
+
cancel(id: string): void | Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
/** Private CloudKit adapter. The native transport resolves writes/deletes only
|
|
7
|
+
* after Apple's server completion, not when a CKAsset file is staged locally. */
|
|
8
|
+
export declare function createCloudKitMessagingBackupCloud(options: {
|
|
9
|
+
container: string;
|
|
10
|
+
transport: MessagingCloudKitTransport;
|
|
11
|
+
randomId: () => string;
|
|
12
|
+
openSettings: () => Promise<void>;
|
|
13
|
+
retainedSnapshots?: number;
|
|
14
|
+
}): MessagingBackupCloud;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { MessagingBackupError, withMessagingDeadline } from '@robono/messaging';
|
|
2
|
+
import { encodeBackupBase64, decodeBackupBase64 } from './backup-base64.js';
|
|
3
|
+
const valid = (scope, snapshot, part) => {
|
|
4
|
+
if (!/^[a-f0-9]{64}$/.test(scope) || snapshot !== undefined && !/^[a-f0-9]{32}$/.test(snapshot) || part !== undefined && !/^(manifest|protection|commit|\d{1,6})$/.test(part))
|
|
5
|
+
throw new MessagingBackupError('invalid_backup');
|
|
6
|
+
};
|
|
7
|
+
const limit = (part) => part === 'manifest' ? 16 * 1024 * 1024 + 28 : ['commit', 'protection'].includes(part) ? 8192 : 4 * 1024 * 1024 + 28;
|
|
8
|
+
/** Private CloudKit adapter. The native transport resolves writes/deletes only
|
|
9
|
+
* after Apple's server completion, not when a CKAsset file is staged locally. */
|
|
10
|
+
export function createCloudKitMessagingBackupCloud(options) {
|
|
11
|
+
if (!/^iCloud\.[A-Za-z0-9.-]{1,180}$/.test(options.container))
|
|
12
|
+
throw new MessagingBackupError('unavailable');
|
|
13
|
+
const retained = options.retainedSnapshots ?? 2;
|
|
14
|
+
if (!Number.isInteger(retained) || retained < 2 || retained > 10)
|
|
15
|
+
throw new MessagingBackupError('invalid_backup');
|
|
16
|
+
const identities = new WeakMap(), snapshots = new Map(), uploads = new Map();
|
|
17
|
+
const invoke = async (input, signal) => {
|
|
18
|
+
const id = options.randomId();
|
|
19
|
+
if (signal.aborted)
|
|
20
|
+
throw new MessagingBackupError('cancelled');
|
|
21
|
+
const abort = () => { void Promise.resolve().then(() => options.transport.cancel(id)).catch(() => { }); };
|
|
22
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
23
|
+
try {
|
|
24
|
+
const result = await options.transport.request(id, { ...input, container: options.container });
|
|
25
|
+
if (signal.aborted)
|
|
26
|
+
throw new MessagingBackupError('cancelled');
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (signal.aborted)
|
|
31
|
+
throw new MessagingBackupError('cancelled');
|
|
32
|
+
if (e instanceof MessagingBackupError)
|
|
33
|
+
throw e;
|
|
34
|
+
throw new MessagingBackupError(['cancelled', 'invalid_backup', 'storage_full', 'unavailable'].includes(e?.code) ? e.code : 'connection');
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
signal.removeEventListener('abort', abort);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const run = async (parent, task, timeout = 120000) => {
|
|
41
|
+
try {
|
|
42
|
+
return await withMessagingDeadline(task, { signal: parent, timeoutMs: timeout });
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
if (parent.aborted)
|
|
46
|
+
throw new MessagingBackupError('cancelled');
|
|
47
|
+
if (e instanceof MessagingBackupError)
|
|
48
|
+
throw e;
|
|
49
|
+
throw new MessagingBackupError('connection');
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const account = async (signal) => {
|
|
53
|
+
const value = await invoke({ action: 'account' }, signal);
|
|
54
|
+
if (value === null)
|
|
55
|
+
return null;
|
|
56
|
+
if (!value || !/^[a-f0-9]{64}$/.test(value.id) || value.provider !== 'icloud')
|
|
57
|
+
throw new MessagingBackupError('connection');
|
|
58
|
+
const previous = identities.get(signal);
|
|
59
|
+
if (previous && previous !== value.id)
|
|
60
|
+
throw new MessagingBackupError('connection');
|
|
61
|
+
identities.set(signal, value.id);
|
|
62
|
+
return { id: value.id, label: 'iCloud', provider: 'icloud' };
|
|
63
|
+
};
|
|
64
|
+
const request = async (action, scope, signal, extra = {}) => {
|
|
65
|
+
valid(scope, extra.snapshot, extra.part);
|
|
66
|
+
const owner = await account(signal);
|
|
67
|
+
if (!owner)
|
|
68
|
+
throw new MessagingBackupError('connection');
|
|
69
|
+
if (extra.snapshot) {
|
|
70
|
+
const key = scope + ':' + extra.snapshot, previous = snapshots.get(key);
|
|
71
|
+
if (previous && previous !== owner.id)
|
|
72
|
+
throw new MessagingBackupError('connection');
|
|
73
|
+
snapshots.set(key, owner.id);
|
|
74
|
+
}
|
|
75
|
+
return invoke({ ...extra, action, scope, account: owner.id }, signal);
|
|
76
|
+
};
|
|
77
|
+
const list = async (scope, signal) => {
|
|
78
|
+
const parts = [], seen = new Set(), cursors = new Set();
|
|
79
|
+
let cursor;
|
|
80
|
+
do {
|
|
81
|
+
const result = await request('list', scope, signal, cursor ? { cursor } : {});
|
|
82
|
+
if (!Array.isArray(result?.files) || result.files.length > 200)
|
|
83
|
+
throw new MessagingBackupError('invalid_backup');
|
|
84
|
+
for (const p of result.files) {
|
|
85
|
+
if (typeof p?.snapshot !== 'string' || typeof p?.part !== 'string')
|
|
86
|
+
throw new MessagingBackupError('invalid_backup');
|
|
87
|
+
valid(scope, p.snapshot, p.part);
|
|
88
|
+
if (!Number.isSafeInteger(p.byteSize) || p.byteSize < 0 || p.byteSize > limit(p.part) || !Number.isFinite(p.createdAt) || p.createdAt <= 0)
|
|
89
|
+
throw new MessagingBackupError('invalid_backup');
|
|
90
|
+
const key = p.snapshot + ':' + p.part;
|
|
91
|
+
if (seen.has(key))
|
|
92
|
+
throw new MessagingBackupError('invalid_backup');
|
|
93
|
+
seen.add(key);
|
|
94
|
+
parts.push(p);
|
|
95
|
+
}
|
|
96
|
+
if (parts.length > 100003)
|
|
97
|
+
throw new MessagingBackupError('invalid_backup');
|
|
98
|
+
cursor = result.cursor ?? undefined;
|
|
99
|
+
if (cursor !== undefined) {
|
|
100
|
+
if (typeof cursor !== 'string' || !cursor || cursor.length > 32768 || cursors.has(cursor))
|
|
101
|
+
throw new MessagingBackupError('invalid_backup');
|
|
102
|
+
cursors.add(cursor);
|
|
103
|
+
}
|
|
104
|
+
} while (cursor);
|
|
105
|
+
return parts;
|
|
106
|
+
};
|
|
107
|
+
const read = async (scope, snapshot, part, signal) => {
|
|
108
|
+
const result = await request('read', scope, signal, { snapshot, part });
|
|
109
|
+
if (typeof result?.base64 !== 'string' || result.base64.length > Math.ceil(limit(part) / 3) * 4 || /[^A-Za-z0-9+/=]/.test(result.base64))
|
|
110
|
+
throw new MessagingBackupError('invalid_backup');
|
|
111
|
+
let bytes;
|
|
112
|
+
try {
|
|
113
|
+
bytes = decodeBackupBase64(result.base64, limit(part));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
throw new MessagingBackupError('invalid_backup');
|
|
117
|
+
}
|
|
118
|
+
if (bytes.length > limit(part))
|
|
119
|
+
throw new MessagingBackupError('invalid_backup');
|
|
120
|
+
return bytes;
|
|
121
|
+
};
|
|
122
|
+
const write = async (scope, snapshot, part, bytes, signal) => {
|
|
123
|
+
valid(scope, snapshot, part);
|
|
124
|
+
if (bytes.length > limit(part))
|
|
125
|
+
throw new MessagingBackupError('invalid_backup');
|
|
126
|
+
const key = scope + ':' + snapshot, parts = uploads.get(key) ?? new Map();
|
|
127
|
+
uploads.set(key, parts);
|
|
128
|
+
if (parts.size > 100003 || parts.has(part))
|
|
129
|
+
throw new MessagingBackupError('invalid_backup');
|
|
130
|
+
parts.set(part, { bytes: bytes.length, confirmed: false });
|
|
131
|
+
const result = await request('write', scope, signal, { snapshot, part, base64: encodeBackupBase64(bytes) });
|
|
132
|
+
if (result?.confirmed !== true)
|
|
133
|
+
throw new MessagingBackupError('connection');
|
|
134
|
+
parts.set(part, { bytes: bytes.length, confirmed: true });
|
|
135
|
+
};
|
|
136
|
+
const summary = async (scope, id, signal) => {
|
|
137
|
+
let value;
|
|
138
|
+
try {
|
|
139
|
+
value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(await read(scope, id, 'commit', signal)));
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
if (e instanceof MessagingBackupError)
|
|
143
|
+
throw e;
|
|
144
|
+
throw new MessagingBackupError('invalid_backup');
|
|
145
|
+
}
|
|
146
|
+
if (value?.id !== id || value.encrypted !== true || !Number.isSafeInteger(value.byteSize) || value.byteSize < 28 || !Number.isFinite(value.createdAt) || value.createdAt <= 0 || typeof value.includeVideos !== 'boolean' || value.protection !== undefined && !['password', 'passkey', 'recovery-key'].includes(value.protection))
|
|
147
|
+
throw new MessagingBackupError('invalid_backup');
|
|
148
|
+
return value;
|
|
149
|
+
};
|
|
150
|
+
const remove = async (scope, p, signal) => { if ((await request('delete', scope, signal, { snapshot: p.snapshot, part: p.part }))?.confirmed !== true)
|
|
151
|
+
throw new MessagingBackupError('connection'); };
|
|
152
|
+
const cleanupOrder = (a, b) => order(a) - order(b), order = (p) => p.part === 'commit' ? -1 : ['0', 'manifest'].includes(p.part) ? 1 : 0;
|
|
153
|
+
return {
|
|
154
|
+
account: s => run(s, account), async connect(s) { if (!await run(s, account))
|
|
155
|
+
await options.openSettings(); }, manageStorage: options.openSettings,
|
|
156
|
+
latest: (scope, parent) => run(parent, async (signal) => { const commits = (await list(scope, signal)).filter(p => p.part === 'commit').sort((a, b) => b.createdAt - a.createdAt || b.snapshot.localeCompare(a.snapshot)); return commits.length ? summary(scope, commits[0].snapshot, signal) : null; }),
|
|
157
|
+
read: (scope, id, part, parent) => run(parent, signal => read(scope, id, part, signal)),
|
|
158
|
+
write: (scope, id, part, bytes, parent) => run(parent, signal => write(scope, id, part, bytes, signal)),
|
|
159
|
+
commit: (scope, value, parent) => run(parent, async (signal) => {
|
|
160
|
+
// CloudKit query indexes may lag. Use individual server acknowledgements,
|
|
161
|
+
// never a local file or a query that may omit a just-uploaded part.
|
|
162
|
+
const parts = uploads.get(scope + ':' + value.id);
|
|
163
|
+
if (!parts?.has('manifest') || parts.has('commit') || [...parts.values()].some(p => !p.confirmed) || [...parts.values()].reduce((n, p) => n + p.bytes, 0) !== value.byteSize || (['password', 'passkey'].includes(value.protection ?? '')) !== parts.has('protection'))
|
|
164
|
+
throw new MessagingBackupError('invalid_backup');
|
|
165
|
+
const data = new TextEncoder().encode(JSON.stringify(value));
|
|
166
|
+
await write(scope, value.id, 'commit', data, signal);
|
|
167
|
+
if (JSON.stringify(await summary(scope, value.id, signal)) !== JSON.stringify(value))
|
|
168
|
+
throw new MessagingBackupError('invalid_backup');
|
|
169
|
+
snapshots.delete(scope + ':' + value.id);
|
|
170
|
+
uploads.delete(scope + ':' + value.id);
|
|
171
|
+
}),
|
|
172
|
+
async discard(scope, id) { const key = scope + ':' + id; if (!snapshots.has(key))
|
|
173
|
+
return; await run(new AbortController().signal, async (signal) => { const known = uploads.get(key); const parts = known ? [...known].map(([part, p]) => ({ snapshot: id, part, byteSize: p.bytes, createdAt: Date.now() })) : (await list(scope, signal)).filter(p => p.snapshot === id); for (const p of parts.sort(cleanupOrder))
|
|
174
|
+
await remove(scope, p, signal); snapshots.delete(key); uploads.delete(key); }); },
|
|
175
|
+
maintain: (scope, parent) => run(parent, async (signal) => {
|
|
176
|
+
const all = await list(scope, signal), commits = all.filter(p => p.part === 'commit').sort((a, b) => b.createdAt - a.createdAt), keep = new Set(commits.slice(0, retained).map(p => p.snapshot));
|
|
177
|
+
for (const id of keep)
|
|
178
|
+
await summary(scope, id, signal);
|
|
179
|
+
let remaining = 200;
|
|
180
|
+
for (const id of [...new Set(all.map(p => p.snapshot))].filter(id => !keep.has(id)).slice(0, 20)) {
|
|
181
|
+
const parts = all.filter(p => p.snapshot === id);
|
|
182
|
+
if (uploads.has(scope + ':' + id) || parts.some(p => p.createdAt > Date.now() - 7 * 86400000))
|
|
183
|
+
continue;
|
|
184
|
+
for (const p of parts.sort(cleanupOrder)) {
|
|
185
|
+
if (!remaining--)
|
|
186
|
+
return;
|
|
187
|
+
await remove(scope, p, signal);
|
|
188
|
+
}
|
|
189
|
+
snapshots.delete(scope + ':' + id);
|
|
190
|
+
}
|
|
191
|
+
}, 5000),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -79,7 +79,7 @@ export function ConversationDetails(props) {
|
|
|
79
79
|
}
|
|
80
80
|
useEffect(() => { setMessages([]); setMembers([]); setNext(null); if (tab === 'members' || tab === 'media' && state.sharedMediaAvailable)
|
|
81
81
|
void load(); return () => { ++generation.current; request.current?.abort(); }; }, [client, state.conversationId, tab]);
|
|
82
|
-
const footer = _jsxs(View, { children: [busy && _jsx(ActivityIndicator, { accessibilityLabel: uiText("Loading conversation details"), color: accent
|
|
82
|
+
const footer = _jsxs(View, { style: { minHeight: 48 }, children: [_jsx(View, { pointerEvents: "none", style: { position: "absolute", top: 0, left: 0, right: 0, height: 48, alignItems: "center", justifyContent: "center" }, children: busy && _jsx(ActivityIndicator, { accessibilityLabel: uiText("Loading conversation details"), color: accent }) }), !!error && _jsxs(_Fragment, { children: [_jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, padding: 12 }, children: error }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => void load(!!next), style: { minHeight: 44, justifyContent: 'center' }, children: _jsx(Text, { style: { color: accent }, children: uiText("Try again") }) })] }), next && !error && _jsx(Pressable, { disabled: busy, accessibilityState: { busy }, accessibilityRole: "button", onPress: () => void load(true), style: { minHeight: 48, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: accent, opacity: busy ? 0 : 1 }, children: uiText("Load more") }) })] });
|
|
83
83
|
return _jsx(MessagingPopup, { screen: styleScreen, visible: visible, onDismiss: dismiss, title: leaving ? uiText("Leave group?") : group ? uiText("Group details") : uiText("Contact details"), compact: leaving, closeDisabled: leaving && busy, background: c.background, onClose: () => { if (!leaving || !busy) {
|
|
84
84
|
if (leaving)
|
|
85
85
|
setLeaving(false);
|
package/dist/customization.d.ts
CHANGED
package/dist/delivery-bar.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
/** A two-pixel inside edge
|
|
2
|
+
/** A two-pixel inside edge with short, tapered curves at both bubble corners. */
|
|
3
3
|
export declare function DeliveryBar({ color, topRadius, bottomRadius, roundedStart }: {
|
|
4
4
|
color: string;
|
|
5
5
|
topRadius: number;
|