@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.
@@ -1,21 +1,19 @@
1
1
  /**
2
2
  * @feat:chat
3
- * One conversation: a list oldest first, top to bottom, the order it reads in
4
- * with VoiceOver (FlashList's bottom-anchored chat mode when the app gave it,
5
- * else FlatList), that opens at the newest message, follows new ones while
6
- * you are at the bottom, goes to the bottom when you send, and keeps its
7
- * place while earlier ones load at the top; day separators, the "New messages" line,
3
+ * One conversation, on genesis-ui-native's `NativeThreadList`: oldest first,
4
+ * top to bottom, the order it reads in with VoiceOver (FlashList's
5
+ * bottom-anchored chat mode when the app gave it, else FlatList), opening at
6
+ * the newest message, following new ones while you are at the bottom, going
7
+ * to the bottom when you send, and keeping its place while earlier ones load
8
+ * at the top; day separators, the "New messages" line,
8
9
  * grouped bubbles with names and avatars in groups, who is typing or
9
10
  * recording, retry and delete on a send that failed, the long-press sheet and
10
11
  * swipe to reply, a message's photos in the full-screen viewer, and the composer above
11
12
  * the keyboard (or, when your role couldn't be read, Retry). Render it as the screen's only content, under the
12
13
  * navigator's header with `useChatThreadStackOptions` (an opaque bar).
13
14
  *
14
- * Not inverted: FlashList 2 keeps the first visible row in place when rows
15
- * change and only follows new rows at the bottom (`autoscrollToBottomThreshold`;
16
- * it declares `autoscrollToTopThreshold` but never reads it), so in an inverted list a new message
17
- * at index 0 was pushed under the composer. Inverted, VoiceOver also read
18
- * each day's heading after its messages.
15
+ * A row is keyed by the message's client id (it keeps its row when the
16
+ * server's copy lands) and gone to by the server's id (`jumpId`).
19
17
  *
20
18
  * Organising: a topic bar when the conversation has topics (the list shows the topic chosen; a
21
19
  * closed one takes no posts from members), the away line under the header, scheduled send
@@ -23,9 +21,9 @@
23
21
  * message (a search result), and moderation's markers.
24
22
  */
25
23
  import { useCallback, useEffect, useMemo, useRef, useState, type ComponentType } from "react";
26
- import { AccessibilityInfo, FlatList, KeyboardAvoidingView, Platform, Pressable, View, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent } from "react-native";
24
+ import { KeyboardAvoidingView, Platform, View } from "react-native";
27
25
  import { SafeAreaView } from "react-native-safe-area-context";
28
- import { NativeEmptyState, NativeSkeleton, NativeText, useGenesisModules, useToast } from "@marktiderman/genesis-ui-native/components";
26
+ import { NativeEmptyState, NativeText, NativeThreadList, useGenesisModules, useToast, type NativeThreadListHandle, type ThreadRowInfo } from "@marktiderman/genesis-ui-native/components";
29
27
  import { useReducedMotion, useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
30
28
  import { activityLine } from "../core/thread";
31
29
  import type { ChatMessage, PendingFile } from "../core/types";
@@ -40,7 +38,7 @@ import { ChatAwayLine, useAwayLine } from "./availability";
40
38
  import { fill } from "./copy";
41
39
  import { ChatScheduledBar, ChatScheduleSheet, useScheduleSend } from "./schedule-sheet";
42
40
  import { canManageTopics, ChatTopicBar, topicClosedFor } from "./topics";
43
- import { rowIndexOf, useJumpToMessage, type JumpTarget } from "./use-jump";
41
+ import type { JumpTarget } from "./use-jump";
44
42
  import type { MessageActionId } from "./actions";
45
43
  import { ChatComposer } from "./composer";
46
44
  import { composerDisabledReason, filesFromAssets, replyTargetFor } from "./composer-state";
@@ -102,34 +100,9 @@ export interface ChatThreadScreenSlots {
102
100
  attachment?: ChatAttachmentSlot | null;
103
101
  }
104
102
 
105
- /** The list props chat passes; FlashList v2 and FlatList both take them. */
106
- interface ChatListProps {
107
- ref?: unknown;
108
- data: readonly ThreadRow[];
109
- renderItem: (info: { item: ThreadRow; index: number }) => React.ReactElement | null;
110
- keyExtractor: (row: ThreadRow) => string;
111
- getItemType?: (row: ThreadRow) => string;
112
- inverted?: boolean;
113
- onStartReached?: () => void;
114
- onStartReachedThreshold?: number;
115
- ListHeaderComponent?: React.ReactElement | null;
116
- ListFooterComponent?: React.ReactElement | null;
117
- keyboardShouldPersistTaps?: "handled";
118
- keyboardDismissMode?: "interactive" | "on-drag";
119
- contentContainerStyle?: Record<string, unknown>;
120
- maintainVisibleContentPosition?: Record<string, unknown>;
121
- onScroll?: (e: NativeSyntheticEvent<NativeScrollEvent>) => void;
122
- scrollEventThrottle?: number;
123
- onContentSizeChange?: (width: number, height: number) => void;
124
- onLayout?: (e: LayoutChangeEvent) => void;
125
- extraData?: unknown;
126
- onScrollToIndexFailed?: (info: { index: number; averageItemLength: number }) => void;
127
- testID?: string;
128
- }
129
-
130
103
  /**
131
104
  * Points from the bottom that still count as "at the bottom" (FlatList, which follows by hand).
132
- * @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.
105
+ * @deprecated Use genesis-ui-native's `THREAD_AT_BOTTOM_POINTS`. ChatThreadScreen is on NativeThreadList; this copy is removed in a later minor.
133
106
  */
134
107
  export const AT_BOTTOM_POINTS = 120;
135
108
 
@@ -139,7 +112,7 @@ export const AT_BOTTOM_POINTS = 120;
139
112
  * a screen of it, keeps the first visible row in place when earlier ones load
140
113
  * at the top). FlatList: keeps its place when earlier rows load at the top;
141
114
  * the screen follows new rows itself (`followsByHand`).
142
- * @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.
115
+ * @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.
143
116
  */
144
117
  export function threadListMode(flash: boolean, reducedMotion: boolean): { followsByHand: boolean; maintainVisibleContentPosition: Record<string, unknown> } {
145
118
  if (flash) {
@@ -153,7 +126,7 @@ export function threadListMode(flash: boolean, reducedMotion: boolean): { follow
153
126
 
154
127
  /**
155
128
  * Whether a scroll position is at (or near) the bottom of its content.
156
- * @deprecated Promoted to genesis-ui-native as `threadNearBottom`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
129
+ * @deprecated Use genesis-ui-native's `threadNearBottom`. ChatThreadScreen is on NativeThreadList; this copy is removed in a later minor.
157
130
  */
158
131
  export function nearBottom(m: { contentOffset: { y: number }; contentSize: { height: number }; layoutMeasurement: { height: number } }, slack = AT_BOTTOM_POINTS): boolean {
159
132
  return m.contentOffset.y + m.layoutMeasurement.height >= m.contentSize.height - slack;
@@ -190,30 +163,9 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
190
163
  const colors = useThemeRoles();
191
164
  const reducedMotion = useReducedMotion();
192
165
  const genesis = useGenesisModules();
193
- const List = (genesis.list ?? FlatList) as unknown as ComponentType<ChatListProps>;
194
- const mode = threadListMode(Boolean(genesis.list), reducedMotion);
195
- const listRef = useRef<{
196
- scrollToEnd?: (o?: { animated?: boolean }) => void;
197
- scrollToIndex?: (o: { index: number; animated?: boolean; viewPosition?: number }) => void;
198
- scrollToOffset?: (o: { offset: number; animated?: boolean }) => void;
199
- } | null>(null);
200
- // FlatList follows by hand: at the bottom (or not yet scrolled), new rows and a shorter list keep it there.
201
- const atBottom = useRef(true);
202
- // FlatList opens at the top and is moved to the bottom a frame later: until it has been, the top
203
- // isn't "reached" (it would load an earlier page on every open).
204
- const placed = useRef(!mode.followsByHand);
205
- const toBottom = useCallback(
206
- (animated: boolean) => {
207
- const go = (a: boolean) => listRef.current?.scrollToEnd?.({ animated: a && !reducedMotion });
208
- requestAnimationFrame(() => {
209
- go(animated);
210
- placed.current = true;
211
- });
212
- // Once more after the new row has its size (FlashList measures it after the first pass).
213
- if (animated) setTimeout(() => go(true), 180);
214
- },
215
- [reducedMotion],
216
- );
166
+ const listRef = useRef<NativeThreadListHandle | null>(null);
167
+ // What you send is what you look at next, wherever the list was.
168
+ const toNewest = useCallback(() => listRef.current?.scrollToEnd({ animated: true }), []);
217
169
  const composer = useChatComposer(conversationId, threadRootId, userId);
218
170
  const { setReply } = composer;
219
171
  const [actionsFor, setActionsFor] = useState<ChatMessage | null>(null);
@@ -344,53 +296,46 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
344
296
  );
345
297
  const observer = conv.role === "observer";
346
298
  const { loadUntil } = conv;
347
- // The message being gone to, for FlatList's retry once it has measured that far (by id: rows may have moved).
348
- const jumpingTo = useRef<{ id: string; tries: number } | null>(null);
349
- const retryTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
350
- useEffect(() => () => {
351
- if (retryTimer.current) clearTimeout(retryTimer.current);
352
- }, []);
353
- const rowsNow = useRef(rows);
354
- rowsNow.current = rows;
355
- const { highlightedId, jumping } = useJumpToMessage({
356
- target: jumpTo,
357
- rows,
358
- loading: conv.isLoading,
359
- has: useCallback((id: string) => byId.has(id), [byId]),
360
- loadUntil,
361
- scrollTo: (index, id) => {
362
- jumpingTo.current = { id, tries: 0 };
363
- const scroll = (at: number) => listRef.current?.scrollToIndex?.({ index: at, animated: !reducedMotion, viewPosition: 0.5 });
364
- requestAnimationFrame(() => scroll(index));
365
- // Once more after the first layout: with the message already loaded (the thread was opened
366
- // before), the jump runs on the first frame, and FlashList's start-at-the-bottom placement,
367
- // which comes after it, would win and leave the thread at the bottom.
368
- if (retryTimer.current) clearTimeout(retryTimer.current);
369
- retryTimer.current = setTimeout(() => {
370
- const at = rowIndexOf(rowsNow.current, id);
371
- if (at >= 0) scroll(at);
372
- }, 250);
373
- },
374
- onStart: () => {
375
- atBottom.current = false;
376
- placed.current = true;
377
- },
378
- onLanded: (id) => {
379
- const m = byId.get(id);
380
- if (m) AccessibilityInfo.announceForAccessibility?.(fill(copy.jumpedTo, { name: nameOf(m.senderId), text: attachmentPreview(displayBody(m.body), m.attachments[0], attachmentKinds, Boolean(m.deletedAt)) }));
299
+ // A jump names the server's message id; its seq says how far back to load.
300
+ const jumpSeq = jumpTo?.seq;
301
+ // Not while the first page has failed: there's nothing to look in, so the message isn't known to be
302
+ // gone. The reader hears the read failed, and the jump goes ahead when the rows come. Messages, not
303
+ // rows: a saved outbox row is drawn even when nothing could be read.
304
+ const firstPageFailed = Boolean(conv.error) && conv.messages.length === 0;
305
+ const jumpMessageId = firstPageFailed ? null : (jumpTo?.messageId ?? null);
306
+ const jumpBlocked = firstPageFailed && Boolean(jumpTo);
307
+ useEffect(() => {
308
+ if (jumpBlocked) fail();
309
+ }, [jumpBlocked, fail]);
310
+ // A load that failed has said so: the message isn't known to be gone.
311
+ const jumpLoadFailed = useRef(false);
312
+ const onLoadUntil = useCallback(
313
+ (id: string) => {
314
+ jumpLoadFailed.current = false;
315
+ if (id !== jumpMessageId || jumpSeq == null) return Promise.resolve(false);
316
+ return loadUntil(jumpSeq).catch(() => {
317
+ jumpLoadFailed.current = true;
318
+ fail();
319
+ return false;
320
+ });
381
321
  },
382
- onGone: () => {
383
- toast.show({ title: copy.messageGone });
384
- // Back to where the thread opens: the newest messages.
385
- atBottom.current = true;
386
- toBottom(false);
322
+ [jumpMessageId, jumpSeq, loadUntil, fail],
323
+ );
324
+ const jumpAnnouncement = useCallback(
325
+ (row: ThreadRow) => {
326
+ const m = row.type === "message" && row.item.type === "message" ? row.item.message : null;
327
+ return m ? fill(copy.jumpedTo, { name: nameOf(m.senderId), text: attachmentPreview(displayBody(m.body), m.attachments[0], attachmentKinds, Boolean(m.deletedAt)) }) : "";
387
328
  },
388
- onError: fail,
389
- });
329
+ [copy.jumpedTo, nameOf, attachmentKinds],
330
+ );
331
+ const onJumpFailed = useCallback(() => {
332
+ if (jumpLoadFailed.current) jumpLoadFailed.current = false;
333
+ else toast.show({ title: copy.messageGone });
334
+ }, [toast, copy.messageGone]);
390
335
  const reattachable = useCallback((files: readonly PendingFile[]) => files.every((f) => !f.lost || f.kind === "image" || f.kind === "video"), []);
391
336
 
392
337
  const renderItem = useCallback(
393
- ({ item: row }: { item: ThreadRow }) => {
338
+ (row: ThreadRow, { highlighted }: ThreadRowInfo) => {
394
339
  if (row.type === "day") return <DaySeparator label={row.label} testID={`${testID}-day-${row.key}`} />;
395
340
  if (row.type === "unread") return <UnreadDivider label={copy.newMessages} testID={`${testID}-unread`} />;
396
341
  const m = row.item.type === "message" ? row.item.message : null;
@@ -412,7 +357,7 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
412
357
  onToggleReaction={allowed ? react : undefined}
413
358
  onOpenImage={onOpenImage}
414
359
  observer={observer}
415
- highlighted={Boolean(m && m.id === highlightedId)}
360
+ highlighted={highlighted}
416
361
  linkPreview={m ? previewToShow(previews[m.id]) : null}
417
362
  linkPreviewImages={linkPreviewImages}
418
363
  attachmentKinds={attachmentKinds}
@@ -423,7 +368,7 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
423
368
  />
424
369
  );
425
370
  },
426
- [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],
371
+ [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],
427
372
  );
428
373
 
429
374
  // ---- Video messages ----
@@ -452,10 +397,9 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
452
397
  (video: RecordedVideo) => {
453
398
  videoUploads.start({ conversationId, userId, video, extra: { replyToId: replyNow, threadRootId }, send: outbox.send, videoUpload, prepared: takePrepared(), openFile: modules.openFile });
454
399
  if (replyNow) setReply(null);
455
- atBottom.current = true;
456
- toBottom(true);
400
+ toNewest();
457
401
  },
458
- [conversationId, userId, replyNow, threadRootId, outbox, videoUpload, takePrepared, modules.openFile, setReply, toBottom],
402
+ [conversationId, userId, replyNow, threadRootId, outbox, videoUpload, takePrepared, modules.openFile, setReply, toNewest],
459
403
  );
460
404
 
461
405
  const activity = activityLine(conv.activity, (id) => nameOf(id));
@@ -485,7 +429,6 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
485
429
  ? { behavior: "translate-with-padding", keyboardVerticalOffset: offset }
486
430
  : { behavior: Platform.OS === "ios" ? "padding" : undefined, keyboardVerticalOffset: offset };
487
431
 
488
- const empty = !conv.isLoading && rows.length === 0;
489
432
  return (
490
433
  <ChatPeopleScope userIds={peopleIds}>
491
434
  <SafeAreaView ref={rootRef as never} onLayout={measureTop} testID={testID} edges={["left", "right", "bottom"]} style={{ flex: 1, backgroundColor: colors.groupedBackground }}>
@@ -495,64 +438,26 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
495
438
  ) : null}
496
439
  <ChatAwayLine text={awayLine} testID={`${testID}-away`} />
497
440
  <View style={{ flex: 1 }}>
498
- {conv.isLoading ? (
499
- <LoadingThread testID={`${testID}-loading`} />
500
- ) : empty ? (
501
- <View style={{ flex: 1, justifyContent: "center" }}>
502
- <NativeEmptyState variant="first-run" title={copy.threadEmptyTitle} body={currentTopic?.closedAt ? copy.topicClosedNotice : copy.threadEmptyBody} testID={`${testID}-empty`} />
503
- </View>
504
- ) : (
505
- <List
506
- ref={listRef}
507
- testID={`${testID}-list`}
508
- data={rows}
509
- renderItem={renderItem}
510
- keyExtractor={(row) => row.key}
511
- getItemType={(row) => (row.type === "message" ? (row.mine ? "mine" : "theirs") : row.type)}
512
- onStartReached={() => {
513
- // Not while going to a message: its pages are loading, and new rows would move it.
514
- if (placed.current && !jumping && conv.hasEarlier && !conv.loadingEarlier) void conv.loadEarlier();
515
- }}
516
- onStartReachedThreshold={0.5}
517
- keyboardShouldPersistTaps="handled"
518
- keyboardDismissMode="interactive"
519
- contentContainerStyle={{ paddingVertical: 8 }}
520
- maintainVisibleContentPosition={mode.maintainVisibleContentPosition}
521
- extraData={highlightedId}
522
- onScrollToIndexFailed={({ index, averageItemLength }) => {
523
- // FlatList hasn't measured that far up yet: get near it, then try again (three times at most).
524
- listRef.current?.scrollToOffset?.({ offset: Math.max(0, index * averageItemLength - 200), animated: false });
525
- const target = jumpingTo.current;
526
- if (!target || target.tries >= 3) return;
527
- target.tries += 1;
528
- if (retryTimer.current) clearTimeout(retryTimer.current);
529
- retryTimer.current = setTimeout(() => {
530
- const at = rowIndexOf(rowsNow.current, target.id);
531
- if (at >= 0) listRef.current?.scrollToIndex?.({ index: at, animated: !reducedMotion, viewPosition: 0.5 });
532
- }, 250);
533
- }}
534
- {...(mode.followsByHand
535
- ? {
536
- scrollEventThrottle: 32,
537
- onScroll: (e: NativeSyntheticEvent<NativeScrollEvent>) => {
538
- atBottom.current = nearBottom(e.nativeEvent);
539
- },
540
- onContentSizeChange: () => {
541
- if (atBottom.current) toBottom(false);
542
- },
543
- onLayout: () => {
544
- if (atBottom.current) toBottom(false);
545
- },
546
- }
547
- : {})}
548
- ListHeaderComponent={
549
- conv.hasEarlier ? (
550
- <EarlierAnchor loading={conv.loadingEarlier} label={copy.loadEarlier} onPress={() => void conv.loadEarlier()} testID={`${testID}-earlier`} />
551
- ) : null
552
- }
553
- ListFooterComponent={activity ? <ActivityLine text={activity} testID={`${testID}-activity`} /> : null}
554
- />
555
- )}
441
+ <NativeThreadList<ThreadRow>
442
+ ref={listRef}
443
+ testID={`${testID}-list`}
444
+ data={rows}
445
+ keyExtractor={threadRowKey}
446
+ jumpId={threadRowMessageId}
447
+ getItemType={threadRowType}
448
+ renderItem={renderItem}
449
+ loading={conv.isLoading}
450
+ hasEarlier={conv.hasEarlier}
451
+ onLoadEarlier={() => void conv.loadEarlier()}
452
+ loadingEarlier={conv.loadingEarlier}
453
+ earlierLabel={copy.loadEarlier}
454
+ jumpTo={jumpMessageId}
455
+ onLoadUntil={onLoadUntil}
456
+ jumpAnnouncement={jumpAnnouncement}
457
+ onJumpFailed={onJumpFailed}
458
+ footer={activity ? <ActivityLine text={activity} testID={`${testID}-activity`} /> : null}
459
+ empty={<NativeEmptyState variant="first-run" title={copy.threadEmptyTitle} body={currentTopic?.closedAt ? copy.topicClosedNotice : copy.threadEmptyBody} testID={`${testID}-empty`} />}
460
+ />
556
461
  </View>
557
462
  {scheduling && !threadRootId ? <ChatScheduledBar conversationId={conversationId} testID={`${testID}-scheduled`} /> : null}
558
463
  <VideoUploadTray conversationId={conversationId} userId={userId} testID={`${testID}-video-uploads`} />
@@ -569,9 +474,7 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
569
474
  role={conv.role}
570
475
  onSend={({ input, files }) => {
571
476
  void conv.send(input, files).catch(fail);
572
- // What you send is what you look at next, wherever the list was.
573
- atBottom.current = true;
574
- toBottom(true);
477
+ toNewest();
575
478
  }}
576
479
  signalTyping={conv.signalTyping}
577
480
  signalRecording={conv.signalRecording}
@@ -640,34 +543,7 @@ function ActivityLine({ text, testID }: { text: string; testID: string }) {
640
543
  );
641
544
  }
642
545
 
643
- function EarlierAnchor({ loading, label, onPress, testID }: { loading: boolean; label: string; onPress: () => void; testID: string }) {
644
- const colors = useThemeRoles();
645
- return (
646
- <View style={{ alignItems: "center", paddingVertical: 12 }}>
647
- {loading ? (
648
- <View testID={`${testID}-loading`} style={{ gap: 8, alignItems: "center" }}>
649
- <NativeSkeleton width={180} height={14} />
650
- <NativeSkeleton width={120} height={14} />
651
- </View>
652
- ) : (
653
- <Pressable testID={testID} accessibilityRole="button" accessibilityLabel={label} onPress={onPress} style={{ minHeight: 44, justifyContent: "center", paddingHorizontal: 16 }}>
654
- <NativeText preset="label" style={{ color: colors.tint }}>
655
- {label}
656
- </NativeText>
657
- </Pressable>
658
- )}
659
- </View>
660
- );
661
- }
662
-
663
- function LoadingThread({ testID }: { testID: string }) {
664
- return (
665
- <View testID={testID} style={{ flex: 1, justifyContent: "flex-end", padding: 16, gap: 10 }}>
666
- <NativeSkeleton width={200} height={36} className="rounded-2xl" />
667
- <View style={{ alignItems: "flex-end" }}>
668
- <NativeSkeleton width={160} height={36} className="rounded-2xl" />
669
- </View>
670
- <NativeSkeleton width={240} height={36} className="rounded-2xl" />
671
- </View>
672
- );
673
- }
546
+ const threadRowKey = (row: ThreadRow) => row.key;
547
+ /** A message row is gone to by the server's id; a day heading, the unread line and a message still sending can't be. */
548
+ const threadRowMessageId = (row: ThreadRow) => (row.type === "message" && row.item.type === "message" ? row.item.message.id : null);
549
+ const threadRowType = (row: ThreadRow) => (row.type === "message" ? (row.mine ? "mine" : "theirs") : row.type);
@@ -12,7 +12,10 @@ export interface JumpTarget {
12
12
  seq?: number;
13
13
  }
14
14
 
15
- /** The row a message is drawn in, or -1. */
15
+ /**
16
+ * The row a message is drawn in, or -1.
17
+ * @deprecated NativeThreadList finds a row by `jumpId`. Removed in a later minor, with `useJumpToMessage`.
18
+ */
16
19
  export function rowIndexOf(rows: readonly ThreadRow[], messageId: string): number {
17
20
  return rows.findIndex((r) => r.type === "message" && r.item.type === "message" && r.item.message.id === messageId);
18
21
  }
@@ -39,7 +42,7 @@ export interface UseJumpOptions {
39
42
  type Pending = JumpTarget & { phase: "new" | "loading" | "loaded" };
40
43
 
41
44
  /**
42
- * @deprecated Promoted to genesis-ui-native as `useThreadJump`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
45
+ * @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.
43
46
  */
44
47
  export function useJumpToMessage({ target, rows, loading, has, loadUntil, scrollTo, onStart, onLanded, onGone, onError }: UseJumpOptions) {
45
48
  const [pending, setPending] = useState<Pending | null>(target ? { ...target, phase: "new" } : null);
@@ -50,13 +50,26 @@ export interface ChatAttachmentSlotProps {
50
50
 
51
51
  export const BUILT_IN_KINDS = new Set(["image", "voice", "video", "file", "link"]);
52
52
 
53
+ const hostOf = (url: string | null): string => {
54
+ try {
55
+ return url ? new URL(url).host : "";
56
+ } catch {
57
+ return "";
58
+ }
59
+ };
60
+
53
61
  export function toAttachmentView(a: ChatAttachment, urls: Record<string, string>): AttachmentView {
62
+ const signed = a.path ? (urls[a.path] ?? null) : null;
63
+ const url = a.path ? signed : a.provider === "external" || a.kind === "link" ? a.url : null;
64
+ // Media from outside storage is a link naming its host: whoever sent it chose that address, so a
65
+ // reader's browser loads nothing until they ask.
66
+ const outsideMedia = (a.kind === "image" || a.kind === "video" || a.kind === "voice") && !a.path && Boolean(url);
54
67
  return {
55
68
  key: a.id,
56
- kind: a.kind,
57
- url: (a.path ? urls[a.path] : null) ?? (a.provider === "external" ? a.url : null) ?? (a.kind === "link" ? a.url : null),
69
+ kind: outsideMedia ? "file" : a.kind,
70
+ url,
58
71
  posterUrl: a.posterPath ? (urls[a.posterPath] ?? null) : null,
59
- name: a.name,
72
+ name: outsideMedia ? `${a.name ?? "File"} (${hostOf(url)})` : a.name,
60
73
  mime: a.mime,
61
74
  bytes: a.bytes,
62
75
  width: a.width,
@@ -64,6 +64,8 @@ export interface MessageRowProps {
64
64
  item: ThreadItem;
65
65
  /** First of a run from one sender: the name and avatar show (others' messages, in groups). */
66
66
  startsGroup: boolean;
67
+ /** A jump just landed here (ThreadPage says so). */
68
+ highlighted?: boolean;
67
69
  className?: string;
68
70
  }
69
71
 
@@ -139,7 +141,7 @@ export function plainText(body: string): string {
139
141
  return body.replace(/@\[([^\]]+)\]\(user:[0-9a-f-]{36}\)/gi, "@$1");
140
142
  }
141
143
 
142
- export function MessageRow({ item, startsGroup, className }: MessageRowProps) {
144
+ export function MessageRow({ item, startsGroup, highlighted: highlightedProp, className }: MessageRowProps) {
143
145
  const ctx = useThreadContext();
144
146
  const keepFocus = useRef<(() => void) | null>(null);
145
147
  const pending = item.type === "pending" ? item.pending : null;
@@ -165,7 +167,7 @@ export function MessageRow({ item, startsGroup, className }: MessageRowProps) {
165
167
  const progress = pending ? pendingProgress(pending) : null;
166
168
  const editing = ctx.editingId === message.id;
167
169
  const reactions = pending ? [] : summarizeReactions(message, ctx.me);
168
- const highlighted = ctx.highlightedId === message.id;
170
+ const highlighted = highlightedProp ?? ctx.highlightedId === message.id;
169
171
  const actionable = !pending && !deleted;
170
172
  const hidden = !deleted && message.moderation === "hidden";
171
173
  const flagged = !deleted && message.moderation === "flagged";
@@ -7,10 +7,8 @@
7
7
  * camera, emoji, and scheduled send (the arrow beside Send). Where you may not
8
8
  * post it says why instead; when who you are couldn't load, it offers a retry.
9
9
  *
10
- * Moving onto genesis-ui (feature `inbox-thread`): its scrolling, list and composer are the same
11
- * behaviour as genesis-ui's `ComposerBar`, which were promoted from here. This screen keeps its data
12
- * wiring (the chat client, realtime, read state) and moves its rendering onto `ComposerBar` with chat's
13
- * builder; until then fix behaviour in both places.
10
+ * In ChatThread it fills `ThreadPage`'s `composer` slot. Its input isn't on genesis-ui's `ComposerBar`
11
+ * yet: the web bar has no attachments-only send, or a mic in Send's place, as the native one has.
14
12
  */
15
13
  import {
16
14
  useCallback,
package/src/web/dock.tsx CHANGED
@@ -76,8 +76,8 @@ export interface ChatDockPanel {
76
76
  /** Opening the same id again brings that window back rather than adding a second. */
77
77
  id: string;
78
78
  title: string;
79
- /** Its body, filling the window under the dock's title bar. */
80
- render: () => ReactNode;
79
+ /** Its body, filling the window under the dock's title bar. `visible`: it stays mounted when minimized, so pause what mustn't happen out of sight (marking read). */
80
+ render: (state: { visible: boolean }) => ReactNode;
81
81
  /** In place of the avatar in the title bar. */
82
82
  icon?: ReactNode;
83
83
  /** Unread count on the bar and the bubble. */
@@ -649,7 +649,7 @@ function DockItemView({ item, inbox, resolveUser, threadProps, labels, inSheet,
649
649
  toggleRef={toggleRef}
650
650
  />
651
651
  <div className="flex min-h-0 flex-1 flex-col overflow-y-auto" hidden={!visible} data-testid="genesis-chat-dock-panel">
652
- {item.render()}
652
+ {item.render({ visible })}
653
653
  </div>
654
654
  </>
655
655
  );