@marktiderman/genesis-chat 0.8.0 → 0.9.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.d.ts CHANGED
@@ -808,7 +808,10 @@ interface JumpTarget {
808
808
  messageId: string;
809
809
  seq?: number;
810
810
  }
811
- /** The row a message is drawn in, or -1. */
811
+ /**
812
+ * The row a message is drawn in, or -1.
813
+ * @deprecated NativeThreadList finds a row by `jumpId`. Removed in a later minor, with `useJumpToMessage`.
814
+ */
812
815
  declare function rowIndexOf(rows: readonly ThreadRow[], messageId: string): number;
813
816
  interface UseJumpOptions {
814
817
  /** What to go to; a new target (another id or seq) starts again. */
@@ -829,7 +832,7 @@ interface UseJumpOptions {
829
832
  onError: (e: unknown) => void;
830
833
  }
831
834
  /**
832
- * @deprecated Promoted to genesis-ui-native as `useThreadJump`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
835
+ * @deprecated Use genesis-ui-native's `NativeThreadList` (`jumpTo`, `jumpId`, `onLoadUntil`), or `useThreadJump` for a list of your own. ChatThreadScreen is on NativeThreadList; this copy is removed in a later minor.
833
836
  */
834
837
  declare function useJumpToMessage({ target, rows, loading, has, loadUntil, scrollTo, onStart, onLanded, onGone, onError }: UseJumpOptions): {
835
838
  highlightedId: string | null;
@@ -880,7 +883,7 @@ interface ChatThreadScreenSlots {
880
883
  }
881
884
  /**
882
885
  * 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.
886
+ * @deprecated Use genesis-ui-native's `THREAD_AT_BOTTOM_POINTS`. ChatThreadScreen is on NativeThreadList; this copy is removed in a later minor.
884
887
  */
885
888
  declare const AT_BOTTOM_POINTS = 120;
886
889
  /**
@@ -889,7 +892,7 @@ declare const AT_BOTTOM_POINTS = 120;
889
892
  * a screen of it, keeps the first visible row in place when earlier ones load
890
893
  * at the top). FlatList: keeps its place when earlier rows load at the top;
891
894
  * 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.
895
+ * @deprecated Use genesis-ui-native's `threadListMode` (which anchors FlatList past the header, `minIndexForVisible: 1`). ChatThreadScreen is on NativeThreadList; this copy is removed in a later minor.
893
896
  */
894
897
  declare function threadListMode(flash: boolean, reducedMotion: boolean): {
895
898
  followsByHand: boolean;
@@ -897,7 +900,7 @@ declare function threadListMode(flash: boolean, reducedMotion: boolean): {
897
900
  };
898
901
  /**
899
902
  * 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.
903
+ * @deprecated Use genesis-ui-native's `threadNearBottom`. ChatThreadScreen is on NativeThreadList; this copy is removed in a later minor.
901
904
  */
902
905
  declare function nearBottom(m: {
903
906
  contentOffset: {
package/dist/native.js CHANGED
@@ -6,7 +6,7 @@ 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, NativeProgress, useToast, NativeSheet, NativeDatePicker, NativeTimePicker, NativeListItem, NativeSkeleton, NativeEmptyState, NativeTextarea, NativeSwitch, NativeCombobox, NativeChipGroup, NativeChip, NativeInput, NativeSearchBar, NativeInlineAlert, NativeLightbox, useGenesisModules, NativeThreadList, 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';
@@ -1398,7 +1398,7 @@ function MessageBubbleImpl(props) {
1398
1398
  testID,
1399
1399
  accessibilityElementsHidden: invisible || void 0,
1400
1400
  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 },
1401
+ style: { paddingTop: row.groupStart ? 8 : 2, borderRadius: 12, backgroundColor: props.highlighted ? colors.fill : void 0, display: invisible ? "none" : void 0 },
1402
1402
  children: [
1403
1403
  row.showName && sender?.name ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", style: { marginLeft: group ? 48 : 12, marginBottom: 2, color: colors.secondaryLabel }, children: sender.name }) : null,
1404
1404
  /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "flex-end", justifyContent: mine ? "flex-end" : "flex-start" }, children: [
@@ -2955,55 +2955,6 @@ function ChatTopicBar({ topics, value, onValueChange, canManage = false, onSetTo
2955
2955
  )) }) })
2956
2956
  ] });
2957
2957
  }
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
2958
 
3008
2959
  // src/native/emoji-data.ts
3009
2960
  var EMOJI_GROUP_DATA = {
@@ -4121,22 +4072,8 @@ function ChatThreadScreen(props) {
4121
4072
  const colors = useThemeRoles();
4122
4073
  const reducedMotion = useReducedMotion();
4123
4074
  const genesis = useGenesisModules();
4124
- const List = genesis.list ?? FlatList;
4125
- const mode = threadListMode(Boolean(genesis.list), reducedMotion);
4126
4075
  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
- );
4076
+ const toNewest = useCallback(() => listRef.current?.scrollToEnd({ animated: true }), []);
4140
4077
  const composer = useChatComposer(conversationId, threadRootId, userId);
4141
4078
  const { setReply } = composer;
4142
4079
  const [actionsFor, setActionsFor] = useState(null);
@@ -4249,47 +4186,29 @@ function ChatThreadScreen(props) {
4249
4186
  );
4250
4187
  const observer = conv.role === "observer";
4251
4188
  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)) }));
4189
+ const jumpSeq = jumpTo?.seq;
4190
+ const jumpMessageId = jumpTo?.messageId ?? null;
4191
+ const onLoadUntil = useCallback(
4192
+ (id) => {
4193
+ if (id !== jumpMessageId || jumpSeq == null) return Promise.resolve(false);
4194
+ return loadUntil(jumpSeq).catch(() => {
4195
+ fail();
4196
+ return false;
4197
+ });
4282
4198
  },
4283
- onGone: () => {
4284
- toast.show({ title: copy.messageGone });
4285
- atBottom.current = true;
4286
- toBottom(false);
4199
+ [jumpMessageId, jumpSeq, loadUntil, fail]
4200
+ );
4201
+ const jumpAnnouncement = useCallback(
4202
+ (row) => {
4203
+ const m = row.type === "message" && row.item.type === "message" ? row.item.message : null;
4204
+ return m ? fill(copy.jumpedTo, { name: nameOf(m.senderId), text: attachmentPreview(displayBody(m.body), m.attachments[0], attachmentKinds, Boolean(m.deletedAt)) }) : "";
4287
4205
  },
4288
- onError: fail
4289
- });
4206
+ [copy.jumpedTo, nameOf, attachmentKinds]
4207
+ );
4208
+ const onJumpFailed = useCallback(() => toast.show({ title: copy.messageGone }), [toast, copy.messageGone]);
4290
4209
  const reattachable = useCallback((files) => files.every((f) => !f.lost || f.kind === "image" || f.kind === "video"), []);
4291
4210
  const renderItem = useCallback(
4292
- ({ item: row }) => {
4211
+ (row, { highlighted }) => {
4293
4212
  if (row.type === "day") return /* @__PURE__ */ jsx(DaySeparator, { label: row.label, testID: `${testID}-day-${row.key}` });
4294
4213
  if (row.type === "unread") return /* @__PURE__ */ jsx(UnreadDivider, { label: copy.newMessages, testID: `${testID}-unread` });
4295
4214
  const m = row.item.type === "message" ? row.item.message : null;
@@ -4312,7 +4231,7 @@ function ChatThreadScreen(props) {
4312
4231
  onToggleReaction: allowed ? react : void 0,
4313
4232
  onOpenImage,
4314
4233
  observer,
4315
- highlighted: Boolean(m && m.id === highlightedId),
4234
+ highlighted,
4316
4235
  linkPreview: m ? previewToShow(previews[m.id]) : null,
4317
4236
  linkPreviewImages,
4318
4237
  attachmentKinds,
@@ -4323,7 +4242,7 @@ function ChatThreadScreen(props) {
4323
4242
  }
4324
4243
  );
4325
4244
  },
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]
4245
+ [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
4246
  );
4328
4247
  const [videoOpen, setVideoOpen] = useState(false);
4329
4248
  const preparedVideo = useRef(null);
@@ -4347,10 +4266,9 @@ function ChatThreadScreen(props) {
4347
4266
  (video) => {
4348
4267
  videoUploads.start({ conversationId, userId, video, extra: { replyToId: replyNow, threadRootId }, send: outbox.send, videoUpload, prepared: takePrepared(), openFile: modules.openFile });
4349
4268
  if (replyNow) setReply(null);
4350
- atBottom.current = true;
4351
- toBottom(true);
4269
+ toNewest();
4352
4270
  },
4353
- [conversationId, userId, replyNow, threadRootId, outbox, videoUpload, takePrepared, modules.openFile, setReply, toBottom]
4271
+ [conversationId, userId, replyNow, threadRootId, outbox, videoUpload, takePrepared, modules.openFile, setReply, toNewest]
4354
4272
  );
4355
4273
  const activity = activityLine(conv.activity, (id) => nameOf(id));
4356
4274
  const topics = topicsState.topics;
@@ -4372,54 +4290,31 @@ function ChatThreadScreen(props) {
4372
4290
  const KeyboardAvoiding = keyboardModule ?? KeyboardAvoidingView;
4373
4291
  const offset = keyboardVerticalOffset ?? measuredTop;
4374
4292
  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
4293
  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
4294
  /* @__PURE__ */ jsxs(KeyboardAvoiding, { style: { flex: 1 }, ...keyboardProps, children: [
4378
4295
  showTopicBar ? /* @__PURE__ */ jsx(ChatTopicBar, { topics, value: topic ?? null, onValueChange: setChosenTopic, canManage: canManageTopics(conv.role), onSetTopic: topicsState.setTopic, testID: `${testID}-topics` }) : null,
4379
4296
  /* @__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,
4297
+ /* @__PURE__ */ jsx(View, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(
4298
+ NativeThreadList,
4382
4299
  {
4383
4300
  ref: listRef,
4384
4301
  testID: `${testID}-list`,
4385
4302
  data: rows,
4303
+ keyExtractor: threadRowKey,
4304
+ jumpId: threadRowMessageId,
4305
+ getItemType: threadRowType,
4386
4306
  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
4307
+ loading: conv.isLoading,
4308
+ hasEarlier: conv.hasEarlier,
4309
+ onLoadEarlier: () => void conv.loadEarlier(),
4310
+ loadingEarlier: conv.loadingEarlier,
4311
+ earlierLabel: copy.loadEarlier,
4312
+ jumpTo: jumpMessageId,
4313
+ onLoadUntil,
4314
+ jumpAnnouncement,
4315
+ onJumpFailed,
4316
+ footer: activity ? /* @__PURE__ */ jsx(ActivityLine, { text: activity, testID: `${testID}-activity` }) : null,
4317
+ empty: /* @__PURE__ */ jsx(NativeEmptyState, { variant: "first-run", title: copy.threadEmptyTitle, body: currentTopic?.closedAt ? copy.topicClosedNotice : copy.threadEmptyBody, testID: `${testID}-empty` })
4423
4318
  }
4424
4319
  ) }),
4425
4320
  scheduling && !threadRootId ? /* @__PURE__ */ jsx(ChatScheduledBar, { conversationId, testID: `${testID}-scheduled` }) : null,
@@ -4436,8 +4331,7 @@ function ChatThreadScreen(props) {
4436
4331
  role: conv.role,
4437
4332
  onSend: ({ input, files }) => {
4438
4333
  void conv.send(input, files).catch(fail);
4439
- atBottom.current = true;
4440
- toBottom(true);
4334
+ toNewest();
4441
4335
  },
4442
4336
  signalTyping: conv.signalTyping,
4443
4337
  signalRecording: conv.signalRecording,
@@ -4490,20 +4384,9 @@ function ActivityLine({ text, testID }) {
4490
4384
  const colors = useThemeRoles();
4491
4385
  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
4386
  }
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
- }
4387
+ var threadRowKey = (row) => row.key;
4388
+ var threadRowMessageId = (row) => row.type === "message" && row.item.type === "message" ? row.item.message.id : null;
4389
+ var threadRowType = (row) => row.type === "message" ? row.mine ? "mine" : "theirs" : row.type;
4507
4390
  function chatThreadStackOptions(props, background) {
4508
4391
  return getThreadPageStackOptions({
4509
4392
  ...props,
@@ -5004,6 +4887,55 @@ function HitRow({ testID, accessibilityLabel, onPress, children }) {
5004
4887
  }
5005
4888
  );
5006
4889
  }
4890
+ function rowIndexOf(rows, messageId) {
4891
+ return rows.findIndex((r) => r.type === "message" && r.item.type === "message" && r.item.message.id === messageId);
4892
+ }
4893
+ function useJumpToMessage({ target, rows, loading, has, loadUntil, scrollTo, onStart, onLanded, onGone, onError }) {
4894
+ const [pending, setPending] = useState(target ? { ...target, phase: "new" } : null);
4895
+ const [highlightedId, setHighlightedId] = useState(null);
4896
+ useEffect(() => {
4897
+ if (target) setPending({ ...target, phase: "new" });
4898
+ }, [target?.messageId, target?.seq]);
4899
+ const latest = useRef({ rows, scrollTo, onStart, onLanded, onGone, onError });
4900
+ latest.current = { rows, scrollTo, onStart, onLanded, onGone, onError };
4901
+ const timer = useRef(null);
4902
+ useEffect(() => () => {
4903
+ if (timer.current) clearTimeout(timer.current);
4904
+ }, []);
4905
+ const go = useCallback((messageId) => {
4906
+ const index2 = rowIndexOf(latest.current.rows, messageId);
4907
+ if (index2 < 0) return;
4908
+ latest.current.onStart?.();
4909
+ latest.current.scrollTo(index2, messageId);
4910
+ latest.current.onLanded?.(messageId);
4911
+ setHighlightedId(messageId);
4912
+ if (timer.current) clearTimeout(timer.current);
4913
+ timer.current = setTimeout(() => setHighlightedId((h) => h === messageId ? null : h), 2e3);
4914
+ }, []);
4915
+ useEffect(() => {
4916
+ if (!pending || loading) return;
4917
+ const { messageId, seq: seq2, phase } = pending;
4918
+ if (has(messageId)) {
4919
+ setPending(null);
4920
+ go(messageId);
4921
+ return;
4922
+ }
4923
+ if (phase === "loading") return;
4924
+ if (phase === "loaded" || seq2 == null) {
4925
+ setPending(null);
4926
+ latest.current.onGone();
4927
+ return;
4928
+ }
4929
+ latest.current.onStart?.();
4930
+ setPending({ messageId, seq: seq2, phase: "loading" });
4931
+ const settle = () => setPending((p) => p && p.messageId === messageId ? { ...p, phase: "loaded" } : p);
4932
+ void loadUntil(seq2).then(settle, (e) => {
4933
+ latest.current.onError(e);
4934
+ settle();
4935
+ });
4936
+ }, [pending, loading, has, loadUntil, go]);
4937
+ return { highlightedId, jumping: pending !== null };
4938
+ }
5007
4939
 
5008
4940
  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
4941
  //# sourceMappingURL=native.js.map