@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
package/dist/web.js
CHANGED
|
@@ -4,12 +4,12 @@ import { snippetParts, isHttpsUrl, scheduleQuickPicks, isSchedulable, scheduleLa
|
|
|
4
4
|
import { useChat, useInbox, useSearch, useScheduled, useAvailability, useTopics, useConversation, useMessageActions, usePins, useFileUrls, useLinkPreviews, useBroadcast } from './chunk-D4RPOYB7.js';
|
|
5
5
|
import { previewText, summarizeReactions, activityLine, itemSender, startsDay, dayLabel, itemTime, startsGroup, parseMentions } from './chunk-ZQFREERR.js';
|
|
6
6
|
import { fileExtension, formatDuration, nextPlaybackRate, awaySummary, awayLine, WEEKDAYS, CHAT_LIMITS, waveformPeaks, recordingLimitMs, isAllowedExtension, attachmentKindFor, randomId, ChatError } from './chunk-5XYDVUPS.js';
|
|
7
|
-
import { createContext,
|
|
8
|
-
import { MessageSquare, Pin, BellOff, AtSign, Search, X, Mic, ClipboardList, ExternalLink, VideoOff, Video, RotateCcw, SendHorizontal, Square, Circle, Pause, Play, Paperclip, FileText, Download, Lock, Ban, EyeOff, ShieldAlert, AlertCircle, Clock, Reply, Copy, Pencil, PinOff, Bookmark, Flag, Trash2, SmilePlus, Plus, MoreHorizontal, ChevronUp, CalendarClock, Moon, RefreshCw, Smile, Hash, LockOpen,
|
|
9
|
-
import {
|
|
7
|
+
import { createContext, useMemo, useState, useRef, Fragment as Fragment$1, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useReducer, useContext, useSyncExternalStore } from 'react';
|
|
8
|
+
import { MessageSquare, Pin, BellOff, AtSign, Search, X, Mic, ClipboardList, ExternalLink, VideoOff, Video, RotateCcw, SendHorizontal, Square, Circle, Pause, Play, Paperclip, FileText, Download, Lock, Ban, EyeOff, ShieldAlert, AlertCircle, Clock, Reply, Copy, Pencil, PinOff, Bookmark, Flag, Trash2, SmilePlus, Plus, MoreHorizontal, ChevronUp, CalendarClock, Moon, RefreshCw, Smile, Hash, LockOpen, ImagePlus, Megaphone, MessageCircle, Link2, ArrowLeft, ChevronDown, Maximize2 } from 'lucide-react';
|
|
9
|
+
import { InboxPage, cn, EmptyState, Button, UserAvatar, Badge, Input, Skeleton, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Alert, AlertDescription, Spinner, Collapsible, CollapsibleTrigger, CollapsibleContent, Lightbox as Lightbox$1, Progress, ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuSeparator, ContextMenuItem, Tooltip, Textarea, Popover, PopoverTrigger, PopoverContent, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuSeparator, DropdownMenuItem, DropdownMenuLabel, Label, DialogFooter, toast, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Toggle, ToggleGroup, ToggleGroupItem, ThreadPage, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction, RadioGroup, RadioGroupItem, Split, Checkbox } from '@marktiderman/genesis-ui';
|
|
10
10
|
import { renderSlot } from '@marktiderman/genesis-core/slots';
|
|
11
11
|
import { relativeTime as relativeTime$1 } from '@marktiderman/genesis-ui/utils';
|
|
12
|
-
import { jsx,
|
|
12
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
13
13
|
import { EmojiPicker } from 'frimousse';
|
|
14
14
|
import { useIsMobile } from '@marktiderman/genesis-ui/hooks';
|
|
15
15
|
import { createLocalStorageAdapter } from '@marktiderman/genesis-core/storage';
|
|
@@ -48,54 +48,67 @@ function inboxTitle(item, resolveUser, fallback) {
|
|
|
48
48
|
if (item.otherUserId) return resolveUser(item.otherUserId).name;
|
|
49
49
|
return fallback?.(item) ?? "Conversation";
|
|
50
50
|
}
|
|
51
|
+
var formatTime = (date) => relativeTime(date.toISOString());
|
|
51
52
|
function ChatInbox({ resolveUser, onSelect, selectedId, kind, archived = false, fallbackTitle, slots, className, ...rest }) {
|
|
52
53
|
const { userId: me, attachmentKinds } = useChat();
|
|
53
54
|
const { items, isLoading, error, refetch } = useInbox({ kind, archived });
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
55
|
+
const rows = useMemo(
|
|
56
|
+
() => items.map((item) => {
|
|
57
|
+
const title = inboxTitle(item, resolveUser, fallbackTitle);
|
|
58
|
+
const last = item.lastMessage;
|
|
59
|
+
let preview = last ? attachmentPreview(last.body, last.attachment, attachmentKinds, last.deleted) : "";
|
|
60
|
+
if (last && last.kind !== "system" && !last.deleted && last.senderId) {
|
|
61
|
+
if (last.senderId === me) preview = `You: ${preview}`;
|
|
62
|
+
else if (!item.otherUserId && item.memberCount > 2) preview = `${resolveUser(last.senderId).name}: ${preview}`;
|
|
63
|
+
}
|
|
64
|
+
const timestamp = item.lastMessageAt ?? last?.createdAt;
|
|
65
|
+
return {
|
|
66
|
+
id: item.conversationId,
|
|
67
|
+
title,
|
|
68
|
+
preview,
|
|
69
|
+
unreadCount: item.unread,
|
|
70
|
+
...timestamp ? { timestamp } : {},
|
|
71
|
+
chat: item,
|
|
72
|
+
avatarUrl: item.otherUserId ? resolveUser(item.otherUserId).avatarUrl : void 0
|
|
73
|
+
};
|
|
74
|
+
}),
|
|
75
|
+
[items, me, resolveUser, fallbackTitle, attachmentKinds]
|
|
76
|
+
);
|
|
77
|
+
const label = rest["aria-label"] ?? "Conversations";
|
|
78
|
+
return /* @__PURE__ */ jsx("nav", { "aria-label": label, className: cn("flex min-h-0 flex-col", className), children: /* @__PURE__ */ jsx(
|
|
79
|
+
InboxPage,
|
|
80
|
+
{
|
|
81
|
+
testID: "genesis-chat-inbox",
|
|
82
|
+
items: rows,
|
|
83
|
+
selectedId,
|
|
84
|
+
onSelect,
|
|
85
|
+
loading: isLoading,
|
|
86
|
+
error: Boolean(error) && rows.length === 0,
|
|
87
|
+
label,
|
|
88
|
+
loadingLabel: "Loading conversations",
|
|
89
|
+
formatTime,
|
|
90
|
+
slots: INBOX_SLOTS,
|
|
91
|
+
slotProps: { empty: { override: slots?.empty, archived, onRetry: () => void refetch(), failed: Boolean(error) } }
|
|
92
|
+
}
|
|
93
|
+
) });
|
|
94
|
+
}
|
|
95
|
+
function InboxEmpty({ override, archived, onRetry, failed }) {
|
|
96
|
+
if (failed) {
|
|
97
|
+
return /* @__PURE__ */ jsx(
|
|
74
98
|
EmptyState,
|
|
75
99
|
{
|
|
76
100
|
icon: MessageSquare,
|
|
77
101
|
title: "Couldn't load your conversations",
|
|
78
102
|
description: "Check your connection and try again.",
|
|
79
|
-
action: /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick:
|
|
103
|
+
action: /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onRetry, children: "Try again" })
|
|
80
104
|
}
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
if (items.length === 0) {
|
|
84
|
-
return /* @__PURE__ */ jsx("div", { className, children: renderSlot(DefaultEmpty, slots?.empty, { archived }) });
|
|
105
|
+
);
|
|
85
106
|
}
|
|
86
|
-
return /* @__PURE__ */ jsx(
|
|
107
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderSlot(DefaultEmpty, override, { archived }) });
|
|
87
108
|
}
|
|
88
|
-
function InboxRow(
|
|
89
|
-
const
|
|
90
|
-
const other = item.otherUserId ? resolveUser(item.otherUserId) : null;
|
|
91
|
-
const last = item.lastMessage;
|
|
109
|
+
function InboxRow(row) {
|
|
110
|
+
const { chat: item, title, preview, timeLabel, selected, onPress, rowProps, testID, avatarUrl } = row;
|
|
92
111
|
const unread = item.unread > 0;
|
|
93
|
-
let preview = last ? attachmentPreview(last.body, last.attachment, kinds, last.deleted) : "";
|
|
94
|
-
if (last && last.kind !== "system" && !last.deleted && last.senderId) {
|
|
95
|
-
if (last.senderId === me) preview = `You: ${preview}`;
|
|
96
|
-
else if (!item.otherUserId && item.memberCount > 2) preview = `${resolveUser(last.senderId).name}: ${preview}`;
|
|
97
|
-
}
|
|
98
|
-
const time = relativeTime(item.lastMessageAt ?? last?.createdAt);
|
|
99
112
|
const count = item.unread >= 99 ? "99+" : String(item.unread);
|
|
100
113
|
const label = [
|
|
101
114
|
title,
|
|
@@ -104,30 +117,30 @@ function InboxRow({ item, me, kinds, resolveUser, fallbackTitle, selected, onSel
|
|
|
104
117
|
item.muted ? "muted" : null,
|
|
105
118
|
item.pinned ? "pinned" : null,
|
|
106
119
|
preview || null,
|
|
107
|
-
|
|
120
|
+
timeLabel || null
|
|
108
121
|
].filter(Boolean).join(", ");
|
|
109
122
|
return /* @__PURE__ */ jsxs(
|
|
110
123
|
"button",
|
|
111
124
|
{
|
|
112
125
|
type: "button",
|
|
113
|
-
|
|
126
|
+
...rowProps,
|
|
114
127
|
"aria-current": selected ? "true" : void 0,
|
|
115
128
|
"aria-label": label,
|
|
116
|
-
onClick:
|
|
129
|
+
onClick: onPress,
|
|
117
130
|
className: cn(
|
|
118
131
|
"flex w-full items-center gap-3 px-3 py-2.5 text-left transition-colors hover:bg-accent focus-visible:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
|
|
119
132
|
selected && "bg-accent"
|
|
120
133
|
),
|
|
121
|
-
"data-testid":
|
|
134
|
+
"data-testid": testID,
|
|
122
135
|
children: [
|
|
123
|
-
/* @__PURE__ */ jsx(UserAvatar, { name: title, src:
|
|
136
|
+
/* @__PURE__ */ jsx(UserAvatar, { name: title, src: avatarUrl, className: "shrink-0" }),
|
|
124
137
|
/* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", "aria-hidden": true, children: [
|
|
125
138
|
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
126
139
|
/* @__PURE__ */ jsx("span", { className: cn("min-w-0 flex-1 truncate text-sm", unread ? "font-semibold text-foreground" : "font-medium text-foreground"), children: title }),
|
|
127
|
-
/* @__PURE__ */ jsx("span", { className: cn("shrink-0 text-xs tabular-nums", unread && !item.muted ? "font-medium text-primary" : "text-muted-foreground"), children:
|
|
140
|
+
/* @__PURE__ */ jsx("span", { className: cn("shrink-0 text-xs tabular-nums", unread && !item.muted ? "font-medium text-primary" : "text-muted-foreground"), children: timeLabel })
|
|
128
141
|
] }),
|
|
129
142
|
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
|
|
130
|
-
/* @__PURE__ */ jsx("span", { className: cn("min-w-0 flex-1 truncate text-sm", unread ? "text-foreground" : "text-muted-foreground"), children: preview || "
|
|
143
|
+
/* @__PURE__ */ jsx("span", { className: cn("min-w-0 flex-1 truncate text-sm", unread ? "text-foreground" : "text-muted-foreground"), children: preview || " " }),
|
|
131
144
|
item.pinned ? /* @__PURE__ */ jsx(Pin, { className: "size-3.5 shrink-0 text-muted-foreground" }) : null,
|
|
132
145
|
item.muted ? /* @__PURE__ */ jsx(BellOff, { className: "size-3.5 shrink-0 text-muted-foreground" }) : null,
|
|
133
146
|
item.mentioned ? /* @__PURE__ */ jsx("span", { className: "flex size-5 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground", children: /* @__PURE__ */ jsx(AtSign, { className: "size-3" }) }) : null,
|
|
@@ -138,6 +151,7 @@ function InboxRow({ item, me, kinds, resolveUser, fallbackTitle, selected, onSel
|
|
|
138
151
|
}
|
|
139
152
|
);
|
|
140
153
|
}
|
|
154
|
+
var INBOX_SLOTS = { row: InboxRow, empty: InboxEmpty };
|
|
141
155
|
function SearchSnippet({ snippet, className }) {
|
|
142
156
|
return /* @__PURE__ */ jsx("span", { className, children: snippetParts(snippet).map(
|
|
143
157
|
(p, i) => p.match ? /* @__PURE__ */ jsx("mark", { className: "rounded-sm bg-warning/30 px-0.5 text-foreground", children: p.text }, i) : /* @__PURE__ */ jsx("span", { children: p.text }, i)
|
|
@@ -344,7 +358,7 @@ function renderNodes(nodes, opts) {
|
|
|
344
358
|
return nodes.map((n, i) => {
|
|
345
359
|
switch (n.type) {
|
|
346
360
|
case "text":
|
|
347
|
-
return /* @__PURE__ */ jsx(Fragment, { children: n.text }, i);
|
|
361
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: n.text }, i);
|
|
348
362
|
case "break":
|
|
349
363
|
return /* @__PURE__ */ jsx("br", {}, i);
|
|
350
364
|
case "bold":
|
|
@@ -376,7 +390,7 @@ function renderNodes(nodes, opts) {
|
|
|
376
390
|
i
|
|
377
391
|
);
|
|
378
392
|
case "mention": {
|
|
379
|
-
if (opts.renderMention) return /* @__PURE__ */ jsx(Fragment, { children: opts.renderMention(n) }, i);
|
|
393
|
+
if (opts.renderMention) return /* @__PURE__ */ jsx(Fragment$1, { children: opts.renderMention(n) }, i);
|
|
380
394
|
const mine = opts.me && n.userId === opts.me.toLowerCase();
|
|
381
395
|
return /* @__PURE__ */ jsxs(
|
|
382
396
|
"span",
|
|
@@ -722,7 +736,7 @@ function ChatVideoRecorder({ open, onOpenChange, maxMs, send, extra, videoUpload
|
|
|
722
736
|
] }),
|
|
723
737
|
/* @__PURE__ */ jsx("div", { className: "sr-only", role: "status", children: recording ? "Recording" : rec.state === "recorded" ? "Recorded. Watch it, retake it or send it." : "" }),
|
|
724
738
|
sendError ? /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", role: "alert", children: sendError }) : null,
|
|
725
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-3", children: rec.state === "recorded" ? /* @__PURE__ */ jsxs(Fragment
|
|
739
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-3", children: rec.state === "recorded" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
726
740
|
/* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", onClick: () => void rec.retake(), disabled: sending, "data-testid": "genesis-chat-video-retake", children: [
|
|
727
741
|
/* @__PURE__ */ jsx(RotateCcw, {}),
|
|
728
742
|
" Retake"
|
|
@@ -972,13 +986,23 @@ function VoiceNote({ src, durationMs, waveform, transcript, transcriptStatus, to
|
|
|
972
986
|
/* @__PURE__ */ jsx("audio", { ref: audio, src: src ?? void 0, preload: "metadata", className: "hidden" })
|
|
973
987
|
] });
|
|
974
988
|
}
|
|
989
|
+
var hostOf = (url) => {
|
|
990
|
+
try {
|
|
991
|
+
return url ? new URL(url).host : "";
|
|
992
|
+
} catch {
|
|
993
|
+
return "";
|
|
994
|
+
}
|
|
995
|
+
};
|
|
975
996
|
function toAttachmentView(a, urls) {
|
|
997
|
+
const signed = a.path ? urls[a.path] ?? null : null;
|
|
998
|
+
const url = a.path ? signed : a.provider === "external" || a.kind === "link" ? a.url : null;
|
|
999
|
+
const outsideMedia = (a.kind === "image" || a.kind === "video" || a.kind === "voice") && !a.path && Boolean(url);
|
|
976
1000
|
return {
|
|
977
1001
|
key: a.id,
|
|
978
|
-
kind: a.kind,
|
|
979
|
-
url
|
|
1002
|
+
kind: outsideMedia ? "file" : a.kind,
|
|
1003
|
+
url,
|
|
980
1004
|
posterUrl: a.posterPath ? urls[a.posterPath] ?? null : null,
|
|
981
|
-
name: a.name,
|
|
1005
|
+
name: outsideMedia ? `${a.name ?? "File"} (${hostOf(url)})` : a.name,
|
|
982
1006
|
mime: a.mime,
|
|
983
1007
|
bytes: a.bytes,
|
|
984
1008
|
width: a.width,
|
|
@@ -993,7 +1017,7 @@ function toAttachmentView(a, urls) {
|
|
|
993
1017
|
}
|
|
994
1018
|
function GenericAttachment({ attachment: attachment2, url }) {
|
|
995
1019
|
const label = attachment2.name ?? attachment2.kind.charAt(0).toUpperCase() + attachment2.kind.slice(1);
|
|
996
|
-
const body = /* @__PURE__ */ jsxs(Fragment
|
|
1020
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
997
1021
|
/* @__PURE__ */ jsx(Paperclip, { className: "size-4 shrink-0 text-muted-foreground", "aria-hidden": true }),
|
|
998
1022
|
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
999
1023
|
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: label }),
|
|
@@ -1010,7 +1034,7 @@ function ImageGrid({ images, className }) {
|
|
|
1010
1034
|
const shown = images.slice(0, 4);
|
|
1011
1035
|
const more = images.length - shown.length;
|
|
1012
1036
|
const cols = shown.length === 1 ? "grid-cols-1" : "grid-cols-2";
|
|
1013
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
1037
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1014
1038
|
/* @__PURE__ */ jsx("div", { className: cn("grid w-[min(18rem,100%)] gap-1 overflow-hidden rounded-xl", cols, className), "data-testid": "genesis-chat-images", children: shown.map((img, i) => {
|
|
1015
1039
|
const tall = shown.length === 3 && i === 0;
|
|
1016
1040
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1331,7 +1355,7 @@ function returnFocus(e, keepFocus) {
|
|
|
1331
1355
|
function plainText(body) {
|
|
1332
1356
|
return body.replace(/@\[([^\]]+)\]\(user:[0-9a-f-]{36}\)/gi, "@$1");
|
|
1333
1357
|
}
|
|
1334
|
-
function MessageRow({ item, startsGroup: startsGroup2, className }) {
|
|
1358
|
+
function MessageRow({ item, startsGroup: startsGroup2, highlighted: highlightedProp, className }) {
|
|
1335
1359
|
const ctx = useThreadContext();
|
|
1336
1360
|
const keepFocus = useRef(null);
|
|
1337
1361
|
const pending = item.type === "pending" ? item.pending : null;
|
|
@@ -1349,7 +1373,7 @@ function MessageRow({ item, startsGroup: startsGroup2, className }) {
|
|
|
1349
1373
|
const progress = pending ? pendingProgress(pending) : null;
|
|
1350
1374
|
const editing = ctx.editingId === message.id;
|
|
1351
1375
|
const reactions = pending ? [] : summarizeReactions(message, ctx.me);
|
|
1352
|
-
const highlighted = ctx.highlightedId === message.id;
|
|
1376
|
+
const highlighted = highlightedProp ?? ctx.highlightedId === message.id;
|
|
1353
1377
|
const actionable = !pending && !deleted;
|
|
1354
1378
|
const hidden = !deleted && message.moderation === "hidden";
|
|
1355
1379
|
const flagged = !deleted && message.moderation === "flagged";
|
|
@@ -1377,7 +1401,7 @@ function MessageRow({ item, startsGroup: startsGroup2, className }) {
|
|
|
1377
1401
|
deleted ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5 italic", children: [
|
|
1378
1402
|
/* @__PURE__ */ jsx(Ban, { className: "size-3.5", "aria-hidden": true }),
|
|
1379
1403
|
" Message deleted"
|
|
1380
|
-
] }) : editing ? /* @__PURE__ */ jsx(EditBox, { message }) : /* @__PURE__ */ jsxs(Fragment
|
|
1404
|
+
] }) : editing ? /* @__PURE__ */ jsx(EditBox, { message }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1381
1405
|
message.replyToId ? /* @__PURE__ */ jsx(ReplyQuote, { id: message.replyToId, tone }) : null,
|
|
1382
1406
|
views.length ? /* @__PURE__ */ jsxs("div", { className: cn(message.body ? "mb-1.5" : ""), children: [
|
|
1383
1407
|
/* @__PURE__ */ jsx(MessageAttachments, { views, message: pending ? void 0 : message, mine, tone, slot: ctx.attachmentSlot, kinds: ctx.attachmentKinds }),
|
|
@@ -1478,7 +1502,7 @@ function Meta({ message, pending, tone }) {
|
|
|
1478
1502
|
const muted = tone === "primary" ? "text-primary-foreground/75" : "text-muted-foreground";
|
|
1479
1503
|
return /* @__PURE__ */ jsxs("span", { className: cn("float-right ml-3 mt-1 flex translate-y-1 items-center gap-1 text-[11px] leading-none", muted), children: [
|
|
1480
1504
|
message.editedAt ? /* @__PURE__ */ jsx("span", { children: "edited" }) : null,
|
|
1481
|
-
pending?.status === "sending" ? /* @__PURE__ */ jsxs(Fragment
|
|
1505
|
+
pending?.status === "sending" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1482
1506
|
/* @__PURE__ */ jsx(Clock, { className: "size-3", "aria-hidden": true }),
|
|
1483
1507
|
/* @__PURE__ */ jsx("span", { children: "Sending\u2026" })
|
|
1484
1508
|
] }) : pending?.status === "failed" ? /* @__PURE__ */ jsx(AlertCircle, { className: "size-3", "aria-label": "Not sent" }) : /* @__PURE__ */ jsx("time", { dateTime: message.createdAt, children: clockTime(message.createdAt) })
|
|
@@ -1561,8 +1585,8 @@ function ActionItems({ message, mine, keepFocus, Item, Separator }) {
|
|
|
1561
1585
|
const pinned = ctx.pins.has(message.id);
|
|
1562
1586
|
const canDelete = mine || ctx.canModerate;
|
|
1563
1587
|
const canEdit = mine && message.kind === "text" && message.body.length > 0;
|
|
1564
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
1565
|
-
ctx.canPost ? /* @__PURE__ */ jsxs(Fragment
|
|
1588
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1589
|
+
ctx.canPost ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1566
1590
|
/* @__PURE__ */ jsx("div", { className: "flex justify-between gap-0.5 px-1 py-1", role: "group", "aria-label": "React", children: ctx.quickReactions.map((emoji) => {
|
|
1567
1591
|
const on = message.reactions.some((r) => r.emoji === emoji && r.userId === ctx.me);
|
|
1568
1592
|
return /* @__PURE__ */ jsx(
|
|
@@ -1609,7 +1633,7 @@ function ActionItems({ message, mine, keepFocus, Item, Separator }) {
|
|
|
1609
1633
|
/* @__PURE__ */ jsx(Flag, { className: "size-4", "aria-hidden": true }),
|
|
1610
1634
|
" Report"
|
|
1611
1635
|
] }) : null,
|
|
1612
|
-
canDelete ? /* @__PURE__ */ jsxs(Fragment
|
|
1636
|
+
canDelete ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1613
1637
|
/* @__PURE__ */ jsx(Separator, {}),
|
|
1614
1638
|
/* @__PURE__ */ jsxs(Item, { onSelect: () => ctx.askDelete(message), className: "gap-2 text-destructive focus:text-destructive", children: [
|
|
1615
1639
|
/* @__PURE__ */ jsx(Trash2, { className: "size-4", "aria-hidden": true }),
|
|
@@ -1703,7 +1727,7 @@ function toLocalInput(d) {
|
|
|
1703
1727
|
function ChatScheduleMenu({ onSchedule, disabled, now }) {
|
|
1704
1728
|
const [picking, setPicking] = useState(false);
|
|
1705
1729
|
const picks = useMemo(() => scheduleQuickPicks(now ?? /* @__PURE__ */ new Date()), [now]);
|
|
1706
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
1730
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1707
1731
|
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
1708
1732
|
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
1709
1733
|
Button,
|
|
@@ -2011,7 +2035,7 @@ function ChatAvailabilitySettings({ onSaved, className }) {
|
|
|
2011
2035
|
}
|
|
2012
2036
|
),
|
|
2013
2037
|
/* @__PURE__ */ jsx("span", { className: cn("w-24", !days[d].on && "text-muted-foreground"), children: DAY_NAMES[d] }),
|
|
2014
|
-
days[d].on ? /* @__PURE__ */ jsxs(Fragment
|
|
2038
|
+
days[d].on ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2015
2039
|
/* @__PURE__ */ jsx(
|
|
2016
2040
|
Input,
|
|
2017
2041
|
{
|
|
@@ -2600,7 +2624,7 @@ function ChatComposer({
|
|
|
2600
2624
|
}
|
|
2601
2625
|
) })
|
|
2602
2626
|
] }) : null,
|
|
2603
|
-
hasContent ? /* @__PURE__ */ jsxs(Fragment
|
|
2627
|
+
hasContent ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2604
2628
|
/* @__PURE__ */ jsx(Button, { type: "button", size: "icon", className: "shrink-0 rounded-full", onClick: submit, "aria-label": "Send", "data-testid": "genesis-chat-send", children: /* @__PURE__ */ jsx(SendHorizontal, {}) }),
|
|
2605
2629
|
scheduling && conversationId && !internal ? /* @__PURE__ */ jsx(ChatScheduleMenu, { onSchedule: (at) => void scheduleAt(at), disabled: schedulingNow }) : null
|
|
2606
2630
|
] }) : /* @__PURE__ */ jsx(Tooltip, { content: "Record a voice message", children: /* @__PURE__ */ jsx(
|
|
@@ -2739,15 +2763,6 @@ function ChatTopicBar({ topics, value, onValueChange, canManage = false, onSetTo
|
|
|
2739
2763
|
] }) })
|
|
2740
2764
|
] });
|
|
2741
2765
|
}
|
|
2742
|
-
function centerRow(scroller, row, smooth) {
|
|
2743
|
-
const delta = row.getBoundingClientRect().top - scroller.getBoundingClientRect().top - (scroller.clientHeight - row.offsetHeight) / 2;
|
|
2744
|
-
const top = Math.max(0, scroller.scrollTop + delta);
|
|
2745
|
-
if (smooth && typeof scroller.scrollTo === "function") scroller.scrollTo({ top, behavior: "smooth" });
|
|
2746
|
-
else scroller.scrollTop = top;
|
|
2747
|
-
}
|
|
2748
|
-
function prefersReducedMotion() {
|
|
2749
|
-
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
2750
|
-
}
|
|
2751
2766
|
var REPORT_REASONS = [
|
|
2752
2767
|
{ value: "spam", label: "Spam" },
|
|
2753
2768
|
{ value: "harassment", label: "Harassment or bullying" },
|
|
@@ -2778,6 +2793,63 @@ function DefaultHeader({ title, subtitle, otherUserId, resolveUser, onBack, back
|
|
|
2778
2793
|
function DefaultEmpty2({ canPost }) {
|
|
2779
2794
|
return /* @__PURE__ */ jsx(EmptyState, { icon: MessageSquare, title: "No messages yet", description: canPost ? "Say hello." : void 0 });
|
|
2780
2795
|
}
|
|
2796
|
+
function ChatRowSlot(row) {
|
|
2797
|
+
return (
|
|
2798
|
+
// ThreadPage spaces and insets its own bubbles; chat's row does both itself.
|
|
2799
|
+
/* @__PURE__ */ jsxs("div", { className: "-mx-3 -my-1", children: [
|
|
2800
|
+
row.day ? /* @__PURE__ */ jsx("div", { className: "sticky top-1 z-10 flex justify-center py-2", role: "separator", "aria-label": row.day, children: /* @__PURE__ */ jsx("span", { className: "rounded-full border bg-background/95 px-3 py-0.5 text-xs font-medium text-muted-foreground shadow-sm", children: row.day }) }) : null,
|
|
2801
|
+
row.firstUnread ? /* @__PURE__ */ jsxs("div", { className: "my-2 flex items-center gap-2 px-4", role: "separator", "aria-label": "New messages", "data-testid": "genesis-chat-new-line", children: [
|
|
2802
|
+
/* @__PURE__ */ jsx("span", { className: "h-px flex-1 bg-primary/40" }),
|
|
2803
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-primary", children: "New" }),
|
|
2804
|
+
/* @__PURE__ */ jsx("span", { className: "h-px flex-1 bg-primary/40" })
|
|
2805
|
+
] }) : null,
|
|
2806
|
+
/* @__PURE__ */ jsx(
|
|
2807
|
+
ChatErrorBoundary,
|
|
2808
|
+
{
|
|
2809
|
+
fallback: /* @__PURE__ */ jsx("p", { className: "px-4 py-1 text-xs italic text-muted-foreground", role: "note", "data-testid": "genesis-chat-row-error", children: "This message couldn't be shown." }),
|
|
2810
|
+
children: /* @__PURE__ */ jsx(MessageRow, { item: row.item, startsGroup: row.startsGroup, highlighted: Boolean(row.highlighted) })
|
|
2811
|
+
}
|
|
2812
|
+
)
|
|
2813
|
+
] })
|
|
2814
|
+
);
|
|
2815
|
+
}
|
|
2816
|
+
function ChatComposerSlot({ onSend, chatComposer, composerRef, live }) {
|
|
2817
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2818
|
+
/* @__PURE__ */ jsx("div", { className: "h-5 px-4 text-xs italic text-muted-foreground", "data-testid": "genesis-chat-activity", children: live ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5", children: [
|
|
2819
|
+
/* @__PURE__ */ jsxs("span", { className: "inline-flex gap-0.5", "aria-hidden": true, children: [
|
|
2820
|
+
/* @__PURE__ */ jsx("span", { className: "size-1 animate-bounce rounded-full bg-muted-foreground [animation-delay:-0.3s]" }),
|
|
2821
|
+
/* @__PURE__ */ jsx("span", { className: "size-1 animate-bounce rounded-full bg-muted-foreground [animation-delay:-0.15s]" }),
|
|
2822
|
+
/* @__PURE__ */ jsx("span", { className: "size-1 animate-bounce rounded-full bg-muted-foreground" })
|
|
2823
|
+
] }),
|
|
2824
|
+
live
|
|
2825
|
+
] }) : null }),
|
|
2826
|
+
/* @__PURE__ */ jsx(ChatComposer, { ...chatComposer, ref: composerRef, onSent: onSend })
|
|
2827
|
+
] });
|
|
2828
|
+
}
|
|
2829
|
+
function ChatEmptySlot({ override, conversationId, canPost, failed, onRetry }) {
|
|
2830
|
+
if (failed) {
|
|
2831
|
+
return /* @__PURE__ */ jsx(
|
|
2832
|
+
EmptyState,
|
|
2833
|
+
{
|
|
2834
|
+
icon: MessageSquare,
|
|
2835
|
+
title: "Couldn't load this conversation",
|
|
2836
|
+
description: failed,
|
|
2837
|
+
action: /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onRetry, children: "Try again" })
|
|
2838
|
+
}
|
|
2839
|
+
);
|
|
2840
|
+
}
|
|
2841
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderSlot(DefaultEmpty2, override, { conversationId, canPost }) });
|
|
2842
|
+
}
|
|
2843
|
+
var THREAD_SLOTS = {
|
|
2844
|
+
message: ChatRowSlot,
|
|
2845
|
+
event: ChatRowSlot,
|
|
2846
|
+
// Chat's row draws it, under the day heading.
|
|
2847
|
+
unreadDivider: null,
|
|
2848
|
+
composer: ChatComposerSlot,
|
|
2849
|
+
empty: ChatEmptySlot
|
|
2850
|
+
};
|
|
2851
|
+
var THREAD_COMPOSER = { value: "", onChangeText: () => void 0, onSend: () => void 0 };
|
|
2852
|
+
var GONE = "That message isn't here any more";
|
|
2781
2853
|
function ChatThread({
|
|
2782
2854
|
conversationId,
|
|
2783
2855
|
resolveUser,
|
|
@@ -2819,12 +2891,9 @@ function ChatThread({
|
|
|
2819
2891
|
const pins = useMemo(() => new Set(pinIds), [pinIds]);
|
|
2820
2892
|
const [replyTo, setReplyTo] = useState(null);
|
|
2821
2893
|
const [editingId, setEditingId] = useState(null);
|
|
2822
|
-
const [highlightedId, setHighlightedId] = useState(null);
|
|
2823
2894
|
const [confirmDelete, setConfirmDelete] = useState(null);
|
|
2824
2895
|
const [reporting, setReporting] = useState(null);
|
|
2825
2896
|
const [dragging, setDragging] = useState(false);
|
|
2826
|
-
const [newCount, setNewCount] = useState(0);
|
|
2827
|
-
const [announcement, setAnnouncement] = useState("");
|
|
2828
2897
|
const composer = useRef(null);
|
|
2829
2898
|
useEffect(() => {
|
|
2830
2899
|
if (!autoFocus) return;
|
|
@@ -2834,8 +2903,8 @@ function ChatThread({
|
|
|
2834
2903
|
useEffect(() => {
|
|
2835
2904
|
setReplyTo(null);
|
|
2836
2905
|
setEditingId(null);
|
|
2837
|
-
setNewCount(0);
|
|
2838
2906
|
setChosenTopic(null);
|
|
2907
|
+
setJump(null);
|
|
2839
2908
|
}, [conversationId]);
|
|
2840
2909
|
const topics = topicsState.topics;
|
|
2841
2910
|
const currentTopic = topic ? topics.find((t) => t.topic === topic) : void 0;
|
|
@@ -2869,132 +2938,101 @@ function ChatThread({
|
|
|
2869
2938
|
});
|
|
2870
2939
|
return awaySummary(people) ? people : null;
|
|
2871
2940
|
}, [availability, otherUserId, members, me, avail, resolveUser]);
|
|
2872
|
-
const
|
|
2873
|
-
const
|
|
2874
|
-
const
|
|
2875
|
-
const
|
|
2876
|
-
const edges = useRef({ first: null, last: null });
|
|
2877
|
-
const anchor = useRef(null);
|
|
2878
|
-
const scrollToBottom = useCallback((smooth = false) => {
|
|
2879
|
-
const el = scroller.current;
|
|
2880
|
-
if (!el) return;
|
|
2881
|
-
if (smooth && typeof el.scrollTo === "function") el.scrollTo({ top: el.scrollHeight, behavior: "smooth" });
|
|
2882
|
-
else el.scrollTop = el.scrollHeight;
|
|
2883
|
-
atBottom.current = true;
|
|
2884
|
-
setNewCount(0);
|
|
2885
|
-
}, []);
|
|
2941
|
+
const lastItem = items[items.length - 1];
|
|
2942
|
+
const lastKey = lastItem ? itemKey(lastItem) : null;
|
|
2943
|
+
const seenLast = useRef(lastKey);
|
|
2944
|
+
const [, noteArrival] = useState(0);
|
|
2886
2945
|
useLayoutEffect(() => {
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
const prev = edges.current;
|
|
2893
|
-
edges.current = { first, last };
|
|
2894
|
-
if (initialised.current !== conversationId) {
|
|
2895
|
-
initialised.current = conversationId;
|
|
2896
|
-
const unread = state.firstUnreadId ? document.getElementById(`genesis-chat-msg-${state.firstUnreadId}`) : null;
|
|
2897
|
-
if (unread) centerRow(el, unread, false);
|
|
2898
|
-
else scrollToBottom();
|
|
2899
|
-
return;
|
|
2900
|
-
}
|
|
2901
|
-
if (anchor.current && first !== prev.first) {
|
|
2902
|
-
el.scrollTop = el.scrollHeight - anchor.current.height + anchor.current.top;
|
|
2903
|
-
anchor.current = null;
|
|
2946
|
+
if (lastKey === seenLast.current) return;
|
|
2947
|
+
seenLast.current = lastKey;
|
|
2948
|
+
if (lastItem?.type === "message" && lastItem.message.kind !== "system" && lastItem.message.senderId && lastItem.message.senderId !== me) {
|
|
2949
|
+
arrived.current.set(lastItem.message.senderId, Date.now());
|
|
2950
|
+
noteArrival((n) => n + 1);
|
|
2904
2951
|
}
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2952
|
+
}, [lastKey, lastItem, me]);
|
|
2953
|
+
const firstUnreadId = state.firstUnreadId;
|
|
2954
|
+
const rows = useMemo(
|
|
2955
|
+
() => items.map((item, i) => {
|
|
2956
|
+
const message = item.type === "message" ? item.message : null;
|
|
2957
|
+
const sender = itemSender(item);
|
|
2958
|
+
return {
|
|
2959
|
+
// The client's id, so a message that lands keeps its row; a jump names the server's.
|
|
2960
|
+
id: itemKey(item),
|
|
2961
|
+
...message ? { jumpId: message.id } : {},
|
|
2962
|
+
...message?.kind === "system" ? { kind: "event" } : {},
|
|
2963
|
+
// Plain text: only the list's announcement reads it, and the slot draws the row.
|
|
2964
|
+
body: message ? previewText(message.body, message.attachments[0]?.kind ?? null, Boolean(message.deletedAt)) : "",
|
|
2965
|
+
mine: sender === me,
|
|
2966
|
+
...sender && sender !== me ? { authorName: resolveUser(sender).name } : {},
|
|
2967
|
+
timestamp: itemTime(item),
|
|
2968
|
+
item,
|
|
2969
|
+
startsGroup: startsGroup(items, i),
|
|
2970
|
+
day: startsDay(items, i) ? dayLabel(itemTime(item)) : null,
|
|
2971
|
+
firstUnread: message !== null && message.id === firstUnreadId
|
|
2972
|
+
};
|
|
2973
|
+
}),
|
|
2974
|
+
[items, me, resolveUser, firstUnreadId]
|
|
2975
|
+
);
|
|
2976
|
+
const firstUnreadRow = rows.find((r) => r.firstUnread)?.id ?? null;
|
|
2926
2977
|
const { hasEarlier, loadingEarlier, loadEarlier } = state;
|
|
2927
2978
|
const loadOlder = useCallback(() => {
|
|
2928
|
-
const el = scroller.current;
|
|
2929
|
-
if (!el || !hasEarlier || loadingEarlier) return;
|
|
2930
|
-
anchor.current = { height: el.scrollHeight, top: el.scrollTop };
|
|
2931
2979
|
void loadEarlier().catch((e) => toast.error(errorText(e)));
|
|
2932
|
-
}, [
|
|
2933
|
-
const
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
atBottom.current = bottom;
|
|
2938
|
-
if (bottom && newCount) setNewCount(0);
|
|
2939
|
-
if (el.scrollTop < 200) loadOlder();
|
|
2940
|
-
};
|
|
2941
|
-
const jumpTo = useCallback((id) => {
|
|
2942
|
-
const el = document.getElementById(`genesis-chat-msg-${id}`);
|
|
2943
|
-
if (!el) {
|
|
2944
|
-
toast.info("That message is further up", { description: "Scroll up to load it." });
|
|
2945
|
-
return;
|
|
2946
|
-
}
|
|
2947
|
-
if (scroller.current) centerRow(scroller.current, el, !prefersReducedMotion());
|
|
2948
|
-
setHighlightedId(id);
|
|
2949
|
-
setTimeout(() => setHighlightedId((h) => h === id ? null : h), 1600);
|
|
2980
|
+
}, [loadEarlier]);
|
|
2981
|
+
const [jump, setJump] = useState(null);
|
|
2982
|
+
const goTo = useCallback((target) => {
|
|
2983
|
+
setJump(null);
|
|
2984
|
+
requestAnimationFrame(() => setJump(target));
|
|
2950
2985
|
}, []);
|
|
2986
|
+
const jumpTo = useCallback(
|
|
2987
|
+
(id) => {
|
|
2988
|
+
if (byId.has(id)) goTo({ messageId: id });
|
|
2989
|
+
else toast.info("That message is further up", { description: "Scroll up to load it." });
|
|
2990
|
+
},
|
|
2991
|
+
[byId, goTo]
|
|
2992
|
+
);
|
|
2951
2993
|
const reach = useCallback(
|
|
2952
2994
|
(target) => {
|
|
2953
2995
|
const root = target.threadRootId;
|
|
2954
2996
|
if (!root || root === threadRootId || root === target.messageId) {
|
|
2955
|
-
|
|
2997
|
+
goTo({ messageId: target.messageId, ...target.seq != null ? { seq: target.seq } : {} });
|
|
2956
2998
|
return;
|
|
2957
2999
|
}
|
|
2958
3000
|
void chatClient.message(root).then(
|
|
2959
3001
|
(m) => {
|
|
2960
3002
|
if (!m) {
|
|
2961
|
-
toast.info(
|
|
3003
|
+
toast.info(GONE);
|
|
2962
3004
|
return;
|
|
2963
3005
|
}
|
|
2964
3006
|
onOpenThread?.(m, target.seq != null ? { jumpTo: { messageId: target.messageId, seq: target.seq } } : void 0);
|
|
2965
|
-
|
|
3007
|
+
goTo({ messageId: m.id, seq: m.seq });
|
|
2966
3008
|
},
|
|
2967
3009
|
(e) => toast.error(errorText(e))
|
|
2968
3010
|
);
|
|
2969
3011
|
},
|
|
2970
|
-
[chatClient, onOpenThread, threadRootId]
|
|
3012
|
+
[chatClient, goTo, onOpenThread, threadRootId]
|
|
2971
3013
|
);
|
|
2972
|
-
const [pendingJump, setPendingJump] = useState(jumpToProp && !jumpToProp.threadRootId ? { ...jumpToProp, phase: "new" } : null);
|
|
2973
3014
|
useEffect(() => {
|
|
2974
3015
|
if (jumpToProp) reach(jumpToProp);
|
|
2975
3016
|
}, [jumpToProp?.messageId, jumpToProp?.seq]);
|
|
3017
|
+
const firstPageFailed = Boolean(state.error) && messages.length === 0;
|
|
2976
3018
|
const { loadUntil } = state;
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
toast.error(errorText(e));
|
|
2995
|
-
settle();
|
|
2996
|
-
});
|
|
2997
|
-
}, [pendingJump, byId, state.isLoading, loadUntil, jumpTo]);
|
|
3019
|
+
const jumpLoadFailed = useRef(false);
|
|
3020
|
+
const onLoadUntil = useCallback(
|
|
3021
|
+
(id) => {
|
|
3022
|
+
jumpLoadFailed.current = false;
|
|
3023
|
+
if (jump?.messageId !== id || jump.seq == null) return Promise.resolve(false);
|
|
3024
|
+
return loadUntil(jump.seq).catch((e) => {
|
|
3025
|
+
jumpLoadFailed.current = true;
|
|
3026
|
+
toast.error(errorText(e));
|
|
3027
|
+
return false;
|
|
3028
|
+
});
|
|
3029
|
+
},
|
|
3030
|
+
[jump, loadUntil]
|
|
3031
|
+
);
|
|
3032
|
+
const onJumpFailed = useCallback(() => {
|
|
3033
|
+
if (jumpLoadFailed.current) jumpLoadFailed.current = false;
|
|
3034
|
+
else toast.info(GONE);
|
|
3035
|
+
}, []);
|
|
2998
3036
|
const openHit = useCallback(
|
|
2999
3037
|
(hit) => {
|
|
3000
3038
|
setSearching(false);
|
|
@@ -3029,7 +3067,7 @@ function ChatThread({
|
|
|
3029
3067
|
emojibaseUrl,
|
|
3030
3068
|
linkPreviewImages,
|
|
3031
3069
|
linkPreviewProxyUrl,
|
|
3032
|
-
highlightedId,
|
|
3070
|
+
highlightedId: null,
|
|
3033
3071
|
editingId,
|
|
3034
3072
|
reply: (m) => {
|
|
3035
3073
|
setReplyTo(m);
|
|
@@ -3037,9 +3075,9 @@ function ChatThread({
|
|
|
3037
3075
|
},
|
|
3038
3076
|
focusComposer: () => composer.current?.focus(),
|
|
3039
3077
|
startEdit: setEditingId,
|
|
3040
|
-
saveEdit: async (m,
|
|
3078
|
+
saveEdit: async (m, body) => {
|
|
3041
3079
|
try {
|
|
3042
|
-
await actions.edit(m,
|
|
3080
|
+
await actions.edit(m, body, parseMentions(body));
|
|
3043
3081
|
} catch (e) {
|
|
3044
3082
|
toast.error(errorText(e));
|
|
3045
3083
|
throw e;
|
|
@@ -3078,44 +3116,6 @@ function ChatThread({
|
|
|
3078
3116
|
}
|
|
3079
3117
|
} : {};
|
|
3080
3118
|
const pinnedMessage = pinIds.length ? byId.get(pinIds[pinIds.length - 1]) : void 0;
|
|
3081
|
-
let body;
|
|
3082
|
-
if (state.isLoading) {
|
|
3083
|
-
body = /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3 p-4", "aria-busy": true, "aria-label": "Loading messages", "data-testid": "genesis-chat-thread-loading", children: [40, 60, 30, 50].map((w, i) => /* @__PURE__ */ jsx(Skeleton, { className: cn("h-9 rounded-2xl", i % 2 ? "self-end" : "self-start"), style: { width: `${w}%` } }, i)) });
|
|
3084
|
-
} else if (state.error && items.length === 0) {
|
|
3085
|
-
body = /* @__PURE__ */ jsx(
|
|
3086
|
-
EmptyState,
|
|
3087
|
-
{
|
|
3088
|
-
icon: MessageSquare,
|
|
3089
|
-
title: "Couldn't load this conversation",
|
|
3090
|
-
description: errorText(state.error),
|
|
3091
|
-
action: /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => void state.refetch(), children: "Try again" })
|
|
3092
|
-
}
|
|
3093
|
-
);
|
|
3094
|
-
} else if (items.length === 0) {
|
|
3095
|
-
body = renderSlot(DefaultEmpty2, slots?.empty, { conversationId, canPost });
|
|
3096
|
-
} else {
|
|
3097
|
-
body = /* @__PURE__ */ jsxs("div", { ref: content, className: "flex min-h-full flex-col justify-end pb-2 pt-1", children: [
|
|
3098
|
-
hasEarlier ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-2", children: loadingEarlier ? /* @__PURE__ */ jsx(Spinner, { size: "sm", "aria-label": "Loading earlier messages" }) : /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "h-7 text-xs text-muted-foreground", onClick: loadOlder, children: "Load earlier messages" }) }) : null,
|
|
3099
|
-
items.map((item, i) => {
|
|
3100
|
-
const id = item.type === "message" ? item.message.id : null;
|
|
3101
|
-
return /* @__PURE__ */ jsxs("div", { children: [
|
|
3102
|
-
startsDay(items, i) ? /* @__PURE__ */ jsx("div", { className: "sticky top-1 z-10 flex justify-center py-2", role: "separator", "aria-label": dayLabel(itemTime(item)), children: /* @__PURE__ */ jsx("span", { className: "rounded-full border bg-background/95 px-3 py-0.5 text-xs font-medium text-muted-foreground shadow-sm", children: dayLabel(itemTime(item)) }) }) : null,
|
|
3103
|
-
id && id === state.firstUnreadId ? /* @__PURE__ */ jsxs("div", { className: "my-2 flex items-center gap-2 px-4", role: "separator", "aria-label": "New messages", "data-testid": "genesis-chat-new-line", children: [
|
|
3104
|
-
/* @__PURE__ */ jsx("span", { className: "h-px flex-1 bg-primary/40" }),
|
|
3105
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-primary", children: "New" }),
|
|
3106
|
-
/* @__PURE__ */ jsx("span", { className: "h-px flex-1 bg-primary/40" })
|
|
3107
|
-
] }) : null,
|
|
3108
|
-
/* @__PURE__ */ jsx(
|
|
3109
|
-
ChatErrorBoundary,
|
|
3110
|
-
{
|
|
3111
|
-
fallback: /* @__PURE__ */ jsx("p", { className: "px-4 py-1 text-xs italic text-muted-foreground", role: "note", "data-testid": "genesis-chat-row-error", children: "This message couldn't be shown." }),
|
|
3112
|
-
children: /* @__PURE__ */ jsx(MessageRow, { item, startsGroup: startsGroup(items, i) })
|
|
3113
|
-
}
|
|
3114
|
-
)
|
|
3115
|
-
] }, itemKey(item));
|
|
3116
|
-
})
|
|
3117
|
-
] });
|
|
3118
|
-
}
|
|
3119
3119
|
return /* @__PURE__ */ jsxs(ThreadContext.Provider, { value: ctx, children: [
|
|
3120
3120
|
/* @__PURE__ */ jsxs(
|
|
3121
3121
|
"section",
|
|
@@ -3168,55 +3168,59 @@ function ChatThread({
|
|
|
3168
3168
|
}
|
|
3169
3169
|
) : null,
|
|
3170
3170
|
/* @__PURE__ */ jsxs("div", { className: "relative min-h-0 flex-1", children: [
|
|
3171
|
-
/* @__PURE__ */ jsx(
|
|
3172
|
-
|
|
3173
|
-
Button,
|
|
3171
|
+
/* @__PURE__ */ jsx(
|
|
3172
|
+
ThreadPage,
|
|
3174
3173
|
{
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3174
|
+
testID: "genesis-chat-thread-page",
|
|
3175
|
+
conversationId,
|
|
3176
|
+
messages: rows,
|
|
3177
|
+
composer: THREAD_COMPOSER,
|
|
3178
|
+
hasEarlier,
|
|
3179
|
+
onLoadEarlier: loadOlder,
|
|
3180
|
+
loadingEarlier,
|
|
3181
|
+
firstUnreadId: firstUnreadRow,
|
|
3182
|
+
jumpTo: firstPageFailed ? null : jump?.messageId ?? null,
|
|
3183
|
+
onLoadUntil,
|
|
3184
|
+
onJumpFailed,
|
|
3185
|
+
loading: state.isLoading,
|
|
3186
|
+
slots: THREAD_SLOTS,
|
|
3187
|
+
slotProps: {
|
|
3188
|
+
composer: {
|
|
3189
|
+
live,
|
|
3190
|
+
composerRef: composer,
|
|
3191
|
+
chatComposer: {
|
|
3192
|
+
conversation: state,
|
|
3193
|
+
replyTo,
|
|
3194
|
+
onCancelReply: () => setReplyTo(null),
|
|
3195
|
+
resolveUser,
|
|
3196
|
+
placeholder: currentTopic ? `Message #${currentTopic.title}` : placeholder,
|
|
3197
|
+
topic: topic ?? null,
|
|
3198
|
+
disabledReason: topicClosed ? "This topic is closed" : null,
|
|
3199
|
+
scheduling,
|
|
3200
|
+
emojibaseUrl,
|
|
3201
|
+
accessory: renderSlot(EmptyAccessory, slots?.composerAccessory, {
|
|
3202
|
+
conversationId,
|
|
3203
|
+
insertText: (t) => composer.current?.insertText(t),
|
|
3204
|
+
addFiles: (f) => composer.current?.addFiles(f)
|
|
3205
|
+
})
|
|
3206
|
+
}
|
|
3207
|
+
},
|
|
3208
|
+
empty: {
|
|
3209
|
+
override: slots?.empty,
|
|
3210
|
+
conversationId,
|
|
3211
|
+
canPost,
|
|
3212
|
+
failed: state.error ? errorText(state.error) : null,
|
|
3213
|
+
onRetry: () => void state.refetch()
|
|
3214
|
+
}
|
|
3215
|
+
},
|
|
3216
|
+
className: "h-full"
|
|
3184
3217
|
}
|
|
3185
|
-
)
|
|
3218
|
+
),
|
|
3186
3219
|
dragging ? /* @__PURE__ */ jsxs("div", { className: "pointer-events-none absolute inset-2 flex flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-primary bg-background/90 text-sm font-medium text-primary", children: [
|
|
3187
3220
|
/* @__PURE__ */ jsx(ImagePlus, { className: "size-6", "aria-hidden": true }),
|
|
3188
3221
|
"Drop to attach"
|
|
3189
3222
|
] }) : null
|
|
3190
|
-
] })
|
|
3191
|
-
/* @__PURE__ */ jsx("div", { className: "h-5 px-4 text-xs italic text-muted-foreground", "data-testid": "genesis-chat-activity", children: live ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5", children: [
|
|
3192
|
-
/* @__PURE__ */ jsxs("span", { className: "inline-flex gap-0.5", "aria-hidden": true, children: [
|
|
3193
|
-
/* @__PURE__ */ jsx("span", { className: "size-1 animate-bounce rounded-full bg-muted-foreground [animation-delay:-0.3s]" }),
|
|
3194
|
-
/* @__PURE__ */ jsx("span", { className: "size-1 animate-bounce rounded-full bg-muted-foreground [animation-delay:-0.15s]" }),
|
|
3195
|
-
/* @__PURE__ */ jsx("span", { className: "size-1 animate-bounce rounded-full bg-muted-foreground" })
|
|
3196
|
-
] }),
|
|
3197
|
-
live
|
|
3198
|
-
] }) : null }),
|
|
3199
|
-
/* @__PURE__ */ jsx("div", { className: "sr-only", "aria-live": "polite", "aria-atomic": "true", "data-testid": "genesis-chat-announcer", children: announcement }),
|
|
3200
|
-
/* @__PURE__ */ jsx(
|
|
3201
|
-
ChatComposer,
|
|
3202
|
-
{
|
|
3203
|
-
ref: composer,
|
|
3204
|
-
conversation: state,
|
|
3205
|
-
replyTo,
|
|
3206
|
-
onCancelReply: () => setReplyTo(null),
|
|
3207
|
-
resolveUser,
|
|
3208
|
-
placeholder: currentTopic ? `Message #${currentTopic.title}` : placeholder,
|
|
3209
|
-
topic: topic ?? null,
|
|
3210
|
-
disabledReason: topicClosed ? "This topic is closed" : null,
|
|
3211
|
-
scheduling,
|
|
3212
|
-
emojibaseUrl,
|
|
3213
|
-
accessory: renderSlot(EmptyAccessory, slots?.composerAccessory, {
|
|
3214
|
-
conversationId,
|
|
3215
|
-
insertText: (t) => composer.current?.insertText(t),
|
|
3216
|
-
addFiles: (f) => composer.current?.addFiles(f)
|
|
3217
|
-
})
|
|
3218
|
-
}
|
|
3219
|
-
)
|
|
3223
|
+
] })
|
|
3220
3224
|
]
|
|
3221
3225
|
}
|
|
3222
3226
|
),
|
|
@@ -4411,7 +4415,7 @@ function DockItemView({ item, inbox, resolveUser, threadProps, labels, inSheet,
|
|
|
4411
4415
|
[]
|
|
4412
4416
|
);
|
|
4413
4417
|
if (item.type === "panel") {
|
|
4414
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
4418
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4415
4419
|
/* @__PURE__ */ jsx(
|
|
4416
4420
|
DockTitleBar,
|
|
4417
4421
|
{
|
|
@@ -4425,14 +4429,14 @@ function DockItemView({ item, inbox, resolveUser, threadProps, labels, inSheet,
|
|
|
4425
4429
|
toggleRef
|
|
4426
4430
|
}
|
|
4427
4431
|
),
|
|
4428
|
-
/* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 flex-col overflow-y-auto", hidden: !visible, "data-testid": "genesis-chat-dock-panel", children: item.render() })
|
|
4432
|
+
/* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 flex-col overflow-y-auto", hidden: !visible, "data-testid": "genesis-chat-dock-panel", children: item.render({ visible }) })
|
|
4429
4433
|
] });
|
|
4430
4434
|
}
|
|
4431
4435
|
const row = inbox.get(item.conversationId);
|
|
4432
4436
|
const title = item.title ?? header?.title ?? conversationTitle(item, inbox, resolveUser, labels);
|
|
4433
4437
|
const otherId = header?.otherUserId ?? row?.otherUserId ?? null;
|
|
4434
4438
|
const other = otherId ? resolveUser(otherId) : null;
|
|
4435
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
4439
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4436
4440
|
/* @__PURE__ */ jsx(
|
|
4437
4441
|
DockTitleBar,
|
|
4438
4442
|
{
|
|
@@ -4545,7 +4549,7 @@ function ChatDock({ resolveUser, threadProps, labels: labelOverrides, bubble = t
|
|
|
4545
4549
|
const unreadTotal = dock.items.reduce((n, i) => n + (seen(i) ? 0 : itemUnread(i, inbox)), 0);
|
|
4546
4550
|
const announce = /* @__PURE__ */ jsx("span", { className: "sr-only", "aria-live": "polite", "data-testid": "genesis-chat-dock-announce", children: labels.unreadTotal(unreadTotal) });
|
|
4547
4551
|
if (narrow) {
|
|
4548
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
4552
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4549
4553
|
announce,
|
|
4550
4554
|
bubble && !dock.sheetOpen ? /* @__PURE__ */ jsx("div", { className: cn("pointer-events-none flex justify-end p-4", className), children: /* @__PURE__ */ jsxs(
|
|
4551
4555
|
"button",
|