@robono/messaging-react-native 0.14.0 → 0.15.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.
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import type { ConversationSummary, MessagingAppearance } from '@robono/messaging';
3
+ /** An authorized address-book entry, not a message or a grant of chat access. */
4
+ export interface MessagingDirectoryContact {
5
+ id: string;
6
+ contactId?: string;
7
+ conversationId?: string;
8
+ name: string;
9
+ avatarUrl?: string;
10
+ status: string;
11
+ detail: string;
12
+ /** False keeps the entry visible with its explanation and no composer. */
13
+ available: boolean;
14
+ }
15
+ export interface MessagingDirectoryOptions {
16
+ directory?: readonly MessagingDirectoryContact[];
17
+ /** Recheck permission on your server and return the authorized conversation.
18
+ * Honor cancellation when the account, directory entry or screen changes. */
19
+ onOpenDirectoryContact?: (contact: MessagingDirectoryContact, signal: AbortSignal) => Promise<ConversationSummary>;
20
+ }
21
+ export declare function directoryWithoutChats(directory: readonly MessagingDirectoryContact[], chats: readonly ConversationSummary[], query?: string): MessagingDirectoryContact[];
22
+ export declare function MessagingDirectoryRow({ contact, appearance, onPress }: {
23
+ contact: MessagingDirectoryContact;
24
+ appearance: MessagingAppearance;
25
+ onPress: () => void;
26
+ }): React.JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Image, Pressable, View } from 'react-native';
3
+ import { Text } from './typography.js';
4
+ export function directoryWithoutChats(directory, chats, query = '') {
5
+ const ids = new Set(chats.map(c => c.id)), people = new Set(chats.filter(c => c.kind !== 'group').map(c => c.contactId)), seen = new Set(), term = query.trim().toLocaleLowerCase();
6
+ return directory.filter(c => {
7
+ if (!c.id || seen.has(c.id) || c.conversationId && ids.has(c.conversationId) || c.contactId && people.has(c.contactId))
8
+ return false;
9
+ seen.add(c.id);
10
+ return !term || `${c.name} ${c.status}`.toLocaleLowerCase().includes(term);
11
+ });
12
+ }
13
+ export function MessagingDirectoryRow({ contact, appearance, onPress }) {
14
+ const c = appearance.colors;
15
+ 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: 10, minHeight: 68 }, children: [contact.avatarUrl ? _jsx(Image, { source: { uri: contact.avatarUrl }, style: { width: 40, height: 40, borderRadius: 20 } }) : _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, 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: 16, fontWeight: '700' }, children: contact.name }), _jsx(Text, { numberOfLines: 1, style: { color: c.secondary, marginTop: 3, fontSize: 14 }, children: contact.status })] })] });
16
+ }
@@ -1,3 +1,4 @@
1
+ import type { MessagingDirectoryOptions } from './contact-directory.js';
1
2
  import { createExpoMessengerCalling } from './expo-connected-calling.js';
2
3
  import type { LocationWorkspace } from '@robono/location';
3
4
  import React from 'react';
@@ -113,7 +114,7 @@ export declare function createHostedExpoMessenger(options: Omit<Parameters<typeo
113
114
  availability: MessagingAvailabilityClient | undefined;
114
115
  maps: LocationWorkspace | undefined;
115
116
  }>;
116
- export interface ExpoMessengerProps extends Omit<ExpoMessagingScreenProps, 'contact' | 'renderConversation' | 'onBack'> {
117
+ export interface ExpoMessengerProps extends Omit<ExpoMessagingScreenProps, 'contact' | 'renderConversation' | 'onBack'>, MessagingDirectoryOptions {
117
118
  calling?: ReturnType<typeof createExpoMessengerCalling>;
118
119
  maps?: LocationWorkspace;
119
120
  notifications?: {
@@ -175,5 +175,5 @@ function ExpoMessengerContent({ inbox, contacts = {}, initialConversation, selec
175
175
  const notificationAccount = notifications ? { name: props.account?.name ?? 'Your account', ...props.account, onEnableNotifications: () => notifications.enable() } : props.account;
176
176
  const account = calling?.deviceCheck ? { name: 'Your account', ...notificationAccount, deviceCheck: calling.deviceCheck, renderCallPreview: (stream) => renderNativeCallVideo({ stream, local: true, style: { width: '100%', height: '100%' } }) } : notificationAccount;
177
177
  const contact = selected?.contactId === props.userId ? { name: 'Notes to self' } : selected?.kind === 'group' ? { name: selected.name ?? 'Group' } : contacts[selected?.contactId ?? ''] ?? { name: selected?.contactId ?? 'Chat' };
178
- return _jsxs(View, { style: { flex: 1, minHeight: 0 }, children: [_jsx(MessengerMapsNotice, { error: mapConnection.error, retry: mapConnection.retry }), showMaps && maps ? _jsx(RobonoMaps, { interfaceLocale: mapsLocale, workspace: maps, contacts: contacts, onClose: () => setShowMaps(false) }) : _jsx(ExpoMessagingScreen, { ...props, account: account, contact: contact, participants: props.participants ?? contacts, extras: selected ? props.extras : undefined, callActions: selected && selected.contactId !== props.userId ? { ...autoCalls, ...props.callActions, phoneNumber: contacts[selected.contactId ?? '']?.phoneNumber ?? props.callActions?.phoneNumber } : undefined, onBack: () => { props.client.stop(); setSelected(null); void inbox.refresh().catch(() => { }); }, renderConversation: screen => selected ? _jsx(MessagingCallingScreen, { ...screen, onCall: screen.callActions?.voice, onVideoCall: screen.callActions?.video, callLabel: "Internet call", unansweredCallId: callState.unanswered?.conversationId === selected.id ? callState.unanswered.id : undefined, onDismissCallMessage: calling?.dismissUnanswered }) : _jsxs(MessagingProvider, { ...screen, children: [_jsx(MessagingInbox, { viewMemory: inboxMemory, client: inbox, userId: props.userId, contacts: contacts, companyName: props.companyName, appearance: props.appearance, active: props.active !== false, headerActions: _jsx(MessagingAccountMenu, { onNewConversation: props.onNewConversation, onPublicRooms: inboxState.publicRoomsAvailable ? () => setPublicRooms(true) : undefined, onMaps: mapsAvailable ? () => setShowMaps(true) : undefined, onNewGroup: inboxState.groupCreationAvailable ? () => setNewGroup(true) : undefined }), onSelect: open, onDeleted: id => props.client.forgetConversation(id) }), publicRooms && _jsx(MessagingPublicRooms, { inbox: inbox, accent: (props.appearance ?? inboxState.appearance ?? defaultMessagingSettings().appearance).colors.accent, createRequestId: () => props.client.createForwardId(), onClose: () => setPublicRooms(false), onJoined: (id, name) => { setPublicRooms(false); open(inbox.getSnapshot().conversations.find(c => c.id === id) ?? { id, kind: 'group', name, contactId: null, lastMessage: null, unreadCount: 0, canSend: true }); } }), newGroup && _jsx(MessagingGroupEditor, { client: props.client, inbox: inbox, userId: props.userId, contacts: contacts, groups: inboxState.groups, accent: (props.appearance ?? inboxState.appearance ?? defaultMessagingSettings().appearance).colors.accent, onClose: () => setNewGroup(false), onSaved: (id, name) => { setNewGroup(false); const row = inbox.getSnapshot().conversations.find(c => c.id === id) ?? { id, kind: 'group', name, contactId: null, lastMessage: null, unreadCount: 0, canSend: true }; open(row); } }), props.inboxOverlay] }) }), _jsx(ExpoMessengerCalls, { calling: calling, state: callState })] });
178
+ return _jsxs(View, { style: { flex: 1, minHeight: 0 }, children: [_jsx(MessengerMapsNotice, { error: mapConnection.error, retry: mapConnection.retry }), showMaps && maps ? _jsx(RobonoMaps, { interfaceLocale: mapsLocale, workspace: maps, contacts: contacts, onClose: () => setShowMaps(false) }) : _jsx(ExpoMessagingScreen, { ...props, account: account, contact: contact, participants: props.participants ?? contacts, extras: selected ? props.extras : undefined, callActions: selected && selected.contactId !== props.userId ? { ...autoCalls, ...props.callActions, phoneNumber: contacts[selected.contactId ?? '']?.phoneNumber ?? props.callActions?.phoneNumber } : undefined, onBack: () => { props.client.stop(); setSelected(null); void inbox.refresh().catch(() => { }); }, renderConversation: screen => selected ? _jsx(MessagingCallingScreen, { ...screen, onCall: screen.callActions?.voice, onVideoCall: screen.callActions?.video, callLabel: "Internet call", unansweredCallId: callState.unanswered?.conversationId === selected.id ? callState.unanswered.id : undefined, onDismissCallMessage: calling?.dismissUnanswered }) : _jsxs(MessagingProvider, { ...screen, children: [_jsx(MessagingInbox, { directory: props.directory, onOpenDirectoryContact: props.onOpenDirectoryContact, viewMemory: inboxMemory, client: inbox, userId: props.userId, contacts: contacts, companyName: props.companyName, appearance: props.appearance, active: props.active !== false, headerActions: _jsx(MessagingAccountMenu, { onNewConversation: props.onNewConversation, onPublicRooms: inboxState.publicRoomsAvailable ? () => setPublicRooms(true) : undefined, onMaps: mapsAvailable ? () => setShowMaps(true) : undefined, onNewGroup: inboxState.groupCreationAvailable ? () => setNewGroup(true) : undefined }), onSelect: open, onDeleted: id => props.client.forgetConversation(id) }), publicRooms && _jsx(MessagingPublicRooms, { inbox: inbox, accent: (props.appearance ?? inboxState.appearance ?? defaultMessagingSettings().appearance).colors.accent, createRequestId: () => props.client.createForwardId(), onClose: () => setPublicRooms(false), onJoined: (id, name) => { setPublicRooms(false); open(inbox.getSnapshot().conversations.find(c => c.id === id) ?? { id, kind: 'group', name, contactId: null, lastMessage: null, unreadCount: 0, canSend: true }); } }), newGroup && _jsx(MessagingGroupEditor, { client: props.client, inbox: inbox, userId: props.userId, contacts: contacts, groups: inboxState.groups, accent: (props.appearance ?? inboxState.appearance ?? defaultMessagingSettings().appearance).colors.accent, onClose: () => setNewGroup(false), onSaved: (id, name) => { setNewGroup(false); const row = inbox.getSnapshot().conversations.find(c => c.id === id) ?? { id, kind: 'group', name, contactId: null, lastMessage: null, unreadCount: 0, canSend: true }; open(row); } }), props.inboxOverlay] }) }), _jsx(ExpoMessengerCalls, { calling: calling, state: callState })] });
179
179
  }
package/dist/expo.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './expo-screen.js';
2
2
  export { ExpoMessenger, createExpoMessenger, createHostedExpoMessenger, type ExpoMessengerProps } from './expo-messenger.js';
3
3
  export { MessagingPopup } from './popup.js';
4
4
  export { MessagingConnectionState, type MessagingConnectionStateProps, MessagingSignIn, MessagingPhoneInput, MessagingChoicePicker, type MessagingSignInProps, type MessagingPhoneInputProps, type MessagingChoice, type MessagingChoicePickerProps } from './sign-in.js';
5
+ export type { MessagingDirectoryContact, MessagingDirectoryOptions } from './contact-directory.js';
@@ -2,7 +2,8 @@ import { type InboxViewMemory } from './inbox-view.js';
2
2
  import React from 'react';
3
3
  import type { ConversationSummary, MessagingInboxClient, MessagingAppearance } from '@robono/messaging';
4
4
  /** Main-screen search covers retained messages beyond the current inbox page. */
5
- export declare function InboxMessageSearch({ client, query, appearance, name, chats, onSelect, viewMemory }: {
5
+ export declare function InboxMessageSearch({ client, query, appearance, name, chats, onSelect, viewMemory, directoryHeader }: {
6
+ directoryHeader?: React.ReactNode;
6
7
  viewMemory: InboxViewMemory;
7
8
  client: MessagingInboxClient;
8
9
  query: string;
@@ -5,7 +5,7 @@ import { useRobonoLocale } from './localization.js';
5
5
  import { useEffect, useRef, useState } from 'react';
6
6
  import { ActivityIndicator, FlatList, Pressable, View } from 'react-native';
7
7
  /** Main-screen search covers retained messages beyond the current inbox page. */
8
- export function InboxMessageSearch({ client, query, appearance, name, chats, onSelect, viewMemory }) {
8
+ export function InboxMessageSearch({ client, query, appearance, name, chats, onSelect, viewMemory, directoryHeader }) {
9
9
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
10
10
  const c = appearance.colors, [rows, setRows] = useState([]), [next, setNext] = useState(null), [busy, setBusy] = useState(true), [error, setError] = useState('');
11
11
  const scroll = useInboxScroll(viewMemory, 'search:' + query, rows.length > 0 && !busy, !next);
@@ -61,5 +61,5 @@ export function InboxMessageSearch({ client, query, appearance, name, chats, onS
61
61
  const timer = setTimeout(() => void search(), 300);
62
62
  return () => { clearTimeout(timer); ++generation.current; controller.current?.abort(); };
63
63
  }, [client, query]);
64
- return _jsx(FlatList, { ...scroll, testID: "messaging-inbox-search-results", style: { flex: 1 }, data: rows, keyExtractor: row => row.message.conversationId + ':' + row.message.id, keyboardShouldPersistTaps: "handled", ListHeaderComponent: _jsxs(View, { children: [chats.length > 0 && _jsxs(_Fragment, { children: [_jsx(Text, { style: { paddingHorizontal: 16, paddingVertical: 8, color: c.secondary, fontSize: 14, fontWeight: '600' }, children: uiText("Chats") }), chats.map(chat => _jsx(Pressable, { accessibilityRole: "button", onPress: () => onSelect(chat), style: { minHeight: 48, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: name(chat) }) }, chat.id))] }), _jsx(Text, { style: { paddingHorizontal: 16, paddingVertical: 12, color: c.secondary, fontSize: 14, fontWeight: '600' }, children: uiText("Messages") })] }), ListEmptyComponent: !busy && !error ? _jsx(Text, { style: { padding: 16, color: c.secondary }, children: uiText("No matching messages.") }) : null, renderItem: ({ item }) => _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Message in {value1}: {value2}", { value1: name(item.conversation), value2: item.message.text ?? '' }), onPress: () => onSelect(item.conversation, item.message.id), style: { paddingHorizontal: 16, paddingVertical: 12, gap: 5, borderBottomWidth: 1, borderBottomColor: c.foreground + '16' }, children: [_jsxs(View, { style: { flexDirection: 'row', gap: 8 }, children: [_jsx(Text, { numberOfLines: 1, style: { flex: 1, fontSize: 16, fontWeight: '600', color: c.foreground }, children: name(item.conversation) }), _jsx(Text, { style: { fontSize: 12, color: c.secondary }, children: new Date(item.message.createdAt).toLocaleDateString(uiLocale) })] }), _jsx(Text, { numberOfLines: 3, style: { fontSize: 15, lineHeight: 21, color: c.secondary }, children: item.message.text })] }), ListFooterComponent: _jsxs(View, { children: [busy && _jsx(ActivityIndicator, { accessibilityLabel: uiText("Searching all messages"), color: c.accent, style: { padding: 16 } }), !!error && _jsxs(_Fragment, { children: [_jsx(Text, { accessibilityRole: "alert", style: { padding: 16, color: c.foreground }, children: error }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => void search(rows.length > 0 && !!next), style: { minHeight: 44, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("Try again") }) })] }), next && !busy && !error && _jsx(Pressable, { accessibilityRole: "button", onPress: () => void search(true), style: { minHeight: 48, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("More results") }) })] }) });
64
+ return _jsx(FlatList, { ...scroll, testID: "messaging-inbox-search-results", style: { flex: 1 }, data: rows, keyExtractor: row => row.message.conversationId + ':' + row.message.id, keyboardShouldPersistTaps: "handled", ListHeaderComponent: _jsxs(View, { children: [directoryHeader, chats.length > 0 && _jsxs(_Fragment, { children: [_jsx(Text, { style: { paddingHorizontal: 16, paddingVertical: 8, color: c.secondary, fontSize: 14, fontWeight: '600' }, children: uiText("Chats") }), chats.map(chat => _jsx(Pressable, { accessibilityRole: "button", onPress: () => onSelect(chat), style: { minHeight: 48, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground, fontSize: 16 }, children: name(chat) }) }, chat.id))] }), _jsx(Text, { style: { paddingHorizontal: 16, paddingVertical: 12, color: c.secondary, fontSize: 14, fontWeight: '600' }, children: uiText("Messages") })] }), ListEmptyComponent: !busy && !error ? _jsx(Text, { style: { padding: 16, color: c.secondary }, children: uiText("No matching messages.") }) : null, renderItem: ({ item }) => _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Message in {value1}: {value2}", { value1: name(item.conversation), value2: item.message.text ?? '' }), onPress: () => onSelect(item.conversation, item.message.id), style: { paddingHorizontal: 16, paddingVertical: 12, gap: 5, borderBottomWidth: 1, borderBottomColor: c.foreground + '16' }, children: [_jsxs(View, { style: { flexDirection: 'row', gap: 8 }, children: [_jsx(Text, { numberOfLines: 1, style: { flex: 1, fontSize: 16, fontWeight: '600', color: c.foreground }, children: name(item.conversation) }), _jsx(Text, { style: { fontSize: 12, color: c.secondary }, children: new Date(item.message.createdAt).toLocaleDateString(uiLocale) })] }), _jsx(Text, { numberOfLines: 3, style: { fontSize: 15, lineHeight: 21, color: c.secondary }, children: item.message.text })] }), ListFooterComponent: _jsxs(View, { children: [busy && _jsx(ActivityIndicator, { accessibilityLabel: uiText("Searching all messages"), color: c.accent, style: { padding: 16 } }), !!error && _jsxs(_Fragment, { children: [_jsx(Text, { accessibilityRole: "alert", style: { padding: 16, color: c.foreground }, children: error }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => void search(rows.length > 0 && !!next), style: { minHeight: 44, paddingHorizontal: 16, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("Try again") }) })] }), next && !busy && !error && _jsx(Pressable, { accessibilityRole: "button", onPress: () => void search(true), style: { minHeight: 48, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText("More results") }) })] }) });
65
65
  }
package/dist/inbox.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import { type MessagingDirectoryOptions } from './contact-directory.js';
1
2
  import { type InboxViewMemory } from './inbox-view.js';
2
3
  import React from 'react';
3
4
  import { type MessagingAppearance, type MessagingInboxClient, type ConversationSummary } from '@robono/messaging';
4
- export interface MessagingInboxProps {
5
+ export interface MessagingInboxProps extends MessagingDirectoryOptions {
5
6
  client: MessagingInboxClient;
6
7
  userId: string;
7
8
  contacts?: Record<string, {
@@ -22,4 +23,4 @@ export interface MessagingInboxProps {
22
23
  onDeleted?: (conversationId: string) => Promise<void> | void;
23
24
  }
24
25
  /** Compact Messenger chat rows: avatar, name, last message, time and unread badge. */
25
- export declare function MessagingInbox({ client, userId, contacts, appearance, active, onSelect, onDeleted, companyName, headerActions, searchText, selectedId, query: controlledQuery, onSearchChange, viewMemory }: MessagingInboxProps): React.JSX.Element;
26
+ export declare function MessagingInbox({ client, userId, contacts, appearance, active, onSelect, onDeleted, companyName, headerActions, searchText, selectedId, query: controlledQuery, onSearchChange, viewMemory, directory, onOpenDirectoryContact }: MessagingInboxProps): React.JSX.Element;
package/dist/inbox.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { directoryWithoutChats, MessagingDirectoryRow } from './contact-directory.js';
2
3
  import { createInboxViewMemory, useInboxScroll } from './inbox-view.js';
3
4
  import { MessagingTypography } from './typography.js';
4
5
  import { Text, TextInput } from './typography.js';
@@ -11,7 +12,7 @@ import { AppState, FlatList, Image, Platform, Pressable, ScrollView, View } from
11
12
  import { defaultMessagingSettings } from '@robono/messaging';
12
13
  import { MessagingPopup, MessagingMenuSurface, MessagingPopupHeaderBoundary, messagingPopupColors, messagingPopupBackdrop } from './popup.js';
13
14
  /** Compact Messenger chat rows: avatar, name, last message, time and unread badge. */
14
- export function MessagingInbox({ client, userId, contacts = {}, appearance, active = true, onSelect, onDeleted, companyName, headerActions, searchText, selectedId, query: controlledQuery, onSearchChange, viewMemory }) {
15
+ export function MessagingInbox({ client, userId, contacts = {}, appearance, active = true, onSelect, onDeleted, companyName, headerActions, searchText, selectedId, query: controlledQuery, onSearchChange, viewMemory, directory = [], onOpenDirectoryContact }) {
15
16
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
16
17
  const state = useSyncExternalStore(client.subscribe, client.getSnapshot, client.getSnapshot), design = appearance ?? state.appearance ?? defaultMessagingSettings().appearance, c = design.colors;
17
18
  useEffect(() => { const update = (value) => { if (active && (value === null || value === 'active'))
@@ -25,6 +26,51 @@ export function MessagingInbox({ client, userId, contacts = {}, appearance, acti
25
26
  const scroll = useInboxScroll(memory, 'chats:' + query.trim(), state.conversations.length > 0 && !state.loading, !state.hasMore);
26
27
  const [selected, setSelected] = useState(null), [confirm, setConfirm] = useState(false), [busy, setBusy] = useState(false), [error, setError] = useState('');
27
28
  const title = (row) => row.contactId === userId ? uiText('Notes to self') : row.kind === 'group' ? row.name ?? 'Group' : contacts[row.contactId ?? '']?.name ?? row.contactId ?? 'Chat';
29
+ const [directorySelection, setDirectorySelection] = useState(null), [directoryBusy, setDirectoryBusy] = useState(false), [directoryError, setDirectoryError] = useState('');
30
+ const directoryRequest = useRef(null), directoryRef = useRef(directory);
31
+ directoryRef.current = directory;
32
+ const cancelDirectory = () => { directoryRequest.current?.abort(); directoryRequest.current = null; setDirectoryBusy(false); setDirectorySelection(null); setDirectoryError(''); };
33
+ useEffect(() => { cancelDirectory(); return () => directoryRequest.current?.abort(); }, [client, userId]);
34
+ useEffect(() => { const sub = AppState.addEventListener('change', state => { if (state !== 'active')
35
+ cancelDirectory(); }); return () => sub.remove(); }, []);
36
+ useEffect(() => { if (!active)
37
+ cancelDirectory(); }, [active]);
38
+ useEffect(() => { if (directorySelection) {
39
+ const current = directory.find(c => c.id === directorySelection.id);
40
+ if (!current || current.available !== directorySelection.available || current.contactId !== directorySelection.contactId)
41
+ cancelDirectory();
42
+ } }, [directory, directorySelection]);
43
+ async function openDirectory(entry) {
44
+ directoryRequest.current?.abort();
45
+ setDirectorySelection(entry);
46
+ setDirectoryError('');
47
+ setDirectoryBusy(false);
48
+ if (!entry.available || !onOpenDirectoryContact)
49
+ return;
50
+ const control = new AbortController();
51
+ directoryRequest.current = control;
52
+ setDirectoryBusy(true);
53
+ try {
54
+ const row = await onOpenDirectoryContact(entry, control.signal);
55
+ const current = directoryRef.current.find(c => c.id === entry.id);
56
+ if (control.signal.aborted || !current?.available || current.contactId !== entry.contactId)
57
+ return;
58
+ setDirectorySelection(null);
59
+ onSelect(row);
60
+ }
61
+ catch (e) {
62
+ if (!control.signal.aborted)
63
+ setDirectoryError(e instanceof Error ? e.message : uiText('This conversation is unavailable.'));
64
+ }
65
+ finally {
66
+ if (directoryRequest.current === control) {
67
+ directoryRequest.current = null;
68
+ setDirectoryBusy(false);
69
+ }
70
+ }
71
+ }
72
+ const directoryRows = directoryWithoutChats(directory, state.conversations, query);
73
+ const inboxRows = [...state.conversations.filter(row => !query.trim() || [title(row), row.lastMessage?.text ?? '', searchText?.(row) ?? ''].join(' ').toLocaleLowerCase().includes(query.trim().toLocaleLowerCase())).map(chat => ({ kind: 'chat', chat })), ...directoryRows.map(entry => ({ kind: 'directory', entry }))];
28
74
  const rows = useRef(new Map()), pending = useRef(null);
29
75
  const [menuVisible, setMenuVisible] = useState(false), [confirmVisible, setConfirmVisible] = useState(false), [anchor, setAnchor] = useState({ x: 12, y: 88 });
30
76
  const openOptions = (row) => { if (!state.inboxActionsAvailable)
@@ -61,7 +107,10 @@ export function MessagingInbox({ client, userId, contacts = {}, appearance, acti
61
107
  } }
62
108
  const preview = (row) => { const m = row.lastMessage; if (!m)
63
109
  return 'No messages yet'; const text = m.kind === 'text' ? m.text ?? '' : ({ voice: 'Voice message', image: 'Photo', video: 'Video', document: 'Document', poll: 'Poll' }[m.kind] ?? 'Message'); return (m.senderId === userId ? 'You: ' : '') + text; };
64
- return _jsx(MessagingTypography, { appearance: design, children: _jsxs(View, { style: { flex: 1, minHeight: 0, backgroundColor: c.background }, children: [_jsx(MessagingPopupHeaderBoundary, { children: _jsxs(View, { testID: "messaging-inbox-header", style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', minHeight: 64, paddingHorizontal: 16, paddingVertical: 8, gap: 8 }, children: [_jsx(Text, { accessibilityRole: "header", numberOfLines: 1, style: { flex: 1, color: c.foreground, fontSize: 20, fontWeight: '700' }, children: companyName ?? design.name }), headerActions] }) }), _jsxs(View, { style: { margin: 12, marginTop: 8, flexDirection: 'row', alignItems: 'center', gap: 8, borderRadius: 10, paddingHorizontal: 10, backgroundColor: c.foreground + '0b' }, children: [_jsx(MessageIcon, { name: "search", size: 20, color: c.secondary }), _jsx(TextInput, { accessibilityLabel: uiText("Search chats"), placeholder: state.globalSearchAvailable ? uiText("Search chats and messages") : uiText("Search chats"), placeholderTextColor: c.secondary, value: query, onChangeText: setQuery, maxLength: 200, autoCapitalize: "none", autoCorrect: false, style: { flex: 1, minHeight: 44, color: c.foreground, fontSize: 16 } }), !!query && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Clear chat search"), onPress: () => setQuery(''), style: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "close", size: 20, color: c.secondary }) })] }), state.error && _jsxs(View, { style: { padding: 12 }, children: [_jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground }, children: state.error }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => void client.refresh().catch(() => { }), children: _jsx(Text, { style: { color: c.accent, paddingVertical: 8 }, children: uiText("Try again") }) })] }), query.trim() && state.globalSearchAvailable ? _jsx(InboxMessageSearch, { viewMemory: memory, client: client, query: query.trim(), appearance: design, name: title, chats: state.conversations.filter(row => title(row).toLocaleLowerCase().includes(query.trim().toLocaleLowerCase())), onSelect: onSelect }, userId) : _jsx(FlatList, { ...scroll, testID: "messaging-inbox-list", data: state.conversations.filter(row => !query.trim() || [title(row), row.lastMessage?.text ?? '', searchText?.(row) ?? ''].join(' ').toLocaleLowerCase().includes(query.trim().toLocaleLowerCase())), keyExtractor: row => row.id, contentContainerStyle: { flexGrow: 1 }, ItemSeparatorComponent: () => _jsx(View, { style: { height: 1, backgroundColor: c.foreground + '12', marginLeft: 64 } }), ListEmptyComponent: _jsx(Text, { style: { padding: 20, textAlign: 'center', color: c.secondary }, children: state.loading ? uiText("Loading chats…") : state.error ? '' : query ? uiText("No matching chats.") : uiText("No chats yet") }), ListFooterComponent: state.hasMore ? _jsx(Pressable, { accessibilityRole: "button", disabled: state.loading, onPress: () => void client.loadMore().catch(() => { }), children: _jsx(Text, { style: { padding: 12, textAlign: 'center', color: c.accent }, children: state.loading ? uiText("Loading…") : uiText("More chats") }) }) : null, renderItem: ({ item }) => {
110
+ return _jsx(MessagingTypography, { appearance: design, children: _jsxs(View, { style: { flex: 1, minHeight: 0, backgroundColor: c.background }, children: [_jsx(MessagingPopupHeaderBoundary, { children: _jsxs(View, { testID: "messaging-inbox-header", style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', minHeight: 64, paddingHorizontal: 16, paddingVertical: 8, gap: 8 }, children: [_jsx(Text, { accessibilityRole: "header", numberOfLines: 1, style: { flex: 1, color: c.foreground, fontSize: 20, fontWeight: '700' }, children: companyName ?? design.name }), headerActions] }) }), _jsxs(View, { style: { margin: 12, marginTop: 8, flexDirection: 'row', alignItems: 'center', gap: 8, borderRadius: 10, paddingHorizontal: 10, backgroundColor: c.foreground + '0b' }, children: [_jsx(MessageIcon, { name: "search", size: 20, color: c.secondary }), _jsx(TextInput, { accessibilityLabel: uiText("Search chats"), placeholder: state.globalSearchAvailable ? uiText("Search chats and messages") : uiText("Search chats"), placeholderTextColor: c.secondary, value: query, onChangeText: setQuery, maxLength: 200, autoCapitalize: "none", autoCorrect: false, style: { flex: 1, minHeight: 44, color: c.foreground, fontSize: 16 } }), !!query && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Clear chat search"), onPress: () => setQuery(''), style: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "close", size: 20, color: c.secondary }) })] }), state.error && _jsxs(View, { style: { padding: 12 }, children: [_jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground }, children: state.error }), _jsx(Pressable, { accessibilityRole: "button", onPress: () => void client.refresh().catch(() => { }), children: _jsx(Text, { style: { color: c.accent, paddingVertical: 8 }, children: uiText("Try again") }) })] }), query.trim() && state.globalSearchAvailable ? _jsx(InboxMessageSearch, { viewMemory: memory, client: client, query: query.trim(), appearance: design, name: title, chats: state.conversations.filter(row => title(row).toLocaleLowerCase().includes(query.trim().toLocaleLowerCase())), onSelect: onSelect, directoryHeader: directoryRows.map(entry => _jsx(MessagingDirectoryRow, { contact: entry, appearance: design, onPress: () => void openDirectory(entry) }, entry.id)) }, userId) : _jsx(FlatList, { ...scroll, testID: "messaging-inbox-list", data: inboxRows, keyExtractor: row => row.kind === 'chat' ? 'chat:' + row.chat.id : 'directory:' + row.entry.id, contentContainerStyle: { flexGrow: 1 }, ItemSeparatorComponent: () => _jsx(View, { style: { height: 1, backgroundColor: c.foreground + '12', marginLeft: 64 } }), ListEmptyComponent: _jsx(Text, { style: { padding: 20, textAlign: 'center', color: c.secondary }, children: state.loading ? uiText("Loading chats…") : state.error ? '' : query ? uiText("No matching chats.") : uiText("No chats yet") }), ListFooterComponent: state.hasMore ? _jsx(Pressable, { accessibilityRole: "button", disabled: state.loading, onPress: () => void client.loadMore().catch(() => { }), children: _jsx(Text, { style: { padding: 12, textAlign: 'center', color: c.accent }, children: state.loading ? uiText("Loading…") : uiText("More chats") }) }) : null, renderItem: ({ item: row }) => {
111
+ if (row.kind === 'directory')
112
+ return _jsx(MessagingDirectoryRow, { contact: row.entry, appearance: design, onPress: () => void openDirectory(row.entry) });
113
+ const item = row.chat;
65
114
  const person = item.contactId ? contacts[item.contactId] : undefined, title = item.contactId === userId ? uiText('Notes to self') : item.kind === 'group' ? item.name ?? 'Group' : person?.name ?? item.contactId ?? 'Chat';
66
115
  const date = item.lastMessage ? new Date(item.lastMessage.createdAt) : null;
67
116
  return _jsxs(Pressable, { ref: node => { if (node)
@@ -69,7 +118,7 @@ export function MessagingInbox({ client, userId, contacts = {}, appearance, acti
69
118
  else
70
119
  rows.current.delete(item.id); }, accessibilityRole: "button", accessibilityState: { selected: item.id === selectedId }, accessibilityLabel: item.unreadCount ? uiText('{name}, {count} unread', { name: title, count: uiNumber(item.unreadCount) }) : title, onPress: () => onSelect(item), onLongPress: () => openOptions(item), accessibilityActions: state.inboxActionsAvailable ? [{ name: 'showOptions', label: uiText("Chat options") }] : [], onAccessibilityAction: e => { if (e.nativeEvent.actionName === 'showOptions')
71
120
  openOptions(item); }, ...(Platform.OS === 'web' ? { onContextMenu: (e) => { e.preventDefault(); openOptions(item); } } : {}), style: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingHorizontal: 12, paddingVertical: 10, minHeight: 68, backgroundColor: item.id === selectedId ? c.accent + '15' : undefined }, children: [person?.avatarUrl ? _jsx(Image, { source: { uri: person.avatarUrl }, style: { width: 40, height: 40, borderRadius: 20 } }) : _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, backgroundColor: c.accent + '20', alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent, fontSize: 18, fontWeight: '700' }, children: title.slice(0, 1).toUpperCase() }) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsxs(Text, { numberOfLines: 1, style: { color: c.foreground, fontSize: 16, fontWeight: '700' }, children: [title, item.muted ? uiText(" · Muted") : ''] }), _jsx(Text, { numberOfLines: 1, style: { color: c.secondary, marginTop: 3, fontSize: 14 }, children: preview(item) })] }), _jsxs(View, { style: { alignItems: 'flex-end', gap: 4 }, children: [_jsx(Text, { style: { color: item.unreadCount ? c.accent : c.secondary, fontSize: 12 }, children: date ? date.toDateString() === new Date().toDateString() ? date.toLocaleTimeString(uiLocale, { hour: 'numeric', minute: '2-digit' }) : date.toLocaleDateString(uiLocale, { month: 'short', day: 'numeric' }) : '' }), item.unreadCount > 0 && _jsx(View, { style: { minWidth: 20, height: 20, borderRadius: 10, borderWidth: 1.5, borderColor: c.accent, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 5 }, children: _jsx(Text, { style: { color: c.accent, fontSize: 10, fontWeight: '900' }, children: item.unreadCount > 99 ? '99+' : item.unreadCount }) })] })] });
72
- } }), selected && _jsxs(_Fragment, { children: [_jsx(MessagingMenuSurface, { visible: menuVisible, onDismiss: dismissed, onClose: () => { if (!busy)
121
+ } }), directorySelection && _jsxs(MessagingPopup, { compact: true, title: directorySelection.name, background: c.background, foreground: c.foreground, onClose: cancelDirectory, children: [_jsx(Text, { accessibilityRole: directoryError ? 'alert' : undefined, style: { color: messagingPopupColors.foreground, fontSize: 16, lineHeight: 23, paddingVertical: 12 }, children: directoryBusy ? uiText('Opening chat…') : directoryError || directorySelection.detail }), !!directoryError && directorySelection.available && _jsx(Pressable, { accessibilityRole: "button", onPress: () => void openDirectory(directorySelection), style: { minHeight: 44, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.accent }, children: uiText('Try again') }) })] }), selected && _jsxs(_Fragment, { children: [_jsx(MessagingMenuSurface, { visible: menuVisible, onDismiss: dismissed, onClose: () => { if (!busy)
73
122
  setSelected(null); }, children: rect => {
74
123
  const width = Math.min(218, rect.width - 24), top = Math.max(12, Math.min(anchor.y - rect.top, rect.height - 124));
75
124
  return _jsxs(View, { style: { flex: 1 }, children: [_jsx(Pressable, { accessibilityLabel: uiText("Close chat options"), onPress: () => { if (!busy)
package/dist/index.d.ts CHANGED
@@ -214,3 +214,4 @@ export declare function MessagingScreen(props: MessagingScreenProps): React.JSX.
214
214
  export { MessagingInbox, type MessagingInboxProps } from './inbox.js';
215
215
  export type { PlaybackProps } from './media-ui.js';
216
216
  export type { InboxViewMemory } from './inbox-view.js';
217
+ export type { MessagingDirectoryContact, MessagingDirectoryOptions } from './contact-directory.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robono/messaging-react-native",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Optional, composable direct and group messaging screens for Robono.",