@robono/messaging-react-native 0.23.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 +27 -0
- package/README.md +157 -4
- package/RobonoMessagingRuntime.podspec +16 -0
- package/SBOM.spdx.json +2709 -813
- package/android/build.gradle +10 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/robono/messaging/RobonoBackupCrypto.java +27 -0
- 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 +11 -0
- package/app.plugin.cjs +22 -3
- 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 +6 -2
- package/dist/account.js +37 -11
- package/dist/attachment-preview.d.ts +11 -10
- package/dist/attachment-preview.js +15 -12
- 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.d.ts +24 -0
- package/dist/backup.js +202 -0
- package/dist/brand.js +4 -4
- package/dist/bubble-design.d.ts +1 -1
- package/dist/bubble-design.js +5 -3
- package/dist/cloudkit-backup.d.ts +14 -0
- package/dist/cloudkit-backup.js +193 -0
- package/dist/contact-directory.d.ts +3 -1
- package/dist/contact-directory.js +3 -3
- package/dist/conversation-details.js +2 -2
- package/dist/customization.d.ts +1 -0
- package/dist/delivery-bar.d.ts +3 -2
- package/dist/delivery-bar.js +7 -4
- package/dist/delivery-notice.d.ts +9 -0
- package/dist/delivery-notice.js +15 -0
- package/dist/directory-navigation.d.ts +25 -0
- package/dist/directory-navigation.js +69 -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-crypto.d.ts +3 -0
- package/dist/expo-backup-crypto.js +17 -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 +14 -0
- package/dist/expo-backup-passkeys.js +46 -0
- package/dist/expo-backup-settings.d.ts +4 -0
- package/dist/expo-backup-settings.js +59 -0
- 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-inbox-preferences.d.ts +3 -0
- package/dist/expo-inbox-preferences.js +9 -0
- package/dist/expo-media.d.ts +2 -0
- package/dist/expo-media.js +18 -24
- package/dist/expo-messenger.d.ts +8 -0
- package/dist/expo-messenger.js +27 -11
- 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 +6 -0
- package/dist/expo-reviews.js +145 -0
- package/dist/expo-screen.js +62 -28
- package/dist/expo-thumbnails.d.ts +6 -2
- package/dist/expo-thumbnails.js +73 -8
- package/dist/expo.d.ts +14 -0
- package/dist/expo.js +12 -0
- package/dist/forward.js +2 -2
- package/dist/header-calls.js +1 -1
- package/dist/header-colors.d.ts +5 -0
- package/dist/header-colors.js +7 -0
- package/dist/inbox-search.d.ts +1 -1
- package/dist/inbox-search.js +7 -3
- package/dist/inbox.d.ts +6 -2
- package/dist/inbox.js +27 -55
- package/dist/index.d.ts +14 -6
- package/dist/index.js +195 -78
- package/dist/linked-apps.d.ts +45 -0
- package/dist/linked-apps.js +40 -0
- package/dist/loading-messages.d.ts +5 -0
- package/dist/loading-messages.js +10 -0
- package/dist/media-access.d.ts +8 -0
- package/dist/media-access.js +6 -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/popup.d.ts +6 -3
- package/dist/popup.js +6 -6
- 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 +19 -0
- package/dist/reviews.js +231 -0
- package/dist/scheduled.js +6 -6
- package/dist/search.js +18 -8
- package/ios/RobonoBackupCloudKit.m +96 -0
- package/ios/RobonoBackupCrypto.m +30 -0
- package/ios/RobonoHistoryStore.m +170 -0
- package/package.json +34 -7
- package/plugin/backup-expiration.cjs +23 -0
- package/plugin/prepare-native.cjs +12 -0
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type { MessagingMessage } from '@robono/messaging';
|
|
2
|
-
|
|
3
|
-
refresh?: boolean;
|
|
4
|
-
}) => Promise<{
|
|
2
|
+
type Preview = {
|
|
5
3
|
uri?: string;
|
|
6
4
|
waveform?: number[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
};
|
|
6
|
+
export type AttachmentPreviewLoader = ((message: MessagingMessage, options?: {
|
|
7
|
+
refresh?: boolean;
|
|
8
|
+
}) => Promise<Preview>) & {
|
|
9
|
+
peek?: (message: MessagingMessage) => Preview | undefined;
|
|
10
|
+
};
|
|
11
|
+
/** Warm previews render synchronously. State is scoped to the loader, message
|
|
12
|
+
* and content revision, so a recycled row never exposes the previous photo. */
|
|
10
13
|
export declare function useAttachmentPreview(message: MessagingMessage, load: AttachmentPreviewLoader | undefined, active?: boolean): {
|
|
11
|
-
preview:
|
|
12
|
-
uri?: string;
|
|
13
|
-
waveform?: number[];
|
|
14
|
-
};
|
|
14
|
+
preview: Preview;
|
|
15
15
|
failed: boolean;
|
|
16
16
|
retry: () => void;
|
|
17
17
|
onImageError: () => void;
|
|
18
18
|
};
|
|
19
|
+
export {};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import { useEffect, useState
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
2
|
import { AppState } from 'react-native';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
3
|
+
/** Warm previews render synchronously. State is scoped to the loader, message
|
|
4
|
+
* and content revision, so a recycled row never exposes the previous photo. */
|
|
5
5
|
export function useAttachmentPreview(message, load, active = true) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
6
|
+
const key = JSON.stringify([message.conversationId, message.id, message.media, message.revision, message.deleted]);
|
|
7
|
+
const [result, setResult] = useState(), [retryState, setRetryState] = useState({ key, load, count: 0 }), [failed, setFailed] = useState(false);
|
|
8
|
+
const attempt = retryState.key === key && retryState.load === load ? retryState.count : 0;
|
|
9
|
+
const setAttempt = (change) => setRetryState(previous => ({ key, load, count: change(previous.key === key && previous.load === load ? previous.count : 0) }));
|
|
9
10
|
const retry = () => setAttempt(n => n + 1);
|
|
10
|
-
|
|
11
|
+
const preview = active && !message.deleted ? (result?.key === key && result.load === load ? result.value : load?.peek?.(message) ?? {}) : {};
|
|
11
12
|
useEffect(() => {
|
|
12
13
|
let alive = true, timer;
|
|
13
|
-
if (!
|
|
14
|
+
if (!load || !active || message.deleted) {
|
|
15
|
+
setResult(undefined);
|
|
14
16
|
return;
|
|
17
|
+
}
|
|
15
18
|
setFailed(false);
|
|
16
|
-
void
|
|
17
|
-
return;
|
|
19
|
+
void load(message, { refresh: attempt > 0 }).then(value => { if (!alive)
|
|
20
|
+
return; setResult({ key, load, value }); if (!value.uri && ['image', 'video'].includes(message.kind))
|
|
18
21
|
missing(); }, () => { if (alive)
|
|
19
22
|
missing(); });
|
|
20
23
|
function missing() { setFailed(true); if (attempt < 2)
|
|
@@ -22,6 +25,6 @@ export function useAttachmentPreview(message, load, active = true) {
|
|
|
22
25
|
const subscription = AppState.addEventListener('change', state => { if (state === 'active' && alive)
|
|
23
26
|
setAttempt(n => n < 3 ? n + 1 : n); });
|
|
24
27
|
return () => { alive = false; clearTimeout(timer); subscription.remove(); };
|
|
25
|
-
}, [
|
|
26
|
-
return { preview, failed, retry, onImageError: () => {
|
|
28
|
+
}, [load, key, attempt, active]);
|
|
29
|
+
return { preview, failed, retry, onImageError: () => { setResult({ key, load, value: {} }); setFailed(true); setAttempt(n => n < 2 ? n + 1 : n); } };
|
|
27
30
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MessagingBackupClient } from '@robono/messaging';
|
|
2
|
+
export interface MessagingBackgroundBackupSession {
|
|
3
|
+
/** The same opaque endpoint/tenant/user scope used by durable history. */
|
|
4
|
+
accountScope: string;
|
|
5
|
+
client: Pick<MessagingBackupClient, 'runScheduled' | 'getSnapshot' | 'dispose'>;
|
|
6
|
+
/** Release any history/network resources owned by this headless session. */
|
|
7
|
+
close(): void;
|
|
8
|
+
}
|
|
9
|
+
export interface MessagingBackgroundBackupOptions {
|
|
10
|
+
/** Restore the host's current authenticated identity, without prompting. */
|
|
11
|
+
accountScope(): Promise<string | null>;
|
|
12
|
+
/** Notify synchronously on sign-out/account replacement, before changing stores. */
|
|
13
|
+
subscribeAccountChange(listener: () => void): () => void;
|
|
14
|
+
/** Create a fresh, exclusively owned client; never return the screen's client.
|
|
15
|
+
* Do not prompt for sign-in or key setup from a background launch. */
|
|
16
|
+
openSession(signal: AbortSignal): Promise<MessagingBackgroundBackupSession | null>;
|
|
17
|
+
/** Bound each OS wake. Defaults to two minutes; never more than four minutes. */
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
/** One current account per wake, with cancellation even during authentication.
|
|
21
|
+
* OS launches and foreground resumes share this runner to avoid duplicate work. */
|
|
22
|
+
export declare function createMessagingBackgroundBackupRunner(options: MessagingBackgroundBackupOptions): {
|
|
23
|
+
run: () => Promise<boolean>;
|
|
24
|
+
cancel: () => void | undefined;
|
|
25
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** One current account per wake, with cancellation even during authentication.
|
|
2
|
+
* OS launches and foreground resumes share this runner to avoid duplicate work. */
|
|
3
|
+
export function createMessagingBackgroundBackupRunner(options) {
|
|
4
|
+
const timeout = options.timeoutMs ?? 120000;
|
|
5
|
+
if (!Number.isFinite(timeout) || timeout < 1 || timeout > 240000)
|
|
6
|
+
throw Error('Invalid background backup deadline.');
|
|
7
|
+
let active = null, abort = null;
|
|
8
|
+
const cancel = () => abort?.abort();
|
|
9
|
+
const run = () => {
|
|
10
|
+
if (active)
|
|
11
|
+
return active;
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
abort = controller;
|
|
14
|
+
let session = null, closed = false;
|
|
15
|
+
const close = () => { if (!session || closed)
|
|
16
|
+
return; closed = true; try {
|
|
17
|
+
session.client.dispose();
|
|
18
|
+
}
|
|
19
|
+
catch { } try {
|
|
20
|
+
session.close();
|
|
21
|
+
}
|
|
22
|
+
catch { } };
|
|
23
|
+
let release = () => { }, timer;
|
|
24
|
+
const cancelled = new Promise(resolve => controller.signal.addEventListener('abort', () => { try {
|
|
25
|
+
close();
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
resolve(false);
|
|
29
|
+
} }, { once: true }));
|
|
30
|
+
const work = (async () => {
|
|
31
|
+
try {
|
|
32
|
+
release = options.subscribeAccountChange(() => controller.abort());
|
|
33
|
+
timer = setTimeout(() => controller.abort(), timeout);
|
|
34
|
+
const scope = await options.accountScope();
|
|
35
|
+
if (!scope || controller.signal.aborted)
|
|
36
|
+
return true;
|
|
37
|
+
session = await options.openSession(controller.signal);
|
|
38
|
+
if (controller.signal.aborted) {
|
|
39
|
+
close();
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (!session)
|
|
43
|
+
return true; // Signed out, locked keychain or no backup setup: no prompt.
|
|
44
|
+
if (session.accountScope !== scope || await options.accountScope() !== scope || controller.signal.aborted) {
|
|
45
|
+
controller.abort();
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
await session.client.runScheduled();
|
|
49
|
+
return !controller.signal.aborted && !session.client.getSnapshot().error;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
active = Promise.race([work, cancelled]).finally(() => {
|
|
56
|
+
if (timer)
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
try {
|
|
59
|
+
release();
|
|
60
|
+
}
|
|
61
|
+
catch { }
|
|
62
|
+
close();
|
|
63
|
+
if (abort === controller) {
|
|
64
|
+
abort = null;
|
|
65
|
+
active = null;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return active;
|
|
69
|
+
};
|
|
70
|
+
return { run, cancel };
|
|
71
|
+
}
|
|
@@ -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.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type MessagingBackupClient } from '@robono/messaging';
|
|
3
|
+
/** Shared native/web account settings. Card/button geometry follows the original
|
|
4
|
+
* Messenger's settingsCard, settingsRow and PrimaryButton, not a separate theme. */
|
|
5
|
+
export interface MessagingBackupPageState {
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
form: boolean;
|
|
9
|
+
isRoot: boolean;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
content: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/** Standalone public screen; Account reuses its own persistent surface below. */
|
|
14
|
+
export declare function MessagingBackupScreen({ client, onClose }: {
|
|
15
|
+
client: MessagingBackupClient;
|
|
16
|
+
onClose: () => void;
|
|
17
|
+
}): React.JSX.Element;
|
|
18
|
+
/** Page state/content without owning a second modal or portal. */
|
|
19
|
+
export declare function MessagingBackupPage({ client, onClose, active, render }: {
|
|
20
|
+
client: MessagingBackupClient;
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
active?: boolean;
|
|
23
|
+
render: (page: MessagingBackupPageState) => React.ReactNode;
|
|
24
|
+
}): React.ReactNode;
|
package/dist/backup.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { ActivityIndicator, AppState, Platform, Pressable, ScrollView, StyleSheet, View } from 'react-native';
|
|
4
|
+
import { formatMessagingDateTime, messagingContrastInk } from '@robono/messaging';
|
|
5
|
+
import { Text, TextInput } from './typography.js';
|
|
6
|
+
import { useRobonoLocale } from './localization.js';
|
|
7
|
+
import { MessageIcon } from './icons.js';
|
|
8
|
+
import { MessagingPopup, useMessagingPopupColors } from './popup.js';
|
|
9
|
+
function size(bytes) {
|
|
10
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
11
|
+
let unit = 0, value = bytes;
|
|
12
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
13
|
+
value /= 1024;
|
|
14
|
+
unit++;
|
|
15
|
+
}
|
|
16
|
+
return `${unit ? value.toFixed(1) : value} ${units[unit]}`;
|
|
17
|
+
}
|
|
18
|
+
const frequencies = [['off', 'Off'], ['daily', 'Daily'], ['weekly', 'Weekly'], ['monthly', 'Monthly']];
|
|
19
|
+
/** Standalone public screen; Account reuses its own persistent surface below. */
|
|
20
|
+
export function MessagingBackupScreen({ client, onClose }) {
|
|
21
|
+
const c = useMessagingPopupColors(undefined, 'account');
|
|
22
|
+
return _jsx(MessagingBackupPage, { client: client, onClose: onClose, render: page => _jsx(MessagingPopup, { screen: "account", form: page.form, title: page.title, description: page.description, headerBack: true, onClose: page.onClose, background: c.background, contentWidth: 640, children: page.content }) });
|
|
23
|
+
}
|
|
24
|
+
/** Page state/content without owning a second modal or portal. */
|
|
25
|
+
export function MessagingBackupPage({ client, onClose, active = true, render }) {
|
|
26
|
+
const state = useSyncExternalStore(client.subscribe, client.getSnapshot, client.getSnapshot), c = useMessagingPopupColors(undefined, 'account'), { text, locale } = useRobonoLocale();
|
|
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
|
+
const [protectionPage, setProtectionPage] = useState(null), [password, setPassword] = useState(''), [confirmPassword, setConfirmPassword] = useState(''), [restoreMethod, setRestoreMethod] = useState(null);
|
|
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]);
|
|
33
|
+
useEffect(() => { mounted.current = active; if (active)
|
|
34
|
+
void client.refresh();
|
|
35
|
+
else {
|
|
36
|
+
void pending.current?.cancel();
|
|
37
|
+
pending.current = null;
|
|
38
|
+
setRecovery(null);
|
|
39
|
+
setKey('');
|
|
40
|
+
setSaved(false);
|
|
41
|
+
setRestore(false);
|
|
42
|
+
setChoosing(false);
|
|
43
|
+
setLocalError('');
|
|
44
|
+
setProtectionPage(null);
|
|
45
|
+
setPassword('');
|
|
46
|
+
setConfirmPassword('');
|
|
47
|
+
setRestoreMethod(null);
|
|
48
|
+
} return () => { mounted.current = false; void pending.current?.cancel(); pending.current = null; }; }, [client, active]);
|
|
49
|
+
useEffect(() => { const sub = AppState.addEventListener('change', value => { if (value === 'background') {
|
|
50
|
+
setVisibleFields({});
|
|
51
|
+
setPassword('');
|
|
52
|
+
setConfirmPassword('');
|
|
53
|
+
void pending.current?.cancel();
|
|
54
|
+
pending.current = null;
|
|
55
|
+
setRecovery(null);
|
|
56
|
+
setKey('');
|
|
57
|
+
setSaved(false);
|
|
58
|
+
} }); return () => sub.remove(); }, []);
|
|
59
|
+
const busy = state.phase !== 'idle', border = c.foreground + '14';
|
|
60
|
+
const card = (children) => _jsx(View, { style: [s.card, { backgroundColor: c.incoming, borderColor: border }], children: children });
|
|
61
|
+
const copy = (value) => _jsx(Text, { style: [s.copy, { color: c.secondary }], children: text(value) });
|
|
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
|
+
};
|
|
71
|
+
// Same compact switch geometry as Chat options; the entire row is a touch target.
|
|
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' } }) })] });
|
|
73
|
+
const divider = _jsx(View, { style: { height: StyleSheet.hairlineWidth, backgroundColor: border } });
|
|
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
|
+
} };
|
|
89
|
+
const close = () => { if (busy) {
|
|
90
|
+
client.cancel();
|
|
91
|
+
return;
|
|
92
|
+
} if (recovery) {
|
|
93
|
+
void recovery.cancel();
|
|
94
|
+
pending.current = null;
|
|
95
|
+
setRecovery(null);
|
|
96
|
+
setSaved(false);
|
|
97
|
+
}
|
|
98
|
+
else if (protectionPage) {
|
|
99
|
+
setProtectionPage(protectionPage === 'password' ? 'choose' : null);
|
|
100
|
+
setPassword('');
|
|
101
|
+
setConfirmPassword('');
|
|
102
|
+
setLocalError('');
|
|
103
|
+
}
|
|
104
|
+
else if (restore) {
|
|
105
|
+
setRestore(false);
|
|
106
|
+
setKey('');
|
|
107
|
+
setPassword('');
|
|
108
|
+
setRestoreMethod(null);
|
|
109
|
+
}
|
|
110
|
+
else
|
|
111
|
+
onClose(); };
|
|
112
|
+
const confirm = async () => { if (!recovery || !saved)
|
|
113
|
+
return; try {
|
|
114
|
+
await recovery.confirm();
|
|
115
|
+
pending.current = null;
|
|
116
|
+
setRecovery(null);
|
|
117
|
+
setSaved(false);
|
|
118
|
+
setProtectionPage(null);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
setLocalError(text('Recovery setup could not finish. Please try again.'));
|
|
122
|
+
} };
|
|
123
|
+
const available = state.availableMethods ?? ['recovery-key'];
|
|
124
|
+
const setup = async (method) => {
|
|
125
|
+
setLocalError('');
|
|
126
|
+
if (method === 'password' && password !== confirmPassword) {
|
|
127
|
+
setLocalError(text('Passwords do not match.'));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const value = password;
|
|
131
|
+
setPendingMethod(method === 'passkey' ? 'Passkey' : 'Password');
|
|
132
|
+
const result = await client.prepareProtection(method === 'password' ? { method, password: value } : { method }).finally(() => setPendingMethod(null));
|
|
133
|
+
if (!result)
|
|
134
|
+
return;
|
|
135
|
+
if (!mounted.current) {
|
|
136
|
+
await result.cancel();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
pending.current = result;
|
|
140
|
+
try {
|
|
141
|
+
await result.confirm();
|
|
142
|
+
pending.current = null;
|
|
143
|
+
setPassword('');
|
|
144
|
+
setConfirmPassword('');
|
|
145
|
+
setProtectionPage(null);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
setLocalError(text('Backup protection could not be saved. Please try again.'));
|
|
149
|
+
}
|
|
150
|
+
};
|
|
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
|
+
};
|
|
170
|
+
const method = restoreMethod ?? state.lastBackup?.protection ?? 'recovery-key';
|
|
171
|
+
const restoreBackup = () => {
|
|
172
|
+
const credential = method === 'password' ? { method, password } : method === 'passkey' ? { method } : { method, recoveryKey: key };
|
|
173
|
+
setPassword('');
|
|
174
|
+
setKey('');
|
|
175
|
+
void client.restore(state.encryptionReady && !password && !key && method !== 'passkey' ? undefined : credential).then(ok => { if (ok) {
|
|
176
|
+
setRestore(false);
|
|
177
|
+
setRestoreMethod(null);
|
|
178
|
+
} });
|
|
179
|
+
};
|
|
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
|
+
};
|
|
184
|
+
const progress = state.progress?.total ? Math.min(100, Math.round(state.progress.completed / state.progress.total * 100)) : null;
|
|
185
|
+
const activity = state.phase === 'uploading' ? 'Backing up…' : state.phase === 'restoring' ? 'Restoring…' : state.phase === 'connecting' ? 'Connecting…' : 'Preparing…';
|
|
186
|
+
const provider = state.account?.provider === 'google' ? 'Google' : state.account?.provider === 'icloud' ? 'iCloud' : text('cloud');
|
|
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 });
|
|
191
|
+
}
|
|
192
|
+
const s = StyleSheet.create({
|
|
193
|
+
content: { paddingBottom: 16, gap: 12 },
|
|
194
|
+
card: { borderRadius: 8, borderWidth: 1, padding: 16, gap: 10 },
|
|
195
|
+
row: { minHeight: 52, flexDirection: 'row', alignItems: 'center', gap: 12 },
|
|
196
|
+
rowText: { flex: 1, minWidth: 0, gap: 4 },
|
|
197
|
+
label: { fontSize: 14, lineHeight: 20, fontWeight: '700' },
|
|
198
|
+
copy: { fontSize: 13, lineHeight: 18 },
|
|
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 },
|
|
201
|
+
input: { minHeight: 48, borderWidth: 1, borderRadius: 8, paddingHorizontal: 12, fontSize: 16 },
|
|
202
|
+
});
|
package/dist/brand.js
CHANGED
|
@@ -6,7 +6,7 @@ import { messagingScreenStyle } from '@robono/messaging';
|
|
|
6
6
|
const sizes = new Map();
|
|
7
7
|
/** The original Messenger reserves 145 × 38 points for branding. No cropping. */
|
|
8
8
|
export function MessagingBrand({ appearance, companyName }) {
|
|
9
|
-
const textRef = useRef(null), [fittedSize, setFittedSize] = useState();
|
|
9
|
+
const textRef = useRef(null), [fittedSize, setFittedSize] = useState(), [slotWidth, setSlotWidth] = useState(145);
|
|
10
10
|
const settings = appearance.screens?.friends, url = settings?.branding === 'name' ? '' : appearance.logoUrl;
|
|
11
11
|
const [source, setSource] = useState({ url: '', width: 0, height: 0, failed: false });
|
|
12
12
|
useEffect(() => { let active = true; if (!url)
|
|
@@ -22,11 +22,11 @@ export function MessagingBrand({ appearance, companyName }) {
|
|
|
22
22
|
apply(size);
|
|
23
23
|
} }, () => { if (active)
|
|
24
24
|
setSource({ url, width: 0, height: 0, failed: true }); }); return () => { active = false; }; }, [url]);
|
|
25
|
-
const ready = source.url === url && source.width > 0, scale = ready ? Math.min(
|
|
25
|
+
const ready = source.url === url && source.width > 0, scale = ready ? Math.min(slotWidth / source.width, 38 / source.height) : 1;
|
|
26
26
|
const mainText = messagingScreenStyle(appearance).typography, fontFamily = messagingFontFamily(settings?.brandFont ?? mainText?.font);
|
|
27
27
|
useEffect(() => { if (Platform.OS !== 'web')
|
|
28
28
|
return; let active = true; const measure = () => { const element = textRef.current; if (!active || !element)
|
|
29
29
|
return; const base = settings?.brandTextSize ?? 24, canvas = document.createElement('canvas'), context = canvas.getContext('2d'); if (!context)
|
|
30
|
-
return; const style = getComputedStyle(element); context.font = `${settings?.brandItalic ?? mainText?.italic ? 'italic ' : ''}${settings?.brandWeight ?? (mainText?.bold === false ? '400' : '700')} ${base * (mainText?.textScale ?? 1)}px ${style.fontFamily}`; const width = context.measureText(companyName ?? appearance.name).width; setFittedSize(Math.max(base * .5, Math.min(base, base *
|
|
31
|
-
return _jsx(View, { testID: "messaging-brand-slot", style: { width: 145, height: 38, flexShrink:
|
|
30
|
+
return; const style = getComputedStyle(element); context.font = `${settings?.brandItalic ?? mainText?.italic ? 'italic ' : ''}${settings?.brandWeight ?? (mainText?.bold === false ? '400' : '700')} ${base * (mainText?.textScale ?? 1)}px ${style.fontFamily}`; const width = context.measureText(companyName ?? appearance.name).width; setFittedSize(Math.max(base * .5, Math.min(base, base * slotWidth / Math.max(1, width)))); }; measure(); void document.fonts?.ready.then(measure); return () => { active = false; }; }, [companyName, appearance.name, url, source.failed, settings?.brandFont, mainText?.font, mainText?.bold, mainText?.textScale, mainText?.italic, settings?.brandItalic, settings?.brandWeight, settings?.brandTextSize, appearance.presentation?.textScale, slotWidth]);
|
|
31
|
+
return _jsx(View, { testID: "messaging-brand-slot", onLayout: event => setSlotWidth(event.nativeEvent.layout.width), style: { width: 145, minWidth: 0, height: 38, flexShrink: 1, alignSelf: 'center', alignItems: (settings?.brandAlign ?? 'left') === 'left' ? 'flex-start' : settings?.brandAlign === 'center' ? 'center' : 'flex-end', justifyContent: 'center' }, children: url && !(source.url === url && source.failed) ? _jsx(Image, { testID: "messaging-brand-logo", accessibilityLabel: appearance.name + ' logo', source: { uri: url }, onError: () => { sizes.delete(url); setSource({ url, width: 0, height: 0, failed: true }); }, resizeMode: "contain", style: { width: ready ? source.width * scale : slotWidth, height: ready ? source.height * scale : 38 } }) : _jsx(Text, { inheritEmphasis: false, ref: textRef, accessibilityRole: "header", accessibilityLabel: companyName ?? appearance.name, numberOfLines: 1, adjustsFontSizeToFit: true, minimumFontScale: 0.5, style: { width: '100%', textAlign: settings?.brandAlign ?? 'left', color: settings?.headerText ?? appearance.colors.foreground, fontFamily, fontSize: Platform.OS === 'web' ? (fittedSize ?? settings?.brandTextSize ?? 24) : (settings?.brandTextSize ?? 24), fontWeight: settings?.brandWeight ?? (mainText?.bold === false ? '400' : '700'), fontStyle: (settings?.brandItalic ?? mainText?.italic) ? 'italic' : 'normal', textDecorationLine: (settings?.brandUnderline ?? mainText?.underline) ? 'underline' : 'none' }, children: companyName ?? appearance.name }) });
|
|
32
32
|
}
|
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
|
};
|