@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/README.md +1 -1
- package/dist/native.d.ts +11 -6
- package/dist/native.js +167 -233
- package/dist/native.js.map +1 -1
- package/dist/web.d.ts +7 -3
- package/dist/web.js +269 -265
- package/dist/web.js.map +1 -1
- package/migrations/0005_genesis_chat_attachment_paths.sql +80 -0
- package/migrations/tests/0005_genesis_chat_attachment_paths.test.sql +111 -0
- package/package.json +13 -9
- package/src/__tests__/web-attachment-view.test.ts +33 -0
- package/src/__tests__/web.test.tsx +160 -3
- package/src/native/__tests__/composer.test.tsx +75 -0
- package/src/native/__tests__/organise-screens.test.tsx +1 -1
- package/src/native/__tests__/thread-screen.test.tsx +104 -2
- package/src/native/composer.tsx +53 -79
- package/src/native/context.tsx +9 -2
- package/src/native/message-bubble.tsx +3 -3
- package/src/native/modules.ts +13 -18
- package/src/native/organise-copy.ts +3 -0
- package/src/native/thread-screen.tsx +81 -205
- package/src/native/use-jump.ts +5 -2
- package/src/web/attachments.tsx +16 -3
- package/src/web/bubble.tsx +4 -2
- package/src/web/composer.tsx +2 -4
- package/src/web/dock.tsx +3 -3
- package/src/web/inbox.tsx +82 -90
- package/src/web/thread.tsx +248 -259
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @feat:chat
|
|
3
|
-
* One conversation
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
*
|
|
15
|
-
*
|
|
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 {
|
|
24
|
+
import { KeyboardAvoidingView, Platform, View } from "react-native";
|
|
27
25
|
import { SafeAreaView } from "react-native-safe-area-context";
|
|
28
|
-
import { NativeEmptyState,
|
|
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 {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
194
|
-
|
|
195
|
-
const
|
|
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
|
-
//
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
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
|
-
(
|
|
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={
|
|
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
|
|
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
|
-
|
|
456
|
-
toBottom(true);
|
|
400
|
+
toNewest();
|
|
457
401
|
},
|
|
458
|
-
[conversationId, userId, replyNow, threadRootId, outbox, videoUpload, takePrepared, modules.openFile, setReply,
|
|
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
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
-
|
|
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
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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);
|
package/src/native/use-jump.ts
CHANGED
|
@@ -12,7 +12,10 @@ export interface JumpTarget {
|
|
|
12
12
|
seq?: number;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
/**
|
|
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
|
|
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);
|
package/src/web/attachments.tsx
CHANGED
|
@@ -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
|
|
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,
|
package/src/web/bubble.tsx
CHANGED
|
@@ -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";
|
package/src/web/composer.tsx
CHANGED
|
@@ -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
|
-
*
|
|
11
|
-
*
|
|
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
|
);
|