@marktiderman/genesis-chat 0.7.0 → 0.8.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 (51) hide show
  1. package/README.md +132 -3
  2. package/dist/{chunk-GBJ3YI4E.js → chunk-5XYDVUPS.js} +6 -3
  3. package/dist/chunk-5XYDVUPS.js.map +1 -0
  4. package/dist/{chunk-XQ2ULNHV.js → chunk-D4RPOYB7.js} +4 -4
  5. package/dist/chunk-D4RPOYB7.js.map +1 -0
  6. package/dist/{chunk-RYD6WJE5.js → chunk-O2QSBRSH.js} +3 -3
  7. package/dist/{chunk-RYD6WJE5.js.map → chunk-O2QSBRSH.js.map} +1 -1
  8. package/dist/{chunk-A4YJX7KT.js → chunk-ZQFREERR.js} +3 -3
  9. package/dist/{chunk-A4YJX7KT.js.map → chunk-ZQFREERR.js.map} +1 -1
  10. package/dist/{client-DUIG1hum.d.ts → client-DP7rhJ1U.d.ts} +17 -6
  11. package/dist/index.d.ts +4 -4
  12. package/dist/index.js +2 -2
  13. package/dist/native.d.ts +31 -15
  14. package/dist/native.js +74 -328
  15. package/dist/native.js.map +1 -1
  16. package/dist/{outbox-B9NAWQ58.d.ts → outbox-C4LnqpKT.d.ts} +1 -1
  17. package/dist/push.d.ts +2 -2
  18. package/dist/react.d.ts +4 -8
  19. package/dist/react.js +3 -3
  20. package/dist/server.d.ts +1 -1
  21. package/dist/server.js +1 -1
  22. package/dist/{thread-oPra7pkW.d.ts → thread-CSzdqNR_.d.ts} +1 -1
  23. package/dist/web.d.ts +201 -7
  24. package/dist/web.js +580 -56
  25. package/dist/web.js.map +1 -1
  26. package/migrations/0004_genesis_chat_tenants.sql +716 -0
  27. package/migrations/tests/0001_genesis_chat.test.sql +10 -2
  28. package/migrations/tests/0002_genesis_chat_coaching.test.sql +8 -0
  29. package/migrations/tests/0003_genesis_chat_search_threads.test.sql +8 -0
  30. package/migrations/tests/0004_genesis_chat_tenants.test.sql +259 -0
  31. package/package.json +18 -7
  32. package/src/__tests__/core.test.ts +12 -0
  33. package/src/__tests__/web-dock.test.tsx +465 -0
  34. package/src/__tests__/web-photo-viewer.test.tsx +43 -0
  35. package/src/__tests__/web.test.tsx +26 -0
  36. package/src/core/client.ts +5 -1
  37. package/src/core/types.ts +16 -0
  38. package/src/native/__tests__/photo-viewer.test.tsx +24 -5
  39. package/src/native/photo-viewer.tsx +109 -422
  40. package/src/native/thread-screen.tsx +14 -5
  41. package/src/native/use-jump.ts +3 -0
  42. package/src/react/index.tsx +2 -1
  43. package/src/web/attachments.tsx +39 -55
  44. package/src/web/composer.tsx +5 -0
  45. package/src/web/dock.tsx +889 -0
  46. package/src/web/inbox.tsx +5 -0
  47. package/src/web/index.ts +23 -0
  48. package/src/web/memory-client.ts +1 -1
  49. package/src/web/thread.tsx +42 -3
  50. package/dist/chunk-GBJ3YI4E.js.map +0 -1
  51. package/dist/chunk-XQ2ULNHV.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { extractLinks, isHttpsUrl, isSchedulable, scheduleLabel, scheduleQuickPicks, snippetParts, topicKey } from './chunk-BJCE5O7V.js';
2
- export { activityLine, createOutbox, currentActivity, dayLabel, firstUnreadId, itemSender, itemTime, memoryOutboxStore, mergeThread, parseMentions, previewText, releaseObjectUrl, sameDay, startsDay, startsGroup, summarizeReactions, throttle, upsertMessages } from './chunk-A4YJX7KT.js';
3
- export { ALLOWED_EXTENSIONS, CHAT_BUCKET, CHAT_LIMITS, CHAT_SCHEMA, ChatError, MAX_RANGES_PER_DAY, PLAYBACK_RATES, WEEKDAYS, attachmentKindFor, awayLine, awaySummary, conversationTopic, createChatClient, fileExtension, formatDuration, hoursSummary, isAllowedExtension, isAway, isWithinWorkingHours, localClock, minutesOf, namesLine, nextPlaybackRate, normalizeHours, randomId, recordingLimitMs, sendBytes, timeZoneLabel, toAttachment, toAvailability, toLinkPreview, toMessage, toScheduled, toSearchHit, toTopic, untilLabel, userTopic, waveformFromMetering, waveformPeaks } from './chunk-GBJ3YI4E.js';
2
+ export { activityLine, createOutbox, currentActivity, dayLabel, firstUnreadId, itemSender, itemTime, memoryOutboxStore, mergeThread, parseMentions, previewText, releaseObjectUrl, sameDay, startsDay, startsGroup, summarizeReactions, throttle, upsertMessages } from './chunk-ZQFREERR.js';
3
+ export { ALLOWED_EXTENSIONS, CHAT_BUCKET, CHAT_LIMITS, CHAT_SCHEMA, ChatError, MAX_RANGES_PER_DAY, PLAYBACK_RATES, WEEKDAYS, attachmentKindFor, awayLine, awaySummary, conversationTopic, createChatClient, fileExtension, formatDuration, hoursSummary, isAllowedExtension, isAway, isWithinWorkingHours, localClock, minutesOf, namesLine, nextPlaybackRate, normalizeHours, randomId, recordingLimitMs, sendBytes, timeZoneLabel, toAttachment, toAvailability, toLinkPreview, toMessage, toScheduled, toSearchHit, toTopic, untilLabel, userTopic, waveformFromMetering, waveformPeaks } from './chunk-5XYDVUPS.js';
4
4
  //# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map
package/dist/native.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as react from 'react';
2
2
  import { ComponentType, ReactNode, ReactElement } from 'react';
3
3
  import { InboxPageProps, InboxItem, ScreenHeaderProps } from '@marktiderman/genesis-ui-native/layouts';
4
- import { m as ChatInboxItem, h as ChatAttachment, q as ChatMessage, k as ChatConversation, t as ChatRole, P as PendingFile, o as ChatLinkPreview, F as SendInput, x as ChatTopic, T as TopicInput, S as ScheduleInput, W as Weekday, C as ChatAvailability, d as AvailabilityInput, p as ChatMember, a as WorkingHours, u as ChatSearchHit } from './client-DUIG1hum.js';
4
+ import { m as ChatInboxItem, h as ChatAttachment, q as ChatMessage, k as ChatConversation, t as ChatRole, P as PendingFile, o as ChatLinkPreview, F as SendInput, x as ChatTopic, T as TopicInput, S as ScheduleInput, W as Weekday, C as ChatAvailability, d as AvailabilityInput, p as ChatMember, a as WorkingHours, u as ChatSearchHit } from './client-DP7rhJ1U.js';
5
5
  import { ChatAttachmentKind, ChatCardContext, ChatVideoUpload } from './react.js';
6
- import { T as ThreadItem } from './thread-oPra7pkW.js';
6
+ import { T as ThreadItem } from './thread-CSzdqNR_.js';
7
7
  import { ColorValue } from 'react-native';
8
- import { L as LocalFile } from './outbox-B9NAWQ58.js';
8
+ import { L as LocalFile } from './outbox-C4LnqpKT.js';
9
+ import { lightboxPanLimit, lightboxPinchScale, lightboxShouldDismiss, NativeIconName } from '@marktiderman/genesis-ui-native/components';
9
10
  export { CHAT_MARK_READ_ACTION, CHAT_PUSH_CATEGORY, CHAT_REPLY_ACTION, ChatPushCopy, ChatPushData, ChatPushOutboxDeps, ChatPushOutcome, ChatPushPayload, ChatPushPayloadInput, ChatPushResponseLike, NotificationCategoriesLike, PUSH_REPLY_WAIT_MS, chatNotificationActions, chatPath, chatPushCategory, chatPushCopy, chatPushPayload, chatThreadMatch, conversationIdFromData, failedReply, handleChatPushResponse, registerChatNotificationActions, replyClientId, replyClientIdFor } from './push.js';
10
- import { NativeIconName } from '@marktiderman/genesis-ui-native/components';
11
11
  import '@supabase/supabase-js';
12
12
  import '@tanstack/query-core';
13
13
 
@@ -828,6 +828,9 @@ interface UseJumpOptions {
828
828
  onGone: () => void;
829
829
  onError: (e: unknown) => void;
830
830
  }
831
+ /**
832
+ * @deprecated Promoted to genesis-ui-native as `useThreadJump`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
833
+ */
831
834
  declare function useJumpToMessage({ target, rows, loading, has, loadUntil, scrollTo, onStart, onLanded, onGone, onError }: UseJumpOptions): {
832
835
  highlightedId: string | null;
833
836
  jumping: boolean;
@@ -875,7 +878,10 @@ interface ChatThreadScreenSlots {
875
878
  /** Draws the app's own attachment kinds; the card by default. */
876
879
  attachment?: ChatAttachmentSlot | null;
877
880
  }
878
- /** Points from the bottom that still count as "at the bottom" (FlatList, which follows by hand). */
881
+ /**
882
+ * Points from the bottom that still count as "at the bottom" (FlatList, which follows by hand).
883
+ * @deprecated Promoted to genesis-ui-native as `THREAD_AT_BOTTOM_POINTS`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
884
+ */
879
885
  declare const AT_BOTTOM_POINTS = 120;
880
886
  /**
881
887
  * How the thread's list is set up, oldest first and not inverted. FlashList:
@@ -883,12 +889,16 @@ declare const AT_BOTTOM_POINTS = 120;
883
889
  * a screen of it, keeps the first visible row in place when earlier ones load
884
890
  * at the top). FlatList: keeps its place when earlier rows load at the top;
885
891
  * the screen follows new rows itself (`followsByHand`).
892
+ * @deprecated Promoted to genesis-ui-native as `threadListMode` (which anchors FlatList past the header, `minIndexForVisible: 1`). ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
886
893
  */
887
894
  declare function threadListMode(flash: boolean, reducedMotion: boolean): {
888
895
  followsByHand: boolean;
889
896
  maintainVisibleContentPosition: Record<string, unknown>;
890
897
  };
891
- /** Whether a scroll position is at (or near) the bottom of its content. */
898
+ /**
899
+ * Whether a scroll position is at (or near) the bottom of its content.
900
+ * @deprecated Promoted to genesis-ui-native as `threadNearBottom`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
901
+ */
892
902
  declare function nearBottom(m: {
893
903
  contentOffset: {
894
904
  y: number;
@@ -1295,19 +1305,25 @@ interface ChatPhotoViewerProps {
1295
1305
  onClose: () => void;
1296
1306
  testID?: string;
1297
1307
  }
1298
- /** Points pulled down (or dragged, on Android) that close the viewer on release. */
1308
+ /** @deprecated Use `LIGHTBOX_DISMISS_DISTANCE` from `@marktiderman/genesis-ui-native/components`. */
1299
1309
  declare const DISMISS_DISTANCE = 110;
1300
- /** Or a quick flick down, in points per millisecond. */
1310
+ /** @deprecated Use `LIGHTBOX_DISMISS_VELOCITY` from `@marktiderman/genesis-ui-native/components`. */
1301
1311
  declare const DISMISS_VELOCITY = 1.1;
1312
+ /** @deprecated Use `LIGHTBOX_MAX_ZOOM` from `@marktiderman/genesis-ui-native/components`. */
1302
1313
  declare const MAX_ZOOM = 4;
1303
- /** Whether a drag down that ended here closes the viewer. */
1304
- declare function shouldDismiss(dy: number, vy: number): boolean;
1305
- /** The zoom a pinch has reached: from where it started, by how far the fingers spread. */
1306
- declare function pinchScale(startScale: number, startDistance: number, distance: number): number;
1307
- /** How far a zoomed photo may pan before an edge shows, per axis. */
1308
- declare function panLimit(scale: number, size: number): number;
1309
- /** A file already on the phone, which shares and saves without a download. */
1314
+ /** @deprecated Use `lightboxShouldDismiss` from `@marktiderman/genesis-ui-native/components`. */
1315
+ declare const shouldDismiss: typeof lightboxShouldDismiss;
1316
+ /** @deprecated Use `lightboxPinchScale` from `@marktiderman/genesis-ui-native/components`. */
1317
+ declare const pinchScale: typeof lightboxPinchScale;
1318
+ /** @deprecated Use `lightboxPanLimit` from `@marktiderman/genesis-ui-native/components`. */
1319
+ declare const panLimit: typeof lightboxPanLimit;
1320
+ /** A file on the phone (a photo still sending), not a link. */
1310
1321
  declare function isLocalUri(uri: string): boolean;
1322
+ /**
1323
+ * Chat's photos full screen: genesis-ui-native's `NativeLightbox` (pinch and double-tap zoom, pull
1324
+ * down to close, an adjustable pager), with chat's words and its Save and Share buttons when the
1325
+ * app passes `mediaLibrary` and `sharing` to `ChatNativeProvider`.
1326
+ */
1311
1327
  declare function ChatPhotoViewer({ photos, initialIndex, onClose, testID }: ChatPhotoViewerProps): react.JSX.Element;
1312
1328
  /**
1313
1329
  * The photos of the message a tapped photo belongs to, and where it is among them, for
package/dist/native.js CHANGED
@@ -1,12 +1,12 @@
1
- import { cardTitle, attachmentPreview, callAttachmentKind, ChatErrorBoundary, messagePreview } from './chunk-RYD6WJE5.js';
2
- export { attachmentPreview, cardTitle, messagePreview } from './chunk-RYD6WJE5.js';
1
+ import { cardTitle, attachmentPreview, callAttachmentKind, ChatErrorBoundary, messagePreview } from './chunk-O2QSBRSH.js';
2
+ export { attachmentPreview, cardTitle, messagePreview } from './chunk-O2QSBRSH.js';
3
3
  import { isHttpsUrl, extractLinks, scheduleLabel, scheduleQuickPicks, isSchedulable, topicKey, snippetParts } from './chunk-BJCE5O7V.js';
4
- import { useChat, useInbox, usePeople, chatKeys, useScheduled, useAvailability, useTopics, useConversation, usePins, useMessageActions, useFileUrls, useLinkPreviews, useStartConversation, useBroadcast, useSearch } from './chunk-XQ2ULNHV.js';
5
- import { summarizeReactions, parseMentions, startsDay, dayLabel, itemTime, itemSender, startsGroup, activityLine } from './chunk-A4YJX7KT.js';
6
- import { formatDuration, nextPlaybackRate, ChatError, CHAT_LIMITS, fileExtension, isAllowedExtension, attachmentKindFor, awaySummary, WEEKDAYS, minutesOf, waveformFromMetering, recordingLimitMs, CHAT_BUCKET, randomId } from './chunk-GBJ3YI4E.js';
4
+ import { useChat, useInbox, usePeople, chatKeys, useScheduled, useAvailability, useTopics, useConversation, usePins, useMessageActions, useFileUrls, useLinkPreviews, useStartConversation, useBroadcast, useSearch } from './chunk-D4RPOYB7.js';
5
+ import { summarizeReactions, parseMentions, startsDay, dayLabel, itemTime, itemSender, startsGroup, activityLine } from './chunk-ZQFREERR.js';
6
+ import { formatDuration, nextPlaybackRate, ChatError, CHAT_LIMITS, fileExtension, isAllowedExtension, attachmentKindFor, awaySummary, WEEKDAYS, minutesOf, waveformFromMetering, recordingLimitMs, CHAT_BUCKET, randomId } from './chunk-5XYDVUPS.js';
7
7
  export { CHAT_MARK_READ_ACTION, CHAT_PUSH_CATEGORY, CHAT_REPLY_ACTION, PUSH_REPLY_WAIT_MS, chatNotificationActions, chatPath, chatPushCategory, chatPushCopy, chatPushPayload, chatThreadMatch, conversationIdFromData, failedReply, handleChatPushResponse, registerChatNotificationActions, replyClientId, replyClientIdFor } from './chunk-BTG4JWLF.js';
8
8
  import { createContext, memo, useMemo, useState, useCallback, useRef, useContext, useSyncExternalStore, useLayoutEffect, useEffect, useReducer } from 'react';
9
- import { NativeText, NativeAvatar, NativeImage, NativeIcon, NativeButton, NativeProgress, useToast, NativeSheet, NativeDatePicker, NativeTimePicker, NativeListItem, NativeSkeleton, NativeEmptyState, NativeTextarea, NativeSwitch, NativeCombobox, NativeChipGroup, NativeChip, NativeInput, NativeSearchBar, NativeInlineAlert, NativeFullScreenModal, FULL_SCREEN_DARK, useGenesisModules, NativeSheetScrollView, NativeCheckbox, NativeBadge } from '@marktiderman/genesis-ui-native/components';
9
+ import { NativeText, NativeAvatar, NativeImage, NativeIcon, NativeButton, LIGHTBOX_DISMISS_DISTANCE, LIGHTBOX_DISMISS_VELOCITY, LIGHTBOX_MAX_ZOOM, lightboxPanLimit, lightboxPinchScale, lightboxShouldDismiss, NativeProgress, useToast, NativeSheet, NativeDatePicker, NativeTimePicker, NativeListItem, NativeSkeleton, NativeEmptyState, NativeTextarea, NativeSwitch, NativeCombobox, NativeChipGroup, NativeChip, NativeInput, NativeSearchBar, NativeInlineAlert, NativeLightbox, useGenesisModules, NativeSheetScrollView, NativeCheckbox, NativeBadge } from '@marktiderman/genesis-ui-native/components';
10
10
  import { InboxPage, SettingsSubPage, getThreadPageStackOptions, formatInboxTime } from '@marktiderman/genesis-ui-native/layouts';
11
11
  import { Pressable, Animated, PanResponder, View, Linking, useWindowDimensions, ActivityIndicator, AppState, Modal, AccessibilityInfo, ScrollView, FlatList, TextInput, Platform, KeyboardAvoidingView, Alert } from 'react-native';
12
12
  import { useThemeRoles, useReducedMotion } from '@marktiderman/genesis-ui-native/hooks';
@@ -3829,173 +3829,91 @@ function ChatAccessError({ onRetry, retrying = false, testID = "chat-access-erro
3829
3829
  /* @__PURE__ */ jsx(NativeButton, { variant: "outline", size: "lg", onPress: onRetry, loading: retrying, testID: `${testID}-retry`, children: copy.retry })
3830
3830
  ] });
3831
3831
  }
3832
- var DISMISS_DISTANCE = 110;
3833
- var DISMISS_VELOCITY = 1.1;
3834
- var MAX_ZOOM = 4;
3835
- function shouldDismiss(dy, vy) {
3836
- return dy > DISMISS_DISTANCE || dy > 24 && vy > DISMISS_VELOCITY;
3837
- }
3838
- function pinchScale(startScale, startDistance, distance) {
3839
- if (startDistance <= 0) return startScale;
3840
- return Math.min(MAX_ZOOM, Math.max(0.8, startScale * (distance / startDistance)));
3841
- }
3842
- function touchDistance(touches) {
3843
- const [a, b] = touches;
3844
- if (!a || !b) return 0;
3845
- return Math.hypot(a.pageX - b.pageX, a.pageY - b.pageY);
3846
- }
3847
- function panLimit(scale, size) {
3848
- return Math.max(0, (scale - 1) * size / 2);
3849
- }
3832
+ var DISMISS_DISTANCE = LIGHTBOX_DISMISS_DISTANCE;
3833
+ var DISMISS_VELOCITY = LIGHTBOX_DISMISS_VELOCITY;
3834
+ var MAX_ZOOM = LIGHTBOX_MAX_ZOOM;
3835
+ var shouldDismiss = lightboxShouldDismiss;
3836
+ var pinchScale = lightboxPinchScale;
3837
+ var panLimit = lightboxPanLimit;
3850
3838
  function isLocalUri(uri) {
3851
3839
  return /^(file|ph|content|assets-library):/.test(uri);
3852
3840
  }
3853
- var clamp = (v, limit) => Math.max(-limit, Math.min(limit, v));
3854
- var DOUBLE_TAP_MS = 400;
3855
3841
  function ChatPhotoViewer({ photos, initialIndex = 0, onClose, testID = "chat-photo-viewer" }) {
3856
- const open = photos !== null && photos.length > 0;
3857
- return /* @__PURE__ */ jsx(NativeFullScreenModal, { open, onOpenChange: (o) => o ? void 0 : onClose(), tone: "none", testID, children: open ? /* @__PURE__ */ jsx(ViewerBody, { photos, initialIndex: Math.min(Math.max(0, initialIndex), photos.length - 1), onClose, testID }) : null });
3858
- }
3859
- function ViewerBody({ photos, initialIndex, onClose, testID }) {
3860
3842
  const { copy, modules } = useChatNative();
3861
- const { width, height } = useWindowDimensions();
3862
- const insets = useSafeAreaInsets();
3863
- const reducedMotion = useReducedMotion();
3864
3843
  const [index2, setIndex] = useState(initialIndex);
3865
- const [zoomed, setZoomed] = useState(false);
3866
- const [chrome, setChrome] = useState(true);
3867
3844
  const [busy, setBusy] = useState(false);
3868
3845
  const [notice, setNotice] = useState(null);
3869
- const backdrop = useRef(new Animated.Value(1)).current;
3870
- const listRef = useRef(null);
3871
- const photo = photos[index2] ?? photos[0];
3872
- const many = photos.length > 1;
3846
+ const items = useMemo(() => (photos ?? []).map((p) => ({ id: p.key, src: p.uri, alt: p.alt })), [photos]);
3847
+ useEffect(() => {
3848
+ if (!photos) return;
3849
+ setIndex(initialIndex);
3850
+ setNotice(null);
3851
+ setBusy(false);
3852
+ }, [photos, initialIndex]);
3873
3853
  useEffect(() => {
3874
3854
  if (!notice) return;
3875
3855
  const t = setTimeout(() => setNotice(null), 2500);
3876
3856
  return () => clearTimeout(t);
3877
3857
  }, [notice]);
3878
- const goTo = useCallback(
3879
- (i) => {
3880
- if (i < 0 || i >= photos.length) return;
3881
- setIndex(i);
3882
- setZoomed(false);
3883
- listRef.current?.scrollToIndex?.({ index: i, animated: !reducedMotion });
3884
- },
3885
- [photos.length, reducedMotion]
3886
- );
3887
- const onMomentumEnd = useCallback(
3888
- (e) => {
3889
- const i = Math.round(e.nativeEvent.contentOffset.x / Math.max(1, width));
3890
- if (i !== index2 && i >= 0 && i < photos.length) {
3891
- setIndex(i);
3892
- setZoomed(false);
3893
- }
3894
- },
3895
- [width, index2, photos.length]
3896
- );
3858
+ const list = photos ?? [];
3897
3859
  const local = async (uri) => isLocalUri(uri) ? uri : modules.downloadFile ? modules.downloadFile(uri) : null;
3898
- const reachable = Boolean(modules.downloadFile) || photos.every((p) => isLocalUri(p.uri));
3860
+ const reachable = Boolean(modules.downloadFile) || list.every((p) => isLocalUri(p.uri));
3899
3861
  const canShare = Boolean(modules.sharing) && reachable;
3900
3862
  const canSave = Boolean(modules.mediaLibrary) && reachable;
3901
- const run = async (what) => {
3902
- if (busy) return;
3903
- setBusy(true);
3904
- try {
3905
- if (what === "save") {
3906
- const lib = modules.mediaLibrary;
3907
- const permission = await lib.requestPermissionsAsync(true);
3908
- if (!permission.granted) {
3909
- setNotice(copy.photosDenied);
3910
- return;
3863
+ const run = useCallback(
3864
+ async (what, uri) => {
3865
+ if (busy) return;
3866
+ setBusy(true);
3867
+ try {
3868
+ if (what === "save") {
3869
+ const lib = modules.mediaLibrary;
3870
+ const permission = await lib.requestPermissionsAsync(true);
3871
+ if (!permission.granted) {
3872
+ setNotice(copy.photosDenied);
3873
+ return;
3874
+ }
3875
+ const file = await local(uri);
3876
+ if (!file) throw new Error("no copy on the phone");
3877
+ await lib.saveToLibraryAsync(file);
3878
+ haptic(modules.haptics, "send");
3879
+ setNotice(copy.photoSaved);
3880
+ } else {
3881
+ const sharing = modules.sharing;
3882
+ if (!await sharing.isAvailableAsync()) throw new Error("sharing unavailable");
3883
+ const file = await local(uri);
3884
+ if (!file) throw new Error("no copy on the phone");
3885
+ await sharing.shareAsync(file, { dialogTitle: copy.sharePhoto });
3911
3886
  }
3912
- const file = await local(photo.uri);
3913
- if (!file) throw new Error("no copy on the phone");
3914
- await lib.saveToLibraryAsync(file);
3915
- haptic(modules.haptics, "send");
3916
- setNotice(copy.photoSaved);
3917
- } else {
3918
- const sharing = modules.sharing;
3919
- if (!await sharing.isAvailableAsync()) throw new Error("sharing unavailable");
3920
- const file = await local(photo.uri);
3921
- if (!file) throw new Error("no copy on the phone");
3922
- await sharing.shareAsync(file, { dialogTitle: copy.sharePhoto });
3887
+ } catch {
3888
+ haptic(modules.haptics, "error");
3889
+ setNotice(copy.actionFailed);
3890
+ } finally {
3891
+ setBusy(false);
3923
3892
  }
3924
- } catch {
3925
- haptic(modules.haptics, "error");
3926
- setNotice(copy.actionFailed);
3927
- } finally {
3928
- setBusy(false);
3893
+ },
3894
+ [busy, modules, copy]
3895
+ );
3896
+ return /* @__PURE__ */ jsx(
3897
+ NativeLightbox,
3898
+ {
3899
+ open: photos != null && photos.length > 0,
3900
+ onOpenChange: (open) => !open && onClose(),
3901
+ items,
3902
+ index: index2,
3903
+ onIndexChange: setIndex,
3904
+ labels: {
3905
+ close: copy.closeViewer,
3906
+ position: (n, count) => fill(copy.photoOf, { n, count }),
3907
+ pagerHint: copy.viewerHint
3908
+ },
3909
+ renderActions: (item) => /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", gap: 8 }, children: [
3910
+ canSave ? /* @__PURE__ */ jsx(ViewerButton, { icon: "download", label: copy.savePhoto, onPress: () => void run("save", item.src), disabled: busy, testID: `${testID}-save` }) : null,
3911
+ canShare ? /* @__PURE__ */ jsx(ViewerButton, { icon: "share", label: copy.sharePhoto, onPress: () => void run("share", item.src), disabled: busy, testID: `${testID}-share` }) : null
3912
+ ] }),
3913
+ renderCaption: () => notice ? /* @__PURE__ */ jsx(View, { accessibilityLiveRegion: "assertive", testID: `${testID}-notice`, style: { alignSelf: "center", backgroundColor: "rgba(40,40,40,0.92)", borderRadius: 14, paddingHorizontal: 16, paddingVertical: 10 }, children: /* @__PURE__ */ jsx(NativeText, { style: { color: "#FFFFFF", textAlign: "center" }, children: notice }) }) : null,
3914
+ testID
3929
3915
  }
3930
- };
3931
- const toggleChrome = useCallback(() => setChrome((c) => !c), []);
3932
- const onPull = useCallback((dy) => backdrop.setValue(Math.max(0.35, 1 - Math.max(0, dy) / 400)), [backdrop]);
3933
- const renderItem = useCallback(
3934
- ({ item, index: i }) => /* @__PURE__ */ jsx(
3935
- ZoomablePhoto,
3936
- {
3937
- photo: item,
3938
- width,
3939
- height,
3940
- active: i === index2,
3941
- onZoomChange: setZoomed,
3942
- onPull,
3943
- onDismiss: onClose,
3944
- onTap: toggleChrome,
3945
- testID: `${testID}-photo-${i}`
3946
- }
3947
- ),
3948
- [width, height, index2, onPull, onClose, toggleChrome, testID]
3949
3916
  );
3950
- const counter = many ? fill(copy.photoOf, { n: index2 + 1, count: photos.length }) : null;
3951
- return /* @__PURE__ */ jsxs(View, { style: { flex: 1 }, children: [
3952
- /* @__PURE__ */ jsx(Animated.View, { pointerEvents: "none", style: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0, backgroundColor: FULL_SCREEN_DARK, opacity: backdrop } }),
3953
- /* @__PURE__ */ jsx(
3954
- View,
3955
- {
3956
- style: { flex: 1 },
3957
- accessible: true,
3958
- accessibilityRole: "adjustable",
3959
- accessibilityLabel: photo.alt,
3960
- accessibilityValue: counter ? { text: counter } : void 0,
3961
- accessibilityHint: many ? copy.viewerHint : void 0,
3962
- accessibilityActions: many ? [{ name: "increment" }, { name: "decrement" }] : [],
3963
- onAccessibilityAction: (e) => {
3964
- if (e.nativeEvent.actionName === "increment") goTo(index2 + 1);
3965
- if (e.nativeEvent.actionName === "decrement") goTo(index2 - 1);
3966
- },
3967
- testID: `${testID}-pager`,
3968
- children: /* @__PURE__ */ jsx(
3969
- FlatList,
3970
- {
3971
- ref: listRef,
3972
- testID: `${testID}-list`,
3973
- data: photos,
3974
- horizontal: true,
3975
- pagingEnabled: true,
3976
- scrollEnabled: many && !zoomed,
3977
- showsHorizontalScrollIndicator: false,
3978
- initialScrollIndex: initialIndex,
3979
- getItemLayout: (_d, i) => ({ length: width, offset: width * i, index: i }),
3980
- keyExtractor: (p) => p.key,
3981
- renderItem,
3982
- onMomentumScrollEnd: onMomentumEnd,
3983
- extraData: index2,
3984
- windowSize: 3,
3985
- initialNumToRender: 1
3986
- }
3987
- )
3988
- }
3989
- ),
3990
- chrome ? /* @__PURE__ */ jsxs(View, { pointerEvents: "box-none", style: { position: "absolute", top: insets.top, left: 0, right: 0, flexDirection: "row", alignItems: "center", gap: 8, paddingHorizontal: 8, minHeight: 52 }, children: [
3991
- /* @__PURE__ */ jsx(ViewerButton, { icon: "close", label: copy.closeViewer, onPress: onClose, testID: `${testID}-close` }),
3992
- /* @__PURE__ */ jsx(View, { style: { flex: 1, alignItems: "center" }, children: counter ? /* @__PURE__ */ jsx(NativeText, { testID: `${testID}-counter`, accessibilityLiveRegion: "polite", style: { color: "#FFFFFF", fontWeight: "600", fontVariant: ["tabular-nums"] }, children: counter }) : null }),
3993
- canSave ? /* @__PURE__ */ jsx(ViewerButton, { icon: "download", label: copy.savePhoto, onPress: () => void run("save"), disabled: busy, testID: `${testID}-save` }) : null,
3994
- canShare ? /* @__PURE__ */ jsx(ViewerButton, { icon: "share", label: copy.sharePhoto, onPress: () => void run("share"), disabled: busy, testID: `${testID}-share` }) : null,
3995
- !canSave && !canShare ? /* @__PURE__ */ jsx(View, { style: { width: 44 } }) : null
3996
- ] }) : null,
3997
- notice ? /* @__PURE__ */ jsx(View, { pointerEvents: "none", style: { position: "absolute", left: 24, right: 24, bottom: insets.bottom + 24, alignItems: "center" }, children: /* @__PURE__ */ jsx(View, { accessibilityLiveRegion: "assertive", testID: `${testID}-notice`, style: { backgroundColor: "rgba(40,40,40,0.92)", borderRadius: 14, paddingHorizontal: 16, paddingVertical: 10 }, children: /* @__PURE__ */ jsx(NativeText, { style: { color: "#FFFFFF", textAlign: "center" }, children: notice }) }) }) : null
3998
- ] });
3999
3917
  }
4000
3918
  function ViewerButton({ icon, label, onPress, disabled = false, testID }) {
4001
3919
  return /* @__PURE__ */ jsx(
@@ -4013,179 +3931,6 @@ function ViewerButton({ icon, label, onPress, disabled = false, testID }) {
4013
3931
  }
4014
3932
  );
4015
3933
  }
4016
- function ZoomablePhoto(props) {
4017
- return Platform.OS === "ios" ? /* @__PURE__ */ jsx(ZoomableIos, { ...props }) : /* @__PURE__ */ jsx(ZoomablePan, { ...props });
4018
- }
4019
- function Photo({ photo, width, height, testID }) {
4020
- return /* @__PURE__ */ jsx(NativeImage, { src: photo.uri, alt: photo.alt, width, height, contentFit: "contain", className: "bg-transparent", testID });
4021
- }
4022
- function useTaps(onSingle, onDouble) {
4023
- const last = useRef(0);
4024
- const timer = useRef(null);
4025
- useEffect(
4026
- () => () => {
4027
- if (timer.current) clearTimeout(timer.current);
4028
- },
4029
- []
4030
- );
4031
- return (e) => {
4032
- const now = Date.now();
4033
- const at = { locationX: e.nativeEvent?.locationX ?? 0, locationY: e.nativeEvent?.locationY ?? 0 };
4034
- if (now - last.current < DOUBLE_TAP_MS) {
4035
- last.current = 0;
4036
- if (timer.current) clearTimeout(timer.current);
4037
- onDouble(at);
4038
- return;
4039
- }
4040
- last.current = now;
4041
- timer.current = setTimeout(onSingle, DOUBLE_TAP_MS);
4042
- };
4043
- }
4044
- function zoomTo(view, rect, animated) {
4045
- view?.scrollResponderZoomTo?.({ ...rect, animated }, animated);
4046
- }
4047
- function ZoomableIos({ photo, width, height, active: active2, onZoomChange, onPull, onDismiss, onTap, testID }) {
4048
- const ref = useRef(null);
4049
- const scale = useRef(1);
4050
- const reducedMotion = useReducedMotion();
4051
- useEffect(() => {
4052
- if (!active2 && scale.current > 1.01) {
4053
- zoomTo(ref.current, { x: 0, y: 0, width, height }, false);
4054
- scale.current = 1;
4055
- }
4056
- }, [active2, width, height]);
4057
- const tap = useTaps(onTap, (at) => {
4058
- if (scale.current > 1.01) return zoomTo(ref.current, { x: 0, y: 0, width, height }, !reducedMotion);
4059
- const w = width / 2.5;
4060
- const h = height / 2.5;
4061
- zoomTo(ref.current, { x: at.locationX - w / 2, y: at.locationY - h / 2, width: w, height: h }, !reducedMotion);
4062
- });
4063
- return /* @__PURE__ */ jsx(
4064
- ScrollView,
4065
- {
4066
- ref,
4067
- testID,
4068
- style: { width, height },
4069
- contentContainerStyle: { width, height },
4070
- maximumZoomScale: MAX_ZOOM,
4071
- minimumZoomScale: 1,
4072
- bouncesZoom: true,
4073
- centerContent: true,
4074
- alwaysBounceVertical: true,
4075
- showsHorizontalScrollIndicator: false,
4076
- showsVerticalScrollIndicator: false,
4077
- scrollEventThrottle: 16,
4078
- onScroll: (e) => {
4079
- const z = e.nativeEvent.zoomScale ?? 1;
4080
- if (z > 1.01 !== scale.current > 1.01) onZoomChange(z > 1.01);
4081
- scale.current = z;
4082
- if (z <= 1.01) onPull(-e.nativeEvent.contentOffset.y);
4083
- },
4084
- onScrollEndDrag: (e) => {
4085
- if (scale.current > 1.01) return;
4086
- if (shouldDismiss(-e.nativeEvent.contentOffset.y, -(e.nativeEvent.velocity?.y ?? 0))) onDismiss();
4087
- else onPull(0);
4088
- },
4089
- children: /* @__PURE__ */ jsx(Pressable, { accessible: false, onPress: tap, style: { width, height }, children: /* @__PURE__ */ jsx(Photo, { photo, width, height, testID: `${testID}-image` }) })
4090
- }
4091
- );
4092
- }
4093
- function ZoomablePan({ photo, width, height, active: active2, onZoomChange, onPull, onDismiss, onTap, testID }) {
4094
- const reducedMotion = useReducedMotion();
4095
- const scale = useRef(new Animated.Value(1)).current;
4096
- const tx = useRef(new Animated.Value(0)).current;
4097
- const ty = useRef(new Animated.Value(0)).current;
4098
- const s = useRef({ scale: 1, x: 0, y: 0, startScale: 1, startDistance: 0, startX: 0, startY: 0, pinching: false, dragging: false });
4099
- const settle = useCallback(
4100
- (to) => {
4101
- s.current.scale = to.scale;
4102
- s.current.x = to.x;
4103
- s.current.y = to.y;
4104
- onZoomChange(to.scale > 1.01);
4105
- if (reducedMotion) {
4106
- scale.setValue(to.scale);
4107
- tx.setValue(to.x);
4108
- ty.setValue(to.y);
4109
- return;
4110
- }
4111
- Animated.parallel([
4112
- Animated.spring(scale, { toValue: to.scale, useNativeDriver: true }),
4113
- Animated.spring(tx, { toValue: to.x, useNativeDriver: true }),
4114
- Animated.spring(ty, { toValue: to.y, useNativeDriver: true })
4115
- ]).start();
4116
- },
4117
- [reducedMotion, onZoomChange, scale, tx, ty]
4118
- );
4119
- useEffect(() => {
4120
- if (!active2 && s.current.scale > 1.01) settle({ scale: 1, x: 0, y: 0 });
4121
- }, [active2, settle]);
4122
- const tap = useTaps(onTap, (at) => {
4123
- if (s.current.scale > 1.01) return settle({ scale: 1, x: 0, y: 0 });
4124
- const z = 2.5;
4125
- settle({ scale: z, x: clamp((width / 2 - at.locationX) * (z - 1), panLimit(z, width)), y: clamp((height / 2 - at.locationY) * (z - 1), panLimit(z, height)) });
4126
- });
4127
- const responder = useMemo(
4128
- () => PanResponder.create({
4129
- onStartShouldSetPanResponder: () => false,
4130
- onMoveShouldSetPanResponder: (e, g) => e.nativeEvent.touches.length >= 2 || s.current.scale > 1.01 || g.dy > 8 && Math.abs(g.dy) > Math.abs(g.dx) * 1.5,
4131
- onPanResponderTerminationRequest: () => false,
4132
- onPanResponderGrant: (e) => {
4133
- const st = s.current;
4134
- st.pinching = e.nativeEvent.touches.length >= 2;
4135
- st.dragging = !st.pinching && st.scale <= 1.01;
4136
- st.startScale = st.scale;
4137
- st.startDistance = touchDistance(e.nativeEvent.touches);
4138
- st.startX = st.x;
4139
- st.startY = st.y;
4140
- },
4141
- onPanResponderMove: (e, g) => {
4142
- const st = s.current;
4143
- const touches = e.nativeEvent.touches;
4144
- if (touches.length >= 2) {
4145
- if (!st.pinching) {
4146
- st.pinching = true;
4147
- st.dragging = false;
4148
- st.startScale = st.scale;
4149
- st.startDistance = touchDistance(touches);
4150
- }
4151
- st.scale = pinchScale(st.startScale, st.startDistance, touchDistance(touches));
4152
- scale.setValue(st.scale);
4153
- return;
4154
- }
4155
- if (st.dragging) {
4156
- st.y = Math.max(0, g.dy);
4157
- ty.setValue(st.y);
4158
- onPull(st.y);
4159
- return;
4160
- }
4161
- if (st.scale > 1.01) {
4162
- st.x = clamp(st.startX + g.dx, panLimit(st.scale, width));
4163
- st.y = clamp(st.startY + g.dy, panLimit(st.scale, height));
4164
- tx.setValue(st.x);
4165
- ty.setValue(st.y);
4166
- }
4167
- },
4168
- onPanResponderRelease: (_e, g) => {
4169
- const st = s.current;
4170
- if (st.dragging) {
4171
- st.dragging = false;
4172
- if (shouldDismiss(g.dy, g.vy)) return onDismiss();
4173
- onPull(0);
4174
- return settle({ scale: 1, x: 0, y: 0 });
4175
- }
4176
- st.pinching = false;
4177
- const z = Math.max(1, st.scale);
4178
- settle({ scale: z, x: clamp(st.x, panLimit(z, width)), y: clamp(st.y, panLimit(z, height)) });
4179
- },
4180
- onPanResponderTerminate: () => {
4181
- onPull(0);
4182
- settle({ scale: Math.max(1, s.current.scale), x: 0, y: 0 });
4183
- }
4184
- }),
4185
- [width, height, onPull, onDismiss, settle, scale, tx, ty]
4186
- );
4187
- return /* @__PURE__ */ jsx(View, { testID, style: { width, height, overflow: "hidden" }, ...responder.panHandlers, children: /* @__PURE__ */ jsx(Animated.View, { style: { width, height, transform: [{ translateX: tx }, { translateY: ty }, { scale }] }, children: /* @__PURE__ */ jsx(Pressable, { accessible: false, onPress: tap, style: { width, height }, children: /* @__PURE__ */ jsx(Photo, { photo, width, height, testID: `${testID}-image` }) }) }) });
4188
- }
4189
3934
  function galleryFor(messages, urls, uri, alt, label) {
4190
3935
  for (const m of messages) {
4191
3936
  const images = m.attachments.filter((a) => a.kind === "image").map((a) => fromServer(a, urls));
@@ -4623,9 +4368,10 @@ function ChatThreadScreen(props) {
4623
4368
  setRetryingAccess(true);
4624
4369
  void Promise.resolve(refetchAccess()).finally(() => setRetryingAccess(false));
4625
4370
  }, [refetchAccess]);
4626
- const KeyboardAvoiding = modules.keyboardAvoidingView ?? KeyboardAvoidingView;
4371
+ const keyboardModule = modules.keyboardAvoidingView ?? genesis.keyboardAvoidingView;
4372
+ const KeyboardAvoiding = keyboardModule ?? KeyboardAvoidingView;
4627
4373
  const offset = keyboardVerticalOffset ?? measuredTop;
4628
- const keyboardProps = modules.keyboardAvoidingView ? { behavior: "translate-with-padding", keyboardVerticalOffset: offset } : { behavior: Platform.OS === "ios" ? "padding" : void 0, keyboardVerticalOffset: offset };
4374
+ const keyboardProps = keyboardModule ? { behavior: "translate-with-padding", keyboardVerticalOffset: offset } : { behavior: Platform.OS === "ios" ? "padding" : void 0, keyboardVerticalOffset: offset };
4629
4375
  const empty = !conv.isLoading && rows.length === 0;
4630
4376
  return /* @__PURE__ */ jsx(ChatPeopleScope, { userIds: peopleIds, children: /* @__PURE__ */ jsxs(SafeAreaView, { ref: rootRef, onLayout: measureTop, testID, edges: ["left", "right", "bottom"], style: { flex: 1, backgroundColor: colors.groupedBackground }, children: [
4631
4377
  /* @__PURE__ */ jsxs(KeyboardAvoiding, { style: { flex: 1 }, ...keyboardProps, children: [