@marktiderman/genesis-chat 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/native.js CHANGED
@@ -6,10 +6,10 @@ import { summarizeReactions, parseMentions, startsDay, dayLabel, itemTime, itemS
6
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, 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';
9
+ import { NativeText, NativeAvatar, NativeImage, NativeIcon, NativeButton, LIGHTBOX_DISMISS_DISTANCE, LIGHTBOX_DISMISS_VELOCITY, LIGHTBOX_MAX_ZOOM, lightboxPanLimit, lightboxPinchScale, lightboxShouldDismiss, useGenesisModules, NativeProgress, useToast, NativeSheet, NativeDatePicker, NativeTimePicker, NativeListItem, NativeSkeleton, NativeEmptyState, NativeTextarea, NativeSwitch, NativeCombobox, NativeChipGroup, NativeChip, NativeInput, NativeSearchBar, NativeComposerBar, NativeInlineAlert, NativeLightbox, NativeThreadList, NativeSheetScrollView, NativeCheckbox, NativeBadge } from '@marktiderman/genesis-ui-native/components';
10
10
  import { InboxPage, SettingsSubPage, getThreadPageStackOptions, formatInboxTime } from '@marktiderman/genesis-ui-native/layouts';
11
- import { Pressable, Animated, PanResponder, View, Linking, useWindowDimensions, ActivityIndicator, AppState, Modal, AccessibilityInfo, ScrollView, FlatList, TextInput, Platform, KeyboardAvoidingView, Alert } from 'react-native';
12
- import { useThemeRoles, useReducedMotion } from '@marktiderman/genesis-ui-native/hooks';
11
+ import { Pressable, Animated, PanResponder, View, Linking, useWindowDimensions, ActivityIndicator, AppState, Modal, AccessibilityInfo, ScrollView, FlatList, Platform, KeyboardAvoidingView, Alert } from 'react-native';
12
+ import { useThemeRoles, sentBubbleColor, playHaptic, useReducedMotion } from '@marktiderman/genesis-ui-native/hooks';
13
13
  import { reportError } from '@marktiderman/genesis-core/errors';
14
14
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
15
15
  import { useQueryClient } from '@tanstack/react-query';
@@ -35,6 +35,7 @@ var chatOrganiseCopy = {
35
35
  topicClosedDone: "Closed {name}",
36
36
  topicReopenedDone: "Reopened {name}",
37
37
  schedule: "Schedule message",
38
+ scheduleHoldHint: "Touch and hold to schedule",
38
39
  scheduleTitle: "Schedule message",
39
40
  scheduleHint: "It sends at this time, in your time zone, as if you'd sent it then.",
40
41
  schedulePick: "Pick a date and time",
@@ -256,9 +257,15 @@ var EMPTY_MODULES = Object.freeze({});
256
257
  var DEFAULT = { modules: EMPTY_MODULES, copy: resolveChatCopy(), person: () => void 0 };
257
258
  var Context = createContext(DEFAULT);
258
259
  function ChatNativeProvider({ modules = EMPTY_MODULES, copy, getPerson, children }) {
260
+ const { haptics: genesisHaptics } = useGenesisModules();
259
261
  const value = useMemo(
260
- () => ({ modules, copy: resolveChatCopy(copy), person: (id) => id && getPerson ? getPerson(id) : void 0 }),
261
- [modules, copy, getPerson]
262
+ () => ({
263
+ // Chat's own haptics module, else the one the app gave Genesis, so it's passed once.
264
+ modules: modules.haptics || !genesisHaptics ? modules : { ...modules, haptics: genesisHaptics },
265
+ copy: resolveChatCopy(copy),
266
+ person: (id) => id && getPerson ? getPerson(id) : void 0
267
+ }),
268
+ [modules, genesisHaptics, copy, getPerson]
262
269
  );
263
270
  return /* @__PURE__ */ jsx(Context.Provider, { value, children });
264
271
  }
@@ -1389,7 +1396,7 @@ function MessageBubbleImpl(props) {
1389
1396
  const quote = message?.replyToId ?? pending?.input.replyToId ?? null;
1390
1397
  const quoted = quote && repliedTo ? repliedTo : null;
1391
1398
  const invisible = Boolean(message && !message.deletedAt && !body && !attachments.length && !preview && !quote && !moderation && cards.length && !shownCards.length);
1392
- const bubbleColor = mine ? colors.tint : colors.surface;
1399
+ const bubbleColor = mine ? sentBubbleColor(colors) : colors.surface;
1393
1400
  const fg = mine ? "text-primary-foreground" : void 0;
1394
1401
  const textStyle = mine ? { fontSize: 17, lineHeight: 22 } : { fontSize: 17, lineHeight: 22, color: colors.label };
1395
1402
  return /* @__PURE__ */ jsxs(
@@ -1398,7 +1405,7 @@ function MessageBubbleImpl(props) {
1398
1405
  testID,
1399
1406
  accessibilityElementsHidden: invisible || void 0,
1400
1407
  importantForAccessibility: invisible ? "no-hide-descendants" : void 0,
1401
- style: { paddingHorizontal: 8, paddingTop: row.groupStart ? 8 : 2, backgroundColor: props.highlighted ? colors.fill : void 0, display: invisible ? "none" : void 0 },
1408
+ style: { paddingTop: row.groupStart ? 8 : 2, borderRadius: 12, backgroundColor: props.highlighted ? colors.fill : void 0, display: invisible ? "none" : void 0 },
1402
1409
  children: [
1403
1410
  row.showName && sender?.name ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", style: { marginLeft: group ? 48 : 12, marginBottom: 2, color: colors.secondaryLabel }, children: sender.name }) : null,
1404
1411
  /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "flex-end", justifyContent: mine ? "flex-end" : "flex-start" }, children: [
@@ -1576,18 +1583,16 @@ function ChatInboxScreen({ onOpen, onStart, kind, kinds, excludeKinds, archived,
1576
1583
  }
1577
1584
  );
1578
1585
  }
1579
-
1580
- // src/native/modules.ts
1586
+ var HAPTIC_KIND = {
1587
+ send: "light",
1588
+ "record-lock": "light",
1589
+ "record-start": "medium",
1590
+ select: "select",
1591
+ error: "error",
1592
+ "record-cancel": "warning"
1593
+ };
1581
1594
  function haptic(haptics, event) {
1582
- if (!haptics) return;
1583
- try {
1584
- const style = (s) => s;
1585
- const p = event === "send" || event === "record-lock" ? haptics.impactAsync(style(haptics.ImpactFeedbackStyle.Light)) : event === "record-start" ? haptics.impactAsync(style(haptics.ImpactFeedbackStyle.Medium)) : event === "select" ? haptics.selectionAsync() : haptics.notificationAsync(
1586
- style(event === "error" ? haptics.NotificationFeedbackType.Error : haptics.NotificationFeedbackType.Warning)
1587
- );
1588
- void p?.catch?.(() => void 0);
1589
- } catch {
1590
- }
1595
+ playHaptic(haptics, HAPTIC_KIND[event]);
1591
1596
  }
1592
1597
 
1593
1598
  // src/native/video-recorder-state.ts
@@ -2955,55 +2960,6 @@ function ChatTopicBar({ topics, value, onValueChange, canManage = false, onSetTo
2955
2960
  )) }) })
2956
2961
  ] });
2957
2962
  }
2958
- function rowIndexOf(rows, messageId) {
2959
- return rows.findIndex((r) => r.type === "message" && r.item.type === "message" && r.item.message.id === messageId);
2960
- }
2961
- function useJumpToMessage({ target, rows, loading, has, loadUntil, scrollTo, onStart, onLanded, onGone, onError }) {
2962
- const [pending, setPending] = useState(target ? { ...target, phase: "new" } : null);
2963
- const [highlightedId, setHighlightedId] = useState(null);
2964
- useEffect(() => {
2965
- if (target) setPending({ ...target, phase: "new" });
2966
- }, [target?.messageId, target?.seq]);
2967
- const latest = useRef({ rows, scrollTo, onStart, onLanded, onGone, onError });
2968
- latest.current = { rows, scrollTo, onStart, onLanded, onGone, onError };
2969
- const timer = useRef(null);
2970
- useEffect(() => () => {
2971
- if (timer.current) clearTimeout(timer.current);
2972
- }, []);
2973
- const go = useCallback((messageId) => {
2974
- const index2 = rowIndexOf(latest.current.rows, messageId);
2975
- if (index2 < 0) return;
2976
- latest.current.onStart?.();
2977
- latest.current.scrollTo(index2, messageId);
2978
- latest.current.onLanded?.(messageId);
2979
- setHighlightedId(messageId);
2980
- if (timer.current) clearTimeout(timer.current);
2981
- timer.current = setTimeout(() => setHighlightedId((h) => h === messageId ? null : h), 2e3);
2982
- }, []);
2983
- useEffect(() => {
2984
- if (!pending || loading) return;
2985
- const { messageId, seq: seq2, phase } = pending;
2986
- if (has(messageId)) {
2987
- setPending(null);
2988
- go(messageId);
2989
- return;
2990
- }
2991
- if (phase === "loading") return;
2992
- if (phase === "loaded" || seq2 == null) {
2993
- setPending(null);
2994
- latest.current.onGone();
2995
- return;
2996
- }
2997
- latest.current.onStart?.();
2998
- setPending({ messageId, seq: seq2, phase: "loading" });
2999
- const settle = () => setPending((p) => p && p.messageId === messageId ? { ...p, phase: "loaded" } : p);
3000
- void loadUntil(seq2).then(settle, (e) => {
3001
- latest.current.onError(e);
3002
- settle();
3003
- });
3004
- }, [pending, loading, has, loadUntil, go]);
3005
- return { highlightedId, jumping: pending !== null };
3006
- }
3007
2963
 
3008
2964
  // src/native/emoji-data.ts
3009
2965
  var EMOJI_GROUP_DATA = {
@@ -3532,6 +3488,7 @@ function ComposerWithVoice(props) {
3532
3488
  function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo, onSchedule, placeholder, voice, userId, testID = "chat-composer" }) {
3533
3489
  const { modules, copy } = useChatNative();
3534
3490
  const colors = useThemeRoles();
3491
+ const genesis = useGenesisModules();
3535
3492
  const { state, dispatch } = composer;
3536
3493
  const [attachOpen, setAttachOpen] = useState(false);
3537
3494
  const [canPaste, setCanPaste] = useState(false);
@@ -3555,7 +3512,7 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
3555
3512
  if (!sendable) return;
3556
3513
  const payload = composer.take();
3557
3514
  if (!payload) return;
3558
- haptic(modules.haptics, "send");
3515
+ if (!genesis.haptics) haptic(modules.haptics, "send");
3559
3516
  onSend(payload);
3560
3517
  };
3561
3518
  const openAttach = async () => {
@@ -3599,9 +3556,9 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
3599
3556
  haptic(modules.haptics, "error");
3600
3557
  }
3601
3558
  };
3602
- return /* @__PURE__ */ jsxs(View, { testID, style: { backgroundColor: colors.groupedBackground, paddingHorizontal: 8, paddingTop: 6, paddingBottom: 6, gap: 6 }, children: [
3603
- notice ? /* @__PURE__ */ jsx(NativeText, { testID: `${testID}-notice`, accessibilityLiveRegion: "polite", preset: "caption", style: { color: colors.destructive, paddingHorizontal: 8 }, children: notice }) : null,
3604
- state.replyTo ? /* @__PURE__ */ jsxs(View, { testID: `${testID}-reply`, style: { flexDirection: "row", alignItems: "center", paddingLeft: 12, borderLeftWidth: 3, borderLeftColor: colors.tint, marginHorizontal: 4 }, children: [
3559
+ const above = /* @__PURE__ */ jsxs(Fragment, { children: [
3560
+ notice ? /* @__PURE__ */ jsx(NativeText, { testID: `${testID}-notice`, accessibilityLiveRegion: "polite", preset: "caption", style: { color: colors.destructive, paddingHorizontal: 4 }, children: notice }) : null,
3561
+ state.replyTo ? /* @__PURE__ */ jsxs(View, { testID: `${testID}-reply`, style: { flexDirection: "row", alignItems: "center", paddingLeft: 12, borderLeftWidth: 3, borderLeftColor: colors.tint }, children: [
3605
3562
  /* @__PURE__ */ jsxs(View, { style: { flex: 1 }, children: [
3606
3563
  /* @__PURE__ */ jsx(NativeText, { preset: "caption", style: { color: colors.tint, fontWeight: "600" }, children: fill(copy.replyingTo, { name: state.replyTo.name }) }),
3607
3564
  /* @__PURE__ */ jsx(NativeText, { preset: "caption", numberOfLines: 1, style: { color: colors.secondaryLabel }, children: state.replyTo.preview })
@@ -3622,47 +3579,40 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
3622
3579
  children: /* @__PURE__ */ jsx(NativeIcon, { name: "close", size: 14, color: colors.surface })
3623
3580
  }
3624
3581
  )
3625
- ] }, a.key)) }) : null,
3626
- /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "flex-end", gap: 4 }, children: [
3627
- recording && voice ? /* @__PURE__ */ jsx(RecordingBar, { voice, testID }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3628
- modules.imagePicker || modules.clipboard?.getImageAsync ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-attach`, icon: "plus", label: copy.attach, onPress: () => void openAttach(), color: colors.tint, disabled: !ready }) : null,
3629
- onRecordVideo ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-video`, icon: "video", label: copy.recordVideo, onPress: onRecordVideo, color: colors.tint, disabled: !ready }) : null,
3630
- /* @__PURE__ */ jsx(
3631
- TextInput,
3632
- {
3633
- testID: `${testID}-input`,
3634
- value: state.text,
3635
- onChangeText: (text) => {
3636
- dispatch({ type: "text", text });
3637
- if (text) signalTyping?.();
3638
- },
3639
- onSelectionChange: (e) => {
3640
- selection.current = e.nativeEvent.selection;
3641
- },
3642
- placeholder: placeholder ?? copy.placeholder,
3643
- placeholderTextColor: colors.tertiaryLabel,
3644
- accessibilityLabel: placeholder ?? copy.placeholder,
3645
- editable: ready,
3646
- multiline: true,
3647
- maxLength: CHAT_LIMITS.bodyChars,
3648
- style: {
3649
- flex: 1,
3650
- minHeight: 40,
3651
- maxHeight: 140,
3652
- paddingHorizontal: 14,
3653
- paddingTop: 10,
3654
- paddingBottom: 10,
3655
- borderRadius: 20,
3656
- fontSize: 17,
3657
- color: colors.label,
3658
- backgroundColor: colors.surface
3659
- }
3660
- }
3661
- ),
3662
- /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-emoji`, icon: "smile", label: copy.addEmoji, onPress: () => setEmojiOpen(true), color: colors.secondaryLabel, disabled: !ready })
3663
- ] }),
3664
- sendable && !recording ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-send`, icon: "arrow-up", label: copy.send, onPress: send, onLongPress: onSchedule, longPressLabel: onSchedule ? copy.schedule : void 0, filled: true, color: colors.tint }) : voice ? /* @__PURE__ */ jsx(MicButton, { voice, testID, disabled: !ready }) : /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-send`, icon: "arrow-up", label: copy.send, onPress: send, filled: true, color: colors.tint, disabled: true })
3665
- ] }),
3582
+ ] }, a.key)) }) : null
3583
+ ] });
3584
+ const canAttach = Boolean(modules.imagePicker || modules.clipboard?.getImageAsync);
3585
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3586
+ /* @__PURE__ */ jsx(
3587
+ NativeComposerBar,
3588
+ {
3589
+ testID,
3590
+ value: state.text,
3591
+ onChangeText: (text) => {
3592
+ dispatch({ type: "text", text });
3593
+ if (text) signalTyping?.();
3594
+ },
3595
+ onSelectionChange: (e) => {
3596
+ selection.current = e.nativeEvent.selection;
3597
+ },
3598
+ onSend: send,
3599
+ hasContent: sendable && !recording,
3600
+ editable: ready,
3601
+ placeholder: placeholder ?? copy.placeholder,
3602
+ sendLabel: copy.send,
3603
+ maxLength: CHAT_LIMITS.bodyChars,
3604
+ sendActions: onSchedule ? [{ id: "schedule", label: copy.schedule, onPress: onSchedule }] : void 0,
3605
+ sendActionsHint: copy.scheduleHoldHint,
3606
+ above,
3607
+ leading: canAttach || onRecordVideo ? /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row" }, children: [
3608
+ canAttach ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-attach`, icon: "plus", label: copy.attach, onPress: () => void openAttach(), color: colors.tint, disabled: !ready }) : null,
3609
+ onRecordVideo ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-video`, icon: "video", label: copy.recordVideo, onPress: onRecordVideo, color: colors.tint, disabled: !ready }) : null
3610
+ ] }) : null,
3611
+ trailing: recording ? null : /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-emoji`, icon: "smile", label: copy.addEmoji, onPress: () => setEmojiOpen(true), color: colors.secondaryLabel, disabled: !ready }),
3612
+ idleAction: voice ? /* @__PURE__ */ jsx(MicButton, { voice, testID, disabled: !ready }) : null,
3613
+ replaceInput: recording && voice ? /* @__PURE__ */ jsx(RecordingBar, { voice, testID }) : null
3614
+ }
3615
+ ),
3666
3616
  /* @__PURE__ */ jsx(ChatEmojiPickerSheet, { open: emojiOpen, onClose: () => setEmojiOpen(false), onSelect: insertEmoji, userId, testID: `${testID}-emoji-sheet` }),
3667
3617
  /* @__PURE__ */ jsx(NativeSheet, { open: attachOpen, onOpenChange: setAttachOpen, testID: `${testID}-attach-sheet`, children: /* @__PURE__ */ jsxs(View, { children: [
3668
3618
  modules.imagePicker ? /* @__PURE__ */ jsx(NativeListItem, { testID: `${testID}-attach-library`, title: copy.attachLibrary, leading: /* @__PURE__ */ jsx(NativeIcon, { name: "image" }), onPress: () => void pick("library") }) : null,
@@ -3676,13 +3626,9 @@ function IconButton({
3676
3626
  label,
3677
3627
  onPress,
3678
3628
  color,
3679
- filled = false,
3680
3629
  disabled = false,
3681
- onLongPress,
3682
- longPressLabel,
3683
3630
  testID
3684
3631
  }) {
3685
- const colors = useThemeRoles();
3686
3632
  return /* @__PURE__ */ jsx(
3687
3633
  Pressable,
3688
3634
  {
@@ -3692,12 +3638,8 @@ function IconButton({
3692
3638
  accessibilityState: { disabled },
3693
3639
  disabled,
3694
3640
  onPress,
3695
- onLongPress,
3696
- delayLongPress: onLongPress ? 400 : void 0,
3697
- accessibilityActions: onLongPress && longPressLabel ? [{ name: "longpress", label: longPressLabel }] : void 0,
3698
- onAccessibilityAction: onLongPress ? (e) => e.nativeEvent.actionName === "longpress" && onLongPress() : void 0,
3699
3641
  style: { width: 44, height: 44, alignItems: "center", justifyContent: "center", opacity: disabled ? 0.4 : 1 },
3700
- children: filled ? /* @__PURE__ */ jsx(View, { style: { width: 34, height: 34, borderRadius: 17, backgroundColor: color, alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ jsx(NativeIcon, { name: icon, size: 18, color: colors.surface, weight: "semibold" }) }) : /* @__PURE__ */ jsx(NativeIcon, { name: icon, size: 24, color })
3642
+ children: /* @__PURE__ */ jsx(NativeIcon, { name: icon, size: 24, color })
3701
3643
  }
3702
3644
  );
3703
3645
  }
@@ -4121,22 +4063,8 @@ function ChatThreadScreen(props) {
4121
4063
  const colors = useThemeRoles();
4122
4064
  const reducedMotion = useReducedMotion();
4123
4065
  const genesis = useGenesisModules();
4124
- const List = genesis.list ?? FlatList;
4125
- const mode = threadListMode(Boolean(genesis.list), reducedMotion);
4126
4066
  const listRef = useRef(null);
4127
- const atBottom = useRef(true);
4128
- const placed = useRef(!mode.followsByHand);
4129
- const toBottom = useCallback(
4130
- (animated) => {
4131
- const go = (a) => listRef.current?.scrollToEnd?.({ animated: a && !reducedMotion });
4132
- requestAnimationFrame(() => {
4133
- go(animated);
4134
- placed.current = true;
4135
- });
4136
- if (animated) setTimeout(() => go(true), 180);
4137
- },
4138
- [reducedMotion]
4139
- );
4067
+ const toNewest = useCallback(() => listRef.current?.scrollToEnd({ animated: true }), []);
4140
4068
  const composer = useChatComposer(conversationId, threadRootId, userId);
4141
4069
  const { setReply } = composer;
4142
4070
  const [actionsFor, setActionsFor] = useState(null);
@@ -4249,47 +4177,40 @@ function ChatThreadScreen(props) {
4249
4177
  );
4250
4178
  const observer = conv.role === "observer";
4251
4179
  const { loadUntil } = conv;
4252
- const jumpingTo = useRef(null);
4253
- const retryTimer = useRef(null);
4254
- useEffect(() => () => {
4255
- if (retryTimer.current) clearTimeout(retryTimer.current);
4256
- }, []);
4257
- const rowsNow = useRef(rows);
4258
- rowsNow.current = rows;
4259
- const { highlightedId, jumping } = useJumpToMessage({
4260
- target: jumpTo,
4261
- rows,
4262
- loading: conv.isLoading,
4263
- has: useCallback((id) => byId.has(id), [byId]),
4264
- loadUntil,
4265
- scrollTo: (index2, id) => {
4266
- jumpingTo.current = { id, tries: 0 };
4267
- const scroll = (at) => listRef.current?.scrollToIndex?.({ index: at, animated: !reducedMotion, viewPosition: 0.5 });
4268
- requestAnimationFrame(() => scroll(index2));
4269
- if (retryTimer.current) clearTimeout(retryTimer.current);
4270
- retryTimer.current = setTimeout(() => {
4271
- const at = rowIndexOf(rowsNow.current, id);
4272
- if (at >= 0) scroll(at);
4273
- }, 250);
4274
- },
4275
- onStart: () => {
4276
- atBottom.current = false;
4277
- placed.current = true;
4278
- },
4279
- onLanded: (id) => {
4280
- const m = byId.get(id);
4281
- if (m) AccessibilityInfo.announceForAccessibility?.(fill(copy.jumpedTo, { name: nameOf(m.senderId), text: attachmentPreview(displayBody(m.body), m.attachments[0], attachmentKinds, Boolean(m.deletedAt)) }));
4180
+ const jumpSeq = jumpTo?.seq;
4181
+ const firstPageFailed = Boolean(conv.error) && conv.messages.length === 0;
4182
+ const jumpMessageId = firstPageFailed ? null : jumpTo?.messageId ?? null;
4183
+ const jumpBlocked = firstPageFailed && Boolean(jumpTo);
4184
+ useEffect(() => {
4185
+ if (jumpBlocked) fail();
4186
+ }, [jumpBlocked, fail]);
4187
+ const jumpLoadFailed = useRef(false);
4188
+ const onLoadUntil = useCallback(
4189
+ (id) => {
4190
+ jumpLoadFailed.current = false;
4191
+ if (id !== jumpMessageId || jumpSeq == null) return Promise.resolve(false);
4192
+ return loadUntil(jumpSeq).catch(() => {
4193
+ jumpLoadFailed.current = true;
4194
+ fail();
4195
+ return false;
4196
+ });
4282
4197
  },
4283
- onGone: () => {
4284
- toast.show({ title: copy.messageGone });
4285
- atBottom.current = true;
4286
- toBottom(false);
4198
+ [jumpMessageId, jumpSeq, loadUntil, fail]
4199
+ );
4200
+ const jumpAnnouncement = useCallback(
4201
+ (row) => {
4202
+ const m = row.type === "message" && row.item.type === "message" ? row.item.message : null;
4203
+ return m ? fill(copy.jumpedTo, { name: nameOf(m.senderId), text: attachmentPreview(displayBody(m.body), m.attachments[0], attachmentKinds, Boolean(m.deletedAt)) }) : "";
4287
4204
  },
4288
- onError: fail
4289
- });
4205
+ [copy.jumpedTo, nameOf, attachmentKinds]
4206
+ );
4207
+ const onJumpFailed = useCallback(() => {
4208
+ if (jumpLoadFailed.current) jumpLoadFailed.current = false;
4209
+ else toast.show({ title: copy.messageGone });
4210
+ }, [toast, copy.messageGone]);
4290
4211
  const reattachable = useCallback((files) => files.every((f) => !f.lost || f.kind === "image" || f.kind === "video"), []);
4291
4212
  const renderItem = useCallback(
4292
- ({ item: row }) => {
4213
+ (row, { highlighted }) => {
4293
4214
  if (row.type === "day") return /* @__PURE__ */ jsx(DaySeparator, { label: row.label, testID: `${testID}-day-${row.key}` });
4294
4215
  if (row.type === "unread") return /* @__PURE__ */ jsx(UnreadDivider, { label: copy.newMessages, testID: `${testID}-unread` });
4295
4216
  const m = row.item.type === "message" ? row.item.message : null;
@@ -4312,7 +4233,7 @@ function ChatThreadScreen(props) {
4312
4233
  onToggleReaction: allowed ? react : void 0,
4313
4234
  onOpenImage,
4314
4235
  observer,
4315
- highlighted: Boolean(m && m.id === highlightedId),
4236
+ highlighted,
4316
4237
  linkPreview: m ? previewToShow(previews[m.id]) : null,
4317
4238
  linkPreviewImages,
4318
4239
  attachmentKinds,
@@ -4323,7 +4244,7 @@ function ChatThreadScreen(props) {
4323
4244
  }
4324
4245
  );
4325
4246
  },
4326
- [testID, copy.newMessages, userId, urls, byId, group, reducedMotion, onLongPress, allowed, reply, onSwipeReply, onRetry, onDiscard, react, onOpenImage, picker, reattachable, onReattach, previews, linkPreviewImages, attachmentKinds, onOpenAttachment, attachmentSlot, cardActionTimeoutMs, observer, highlightedId]
4247
+ [testID, copy.newMessages, userId, urls, byId, group, reducedMotion, onLongPress, allowed, reply, onSwipeReply, onRetry, onDiscard, react, onOpenImage, picker, reattachable, onReattach, previews, linkPreviewImages, attachmentKinds, onOpenAttachment, attachmentSlot, cardActionTimeoutMs, observer]
4327
4248
  );
4328
4249
  const [videoOpen, setVideoOpen] = useState(false);
4329
4250
  const preparedVideo = useRef(null);
@@ -4347,10 +4268,9 @@ function ChatThreadScreen(props) {
4347
4268
  (video) => {
4348
4269
  videoUploads.start({ conversationId, userId, video, extra: { replyToId: replyNow, threadRootId }, send: outbox.send, videoUpload, prepared: takePrepared(), openFile: modules.openFile });
4349
4270
  if (replyNow) setReply(null);
4350
- atBottom.current = true;
4351
- toBottom(true);
4271
+ toNewest();
4352
4272
  },
4353
- [conversationId, userId, replyNow, threadRootId, outbox, videoUpload, takePrepared, modules.openFile, setReply, toBottom]
4273
+ [conversationId, userId, replyNow, threadRootId, outbox, videoUpload, takePrepared, modules.openFile, setReply, toNewest]
4354
4274
  );
4355
4275
  const activity = activityLine(conv.activity, (id) => nameOf(id));
4356
4276
  const topics = topicsState.topics;
@@ -4372,54 +4292,31 @@ function ChatThreadScreen(props) {
4372
4292
  const KeyboardAvoiding = keyboardModule ?? KeyboardAvoidingView;
4373
4293
  const offset = keyboardVerticalOffset ?? measuredTop;
4374
4294
  const keyboardProps = keyboardModule ? { behavior: "translate-with-padding", keyboardVerticalOffset: offset } : { behavior: Platform.OS === "ios" ? "padding" : void 0, keyboardVerticalOffset: offset };
4375
- const empty = !conv.isLoading && rows.length === 0;
4376
4295
  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: [
4377
4296
  /* @__PURE__ */ jsxs(KeyboardAvoiding, { style: { flex: 1 }, ...keyboardProps, children: [
4378
4297
  showTopicBar ? /* @__PURE__ */ jsx(ChatTopicBar, { topics, value: topic ?? null, onValueChange: setChosenTopic, canManage: canManageTopics(conv.role), onSetTopic: topicsState.setTopic, testID: `${testID}-topics` }) : null,
4379
4298
  /* @__PURE__ */ jsx(ChatAwayLine, { text: awayLine, testID: `${testID}-away` }),
4380
- /* @__PURE__ */ jsx(View, { style: { flex: 1 }, children: conv.isLoading ? /* @__PURE__ */ jsx(LoadingThread, { testID: `${testID}-loading` }) : empty ? /* @__PURE__ */ jsx(View, { style: { flex: 1, justifyContent: "center" }, children: /* @__PURE__ */ jsx(NativeEmptyState, { variant: "first-run", title: copy.threadEmptyTitle, body: currentTopic?.closedAt ? copy.topicClosedNotice : copy.threadEmptyBody, testID: `${testID}-empty` }) }) : /* @__PURE__ */ jsx(
4381
- List,
4299
+ /* @__PURE__ */ jsx(View, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(
4300
+ NativeThreadList,
4382
4301
  {
4383
4302
  ref: listRef,
4384
4303
  testID: `${testID}-list`,
4385
4304
  data: rows,
4305
+ keyExtractor: threadRowKey,
4306
+ jumpId: threadRowMessageId,
4307
+ getItemType: threadRowType,
4386
4308
  renderItem,
4387
- keyExtractor: (row) => row.key,
4388
- getItemType: (row) => row.type === "message" ? row.mine ? "mine" : "theirs" : row.type,
4389
- onStartReached: () => {
4390
- if (placed.current && !jumping && conv.hasEarlier && !conv.loadingEarlier) void conv.loadEarlier();
4391
- },
4392
- onStartReachedThreshold: 0.5,
4393
- keyboardShouldPersistTaps: "handled",
4394
- keyboardDismissMode: "interactive",
4395
- contentContainerStyle: { paddingVertical: 8 },
4396
- maintainVisibleContentPosition: mode.maintainVisibleContentPosition,
4397
- extraData: highlightedId,
4398
- onScrollToIndexFailed: ({ index: index2, averageItemLength }) => {
4399
- listRef.current?.scrollToOffset?.({ offset: Math.max(0, index2 * averageItemLength - 200), animated: false });
4400
- const target = jumpingTo.current;
4401
- if (!target || target.tries >= 3) return;
4402
- target.tries += 1;
4403
- if (retryTimer.current) clearTimeout(retryTimer.current);
4404
- retryTimer.current = setTimeout(() => {
4405
- const at = rowIndexOf(rowsNow.current, target.id);
4406
- if (at >= 0) listRef.current?.scrollToIndex?.({ index: at, animated: !reducedMotion, viewPosition: 0.5 });
4407
- }, 250);
4408
- },
4409
- ...mode.followsByHand ? {
4410
- scrollEventThrottle: 32,
4411
- onScroll: (e) => {
4412
- atBottom.current = nearBottom(e.nativeEvent);
4413
- },
4414
- onContentSizeChange: () => {
4415
- if (atBottom.current) toBottom(false);
4416
- },
4417
- onLayout: () => {
4418
- if (atBottom.current) toBottom(false);
4419
- }
4420
- } : {},
4421
- ListHeaderComponent: conv.hasEarlier ? /* @__PURE__ */ jsx(EarlierAnchor, { loading: conv.loadingEarlier, label: copy.loadEarlier, onPress: () => void conv.loadEarlier(), testID: `${testID}-earlier` }) : null,
4422
- ListFooterComponent: activity ? /* @__PURE__ */ jsx(ActivityLine, { text: activity, testID: `${testID}-activity` }) : null
4309
+ loading: conv.isLoading,
4310
+ hasEarlier: conv.hasEarlier,
4311
+ onLoadEarlier: () => void conv.loadEarlier(),
4312
+ loadingEarlier: conv.loadingEarlier,
4313
+ earlierLabel: copy.loadEarlier,
4314
+ jumpTo: jumpMessageId,
4315
+ onLoadUntil,
4316
+ jumpAnnouncement,
4317
+ onJumpFailed,
4318
+ footer: activity ? /* @__PURE__ */ jsx(ActivityLine, { text: activity, testID: `${testID}-activity` }) : null,
4319
+ empty: /* @__PURE__ */ jsx(NativeEmptyState, { variant: "first-run", title: copy.threadEmptyTitle, body: currentTopic?.closedAt ? copy.topicClosedNotice : copy.threadEmptyBody, testID: `${testID}-empty` })
4423
4320
  }
4424
4321
  ) }),
4425
4322
  scheduling && !threadRootId ? /* @__PURE__ */ jsx(ChatScheduledBar, { conversationId, testID: `${testID}-scheduled` }) : null,
@@ -4436,8 +4333,7 @@ function ChatThreadScreen(props) {
4436
4333
  role: conv.role,
4437
4334
  onSend: ({ input, files }) => {
4438
4335
  void conv.send(input, files).catch(fail);
4439
- atBottom.current = true;
4440
- toBottom(true);
4336
+ toNewest();
4441
4337
  },
4442
4338
  signalTyping: conv.signalTyping,
4443
4339
  signalRecording: conv.signalRecording,
@@ -4490,20 +4386,9 @@ function ActivityLine({ text, testID }) {
4490
4386
  const colors = useThemeRoles();
4491
4387
  return /* @__PURE__ */ jsx(View, { testID, accessibilityLiveRegion: "polite", style: { paddingHorizontal: 20, paddingVertical: 6 }, children: /* @__PURE__ */ jsx(NativeText, { preset: "caption", style: { color: colors.secondaryLabel, fontStyle: "italic" }, children: text }) });
4492
4388
  }
4493
- function EarlierAnchor({ loading, label, onPress, testID }) {
4494
- const colors = useThemeRoles();
4495
- return /* @__PURE__ */ jsx(View, { style: { alignItems: "center", paddingVertical: 12 }, children: loading ? /* @__PURE__ */ jsxs(View, { testID: `${testID}-loading`, style: { gap: 8, alignItems: "center" }, children: [
4496
- /* @__PURE__ */ jsx(NativeSkeleton, { width: 180, height: 14 }),
4497
- /* @__PURE__ */ jsx(NativeSkeleton, { width: 120, height: 14 })
4498
- ] }) : /* @__PURE__ */ jsx(Pressable, { testID, accessibilityRole: "button", accessibilityLabel: label, onPress, style: { minHeight: 44, justifyContent: "center", paddingHorizontal: 16 }, children: /* @__PURE__ */ jsx(NativeText, { preset: "label", style: { color: colors.tint }, children: label }) }) });
4499
- }
4500
- function LoadingThread({ testID }) {
4501
- return /* @__PURE__ */ jsxs(View, { testID, style: { flex: 1, justifyContent: "flex-end", padding: 16, gap: 10 }, children: [
4502
- /* @__PURE__ */ jsx(NativeSkeleton, { width: 200, height: 36, className: "rounded-2xl" }),
4503
- /* @__PURE__ */ jsx(View, { style: { alignItems: "flex-end" }, children: /* @__PURE__ */ jsx(NativeSkeleton, { width: 160, height: 36, className: "rounded-2xl" }) }),
4504
- /* @__PURE__ */ jsx(NativeSkeleton, { width: 240, height: 36, className: "rounded-2xl" })
4505
- ] });
4506
- }
4389
+ var threadRowKey = (row) => row.key;
4390
+ var threadRowMessageId = (row) => row.type === "message" && row.item.type === "message" ? row.item.message.id : null;
4391
+ var threadRowType = (row) => row.type === "message" ? row.mine ? "mine" : "theirs" : row.type;
4507
4392
  function chatThreadStackOptions(props, background) {
4508
4393
  return getThreadPageStackOptions({
4509
4394
  ...props,
@@ -5004,6 +4889,55 @@ function HitRow({ testID, accessibilityLabel, onPress, children }) {
5004
4889
  }
5005
4890
  );
5006
4891
  }
4892
+ function rowIndexOf(rows, messageId) {
4893
+ return rows.findIndex((r) => r.type === "message" && r.item.type === "message" && r.item.message.id === messageId);
4894
+ }
4895
+ function useJumpToMessage({ target, rows, loading, has, loadUntil, scrollTo, onStart, onLanded, onGone, onError }) {
4896
+ const [pending, setPending] = useState(target ? { ...target, phase: "new" } : null);
4897
+ const [highlightedId, setHighlightedId] = useState(null);
4898
+ useEffect(() => {
4899
+ if (target) setPending({ ...target, phase: "new" });
4900
+ }, [target?.messageId, target?.seq]);
4901
+ const latest = useRef({ rows, scrollTo, onStart, onLanded, onGone, onError });
4902
+ latest.current = { rows, scrollTo, onStart, onLanded, onGone, onError };
4903
+ const timer = useRef(null);
4904
+ useEffect(() => () => {
4905
+ if (timer.current) clearTimeout(timer.current);
4906
+ }, []);
4907
+ const go = useCallback((messageId) => {
4908
+ const index2 = rowIndexOf(latest.current.rows, messageId);
4909
+ if (index2 < 0) return;
4910
+ latest.current.onStart?.();
4911
+ latest.current.scrollTo(index2, messageId);
4912
+ latest.current.onLanded?.(messageId);
4913
+ setHighlightedId(messageId);
4914
+ if (timer.current) clearTimeout(timer.current);
4915
+ timer.current = setTimeout(() => setHighlightedId((h) => h === messageId ? null : h), 2e3);
4916
+ }, []);
4917
+ useEffect(() => {
4918
+ if (!pending || loading) return;
4919
+ const { messageId, seq: seq2, phase } = pending;
4920
+ if (has(messageId)) {
4921
+ setPending(null);
4922
+ go(messageId);
4923
+ return;
4924
+ }
4925
+ if (phase === "loading") return;
4926
+ if (phase === "loaded" || seq2 == null) {
4927
+ setPending(null);
4928
+ latest.current.onGone();
4929
+ return;
4930
+ }
4931
+ latest.current.onStart?.();
4932
+ setPending({ messageId, seq: seq2, phase: "loading" });
4933
+ const settle = () => setPending((p) => p && p.messageId === messageId ? { ...p, phase: "loaded" } : p);
4934
+ void loadUntil(seq2).then(settle, (e) => {
4935
+ latest.current.onError(e);
4936
+ settle();
4937
+ });
4938
+ }, [pending, loading, has, loadUntil, go]);
4939
+ return { highlightedId, jumping: pending !== null };
4940
+ }
5007
4941
 
5008
4942
  export { AT_BOTTOM_POINTS, AppAttachment, BUILT_IN_KINDS, CARD_ACTION_TIMEOUT_MS, CardError, ChatAccessError, ChatAttachmentCard, ChatAutoRetry, ChatAvailabilityScreen, ChatAwayLine, ChatBroadcastSheet, ChatComposer, ChatEmojiPicker, ChatEmojiPickerSheet, ChatIconButton, ChatInboxScreen, ChatLinkPreviewCard, ChatMediaViewer, ChatNativeProvider, ChatPhotoViewer, ChatScheduleSheet, ChatScheduledBar, ChatScheduledList, ChatSearchScreen, ChatStartButton, ChatStartSheet, ChatThreadScreen, ChatTopicBar, ChatVideoPlayer, ChatVideoRecorder, DISMISS_DISTANCE, DISMISS_VELOCITY, EMOJI_CATEGORIES, MAX_ZOOM, MessageActionsSheet, MessageAttachments, MessageBubble, ModerationMarker, QUICK_REACTIONS, RECENT_EMOJI_MAX, SearchSnippet, TRANSCRIPT_LINES, TUS_CHUNK_BYTES, VIDEO_CHUNK_BYTES, VIDEO_HOLD_MS, VIDEO_MIN_MS, VideoUploadTray, VoiceNotePlayer, VoiceTranscript, activePlaybackId, attachmentKindOf, attachmentPaths, availabilityInput, awayLineFor, barsThatFit, base64ToBytes, base64Utf8, broadcastOutcome, broadcastRows, buildThreadRows, canManageTopics, canReactTo, canSend, cardAction, chatNativeCopy, chatOrganiseCopy, chatThreadStackOptions, checkTopicName, chunkedPut, claimPlayback, clearDrafts, clockToDate, composerDisabledReason, composerReducer, createDraftSaver, createTusUpload, createVideoUploads, cycleVideoRate, cycleVoiceNoteRate, dateToClock, defaultScheduleAt, defaultWeek, deviceTimeZone, displayBody, draftKey, emojiEntry, emojiInCategory, emptyComposer, fileFromDataUri, fileSource, filesFromAssets, fill, forgetRecentEmoji, formFrom, formatClock, fullScreenVideo, galleryFor, haptic, hoursFromWeek, idleRecorder, inboxRow, initialVideoRecorder, initials, insertAtSelection, invertedRows, isLocalUri, isOnline, isOpenableHref, isVideoPlaying, linkHost, linkPreviewIds, liveBars, loadDraft, loadRecentEmoji, memoryDraftStorage, messageActionsFor, moderationNote, moderationText, muxPosterUrl, muxStreamUrl, nearBottom, nextOffset, openChatLink, panLimit, pauseChatPlayback, pinchScale, previewToShow, pushRecentEmoji, recentEmojiKey, recordedVideoFile, recorderStep, recordingType, releasePlayback, replyTargetFor, resolveChatCopy, rowIndexOf, rowKey, sameTimeDays, saveRecentEmoji, scheduleInputFrom, scrubSeconds, searchEmoji, shouldDismiss, slotUrl, snippetText, splitCardAttachments, threadListMode, timeZones, toSend, toggleVideo, toggleVideoMute, toggleVoiceNote, topicClosedFor, topicMenuFor, transcriptIsLong, useAwayLine, useCardRuns, useChatAutoRetry, useChatComposer, useChatNative, useChatThreadStackOptions, useJumpToMessage, usePlayingVideo, usePlayingVoiceNote, useScheduleSend, useVideoUploads, useVoiceRecorder, videoRecorderStep, videoSource, videoState, videoUploads, voiceNoteFile, waveformBars, weekFromHours, withDay, withTime };
5009
4943
  //# sourceMappingURL=native.js.map