@robono/messaging-react-native 0.22.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/BRIDGE-MESSENGER.md +72 -10
  2. package/CHANGELOG.md +26 -0
  3. package/README.md +83 -4
  4. package/RobonoMessagingRuntime.podspec +14 -0
  5. package/SBOM.spdx.json +967 -295
  6. package/android/build.gradle +7 -0
  7. package/android/src/main/AndroidManifest.xml +1 -0
  8. package/android/src/main/java/com/robono/messaging/RobonoBackupCrypto.java +27 -0
  9. package/android/src/main/java/com/robono/messaging/RobonoMessagingPackage.java +11 -0
  10. package/app.plugin.cjs +8 -2
  11. package/dist/account.d.ts +4 -1
  12. package/dist/account.js +33 -11
  13. package/dist/attachment-preview.d.ts +11 -10
  14. package/dist/attachment-preview.js +15 -12
  15. package/dist/backup.d.ts +24 -0
  16. package/dist/backup.js +157 -0
  17. package/dist/brand.js +4 -4
  18. package/dist/bubble-design.js +5 -3
  19. package/dist/chat-options.d.ts +5 -1
  20. package/dist/chat-options.js +2 -2
  21. package/dist/contact-directory.d.ts +5 -1
  22. package/dist/contact-directory.js +11 -3
  23. package/dist/conversation-details.js +1 -1
  24. package/dist/delivery-bar.d.ts +2 -1
  25. package/dist/delivery-bar.js +2 -2
  26. package/dist/directory-navigation.d.ts +25 -0
  27. package/dist/directory-navigation.js +69 -0
  28. package/dist/expo-backup-crypto.d.ts +3 -0
  29. package/dist/expo-backup-crypto.js +17 -0
  30. package/dist/expo-backup-passkeys.d.ts +7 -0
  31. package/dist/expo-backup-passkeys.js +22 -0
  32. package/dist/expo-backup-settings.d.ts +4 -0
  33. package/dist/expo-backup-settings.js +41 -0
  34. package/dist/expo-bridge.d.ts +6 -0
  35. package/dist/expo-bridge.js +13 -2
  36. package/dist/expo-inbox-preferences.d.ts +3 -0
  37. package/dist/expo-inbox-preferences.js +9 -0
  38. package/dist/expo-media.js +3 -3
  39. package/dist/expo-messenger.js +10 -5
  40. package/dist/expo-notification-cleanup.js +3 -3
  41. package/dist/expo-notifications.js +7 -3
  42. package/dist/expo-reviews.d.ts +3 -0
  43. package/dist/expo-reviews.js +40 -0
  44. package/dist/expo-screen.d.ts +3 -0
  45. package/dist/expo-screen.js +87 -45
  46. package/dist/expo-thumbnails.d.ts +4 -0
  47. package/dist/expo-thumbnails.js +25 -3
  48. package/dist/expo.d.ts +4 -0
  49. package/dist/expo.js +4 -0
  50. package/dist/forward.js +2 -2
  51. package/dist/header-colors.d.ts +5 -0
  52. package/dist/header-colors.js +7 -0
  53. package/dist/inbox.d.ts +5 -2
  54. package/dist/inbox.js +25 -53
  55. package/dist/index.d.ts +8 -5
  56. package/dist/index.js +78 -36
  57. package/dist/loading-messages.d.ts +5 -0
  58. package/dist/loading-messages.js +10 -0
  59. package/dist/media-access.d.ts +8 -0
  60. package/dist/media-access.js +6 -1
  61. package/dist/media-readiness.d.ts +2 -0
  62. package/dist/media-readiness.js +1 -0
  63. package/dist/playback-reporting.d.ts +8 -0
  64. package/dist/playback-reporting.js +32 -0
  65. package/dist/popup.d.ts +6 -3
  66. package/dist/popup.js +6 -6
  67. package/dist/reviews.d.ts +15 -0
  68. package/dist/reviews.js +204 -0
  69. package/dist/scheduled.js +5 -5
  70. package/ios/RobonoBackupCrypto.m +30 -0
  71. package/package.json +21 -8
@@ -0,0 +1,7 @@
1
+ apply plugin: 'com.android.library'
2
+ android {
3
+ namespace 'com.robono.messaging'
4
+ compileSdkVersion rootProject.ext.has('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
5
+ defaultConfig { minSdkVersion 24 }
6
+ }
7
+ dependencies { implementation 'com.facebook.react:react-android' }
@@ -0,0 +1 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,27 @@
1
+ package com.robono.messaging;
2
+ import com.facebook.react.bridge.*;
3
+ import java.nio.charset.StandardCharsets;
4
+ import java.util.Arrays;
5
+ import java.util.concurrent.ExecutorService;
6
+ import java.util.concurrent.Executors;
7
+ import javax.crypto.SecretKeyFactory;
8
+ import javax.crypto.spec.PBEKeySpec;
9
+ public final class RobonoBackupCrypto extends ReactContextBaseJavaModule {
10
+ private final ExecutorService worker=Executors.newSingleThreadExecutor();
11
+ public RobonoBackupCrypto(ReactApplicationContext context){super(context);}
12
+ @Override public String getName(){return "RobonoBackupCrypto";}
13
+ @Override public void invalidate(){worker.shutdownNow();super.invalidate();}
14
+ @ReactMethod public void passwordKey(String password,String saltHex,double iterations,Promise promise){
15
+ if(iterations!=600000||password.length()>1024||!saltHex.matches("[a-f0-9]{64}")){promise.reject("invalid","Invalid derivation parameters");return;}
16
+ worker.execute(()->{
17
+ char[] chars=password.toCharArray();byte[] salt=new byte[32];byte[] key=null;PBEKeySpec spec=null;
18
+ try{
19
+ byte[] utf8=password.getBytes(StandardCharsets.UTF_8);int length=utf8.length;Arrays.fill(utf8,(byte)0);if(length>1024)throw new IllegalArgumentException();
20
+ for(int i=0;i<32;i++)salt[i]=(byte)Integer.parseInt(saltHex.substring(i*2,i*2+2),16);
21
+ spec=new PBEKeySpec(chars,salt,600000,256);key=SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(spec).getEncoded();
22
+ StringBuilder hex=new StringBuilder(64);for(byte b:key)hex.append(String.format(java.util.Locale.ROOT,"%02x",b&255));promise.resolve(hex.toString());
23
+ }catch(Exception error){promise.reject("derive","Password derivation failed");}
24
+ finally{Arrays.fill(chars,'\0');if(key!=null)Arrays.fill(key,(byte)0);if(spec!=null)spec.clearPassword();}
25
+ });
26
+ }
27
+ }
@@ -0,0 +1,11 @@
1
+ package com.robono.messaging;
2
+ import com.facebook.react.ReactPackage;
3
+ import com.facebook.react.bridge.NativeModule;
4
+ import com.facebook.react.bridge.ReactApplicationContext;
5
+ import com.facebook.react.uimanager.ViewManager;
6
+ import java.util.Collections;
7
+ import java.util.List;
8
+ public final class RobonoMessagingPackage implements ReactPackage {
9
+ @Override public List<NativeModule> createNativeModules(ReactApplicationContext context){return Collections.singletonList(new RobonoBackupCrypto(context));}
10
+ @Override public List<ViewManager> createViewManagers(ReactApplicationContext context){return Collections.emptyList();}
11
+ }
package/app.plugin.cjs CHANGED
@@ -1,5 +1,11 @@
1
- const {withDangerousMod,withInfoPlist,createRunOncePlugin} = require('expo/config-plugins');
2
- module.exports=createRunOncePlugin(config=>{
1
+ const {withDangerousMod,withInfoPlist,withEntitlementsPlist,createRunOncePlugin} = require('expo/config-plugins');
2
+ module.exports=createRunOncePlugin((config,options={})=>{
3
+ if(options.backupPasskeyRpId){
4
+ const rp=options.backupPasskeyRpId;
5
+ if(typeof rp!=='string'||!/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/.test(rp)||rp.length>253)throw Error('backupPasskeyRpId must be a domain name.');
6
+ config=withEntitlementsPlist(config,value=>{value.modResults['com.apple.developer.associated-domains']=[...new Set([...(value.modResults['com.apple.developer.associated-domains']??[]),'webcredentials:'+rp])];return value;});
7
+ }
8
+
3
9
  config=withInfoPlist(config,value=>{
4
10
  value.modResults.UIBackgroundModes=[...new Set([...(value.modResults.UIBackgroundModes??[]),'remote-notification'])];
5
11
  return value;
package/dist/account.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { type CallDeviceCheck } from '@robono/calling-react-native';
2
+ import type { MessagingInboxClient } from '@robono/messaging';
2
3
  import React from 'react';
3
4
  /** Profile and account actions belong to the customer's sign-in system. */
4
5
  export interface MessagingAccount {
6
+ backup?: import('@robono/messaging').MessagingBackupClient;
5
7
  deviceCheck?: CallDeviceCheck;
6
8
  renderCallPreview?: (stream: MediaStream) => React.ReactNode;
7
9
  name: string;
@@ -13,8 +15,9 @@ export interface MessagingAccount {
13
15
  onDeleteAccount?: () => void | Promise<void>;
14
16
  onSignOut?: () => void | Promise<void>;
15
17
  }
16
- export declare function MessagingAccountScreen({ account, companyName, onClose }: {
18
+ export declare function MessagingAccountScreen({ account, companyName, onClose, inbox }: {
17
19
  account?: MessagingAccount;
18
20
  companyName: string;
19
21
  onClose: () => void;
22
+ inbox?: MessagingInboxClient;
20
23
  }): React.JSX.Element;
package/dist/account.js CHANGED
@@ -2,15 +2,34 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { CallDeviceCheckPanel, callDeviceCheckText } from '@robono/calling-react-native';
3
3
  import { Text } from './typography.js';
4
4
  import { useRobonoLocale } from './localization.js';
5
- import { useEffect, useRef, useState } from 'react';
6
- import { AppState, Image, Platform, Pressable, ScrollView, View } from 'react-native';
5
+ import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
6
+ import { AppState, Image, Platform, Pressable, ScrollView, Switch, View } from 'react-native';
7
7
  import { MessagingPopup, useMessagingPopupColors } from './popup.js';
8
8
  import { MessageIcon } from './icons.js';
9
- export function MessagingAccountScreen({ account, companyName, onClose }) {
9
+ import { MessagingBackupPage } from './backup.js';
10
+ /** Keep the page controller and its single popup mounted throughout navigation. */
11
+ function AccountPages({ backup, open, onBack, children }) {
12
+ return backup ? _jsx(MessagingBackupPage, { client: backup, active: open, onClose: onBack, render: children }) : children(null);
13
+ }
14
+ function SelfChatSetting({ inbox }) {
15
+ const state = useSyncExternalStore(inbox.subscribe, inbox.getSnapshot, inbox.getSnapshot), c = useMessagingPopupColors(undefined, 'account'), { text } = useRobonoLocale();
16
+ const [busy, setBusy] = useState(false), [error, setError] = useState('');
17
+ return _jsxs(View, { style: { backgroundColor: c.incoming, borderRadius: 12, padding: 16, gap: 8 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 12 }, children: [_jsxs(View, { style: { flex: 1, gap: 4 }, children: [_jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: text('Show Me in friends') }), _jsx(Text, { style: { color: c.secondary, fontSize: 14 }, children: text('Your private chat stays at the top. Hiding it keeps your messages.') })] }), _jsx(Switch, { accessibilityLabel: text('Show Me in friends'), value: state.showSelf !== false, disabled: busy, onValueChange: async (value) => { setBusy(true); setError(''); try {
18
+ await inbox.setShowSelf(value);
19
+ }
20
+ catch {
21
+ setError(text('The change could not be saved. Please try again.'));
22
+ }
23
+ finally {
24
+ setBusy(false);
25
+ } }, trackColor: { true: c.accent } })] }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground }, children: error })] });
26
+ }
27
+ export function MessagingAccountScreen({ account, companyName, onClose, inbox }) {
10
28
  const deviceColors = useMessagingPopupColors(undefined, 'deviceCheck');
11
29
  const c = useMessagingPopupColors(undefined, 'account');
12
30
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
13
31
  const [checking, setChecking] = useState(false);
32
+ const [backupOpen, setBackupOpen] = useState(false);
14
33
  useEffect(() => { const sub = AppState.addEventListener('change', value => { if (value !== 'active')
15
34
  void account?.deviceCheck?.close(); }); return () => { sub.remove(); void account?.deviceCheck?.close(); }; }, [account?.deviceCheck]);
16
35
  const [busy, setBusy] = useState(false), [error, setError] = useState(''), [visible, setVisible] = useState(true), pending = useRef(null);
@@ -31,12 +50,15 @@ export function MessagingAccountScreen({ account, companyName, onClose }) {
31
50
  finally {
32
51
  setBusy(false);
33
52
  } };
34
- return _jsx(MessagingPopup, { screen: checking ? 'deviceCheck' : 'account', visible: visible, onDismiss: dismissed, title: uiText(checking ? "Check call devices" : "Account"), headerBack: checking, closeLabel: uiText("Close account"), closeDisabled: busy, background: c.background, contentWidth: 640, onClose: () => { if (!busy) {
35
- if (checking) {
36
- void account?.deviceCheck?.close();
37
- setChecking(false);
38
- }
39
- else
40
- onClose();
41
- } }, children: _jsx(ScrollView, { contentContainerStyle: { gap: 16, paddingBottom: 12 }, children: checking && account?.deviceCheck ? _jsx(CallDeviceCheckPanel, { TextComponent: Text, colors: { foreground: deviceColors.foreground, secondary: deviceColors.secondary, controls: deviceColors.incoming }, accent: deviceColors.accent, check: account.deviceCheck, renderVideo: account.renderCallPreview, labels: Object.fromEntries(Object.entries(callDeviceCheckText).map(([key, value]) => [key, uiText(value)])) }) : _jsxs(_Fragment, { children: [_jsxs(View, { style: { backgroundColor: c.incoming, borderRadius: 16, padding: 16, gap: 14 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 14 }, children: [account?.avatarUrl ? _jsx(Image, { source: { uri: account.avatarUrl }, style: { width: 56, height: 56, borderRadius: 28 } }) : _jsx(View, { style: { width: 56, height: 56, borderRadius: 28, backgroundColor: c.incoming, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "person-circle-outline", color: c.foreground, size: 36 }) }), _jsxs(View, { style: { flex: 1, gap: 4 }, children: [_jsx(Text, { style: { color: c.foreground, fontSize: 20, fontWeight: '600' }, children: account?.name ?? uiText("Your account") }), _jsx(Text, { style: { color: c.secondary, fontSize: 14 }, children: companyName })] })] }), account?.phone && _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: account.phone }), account?.email && _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: account.email }), account?.onEditProfile && _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Edit profile"), disabled: busy, onPress: () => begin(account.onEditProfile), style: { minHeight: 44, flexDirection: 'row', alignItems: 'center', gap: 10 }, children: [_jsx(MessageIcon, { name: "edit", color: c.foreground, size: 20 }), _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText("Edit profile") })] })] }), account?.deviceCheck && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Check call devices"), disabled: busy, onPress: () => setChecking(true), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText("Check call devices") }) }), account?.onEnableNotifications && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Enable notifications"), disabled: busy, onPress: () => void run(account.onEnableNotifications), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText("Enable notifications") }) }), account?.onDeleteAccount && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Delete account"), disabled: busy, onPress: () => begin(account.onDeleteAccount), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.danger, fontSize: 16 }, children: uiText("Delete account") }) }), account?.onSignOut && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Sign out"), disabled: busy, onPress: () => begin(account.onSignOut), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText("Sign out") }) }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 15 }, children: error })] }) }) });
53
+ return _jsx(AccountPages, { backup: account?.backup, open: backupOpen, onBack: () => setBackupOpen(false), children: page => _jsxs(MessagingPopup, { form: backupOpen && !!page?.form, screen: checking ? 'deviceCheck' : 'account', visible: visible, onDismiss: dismissed, title: backupOpen && page ? page.title : uiText(checking ? "Check call devices" : "Account"), description: backupOpen ? page?.description : undefined, headerBack: checking || backupOpen, closeLabel: uiText(backupOpen ? (page?.isRoot ? "Back to account" : "Back to chat backup") : "Close account"), closeDisabled: busy, background: c.background, contentWidth: 640, onClose: () => { if (!busy) {
54
+ if (backupOpen && page) {
55
+ page.onClose();
56
+ }
57
+ else if (checking) {
58
+ void account?.deviceCheck?.close();
59
+ setChecking(false);
60
+ }
61
+ else
62
+ onClose();
63
+ } }, children: [_jsx(View, { style: { flex: 1, minHeight: 0, display: backupOpen ? 'none' : 'flex' }, accessibilityElementsHidden: backupOpen, importantForAccessibility: backupOpen ? 'no-hide-descendants' : 'auto', children: _jsx(ScrollView, { contentContainerStyle: { gap: 16, paddingBottom: 12 }, children: checking && account?.deviceCheck ? _jsx(CallDeviceCheckPanel, { TextComponent: Text, colors: { foreground: deviceColors.foreground, secondary: deviceColors.secondary, controls: deviceColors.incoming }, accent: deviceColors.accent, check: account.deviceCheck, renderVideo: account.renderCallPreview, labels: Object.fromEntries(Object.entries(callDeviceCheckText).map(([key, value]) => [key, uiText(value)])) }) : _jsxs(_Fragment, { children: [_jsxs(View, { style: { backgroundColor: c.incoming, borderRadius: 16, padding: 16, gap: 14 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 14 }, children: [account?.avatarUrl ? _jsx(Image, { source: { uri: account.avatarUrl }, style: { width: 56, height: 56, borderRadius: 28 } }) : _jsx(View, { style: { width: 56, height: 56, borderRadius: 28, backgroundColor: c.incoming, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "person-circle-outline", color: c.foreground, size: 36 }) }), _jsxs(View, { style: { flex: 1, gap: 4 }, children: [_jsx(Text, { style: { color: c.foreground, fontSize: 20, fontWeight: '600' }, children: account?.name ?? uiText("Your account") }), _jsx(Text, { style: { color: c.secondary, fontSize: 14 }, children: companyName })] })] }), account?.phone && _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: account.phone }), account?.email && _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: account.email }), account?.onEditProfile && _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Edit profile"), disabled: busy, onPress: () => begin(account.onEditProfile), style: { minHeight: 44, flexDirection: 'row', alignItems: 'center', gap: 10 }, children: [_jsx(MessageIcon, { name: "edit", color: c.foreground, size: 20 }), _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText("Edit profile") })] })] }), inbox && _jsx(SelfChatSetting, { inbox: inbox }), account?.backup && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Chat backup'), onPress: () => setBackupOpen(true), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText('Chat backup') }) }), account?.deviceCheck && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Check call devices"), disabled: busy, onPress: () => setChecking(true), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText("Check call devices") }) }), account?.onEnableNotifications && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Enable notifications"), disabled: busy, onPress: () => void run(account.onEnableNotifications), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText("Enable notifications") }) }), account?.onDeleteAccount && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Delete account"), disabled: busy, onPress: () => begin(account.onDeleteAccount), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.danger, fontSize: 16 }, children: uiText("Delete account") }) }), account?.onSignOut && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Sign out"), disabled: busy, onPress: () => begin(account.onSignOut), style: { backgroundColor: c.incoming, borderRadius: 12, minHeight: 52, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText("Sign out") }) }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 15 }, children: error })] }) }) }), backupOpen && page ? page.content : null] }) });
42
64
  }
@@ -1,18 +1,19 @@
1
1
  import type { MessagingMessage } from '@robono/messaging';
2
- export type AttachmentPreviewLoader = (message: MessagingMessage, options?: {
3
- refresh?: boolean;
4
- }) => Promise<{
2
+ type Preview = {
5
3
  uri?: string;
6
4
  waveform?: number[];
7
- }>;
8
- /** Retry a visible thumbnail a bounded number of times; never keep a failed
9
- * effect dormant forever, and never publish a result from the previous chat. */
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, useRef } from 'react';
1
+ import { useEffect, useState } from 'react';
2
2
  import { AppState } from 'react-native';
3
- /** Retry a visible thumbnail a bounded number of times; never keep a failed
4
- * effect dormant forever, and never publish a result from the previous chat. */
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 loader = useRef(load);
7
- loader.current = load;
8
- const [preview, setPreview] = useState({}), [attempt, setAttempt] = useState(0), [failed, setFailed] = useState(false);
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
- useEffect(() => { setAttempt(0); setPreview({}); }, [message.id, message.conversationId, message.media?.assetId, message.revision]);
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 (!loader.current || !active || message.deleted)
14
+ if (!load || !active || message.deleted) {
15
+ setResult(undefined);
14
16
  return;
17
+ }
15
18
  setFailed(false);
16
- void loader.current(message, { refresh: attempt > 0 }).then(value => { if (!alive)
17
- return; setPreview(value); if (!value.uri && ['image', 'video'].includes(message.kind))
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
- }, [!!load, message.id, message.conversationId, message.media?.assetId, message.revision, message.deleted, attempt, active]);
26
- return { preview, failed, retry, onImageError: () => { setPreview({}); setFailed(true); } };
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,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,157 @@
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 { AppState, 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
+ useEffect(() => { mounted.current = active; if (active)
31
+ void client.refresh();
32
+ else {
33
+ void pending.current?.cancel();
34
+ pending.current = null;
35
+ setRecovery(null);
36
+ setKey('');
37
+ setSaved(false);
38
+ setRestore(false);
39
+ setChoosing(false);
40
+ setLocalError('');
41
+ setProtectionPage(null);
42
+ setPassword('');
43
+ setConfirmPassword('');
44
+ setRestoreMethod(null);
45
+ } return () => { mounted.current = false; void pending.current?.cancel(); pending.current = null; }; }, [client, active]);
46
+ useEffect(() => { const sub = AppState.addEventListener('change', value => { if (value !== 'active') {
47
+ setPassword('');
48
+ setConfirmPassword('');
49
+ void pending.current?.cancel();
50
+ pending.current = null;
51
+ setRecovery(null);
52
+ setKey('');
53
+ setSaved(false);
54
+ } }); return () => sub.remove(); }, []);
55
+ const busy = state.phase !== 'idle', border = c.foreground + '14';
56
+ const card = (children) => _jsx(View, { style: [s.card, { backgroundColor: c.incoming, borderColor: border }], children: children });
57
+ const copy = (value) => _jsx(Text, { style: [s.copy, { color: c.secondary }], children: text(value) });
58
+ const button = (label, onPress, disabled = false, primary = false) => _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: text(label), accessibilityState: { disabled }, disabled: disabled, onPress: onPress, style: [s.button, { backgroundColor: primary ? c.accent : 'transparent', opacity: disabled ? .45 : 1 }], children: _jsx(Text, { style: { color: primary ? messagingContrastInk(c.accent) : c.foreground, fontWeight: '700', fontSize: 14 }, children: text(label) }) });
59
+ const row = (label, detail, action) => _jsxs(Pressable, { accessibilityRole: action ? 'button' : undefined, accessibilityLabel: text(label), disabled: !action || busy, accessibilityState: { disabled: !action || busy }, onPress: action, style: s.row, children: [_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 })] }), action && _jsx(MessageIcon, { name: "chevron-right", color: c.secondary, size: 18 })] });
60
+ // Same compact switch geometry as Chat options; the entire row is a touch target.
61
+ 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
+ const divider = _jsx(View, { style: { height: StyleSheet.hairlineWidth, backgroundColor: border } });
63
+ const prepare = async () => { setLocalError(''); const setup = await client.prepareRecovery(); if (!setup)
64
+ return; if (!mounted.current) {
65
+ await setup.cancel();
66
+ return;
67
+ } pending.current = setup; setRecovery(setup); setSaved(false); };
68
+ const close = () => { if (busy) {
69
+ client.cancel();
70
+ return;
71
+ } if (recovery) {
72
+ void recovery.cancel();
73
+ pending.current = null;
74
+ setRecovery(null);
75
+ setSaved(false);
76
+ }
77
+ else if (protectionPage) {
78
+ setProtectionPage(protectionPage === 'password' ? 'choose' : null);
79
+ setPassword('');
80
+ setConfirmPassword('');
81
+ setLocalError('');
82
+ }
83
+ else if (restore) {
84
+ setRestore(false);
85
+ setKey('');
86
+ setPassword('');
87
+ setRestoreMethod(null);
88
+ }
89
+ else
90
+ onClose(); };
91
+ const confirm = async () => { if (!recovery || !saved)
92
+ return; try {
93
+ await recovery.confirm();
94
+ pending.current = null;
95
+ setRecovery(null);
96
+ setSaved(false);
97
+ setProtectionPage(null);
98
+ }
99
+ catch {
100
+ setLocalError(text('Recovery setup could not finish. Please try again.'));
101
+ } };
102
+ const available = state.availableMethods ?? ['recovery-key'];
103
+ const setup = async (method) => {
104
+ setLocalError('');
105
+ if (method === 'password' && password !== confirmPassword) {
106
+ setLocalError(text('Passwords do not match.'));
107
+ return;
108
+ }
109
+ const value = password;
110
+ setPassword('');
111
+ setConfirmPassword('');
112
+ const result = await client.prepareProtection(method === 'password' ? { method, password: value } : { method });
113
+ if (!result)
114
+ return;
115
+ if (!mounted.current) {
116
+ await result.cancel();
117
+ return;
118
+ }
119
+ pending.current = result;
120
+ try {
121
+ await result.confirm();
122
+ pending.current = null;
123
+ setProtectionPage(null);
124
+ }
125
+ catch {
126
+ setLocalError(text('Backup protection could not be saved. Please try again.'));
127
+ }
128
+ };
129
+ const openRestore = () => { setRestoreMethod(state.lastBackup?.protection ?? 'recovery-key'); setPassword(''); setKey(''); setRestore(true); };
130
+ const method = restoreMethod ?? state.lastBackup?.protection ?? 'recovery-key';
131
+ const restoreBackup = () => {
132
+ const credential = method === 'password' ? { method, password } : method === 'passkey' ? { method } : { method, recoveryKey: key };
133
+ setPassword('');
134
+ setKey('');
135
+ void client.restore(state.encryptionReady && !password && !key && method !== 'passkey' ? undefined : credential).then(ok => { if (ok) {
136
+ setRestore(false);
137
+ setRestoreMethod(null);
138
+ } });
139
+ };
140
+ const field = (label, value, change, newPassword = false) => _jsx(TextInput, { accessibilityLabel: text(label), placeholder: text(label), placeholderTextColor: c.secondary, value: value, onChangeText: value => { change(value); setLocalError(''); }, secureTextEntry: true, autoCorrect: false, autoCapitalize: "none", maxLength: 1024, autoComplete: newPassword ? 'new-password' : 'current-password', editable: !busy, style: [s.input, { color: c.foreground, backgroundColor: c.background, borderColor: border }] });
141
+ const progress = state.progress?.total ? Math.min(100, Math.round(state.progress.completed / state.progress.total * 100)) : null;
142
+ const activity = state.phase === 'uploading' ? 'Backing up…' : state.phase === 'restoring' ? 'Restoring…' : state.phase === 'connecting' ? 'Connecting…' : 'Preparing…';
143
+ const provider = state.account?.provider === 'google' ? 'Google' : state.account?.provider === 'icloud' ? 'iCloud' : text('cloud');
144
+ 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: [_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: state.lastBackup ? formatMessagingDateTime(state.lastBackup.createdAt, { locale, relativeLabels: { today: text('Today'), yesterday: text('Yesterday') } }) : text('Never') }), _jsxs(Text, { style: [s.copy, { color: c.secondary }], children: [text('Size'), ": ", state.lastBackup ? size(state.lastBackup.byteSize) : '—'] })] }), !state.account ? button('Connect backup account', () => void client.connect(), busy, true) : !state.encryptionReady && state.lastBackup ? button('Restore chats', openRestore, busy, true) : !state.encryptionReady ? button('Set up encrypted backup', () => setProtectionPage('choose'), 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.'), state.account && card(_jsxs(_Fragment, { children: [row(state.account.provider === 'google' ? 'Google Account' : state.account.provider === 'icloud' ? 'iCloud account' : 'Backup account', state.account.label, () => void client.connect()), 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())] })), 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)
145
+ 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 }))] })), copy('Automatic backups run when your device and connection allow.'), card(_jsxs(_Fragment, { children: [row('End-to-end encrypted backup', state.encryptionReady ? text(state.protectionMethod === 'password' ? 'On · Password' : state.protectionMethod === 'passkey' ? 'On · Passkey' : 'On · Recovery key') : text('Choose how to protect your backup'), () => setProtectionPage('choose')), state.lastBackup && state.encryptionReady && _jsxs(_Fragment, { children: [divider, row('Restore chats', text('Recover from your last successful backup'), openRestore)] })] }))] }), busy && _jsxs(View, { accessibilityLiveRegion: "polite", style: { gap: 8 }, children: [_jsxs(Text, { style: { color: c.secondary, fontSize: 14 }, children: [text(activity), progress !== null ? ` ${progress}%` : ''] }), (state.phase === 'uploading' || state.phase === 'restoring') && button('Cancel', () => client.cancel())] }), (state.error || localError) && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 14, lineHeight: 20 }, children: localError || text(state.error) }), state.notice && _jsx(Text, { accessibilityLiveRegion: "polite", style: { color: c.secondary, fontSize: 14 }, children: text(state.notice) })] }, recovery ? 'recovery' : protectionPage ?? (restore ? 'restore' : 'backup'));
146
+ 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.' : 'Keep a private backup of your chats and media in your own cloud storage.'), form: restore || protectionPage === 'password', isRoot: !recovery && !restore && !protectionPage, onClose: close, content });
147
+ }
148
+ const s = StyleSheet.create({
149
+ content: { paddingBottom: 16, gap: 12 },
150
+ card: { borderRadius: 8, borderWidth: 1, padding: 16, gap: 10 },
151
+ row: { minHeight: 52, flexDirection: 'row', alignItems: 'center', gap: 12 },
152
+ rowText: { flex: 1, minWidth: 0, gap: 4 },
153
+ label: { fontSize: 14, lineHeight: 20, fontWeight: '700' },
154
+ copy: { fontSize: 13, lineHeight: 18 },
155
+ button: { minHeight: 48, borderRadius: 8, paddingHorizontal: 16, alignItems: 'center', justifyContent: 'center' },
156
+ input: { minHeight: 48, borderWidth: 1, borderRadius: 8, paddingHorizontal: 12, fontSize: 16 },
157
+ });
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(145 / source.width, 38 / source.height) : 1;
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 * 145 / 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]);
31
- return _jsx(View, { testID: "messaging-brand-slot", style: { width: 145, height: 38, flexShrink: 0, alignSelf: 'flex-start', alignItems: settings?.brandAlign === 'left' ? 'flex-start' : settings?.brandAlign === 'center' ? 'center' : 'flex-end', justifyContent: 'flex-start' }, 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 : 145, 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: 145, textAlign: settings?.brandAlign ?? 'right', 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 }) });
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
  }
@@ -1,7 +1,9 @@
1
1
  export function bubbleCorners(appearance, mine, caption = false) {
2
- const radius = appearance.presentation?.bubbleShape === 'square' ? 0 : appearance.presentation?.bubbleShape === 'rounded' ? 16 : 8;
3
- const emphasized = appearance.presentation?.bubbleStyle === 'rounded-corner' ? Math.max(28, radius) : radius;
4
- return { borderTopLeftRadius: radius, borderTopRightRadius: radius, borderBottomLeftRadius: caption ? 0 : mine ? radius : emphasized, borderBottomRightRadius: caption ? 0 : mine ? emphasized : radius };
2
+ // Match the original Messenger: 14px body, 3px sender-side bottom corner.
3
+ const senderCorner = appearance.presentation?.bubbleStyle === 'rounded-corner';
4
+ const radius = appearance.presentation?.bubbleShape === 'square' ? 0 : appearance.presentation?.bubbleShape === 'rounded' ? 16 : senderCorner ? 14 : 8;
5
+ const tail = senderCorner ? Math.min(3, radius) : radius;
6
+ return { borderTopLeftRadius: radius, borderTopRightRadius: radius, borderBottomLeftRadius: caption ? 0 : mine ? radius : tail, borderBottomRightRadius: caption ? 0 : mine ? tail : radius };
5
7
  }
6
8
  export function bubbleDelivery(message, pending, receipts, appearance) {
7
9
  const phase = pending === 'failed' || message.delivery?.state === 'failed' ? 'failed' : pending || message.delivery?.state === 'pending' ? 'sent' : receipts && !!message.readAt ? 'consumed' : 'delivered';
@@ -1,7 +1,11 @@
1
1
  import React from 'react';
2
2
  /** Supplied full Messengers connect these to the authenticated inbox automatically. */
3
3
  export type ConversationActions = import('@robono/messaging').MessagingConversationActions;
4
- export declare function ChatOptions({ actions, privacy, onClose, accent }: {
4
+ export declare function ChatOptions({ actions, privacy, online, onClose, accent }: {
5
+ online?: {
6
+ hidden: boolean;
7
+ set: (hidden: boolean) => Promise<void>;
8
+ };
5
9
  actions?: ConversationActions;
6
10
  privacy?: {
7
11
  enabled: boolean;
@@ -4,7 +4,7 @@ import { Pressable, ScrollView, View } from 'react-native';
4
4
  import { Text } from './typography.js';
5
5
  import { MessagingPopup, useMessagingPopupColors } from './popup.js';
6
6
  import { useRobonoLocale } from './localization.js';
7
- export function ChatOptions({ actions, privacy, onClose, accent }) {
7
+ export function ChatOptions({ actions, privacy, online, onClose, accent }) {
8
8
  const c = useMessagingPopupColors(undefined, 'options');
9
9
  const { text: uiText } = useRobonoLocale();
10
10
  const [busy, setBusy] = useState(false), [error, setError] = useState(''), [confirmDelete, setConfirmDelete] = useState(false);
@@ -21,5 +21,5 @@ export function ChatOptions({ actions, privacy, onClose, accent }) {
21
21
  return _jsx(MessagingPopup, { screen: "options", background: c.background, title: uiText(confirmDelete ? 'Delete chat?' : 'Chat options'), compact: confirmDelete, closeDisabled: busy, onClose: () => { if (confirmDelete)
22
22
  setConfirmDelete(false);
23
23
  else
24
- onClose(); }, children: _jsxs(ScrollView, { contentContainerStyle: { gap: 16, paddingBottom: 12 }, children: [confirmDelete ? _jsxs(_Fragment, { children: [_jsx(Text, { style: { color: c.secondary, fontSize: 16, lineHeight: 23 }, children: uiText('This removes the chat and its messages from your history. The other person keeps their copy. New messages can appear again.') }), _jsxs(View, { style: { flexDirection: 'row', gap: 12 }, children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Cancel'), disabled: busy, onPress: () => setConfirmDelete(false), style: { flex: 1, minHeight: 48, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText('Cancel') }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Delete chat'), disabled: busy, onPress: () => void save(async () => { await actions.deleteConversation(); onClose(); }), style: { flex: 1, minHeight: 48, borderRadius: 12, backgroundColor: '#b72d34', alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: '#fff', fontSize: 16, fontWeight: '600' }, children: uiText('Delete chat') }) })] })] }) : _jsxs(_Fragment, { children: [actions?.setMuted && row(uiText('Mute notifications'), actions.muted, () => actions.setMuted(!actions.muted)), privacy && row(uiText('Privacy Lens'), privacy.enabled, () => privacy.set(!privacy.enabled)), actions?.deleteConversation && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Delete chat'), onPress: () => setConfirmDelete(true), style: { minHeight: 48, justifyContent: 'center' }, children: _jsx(Text, { style: { color: '#ff8282', fontSize: 17 }, children: uiText('Delete chat') }) })] }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground }, children: error })] }) });
24
+ onClose(); }, children: _jsxs(ScrollView, { contentContainerStyle: { gap: 16, paddingBottom: 12 }, children: [confirmDelete ? _jsxs(_Fragment, { children: [_jsx(Text, { style: { color: c.secondary, fontSize: 16, lineHeight: 23 }, children: uiText('This removes the chat and its messages from your history. The other person keeps their copy. New messages can appear again.') }), _jsxs(View, { style: { flexDirection: 'row', gap: 12 }, children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Cancel'), disabled: busy, onPress: () => setConfirmDelete(false), style: { flex: 1, minHeight: 48, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: uiText('Cancel') }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Delete chat'), disabled: busy, onPress: () => void save(async () => { await actions.deleteConversation(); onClose(); }), style: { flex: 1, minHeight: 48, borderRadius: 12, backgroundColor: '#b72d34', alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: '#fff', fontSize: 16, fontWeight: '600' }, children: uiText('Delete chat') }) })] })] }) : _jsxs(_Fragment, { children: [actions?.setMuted && row(uiText('Mute notifications'), actions.muted, () => actions.setMuted(!actions.muted)), online && row(uiText('Hide my online status on all devices'), online.hidden, () => online.set(!online.hidden)), privacy && row(uiText('Privacy Lens'), privacy.enabled, () => privacy.set(!privacy.enabled)), actions?.deleteConversation && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText('Delete chat'), onPress: () => setConfirmDelete(true), style: { minHeight: 48, justifyContent: 'center' }, children: _jsx(Text, { style: { color: '#ff8282', fontSize: 17 }, children: uiText('Delete chat') }) })] }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground }, children: error })] }) });
25
25
  }
@@ -11,10 +11,14 @@ export interface MessagingDirectoryContact {
11
11
  detail: string;
12
12
  /** False keeps the entry visible with its explanation and no composer. */
13
13
  available: boolean;
14
+ /** Fresh authorized status converted to this device’s clock; expires locally. */
15
+ onlineUntil?: number;
14
16
  }
15
17
  export interface MessagingDirectoryOptions {
16
18
  directory?: readonly MessagingDirectoryContact[];
17
- /** Recheck permission on your server and return the authorized conversation.
19
+ /** The shared Messenger opens the conversation destination immediately.
20
+ * Recheck permission on your server and return its authorized conversation summary
21
+ * directly; do not wait for directory/inbox refreshes before returning.
18
22
  * Honor cancellation when the account, directory entry or screen changes. */
19
23
  onOpenDirectoryContact?: (contact: MessagingDirectoryContact, signal: AbortSignal) => Promise<ConversationSummary>;
20
24
  }
@@ -1,5 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { messagingAvatarStyle, messagingFriendsColors } from '@robono/messaging';
3
+ import { useRobonoLocale } from './localization.js';
4
+ import { useEffect, useMemo, useState } from 'react';
3
5
  import { Image, Pressable, View } from 'react-native';
4
6
  import { Text } from './typography.js';
5
7
  export function directoryWithoutChats(directory, chats, query = '') {
@@ -8,10 +10,16 @@ export function directoryWithoutChats(directory, chats, query = '') {
8
10
  if (!c.id || seen.has(c.id) || c.conversationId && ids.has(c.conversationId) || c.contactId && people.has(c.contactId))
9
11
  return false;
10
12
  seen.add(c.id);
11
- return !term || `${c.name} ${c.status}`.toLocaleLowerCase().includes(term);
13
+ return !term || `${c.name} ${c.available ? '' : c.status}`.toLocaleLowerCase().includes(term);
12
14
  });
13
15
  }
14
16
  export function MessagingDirectoryRow({ contact, appearance, onPress }) {
15
- const c = messagingFriendsColors(appearance), f = appearance.screens?.friends, avatar = messagingAvatarStyle(f?.avatarSize ?? 40, f?.avatarShape), padding = f?.rowSpacing === 'compact' ? 6 : f?.rowSpacing === 'relaxed' ? 16 : 10;
16
- return _jsxs(Pressable, { testID: 'messaging-directory-' + contact.id, accessibilityRole: "button", accessibilityLabel: contact.name + ', ' + contact.status, onPress: onPress, style: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingHorizontal: 12, paddingVertical: padding, minHeight: Math.max(44, avatar.height + padding * 2) }, children: [appearance.screens?.friends?.showAvatars !== false && (contact.avatarUrl ? _jsx(Image, { source: { uri: contact.avatarUrl }, style: { ...avatar } }) : _jsx(View, { style: { ...avatar, backgroundColor: c.accent + '20', alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 18, fontWeight: '700' }, children: contact.name.slice(0, 1).toUpperCase() }) })), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { color: c.foreground, fontSize: f?.nameSize ?? 16, fontWeight: '700' }, children: contact.name }), _jsx(Text, { numberOfLines: f?.previewLines ?? 1, style: { color: c.secondary, marginTop: 3, fontSize: f?.previewSize ?? 14 }, children: contact.status })] })] });
17
+ const { text: uiText } = useRobonoLocale();
18
+ const deadline = useMemo(() => Math.min(contact.onlineUntil ?? 0, Date.now() + 45000), [contact.onlineUntil]);
19
+ const [now, setNow] = useState(Date.now());
20
+ useEffect(() => { setNow(Date.now()); const remaining = Math.min(45000, Math.max(0, deadline - Date.now())); if (!remaining)
21
+ return; const timer = setTimeout(() => setNow(Date.now()), remaining + 1); return () => clearTimeout(timer); }, [deadline]);
22
+ const online = contact.available && Number.isFinite(contact.onlineUntil) && deadline > now;
23
+ const c = messagingFriendsColors(appearance), f = appearance.screens?.friends, avatar = messagingAvatarStyle(f?.avatarSize ?? 48, f?.avatarShape), padding = f?.rowSpacing === 'compact' ? 6 : f?.rowSpacing === 'relaxed' ? 16 : 12;
24
+ return _jsxs(Pressable, { testID: 'messaging-directory-' + contact.id, accessibilityRole: "button", accessibilityLabel: contact.available ? contact.name : contact.name + ', ' + contact.status, onPress: onPress, style: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingHorizontal: 16, paddingVertical: padding, minHeight: Math.max(44, avatar.height + padding * 2) }, children: [appearance.screens?.friends?.showAvatars !== false && (contact.avatarUrl ? _jsx(Image, { source: { uri: contact.avatarUrl }, style: { ...avatar } }) : _jsx(View, { style: { ...avatar, backgroundColor: c.accent + '20', alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 18, fontWeight: '700' }, children: contact.name.slice(0, 1).toUpperCase() }) })), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { color: c.foreground, fontSize: f?.nameSize ?? 16, fontWeight: '700' }, children: contact.name }), online && _jsx(View, { testID: "directory-online", accessibilityLabel: uiText("Online now"), style: { width: 8, height: 8, borderRadius: 4, backgroundColor: '#2e9d63' } }), !contact.available && _jsx(Text, { numberOfLines: f?.previewLines ?? 1, style: { color: c.secondary, marginTop: 3, fontSize: f?.previewSize ?? 14 }, children: contact.status })] })] });
17
25
  }
@@ -12,7 +12,7 @@ function MediaThumbnail({ message, preview }) {
12
12
  useEffect(() => { let live = true; setUri(undefined); if (preview && ['image', 'video'].includes(message.kind))
13
13
  void preview(message).then(value => { if (live)
14
14
  setUri(value.uri); }).catch(() => { }); return () => { live = false; }; }, [message.id, message.media?.assetId, preview]);
15
- return _jsxs(View, { style: { width: 56, height: 56, borderRadius: 8, overflow: 'hidden', alignItems: 'center', justifyContent: 'center', backgroundColor: c.incoming }, children: [uri ? _jsx(Image, { source: { uri }, accessibilityLabel: message.media?.fileName ?? uiText("Attachment"), onError: () => setUri(undefined), style: { width: '100%', height: '100%' } }) : _jsx(MessageIcon, { name: message.kind === 'voice' ? 'mic' : message.kind === 'document' ? 'document' : message.kind === 'video' ? 'video' : 'image', color: c.foreground, size: 24 }), uri && message.kind === 'video' && _jsx(View, { style: { position: 'absolute', backgroundColor: '#0008', padding: 3, borderRadius: 20 }, children: _jsx(MessageIcon, { name: "play", color: "#fff", size: 18 }) })] });
15
+ return _jsxs(View, { style: { width: 56, height: 56, borderRadius: 8, overflow: 'hidden', alignItems: 'center', justifyContent: 'center', backgroundColor: c.incoming }, children: [uri ? _jsx(Image, { source: { uri }, accessibilityLabel: message.media?.fileName ?? uiText("Attachment"), resizeMode: "contain", onError: () => setUri(undefined), style: { width: '100%', height: '100%' } }) : _jsx(MessageIcon, { name: message.kind === 'voice' ? 'mic' : message.kind === 'document' ? 'document' : message.kind === 'video' ? 'video' : 'image', color: c.foreground, size: 24 }), uri && message.kind === 'video' && _jsx(View, { style: { position: 'absolute', backgroundColor: '#0008', padding: 3, borderRadius: 20 }, children: _jsx(MessageIcon, { name: "play", color: "#fff", size: 18 }) })] });
16
16
  }
17
17
  /** Contact/group identity and retained shared media, using Messenger's bounded popup. */
18
18
  export function ConversationDetails(props) {