@marktiderman/genesis-chat 0.11.3 → 0.12.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 +116 -3
- package/dist/{chunk-ZQFREERR.js → chunk-2HNQWDLF.js} +3 -3
- package/dist/{chunk-ZQFREERR.js.map → chunk-2HNQWDLF.js.map} +1 -1
- package/dist/{chunk-O2QSBRSH.js → chunk-3HQN2FZ5.js} +3 -3
- package/dist/{chunk-O2QSBRSH.js.map → chunk-3HQN2FZ5.js.map} +1 -1
- package/dist/{chunk-D4RPOYB7.js → chunk-K5GYNHNE.js} +61 -11
- package/dist/chunk-K5GYNHNE.js.map +1 -0
- package/dist/{chunk-5XYDVUPS.js → chunk-VBIYDXL2.js} +9 -3
- package/dist/chunk-VBIYDXL2.js.map +1 -0
- package/dist/{client-DP7rhJ1U.d.ts → client-DJs3ltZc.d.ts} +15 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/native.d.ts +339 -137
- package/dist/native.js +668 -192
- package/dist/native.js.map +1 -1
- package/dist/{outbox-C4LnqpKT.d.ts → outbox-YFTbGIAl.d.ts} +1 -1
- package/dist/push.d.ts +2 -2
- package/dist/react.d.ts +13 -5
- package/dist/react.js +3 -3
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/{thread-CSzdqNR_.d.ts → thread-CgHP00Jw.d.ts} +1 -1
- package/dist/web.d.ts +3 -3
- package/dist/web.js +5 -5
- package/migrations/0006_genesis_chat_read_receipts.sql +110 -0
- package/migrations/tests/0006_genesis_chat_read_receipts.test.sql +131 -0
- package/package.json +9 -5
- package/src/core/client.ts +9 -0
- package/src/core/types.ts +7 -0
- package/src/native/__tests__/bubble-native-feel.test.tsx +153 -0
- package/src/native/__tests__/composer-attach-menu.test.tsx +47 -0
- package/src/native/__tests__/media-cache-key.test.tsx +21 -0
- package/src/native/__tests__/organise-screens.test.tsx +2 -0
- package/src/native/__tests__/receipts.test.ts +95 -0
- package/src/native/__tests__/review-lows.test.tsx +80 -0
- package/src/native/__tests__/sheets-fit.test.tsx +45 -0
- package/src/native/__tests__/stable-hooks.test.tsx +68 -0
- package/src/native/__tests__/thread-screen-audit.test.tsx +248 -0
- package/src/native/__tests__/thread-screen.test.tsx +111 -0
- package/src/native/__tests__/thread-title.test.tsx +59 -0
- package/src/native/composer.tsx +61 -26
- package/src/native/copy.ts +40 -0
- package/src/native/emoji-picker.tsx +1 -1
- package/src/native/index.ts +6 -1
- package/src/native/media.tsx +7 -1
- package/src/native/message-actions-sheet.tsx +1 -1
- package/src/native/message-bubble.tsx +171 -19
- package/src/native/modules.ts +3 -1
- package/src/native/receipts.ts +102 -0
- package/src/native/schedule-sheet.tsx +8 -3
- package/src/native/stack-options.ts +35 -3
- package/src/native/thread-screen.tsx +243 -17
- package/src/native/thread-times.tsx +89 -0
- package/src/native/thread-title.tsx +111 -0
- package/src/native/typing-bubble.tsx +85 -0
- package/src/react/index.tsx +74 -7
- package/dist/chunk-5XYDVUPS.js.map +0 -1
- package/dist/chunk-D4RPOYB7.js.map +0 -1
|
@@ -12,10 +12,17 @@
|
|
|
12
12
|
* app card's action. App attachment kinds draw as cards, or through the app's
|
|
13
13
|
* `attachmentSlot` (see attachment-cards.tsx); a voice note's transcript is
|
|
14
14
|
* part of the bubble's label.
|
|
15
|
+
*
|
|
16
|
+
* Shape: iMessage's. A run of one sender's bubbles is drawn as one: the corners where two meet are
|
|
17
|
+
* tight, and the last (or only) one has a tail at its bottom corner on the sender's side
|
|
18
|
+
* (`bubbleCorners`). Swipe to reply runs on react-native-gesture-handler (the app's
|
|
19
|
+
* `GenesisModules.swipeable`, `ReanimatedSwipeable`) when given, on the UI thread; without it, a
|
|
20
|
+
* PanResponder. A message you just sent rises into place (`GenesisModules.reanimated`'s
|
|
21
|
+
* `FadeInDown`), not with Reduce Motion.
|
|
15
22
|
*/
|
|
16
|
-
import { memo, useCallback, useMemo, useRef, useState } from "react";
|
|
23
|
+
import { memo, useCallback, useMemo, useRef, useState, type ComponentType, type ReactNode } from "react";
|
|
17
24
|
import { Animated, PanResponder, Pressable, View } from "react-native";
|
|
18
|
-
import { NativeAvatar, NativeText } from "@marktiderman/genesis-ui-native/components";
|
|
25
|
+
import { NativeAvatar, NativeIcon, NativeText, useGenesisModules } from "@marktiderman/genesis-ui-native/components";
|
|
19
26
|
import { sentBubbleColor, useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
|
|
20
27
|
import { summarizeReactions } from "../core/thread";
|
|
21
28
|
import type { ChatLinkPreview, ChatMessage, PendingFile } from "../core/types";
|
|
@@ -29,6 +36,7 @@ import { fromPending, fromPendingInput, fromServer, MessageAttachments, type Bub
|
|
|
29
36
|
import { ModerationMarker, moderationNote, moderationText } from "./moderation";
|
|
30
37
|
import { cycleVoiceNoteRate, toggleVoiceNote, usePlayingVoiceNote } from "./voice-player";
|
|
31
38
|
import type { ThreadRow } from "./rows";
|
|
39
|
+
import { TimeRevealRow } from "./thread-times";
|
|
32
40
|
|
|
33
41
|
type MessageRow = Extract<ThreadRow, { type: "message" }>;
|
|
34
42
|
|
|
@@ -72,12 +80,51 @@ export interface MessageBubbleProps {
|
|
|
72
80
|
attachmentSlot?: ChatAttachmentSlot | null;
|
|
73
81
|
/** How long an app card's action may run before it reads as failed; 30 s by default, 0 for never. */
|
|
74
82
|
cardActionTimeoutMs?: number;
|
|
83
|
+
/** Its status under the bubble, on the last message you sent: "Delivered", "Read 9:41" (`receiptText`). */
|
|
84
|
+
receipt?: string | null;
|
|
85
|
+
/** Makes the status a button ("Read by 2" opens who has read it). */
|
|
86
|
+
onReceiptPress?: () => void;
|
|
87
|
+
/** What is drawn behind the bubble, which the tail is cut from. The theme's grouped background by default (what ChatThreadScreen draws). */
|
|
88
|
+
backdrop?: string;
|
|
75
89
|
testID: string;
|
|
76
90
|
}
|
|
77
91
|
|
|
78
92
|
const SWIPE_REPLY = 56;
|
|
79
93
|
const SWIPE_MAX = 80;
|
|
80
94
|
|
|
95
|
+
/** Where a bubble sits in its run of one sender's messages. */
|
|
96
|
+
export type BubblePosition = "single" | "first" | "middle" | "last";
|
|
97
|
+
|
|
98
|
+
export function bubblePosition(row: { groupStart: boolean; groupEnd: boolean }): BubblePosition {
|
|
99
|
+
if (row.groupStart && row.groupEnd) return "single";
|
|
100
|
+
if (row.groupStart) return "first";
|
|
101
|
+
if (row.groupEnd) return "last";
|
|
102
|
+
return "middle";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const ROUND = 18;
|
|
106
|
+
const TIGHT = 5;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A bubble's corners: round, except where it meets the next or the one before in its run, on the
|
|
110
|
+
* sender's side (the trailing side for yours). The last and the only one also get a tail.
|
|
111
|
+
*/
|
|
112
|
+
export function bubbleCorners(position: BubblePosition, mine: boolean) {
|
|
113
|
+
const joinsAbove = position === "middle" || position === "last";
|
|
114
|
+
const joinsBelow = position === "first" || position === "middle";
|
|
115
|
+
const near = { top: joinsAbove ? TIGHT : ROUND, bottom: joinsBelow ? TIGHT : ROUND };
|
|
116
|
+
return {
|
|
117
|
+
borderTopLeftRadius: mine ? ROUND : near.top,
|
|
118
|
+
borderBottomLeftRadius: mine ? ROUND : near.bottom,
|
|
119
|
+
borderTopRightRadius: mine ? near.top : ROUND,
|
|
120
|
+
borderBottomRightRadius: mine ? near.bottom : ROUND,
|
|
121
|
+
tail: position === "last" || position === "single",
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Pending messages younger than this rise in when they first draw; older ones (a relaunch's outbox) don't. */
|
|
126
|
+
const FRESH_MS = 1500;
|
|
127
|
+
|
|
81
128
|
export function formatClock(iso: string): string {
|
|
82
129
|
return new Date(iso).toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
|
|
83
130
|
}
|
|
@@ -146,6 +193,18 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
|
|
|
146
193
|
})
|
|
147
194
|
: [];
|
|
148
195
|
const playingVoice = usePlayingVoiceNote(voices.map((a) => a.key));
|
|
196
|
+
const genesis = useGenesisModules();
|
|
197
|
+
const Swipeable = genesis.swipeable;
|
|
198
|
+
const reanimated = genesis.reanimated;
|
|
199
|
+
// Decided once, on the first draw: only a message just sent rises in.
|
|
200
|
+
const [entering] = useState(() => {
|
|
201
|
+
const rise = reanimated?.FadeInDown;
|
|
202
|
+
if (!pending || reducedMotion || !rise || Date.now() - new Date(pending.createdAt).getTime() >= FRESH_MS) return undefined;
|
|
203
|
+
const timed = rise.duration(240);
|
|
204
|
+
// Reanimated's own check too, should Reduce Motion turn on before it plays.
|
|
205
|
+
return reanimated.ReduceMotion && timed.reduceMotion ? timed.reduceMotion(reanimated.ReduceMotion.System) : timed;
|
|
206
|
+
});
|
|
207
|
+
const swipeRef = useRef<{ close?: () => void } | null>(null);
|
|
149
208
|
|
|
150
209
|
// ---- Swipe to reply ----
|
|
151
210
|
const x = useRef(new Animated.Value(0)).current;
|
|
@@ -189,10 +248,15 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
|
|
|
189
248
|
}
|
|
190
249
|
|
|
191
250
|
const canSwipe = Boolean(message && !message.deletedAt && props.onReply);
|
|
251
|
+
const corners = bubbleCorners(bubblePosition(row), mine);
|
|
252
|
+
// The tail is cut from the thread's background: not over a highlighted row.
|
|
253
|
+
const tail = corners.tail && !props.highlighted;
|
|
254
|
+
const Root = (reanimated ? reanimated.default.View : View) as ComponentType<Record<string, unknown>>;
|
|
192
255
|
const reactions = message ? summarizeReactions(message, me) : [];
|
|
193
256
|
const time = formatClock(createdAt);
|
|
194
257
|
const moderation = moderationNote(message, { mine, observer: Boolean(props.observer) });
|
|
195
|
-
const
|
|
258
|
+
const receipt = failed ? null : (props.receipt ?? null);
|
|
259
|
+
const statusText = failed ? copy.notSent : receipt ? receipt : sending ? copy.sending : null;
|
|
196
260
|
const label = [
|
|
197
261
|
senderName,
|
|
198
262
|
message?.deletedAt ? copy.deleted : displayBody(body),
|
|
@@ -273,27 +337,16 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
|
|
|
273
337
|
const fg = mine ? "text-primary-foreground" : undefined;
|
|
274
338
|
const textStyle = mine ? { fontSize: 17, lineHeight: 22 } : { fontSize: 17, lineHeight: 22, color: colors.label };
|
|
275
339
|
|
|
276
|
-
|
|
277
|
-
<View
|
|
278
|
-
testID={testID}
|
|
279
|
-
accessibilityElementsHidden={invisible || undefined}
|
|
280
|
-
importantForAccessibility={invisible ? "no-hide-descendants" : undefined}
|
|
281
|
-
style={{ paddingTop: row.groupStart ? 8 : 2, borderRadius: 12, backgroundColor: props.highlighted ? colors.fill : undefined, display: invisible ? "none" : undefined }}
|
|
282
|
-
>
|
|
283
|
-
{row.showName && sender?.name ? (
|
|
284
|
-
<NativeText preset="caption" style={{ marginLeft: group ? 48 : 12, marginBottom: 2, color: colors.secondaryLabel }}>
|
|
285
|
-
{sender.name}
|
|
286
|
-
</NativeText>
|
|
287
|
-
) : null}
|
|
340
|
+
const bubbleRow = (
|
|
288
341
|
<View style={{ flexDirection: "row", alignItems: "flex-end", justifyContent: mine ? "flex-end" : "flex-start" }}>
|
|
289
342
|
{group && !mine ? (
|
|
290
|
-
<View style={{ width: 40, alignItems: "flex-start" }}>
|
|
343
|
+
<View style={{ width: 40, alignItems: "flex-start", zIndex: 1 }}>
|
|
291
344
|
{row.showAvatar ? <NativeAvatar size={32} src={sender?.avatarUrl ?? null} fallback={initials(sender?.name)} alt={sender?.name} recyclingKey={row.senderId ?? undefined} /> : null}
|
|
292
345
|
</View>
|
|
293
346
|
) : null}
|
|
294
347
|
<Animated.View
|
|
295
348
|
style={{ maxWidth: "80%", transform: [{ translateX: x }] }}
|
|
296
|
-
{...(canSwipe ? responder.panHandlers : {})}
|
|
349
|
+
{...(canSwipe && !Swipeable ? responder.panHandlers : {})}
|
|
297
350
|
>
|
|
298
351
|
<Pressable
|
|
299
352
|
testID={`${testID}-bubble`}
|
|
@@ -307,7 +360,10 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
|
|
|
307
360
|
style={{
|
|
308
361
|
paddingHorizontal: attachments.length && !body ? 4 : 12,
|
|
309
362
|
paddingVertical: attachments.length && !body ? 4 : 8,
|
|
310
|
-
|
|
363
|
+
borderTopLeftRadius: corners.borderTopLeftRadius,
|
|
364
|
+
borderTopRightRadius: corners.borderTopRightRadius,
|
|
365
|
+
borderBottomLeftRadius: corners.borderBottomLeftRadius,
|
|
366
|
+
borderBottomRightRadius: corners.borderBottomRightRadius,
|
|
311
367
|
backgroundColor: bubbleColor,
|
|
312
368
|
opacity: sending ? 0.6 : moderation === "hidden-mine" ? 0.7 : 1,
|
|
313
369
|
gap: 4,
|
|
@@ -357,8 +413,49 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
|
|
|
357
413
|
{moderation ? <ModerationMarker note={moderation} mine={mine} testID={`${testID}-moderation`} /> : null}
|
|
358
414
|
{preview ? <ChatLinkPreviewCard preview={preview} mine={mine} images={props.linkPreviewImages} testID={`${testID}-preview`} /> : null}
|
|
359
415
|
</Pressable>
|
|
416
|
+
{tail ? <BubbleTail mine={mine} color={bubbleColor} backdrop={props.backdrop ?? (colors.groupedBackground as string)} opacity={sending ? 0.6 : moderation === "hidden-mine" ? 0.7 : 1} testID={`${testID}-tail`} /> : null}
|
|
360
417
|
</Animated.View>
|
|
361
418
|
</View>
|
|
419
|
+
);
|
|
420
|
+
const swipeable =
|
|
421
|
+
canSwipe && Swipeable && message ? (
|
|
422
|
+
<Swipeable
|
|
423
|
+
ref={swipeRef}
|
|
424
|
+
testID={`${testID}-swipe`}
|
|
425
|
+
friction={2}
|
|
426
|
+
leftThreshold={SWIPE_REPLY}
|
|
427
|
+
overshootLeft={false}
|
|
428
|
+
// Leftward drags are the thread's (its times), never this row's.
|
|
429
|
+
dragOffsetFromRightEdge={10_000}
|
|
430
|
+
renderLeftActions={() => <ReplyHint color={colors.secondaryLabel} />}
|
|
431
|
+
onSwipeableWillOpen={() => {
|
|
432
|
+
props.onSwipeReply?.();
|
|
433
|
+
props.onReply?.(message);
|
|
434
|
+
swipeRef.current?.close?.();
|
|
435
|
+
}}
|
|
436
|
+
>
|
|
437
|
+
{bubbleRow}
|
|
438
|
+
</Swipeable>
|
|
439
|
+
) : (
|
|
440
|
+
bubbleRow
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
return (
|
|
444
|
+
<Root
|
|
445
|
+
testID={testID}
|
|
446
|
+
entering={entering}
|
|
447
|
+
accessibilityElementsHidden={invisible || undefined}
|
|
448
|
+
importantForAccessibility={invisible ? "no-hide-descendants" : undefined}
|
|
449
|
+
style={{ paddingTop: row.groupStart ? 8 : 2, borderRadius: 12, backgroundColor: props.highlighted ? colors.fill : undefined, display: invisible ? "none" : undefined }}
|
|
450
|
+
>
|
|
451
|
+
{row.showName && sender?.name ? (
|
|
452
|
+
<NativeText preset="caption" style={{ marginLeft: group ? 48 : 12, marginBottom: 2, color: colors.secondaryLabel }}>
|
|
453
|
+
{sender.name}
|
|
454
|
+
</NativeText>
|
|
455
|
+
) : null}
|
|
456
|
+
<TimeRevealRow time={time} testID={testID}>
|
|
457
|
+
{swipeable}
|
|
458
|
+
</TimeRevealRow>
|
|
362
459
|
{reactions.length ? (
|
|
363
460
|
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 4, marginTop: 2, justifyContent: mine ? "flex-end" : "flex-start", marginLeft: group && !mine ? 40 : 0 }}>
|
|
364
461
|
{reactions.map((r) => (
|
|
@@ -409,15 +506,70 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
|
|
|
409
506
|
</>
|
|
410
507
|
) : (
|
|
411
508
|
<NativeText preset="caption" style={{ color: colors.tertiaryLabel }}>
|
|
412
|
-
{[time, message?.editedAt ? copy.edited : null, sending ? copy.sending : null].filter(Boolean).join(" · ")}
|
|
509
|
+
{[time, message?.editedAt ? copy.edited : null, sending && !receipt ? copy.sending : null].filter(Boolean).join(" · ")}
|
|
413
510
|
</NativeText>
|
|
414
511
|
)}
|
|
415
512
|
</View>
|
|
416
513
|
) : null}
|
|
514
|
+
{receipt ? <ReceiptLine text={receipt} onPress={props.onReceiptPress} hint={copy.receiptReadersHint} testID={`${testID}-receipt`} /> : null}
|
|
515
|
+
</Root>
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* iMessage's tail: a rounded piece of the bubble's color at its bottom corner, its inner curve cut
|
|
521
|
+
* by a piece of the thread's background. Drawn only, never read.
|
|
522
|
+
*/
|
|
523
|
+
function BubbleTail({ mine, color, backdrop, opacity, testID }: { mine: boolean; color: unknown; backdrop: unknown; opacity: number; testID: string }) {
|
|
524
|
+
const side = mine ? "right" : "left";
|
|
525
|
+
return (
|
|
526
|
+
<View testID={testID} pointerEvents="none" accessibilityElementsHidden importantForAccessibility="no-hide-descendants" style={{ position: "absolute", bottom: 0, [side]: -6, width: 20, height: 18 }}>
|
|
527
|
+
<View style={{ position: "absolute", bottom: 0, [side]: 0, width: 20, height: 18, opacity, backgroundColor: color as string, [mine ? "borderBottomLeftRadius" : "borderBottomRightRadius"]: 16 }} />
|
|
528
|
+
<View style={{ position: "absolute", bottom: 0, [side]: -6, width: 12, height: 20, backgroundColor: backdrop as string, [mine ? "borderBottomLeftRadius" : "borderBottomRightRadius"]: 10 }} />
|
|
417
529
|
</View>
|
|
418
530
|
);
|
|
419
531
|
}
|
|
420
532
|
|
|
533
|
+
/** What the swipe to reply uncovers. */
|
|
534
|
+
function ReplyHint({ color }: { color: unknown }): ReactNode {
|
|
535
|
+
return (
|
|
536
|
+
<View pointerEvents="none" accessibilityElementsHidden importantForAccessibility="no-hide-descendants" style={{ width: SWIPE_MAX, alignItems: "center", justifyContent: "center" }}>
|
|
537
|
+
<NativeIcon name="reply" size={20} color={color as string} />
|
|
538
|
+
</View>
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** iMessage's status line: small, bold, under the bubble on your side. Read with the bubble unless it is a button. */
|
|
543
|
+
function ReceiptLine({ text, onPress, hint, testID }: { text: string; onPress?: () => void; hint: string; testID: string }) {
|
|
544
|
+
const colors = useThemeRoles();
|
|
545
|
+
const words = (
|
|
546
|
+
<NativeText preset="caption" style={{ color: colors.secondaryLabel, fontWeight: "600" }}>
|
|
547
|
+
{text}
|
|
548
|
+
</NativeText>
|
|
549
|
+
);
|
|
550
|
+
if (!onPress) {
|
|
551
|
+
return (
|
|
552
|
+
<View testID={testID} accessibilityElementsHidden importantForAccessibility="no-hide-descendants" style={{ alignItems: "flex-end", marginTop: 1, marginRight: 12 }}>
|
|
553
|
+
{words}
|
|
554
|
+
</View>
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
return (
|
|
558
|
+
<Pressable
|
|
559
|
+
testID={testID}
|
|
560
|
+
accessibilityRole="button"
|
|
561
|
+
accessibilityLabel={text}
|
|
562
|
+
accessibilityHint={hint}
|
|
563
|
+
onPress={onPress}
|
|
564
|
+
hitSlop={8}
|
|
565
|
+
// 28 + 8 above and below: a 44 pt target, like the Retry beside a failed send.
|
|
566
|
+
style={{ alignSelf: "flex-end", minHeight: 28, justifyContent: "center", marginRight: 12 }}
|
|
567
|
+
>
|
|
568
|
+
{words}
|
|
569
|
+
</Pressable>
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
421
573
|
function SmallAction({ label, onPress, color, testID }: { label: string; onPress: () => void; color: unknown; testID: string }) {
|
|
422
574
|
return (
|
|
423
575
|
<Pressable testID={testID} accessibilityRole="button" accessibilityLabel={label} onPress={onPress} style={{ minHeight: 44, minWidth: 44, paddingHorizontal: 8, alignItems: "center", justifyContent: "center" }}>
|
package/src/native/modules.ts
CHANGED
|
@@ -254,7 +254,7 @@ export interface ChatNativeModules {
|
|
|
254
254
|
openFile?: (uri: string) => Promise<ChunkFileLike> | ChunkFileLike;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
export type HapticEvent = "send" | "record-start" | "record-lock" | "record-cancel" | "select" | "error";
|
|
257
|
+
export type HapticEvent = "send" | "record-start" | "record-lock" | "record-cancel" | "select" | "long-press" | "error";
|
|
258
258
|
|
|
259
259
|
/** What each of chat's moments plays, in genesis-ui-native's vocabulary. */
|
|
260
260
|
const HAPTIC_KIND: Record<HapticEvent, HapticKind> = {
|
|
@@ -262,6 +262,8 @@ const HAPTIC_KIND: Record<HapticEvent, HapticKind> = {
|
|
|
262
262
|
"record-lock": "light",
|
|
263
263
|
"record-start": "medium",
|
|
264
264
|
select: "select",
|
|
265
|
+
/** A bubble lifting for its menu: UIKit's context-menu tap. */
|
|
266
|
+
"long-press": "medium",
|
|
265
267
|
error: "error",
|
|
266
268
|
"record-cancel": "warning",
|
|
267
269
|
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @feat:chat
|
|
3
|
+
* Message status, the way iMessage shows it: under the last message you sent, "Sending…",
|
|
4
|
+
* "Sent", "Delivered", then "Read 9:41" in a direct conversation or "Read by 2" / "Read by
|
|
5
|
+
* everyone" in a group. A send that failed shows nothing here: its bubble keeps the failure,
|
|
6
|
+
* Retry and Delete.
|
|
7
|
+
*
|
|
8
|
+
* - Sending: still in the outbox, not yet posted.
|
|
9
|
+
* - Sent: posted, but the outbox still holds it (a video's bytes are still going up).
|
|
10
|
+
* - Delivered: the server has it (it has a seq) and nobody else has read that far.
|
|
11
|
+
* - Read: the other member's `lastReadSeq` has reached its seq, with their `lastReadAt` (chat
|
|
12
|
+
* migration 0006) as the time; without it, "Read" with no time.
|
|
13
|
+
* - Read by N: in a group, the other members whose `lastReadSeq` has reached it.
|
|
14
|
+
*/
|
|
15
|
+
import { dayLabel, sameDay, type ThreadItem } from "../core/thread";
|
|
16
|
+
import type { ChatMember } from "../core/types";
|
|
17
|
+
import { fill, type ChatNativeCopy } from "./copy";
|
|
18
|
+
import { rowKey } from "./rows";
|
|
19
|
+
|
|
20
|
+
/** Whether the thread shows message status (`ChatThreadScreen receipts`). */
|
|
21
|
+
export type ChatReceiptsMode = "show" | "hide";
|
|
22
|
+
|
|
23
|
+
export type MessageReceipt =
|
|
24
|
+
| { state: "sending" }
|
|
25
|
+
| { state: "sent" }
|
|
26
|
+
| { state: "delivered" }
|
|
27
|
+
| { state: "read"; at: string | null }
|
|
28
|
+
| { state: "read-by"; readers: string[]; everyone: boolean };
|
|
29
|
+
|
|
30
|
+
export interface MessageReceiptFor {
|
|
31
|
+
/** The row it goes under (`rowKey`). */
|
|
32
|
+
key: string;
|
|
33
|
+
receipt: MessageReceipt;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ReceiptOptions {
|
|
37
|
+
me: string;
|
|
38
|
+
/** The conversation's members (observers aren't counted). */
|
|
39
|
+
members: readonly ChatMember[];
|
|
40
|
+
/** More than two people: "Read by N" instead of "Read". */
|
|
41
|
+
group: boolean;
|
|
42
|
+
/** Client ids the outbox still holds. */
|
|
43
|
+
queued?: ReadonlySet<string>;
|
|
44
|
+
receipts?: ChatReceiptsMode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The status of the last message you sent, and the row it goes under; null when there is none to show. */
|
|
48
|
+
export function lastSentReceipt(items: readonly ThreadItem[], options: ReceiptOptions): MessageReceiptFor | null {
|
|
49
|
+
const { me, members, group, queued, receipts = "show" } = options;
|
|
50
|
+
if (receipts === "hide") return null;
|
|
51
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
52
|
+
const item = items[i]!;
|
|
53
|
+
if (item.type === "pending") {
|
|
54
|
+
if (item.pending.senderId !== me) continue;
|
|
55
|
+
if (item.pending.status === "failed") return null;
|
|
56
|
+
const posted = Boolean((item.pending as { sentMessageId?: string }).sentMessageId);
|
|
57
|
+
return { key: rowKey(item), receipt: { state: posted ? "sent" : "sending" } };
|
|
58
|
+
}
|
|
59
|
+
const m = item.message;
|
|
60
|
+
if (m.senderId !== me || m.kind === "system" || m.deletedAt) continue;
|
|
61
|
+
// Seen by only some (observers), or hidden by moderation: the others' read places say nothing
|
|
62
|
+
// about it, so it carries no status.
|
|
63
|
+
if (m.visibility === "observers" || m.moderation === "hidden") return null;
|
|
64
|
+
return { key: rowKey(item), receipt: receiptFor(m.seq, m.clientId) };
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
|
|
68
|
+
function receiptFor(seq: number, clientId: string): MessageReceipt {
|
|
69
|
+
if (queued?.has(clientId)) return { state: "sent" };
|
|
70
|
+
const others = members.filter((x) => x.userId !== me && x.role !== "observer");
|
|
71
|
+
const readers = others.filter((x) => x.lastReadSeq >= seq);
|
|
72
|
+
if (!group) {
|
|
73
|
+
const other = readers[0];
|
|
74
|
+
return other ? { state: "read", at: other.lastReadAt ?? null } : { state: "delivered" };
|
|
75
|
+
}
|
|
76
|
+
if (readers.length === 0) return { state: "delivered" };
|
|
77
|
+
return { state: "read-by", readers: readers.map((x) => x.userId), everyone: readers.length === others.length };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** When it was read: the time today, else the day ("Yesterday", "Monday", "12 Mar"). */
|
|
82
|
+
export function readWhen(at: string, now = new Date(), locale?: string): string {
|
|
83
|
+
return sameDay(at, now.toISOString()) ? new Date(at).toLocaleTimeString(locale, { hour: "numeric", minute: "2-digit" }) : dayLabel(at, now, locale);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type ReceiptCopy = Pick<ChatNativeCopy, "receiptSending" | "receiptSent" | "receiptDelivered" | "receiptRead" | "receiptReadAt" | "receiptReadBy" | "receiptReadByEveryone">;
|
|
87
|
+
|
|
88
|
+
/** What the line under the message says. */
|
|
89
|
+
export function receiptText(receipt: MessageReceipt, copy: ReceiptCopy, now = new Date(), locale?: string): string {
|
|
90
|
+
switch (receipt.state) {
|
|
91
|
+
case "sending":
|
|
92
|
+
return copy.receiptSending;
|
|
93
|
+
case "sent":
|
|
94
|
+
return copy.receiptSent;
|
|
95
|
+
case "delivered":
|
|
96
|
+
return copy.receiptDelivered;
|
|
97
|
+
case "read":
|
|
98
|
+
return receipt.at ? fill(copy.receiptReadAt, { time: readWhen(receipt.at, now, locale) }) : copy.receiptRead;
|
|
99
|
+
case "read-by":
|
|
100
|
+
return receipt.everyone ? copy.receiptReadByEveryone : fill(copy.receiptReadBy, { count: receipt.readers.length });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
NativeIcon,
|
|
18
18
|
NativeListItem,
|
|
19
19
|
NativeSheet,
|
|
20
|
+
NativeSheetScrollView,
|
|
20
21
|
NativeSkeleton,
|
|
21
22
|
NativeText,
|
|
22
23
|
NativeTimePicker,
|
|
@@ -315,12 +316,16 @@ export function ChatScheduledBar({ conversationId, testID = "chat-scheduled-bar"
|
|
|
315
316
|
{label}
|
|
316
317
|
</NativeText>
|
|
317
318
|
</Pressable>
|
|
318
|
-
<NativeSheet open={open} onOpenChange={setOpen} testID={`${testID}-sheet`}>
|
|
319
|
-
|
|
319
|
+
<NativeSheet open={open} onOpenChange={setOpen} fitContent testID={`${testID}-sheet`}>
|
|
320
|
+
{/* Both shrink inside the sheet's height cap, so the scroll view gets what's left; a short list keeps its height. */}
|
|
321
|
+
<View style={{ paddingVertical: 8, flexShrink: 1 }}>
|
|
320
322
|
<NativeText preset="h4" accessibilityRole="header" style={{ paddingHorizontal: 16, paddingBottom: 4 }}>
|
|
321
323
|
{copy.scheduledTitle}
|
|
322
324
|
</NativeText>
|
|
323
|
-
|
|
325
|
+
{/* Scrolls once the list is taller than the sheet (which stops at 90% of the screen). */}
|
|
326
|
+
<NativeSheetScrollView testID={`${testID}-scroll`} style={{ flexShrink: 1 }}>
|
|
327
|
+
<ChatScheduledList conversationId={conversationId} testID={`${testID}-list`} />
|
|
328
|
+
</NativeSheetScrollView>
|
|
324
329
|
</View>
|
|
325
330
|
</NativeSheet>
|
|
326
331
|
</>
|
|
@@ -13,19 +13,51 @@
|
|
|
13
13
|
* edge effect is drawn over the flipped list. Seen on iOS 27 with FlashList
|
|
14
14
|
* and with FlatList.
|
|
15
15
|
*/
|
|
16
|
+
import { createElement, type ReactNode } from "react";
|
|
16
17
|
import type { ColorValue } from "react-native";
|
|
17
18
|
import { getThreadPageStackOptions, type ScreenHeaderProps } from "@marktiderman/genesis-ui-native/layouts";
|
|
18
19
|
import { useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
|
|
20
|
+
import { ChatThreadTitle, type ChatThreadTitleAvatar } from "./thread-title";
|
|
19
21
|
|
|
20
|
-
export type ChatThreadStackOptionsProps = ScreenHeaderProps & {
|
|
22
|
+
export type ChatThreadStackOptionsProps = ScreenHeaderProps & {
|
|
23
|
+
headerTitle?: string;
|
|
24
|
+
/** Beside the title: who it is (`{ src, name, id }`), or your own element. */
|
|
25
|
+
avatar?: ChatThreadTitleAvatar | ReactNode;
|
|
26
|
+
/**
|
|
27
|
+
* Under the title. Left out with `conversationId`: the away line ("Sam is away until Monday"),
|
|
28
|
+
* which needs `ChatProvider` above the navigator. `null`: none. Show it here, and pass
|
|
29
|
+
* `availability={false}` to `ChatThreadScreen` so it isn't said twice.
|
|
30
|
+
*/
|
|
31
|
+
subtitle?: string | null;
|
|
32
|
+
/** Makes the title a button (to the conversation's details). */
|
|
33
|
+
onPressTitle?: () => void;
|
|
34
|
+
/** VoiceOver's hint on that button. */
|
|
35
|
+
titleHint?: string;
|
|
36
|
+
/** For the default subtitle. */
|
|
37
|
+
conversationId?: string;
|
|
38
|
+
};
|
|
21
39
|
|
|
22
40
|
/** The thread's header options with an opaque bar in `background` (the thread's own background). */
|
|
23
41
|
export function chatThreadStackOptions(props: ChatThreadStackOptionsProps, background: ColorValue): Record<string, unknown> {
|
|
42
|
+
const { avatar, subtitle, onPressTitle, titleHint, conversationId, ...header } = props;
|
|
43
|
+
// A title of its own only when asked for: otherwise the bar's plain title, as before.
|
|
44
|
+
const custom = avatar !== undefined || subtitle !== undefined || onPressTitle !== undefined || conversationId !== undefined;
|
|
45
|
+
const title = header.headerTitle ?? "Conversation";
|
|
24
46
|
return getThreadPageStackOptions({
|
|
25
|
-
...
|
|
47
|
+
...header,
|
|
26
48
|
// Large titles collapse into the content scroll view, which is the flipped list here.
|
|
27
49
|
large: false,
|
|
28
|
-
headerOptions: {
|
|
50
|
+
headerOptions: {
|
|
51
|
+
headerTransparent: false,
|
|
52
|
+
headerStyle: { backgroundColor: background },
|
|
53
|
+
...(custom
|
|
54
|
+
? {
|
|
55
|
+
headerTitle: ({ tintColor }: { tintColor?: string }) =>
|
|
56
|
+
createElement(ChatThreadTitle, { title, subtitle, avatar, onPress: onPressTitle, pressHint: titleHint, conversationId, tintColor }),
|
|
57
|
+
}
|
|
58
|
+
: {}),
|
|
59
|
+
...props.headerOptions,
|
|
60
|
+
},
|
|
29
61
|
});
|
|
30
62
|
}
|
|
31
63
|
|