@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as AttachmentKind, A as AttachmentInput, U as UploadProgress, H as HostedAttachment, i as ChatClient, B as PendingMessage, P as PendingFile, q as ChatMessage, F as SendInput } from './client-
|
|
1
|
+
import { b as AttachmentKind, A as AttachmentInput, U as UploadProgress, H as HostedAttachment, i as ChatClient, B as PendingMessage, P as PendingFile, q as ChatMessage, F as SendInput } from './client-DJs3ltZc.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @feat:chat
|
package/dist/push.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as ChatClient } from './client-
|
|
2
|
-
import { O as Outbox, e as OutboxStore, Q as QueuedMessage } from './outbox-
|
|
1
|
+
import { i as ChatClient } from './client-DJs3ltZc.js';
|
|
2
|
+
import { O as Outbox, e as OutboxStore, Q as QueuedMessage } from './outbox-YFTbGIAl.js';
|
|
3
3
|
import '@supabase/supabase-js';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/react.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _tanstack_query_core from '@tanstack/query-core';
|
|
2
|
-
import { h as ChatAttachment, i as ChatClient, k as ChatConversation, p as ChatMember, t as ChatRole, n as ChatKindRules, q as ChatMessage, g as ChatActivity, F as SendInput, M as MessagePage, C as ChatAvailability, d as AvailabilityInput, v as ChatSignal, m as ChatInboxItem, o as ChatLinkPreview, D as ScheduledMessage, S as ScheduleInput, u as ChatSearchHit, G as StartConversationOptions, x as ChatTopic, T as TopicInput } from './client-
|
|
2
|
+
import { h as ChatAttachment, i as ChatClient, k as ChatConversation, p as ChatMember, t as ChatRole, n as ChatKindRules, q as ChatMessage, g as ChatActivity, F as SendInput, M as MessagePage, C as ChatAvailability, d as AvailabilityInput, v as ChatSignal, m as ChatInboxItem, o as ChatLinkPreview, D as ScheduledMessage, S as ScheduleInput, u as ChatSearchHit, G as StartConversationOptions, x as ChatTopic, T as TopicInput } from './client-DJs3ltZc.js';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
|
-
import { e as OutboxStore, S as StorageUpload, H as HostedUpload, L as LocalFile, O as Outbox, Q as QueuedMessage } from './outbox-
|
|
6
|
-
import { T as ThreadItem } from './thread-
|
|
5
|
+
import { e as OutboxStore, S as StorageUpload, H as HostedUpload, L as LocalFile, O as Outbox, Q as QueuedMessage } from './outbox-YFTbGIAl.js';
|
|
6
|
+
import { T as ThreadItem } from './thread-CgHP00Jw.js';
|
|
7
7
|
import '@supabase/supabase-js';
|
|
8
8
|
|
|
9
9
|
declare const chatKeys: {
|
|
@@ -160,7 +160,6 @@ interface UseConversationOptions {
|
|
|
160
160
|
topic?: string;
|
|
161
161
|
pageSize?: number;
|
|
162
162
|
}
|
|
163
|
-
/** One conversation: its messages (with what you are still sending), members, your role, and who is typing. */
|
|
164
163
|
declare function useConversation(conversationId: string | null | undefined, opts?: UseConversationOptions): {
|
|
165
164
|
conversation: ChatConversation | null;
|
|
166
165
|
members: ChatMember[];
|
|
@@ -192,6 +191,8 @@ declare function useConversation(conversationId: string | null | undefined, opts
|
|
|
192
191
|
loadUntil: (seq: number) => Promise<boolean>;
|
|
193
192
|
/** Where to draw the "New" line, from what you had read when it opened. */
|
|
194
193
|
firstUnreadId: string | null;
|
|
194
|
+
/** Whether `firstUnreadId` is known yet (your read place as of this opening has been fetched). */
|
|
195
|
+
firstUnreadKnown: boolean;
|
|
195
196
|
activity: ChatActivity[];
|
|
196
197
|
signalTyping: () => void;
|
|
197
198
|
signalRecording: () => void;
|
|
@@ -202,6 +203,10 @@ declare function useConversation(conversationId: string | null | undefined, opts
|
|
|
202
203
|
retry: (clientId: string) => Promise<void>;
|
|
203
204
|
discard: (clientId: string) => Promise<void>;
|
|
204
205
|
refetch: () => Promise<void>;
|
|
206
|
+
/** The conversation and its first page again, after either failed (a Retry on the thread's error row). */
|
|
207
|
+
reload: () => Promise<undefined>;
|
|
208
|
+
/** The live channel: true once joined, false when it dropped (errored, timed out, closed), null until the client says. */
|
|
209
|
+
live: boolean | null;
|
|
205
210
|
};
|
|
206
211
|
type ConversationState = ReturnType<typeof useConversation>;
|
|
207
212
|
/** Edit, delete, react, pin, save and report, refreshing what they change. */
|
|
@@ -222,7 +227,10 @@ declare function usePeople(userIds: (string | null | undefined)[]): Record<strin
|
|
|
222
227
|
declare function usePerson(userId: string | null | undefined): ChatPerson | null;
|
|
223
228
|
/** The pinned message ids of a conversation. */
|
|
224
229
|
declare function usePins(conversationId: string | null | undefined): string[];
|
|
225
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* Signed links for files (cached by the client until shortly before they expire). While a new set
|
|
232
|
+
* of paths loads (a photo arrives), the links already signed stay: the photos on screen don't blank.
|
|
233
|
+
*/
|
|
226
234
|
declare function useFileUrls(paths: (string | null | undefined)[]): Record<string, string>;
|
|
227
235
|
/** Starts (or finds again) a conversation, then refreshes the inbox. */
|
|
228
236
|
declare function useStartConversation(): (kind: string, memberIds: string[], opts?: StartConversationOptions) => Promise<string>;
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CATCH_UP_MAX_PAGES, CATCH_UP_PAGE, ChatProvider, LINK_PREVIEW_CONCURRENCY, belongsTo, chatKeys, hostedUploadFrom, useAvailability, useBroadcast, useChat, useConversation, useDebouncedValue, useFileUrls, useInbox, useLinkPreviews, useMessageActions, usePeople, usePerson, usePins, useScheduled, useSearch, useStartConversation, useTopics, useUnreadTotal } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
export { CATCH_UP_MAX_PAGES, CATCH_UP_PAGE, ChatProvider, LINK_PREVIEW_CONCURRENCY, belongsTo, chatKeys, hostedUploadFrom, useAvailability, useBroadcast, useChat, useConversation, useDebouncedValue, useFileUrls, useInbox, useLinkPreviews, useMessageActions, usePeople, usePerson, usePins, useScheduled, useSearch, useStartConversation, useTopics, useUnreadTotal } from './chunk-K5GYNHNE.js';
|
|
2
|
+
import './chunk-2HNQWDLF.js';
|
|
3
|
+
import './chunk-VBIYDXL2.js';
|
|
4
4
|
//# sourceMappingURL=react.js.map
|
|
5
5
|
//# sourceMappingURL=react.js.map
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { w as ChatSupabase } from './client-
|
|
1
|
+
import { w as ChatSupabase } from './client-DJs3ltZc.js';
|
|
2
2
|
export { a as ANTHROPIC_MESSAGES_URL, b as ANTHROPIC_VERSION, c as AnthropicLike, A as AssistantMessage, d as AssistantResult, C as CHAT_ASSISTANT_MODEL, e as ChatAssistant, f as ChatAssistantOptions, D as DraftReplyInput, R as RecapInput, g as createChatAssistant, h as draftPrompt, i as draftSystem, r as recapPrompt, j as recapSystem, t as transcriptLines } from './assistant-DLRCksST.js';
|
|
3
3
|
import '@supabase/supabase-js';
|
|
4
4
|
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CHAT_BUCKET, CHAT_SCHEMA } from './chunk-
|
|
1
|
+
import { CHAT_BUCKET, CHAT_SCHEMA } from './chunk-VBIYDXL2.js';
|
|
2
2
|
import { chatPushPayload } from './chunk-BTG4JWLF.js';
|
|
3
3
|
export { ANTHROPIC_MESSAGES_URL, ANTHROPIC_VERSION, CHAT_ASSISTANT_MODEL, createChatAssistant, draftPrompt, draftSystem, recapPrompt, recapSystem, transcriptLines } from './chunk-ZHZVQ535.js';
|
|
4
4
|
|
package/dist/web.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentType, ReactNode, Ref, Component, ErrorInfo } from 'react';
|
|
3
3
|
import { SlotOverride } from '@marktiderman/genesis-core/slots';
|
|
4
|
-
import { q as ChatMessage, m as ChatInboxItem, o as ChatLinkPreview$1, h as ChatAttachment, k as ChatConversation, p as ChatMember, t as ChatRole, i as ChatClient, g as ChatActivity, C as ChatAvailability, x as ChatTopic, T as TopicInput, u as ChatSearchHit, F as SendInput, A as AttachmentInput } from './client-
|
|
4
|
+
import { q as ChatMessage, m as ChatInboxItem, o as ChatLinkPreview$1, h as ChatAttachment, k as ChatConversation, p as ChatMember, t as ChatRole, i as ChatClient, g as ChatActivity, C as ChatAvailability, x as ChatTopic, T as TopicInput, u as ChatSearchHit, F as SendInput, A as AttachmentInput } from './client-DJs3ltZc.js';
|
|
5
5
|
import { ChatAttachmentKind, ConversationState, ChatVideoUpload } from './react.js';
|
|
6
|
-
import { T as ThreadItem } from './thread-
|
|
7
|
-
import { L as LocalFile } from './outbox-
|
|
6
|
+
import { T as ThreadItem } from './thread-CgHP00Jw.js';
|
|
7
|
+
import { L as LocalFile } from './outbox-YFTbGIAl.js';
|
|
8
8
|
import '@supabase/supabase-js';
|
|
9
9
|
import '@tanstack/query-core';
|
|
10
10
|
|
package/dist/web.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { attachmentPreview, ChatErrorBoundary } from './chunk-
|
|
2
|
-
export { ChatErrorBoundary } from './chunk-
|
|
1
|
+
import { attachmentPreview, ChatErrorBoundary } from './chunk-3HQN2FZ5.js';
|
|
2
|
+
export { ChatErrorBoundary } from './chunk-3HQN2FZ5.js';
|
|
3
3
|
import { snippetParts, isHttpsUrl, scheduleQuickPicks, isSchedulable, scheduleLabel, extractLinks, topicKey } from './chunk-BJCE5O7V.js';
|
|
4
|
-
import { useChat, useInbox, useSearch, useScheduled, useAvailability, useTopics, useConversation, useMessageActions, usePins, useFileUrls, useLinkPreviews, useBroadcast } from './chunk-
|
|
5
|
-
import { previewText, summarizeReactions, activityLine, itemSender, startsDay, dayLabel, itemTime, startsGroup, parseMentions } from './chunk-
|
|
6
|
-
import { fileExtension, formatDuration, nextPlaybackRate, awaySummary, awayLine, WEEKDAYS, CHAT_LIMITS, waveformPeaks, recordingLimitMs, isAllowedExtension, attachmentKindFor, randomId, ChatError } from './chunk-
|
|
4
|
+
import { useChat, useInbox, useSearch, useScheduled, useAvailability, useTopics, useConversation, useMessageActions, usePins, useFileUrls, useLinkPreviews, useBroadcast } from './chunk-K5GYNHNE.js';
|
|
5
|
+
import { previewText, summarizeReactions, activityLine, itemSender, startsDay, dayLabel, itemTime, startsGroup, parseMentions } from './chunk-2HNQWDLF.js';
|
|
6
|
+
import { fileExtension, formatDuration, nextPlaybackRate, awaySummary, awayLine, WEEKDAYS, CHAT_LIMITS, waveformPeaks, recordingLimitMs, isAllowedExtension, attachmentKindFor, randomId, ChatError } from './chunk-VBIYDXL2.js';
|
|
7
7
|
import { createContext, useMemo, useState, useRef, Fragment as Fragment$1, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useReducer, useContext, useSyncExternalStore } from 'react';
|
|
8
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
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';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
-- Genesis Chat 0006: read receipts
|
|
2
|
+
--
|
|
3
|
+
-- Builds on 0001–0005 (never edited once released). Needs nothing from your app, and no other
|
|
4
|
+
-- package's migrations depend on where it runs after chat 0005.
|
|
5
|
+
--
|
|
6
|
+
-- 1. `members.last_read_at`: when the member last read someone else's message, that is, when
|
|
7
|
+
-- their read place (`last_read_seq`) last moved past a message another person sent (any kind
|
|
8
|
+
-- but system: a voice note or video is a message with attachments, and counts). Posting
|
|
9
|
+
-- moves your read place past your own message, which sets nothing. Null until it happens,
|
|
10
|
+
-- on rows written before this migration, and for observers. A sender's "Read 9:41" is this.
|
|
11
|
+
-- 2. Whenever a member's read place moves past someone else's message (even twice in one
|
|
12
|
+
-- transaction, when `now()` and so `last_read_at` don't change), the conversation's live topic
|
|
13
|
+
-- gets a `read` hint ({conversation_id, user_id,
|
|
14
|
+
-- seq, at}), so "Delivered" turns to "Read" while the sender has the thread open. Members
|
|
15
|
+
-- already read each other's `last_read_seq` (members_read); the hint carries nothing more,
|
|
16
|
+
-- and clients treat it only as a cue to read the members again, never as the read place.
|
|
17
|
+
-- An observer's reads are never sent. Conversations of more than 32 members get no hint
|
|
18
|
+
-- (each read would reach every open thread, O(n²) deliveries per message): their "Read by N"
|
|
19
|
+
-- updates when the members are next read (opening the thread, a refresh).
|
|
20
|
+
-- 3. Clients may broadcast only what clients send: `activity` (typing, recording) and presence.
|
|
21
|
+
-- Every other event on a conversation's topic (`message`, `read`, `members`, …) comes from the
|
|
22
|
+
-- database's own triggers through `genesis_chat.broadcast`, so a member can't forge another
|
|
23
|
+
-- member's read receipt (or a message hint) on everyone's screen.
|
|
24
|
+
-- 4. A hidden (moderated) or deleted message doesn't count as read: its sender mustn't see "Read"
|
|
25
|
+
-- on what the other person was never shown.
|
|
26
|
+
--
|
|
27
|
+
-- Privacy: with this migration every member and observer of a conversation can see when each
|
|
28
|
+
-- member last read it (`last_read_at`), as they already see how far (`last_read_seq`).
|
|
29
|
+
|
|
30
|
+
alter table genesis_chat.members add column last_read_at timestamptz;
|
|
31
|
+
|
|
32
|
+
comment on column genesis_chat.members.last_read_at is
|
|
33
|
+
'When this member''s read place last moved past someone else''s message (read receipts). Genesis Chat.';
|
|
34
|
+
|
|
35
|
+
-- Whether a read place moving from p_from to p_to passed a message someone else sent that this
|
|
36
|
+
-- member was shown: any kind but system, to everyone, not hidden by moderation, not deleted.
|
|
37
|
+
create function genesis_chat.read_passed(p_conversation_id uuid, p_user_id uuid, p_from bigint, p_to bigint)
|
|
38
|
+
returns boolean
|
|
39
|
+
language sql
|
|
40
|
+
stable
|
|
41
|
+
security definer
|
|
42
|
+
set search_path = ''
|
|
43
|
+
as $$
|
|
44
|
+
select p_to > p_from and exists (
|
|
45
|
+
select 1 from genesis_chat.messages m
|
|
46
|
+
where m.conversation_id = p_conversation_id
|
|
47
|
+
and m.seq > p_from and m.seq <= p_to
|
|
48
|
+
and m.kind <> 'system' and m.visibility = 'everyone'
|
|
49
|
+
and m.moderation is distinct from 'hidden' and m.deleted_at is null
|
|
50
|
+
and m.sender_id is distinct from p_user_id
|
|
51
|
+
)
|
|
52
|
+
$$;
|
|
53
|
+
revoke execute on function genesis_chat.read_passed(uuid, uuid, bigint, bigint) from public, anon, authenticated;
|
|
54
|
+
|
|
55
|
+
create function genesis_chat.read_moved()
|
|
56
|
+
returns trigger
|
|
57
|
+
language plpgsql
|
|
58
|
+
security definer
|
|
59
|
+
set search_path = ''
|
|
60
|
+
as $$
|
|
61
|
+
begin
|
|
62
|
+
if new.role <> 'observer' and genesis_chat.read_passed(new.conversation_id, new.user_id, old.last_read_seq, new.last_read_seq) then
|
|
63
|
+
new.last_read_at := now();
|
|
64
|
+
end if;
|
|
65
|
+
return new;
|
|
66
|
+
end;
|
|
67
|
+
$$;
|
|
68
|
+
revoke execute on function genesis_chat.read_moved() from public, anon, authenticated;
|
|
69
|
+
create trigger members_read_moved before update of last_read_seq on genesis_chat.members
|
|
70
|
+
for each row execute function genesis_chat.read_moved();
|
|
71
|
+
|
|
72
|
+
create function genesis_chat.read_hint()
|
|
73
|
+
returns trigger
|
|
74
|
+
language plpgsql
|
|
75
|
+
security definer
|
|
76
|
+
set search_path = ''
|
|
77
|
+
as $$
|
|
78
|
+
begin
|
|
79
|
+
if new.role <> 'observer'
|
|
80
|
+
and genesis_chat.read_passed(new.conversation_id, new.user_id, old.last_read_seq, new.last_read_seq)
|
|
81
|
+
and (
|
|
82
|
+
select count(*) from genesis_chat.members m
|
|
83
|
+
where m.conversation_id = new.conversation_id and m.left_at is null
|
|
84
|
+
) <= 32 then
|
|
85
|
+
perform genesis_chat.broadcast('genesis-chat:conv:' || new.conversation_id, 'read',
|
|
86
|
+
jsonb_build_object('conversation_id', new.conversation_id, 'user_id', new.user_id,
|
|
87
|
+
'seq', new.last_read_seq, 'at', new.last_read_at));
|
|
88
|
+
end if;
|
|
89
|
+
return null;
|
|
90
|
+
end;
|
|
91
|
+
$$;
|
|
92
|
+
revoke execute on function genesis_chat.read_hint() from public, anon, authenticated;
|
|
93
|
+
create trigger members_read_hint after update of last_read_seq on genesis_chat.members
|
|
94
|
+
for each row execute function genesis_chat.read_hint();
|
|
95
|
+
|
|
96
|
+
-- Only client events from clients: the server's own hints go out through genesis_chat.broadcast
|
|
97
|
+
-- (SECURITY DEFINER), which this policy doesn't govern.
|
|
98
|
+
do $do$
|
|
99
|
+
begin
|
|
100
|
+
if to_regclass('realtime.messages') is not null then
|
|
101
|
+
execute 'drop policy if exists genesis_chat_signal on realtime.messages';
|
|
102
|
+
execute $p$
|
|
103
|
+
create policy genesis_chat_signal on realtime.messages for insert to authenticated
|
|
104
|
+
with check ((realtime.messages.extension = 'presence'
|
|
105
|
+
or (realtime.messages.extension = 'broadcast' and realtime.messages.event = 'activity'))
|
|
106
|
+
and genesis_chat.can_join_topic(realtime.topic(), true))
|
|
107
|
+
$p$;
|
|
108
|
+
end if;
|
|
109
|
+
end;
|
|
110
|
+
$do$;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
-- @feat:chat
|
|
2
|
+
-- pgTAP test for 0006_genesis_chat_read_receipts.sql.
|
|
3
|
+
-- Copy into your app's `supabase/tests/database/` and run `supabase test db`.
|
|
4
|
+
-- It writes only its own users, kinds and conversations, and rolls everything back.
|
|
5
|
+
--
|
|
6
|
+
-- People: a1 and b2 talk directly.
|
|
7
|
+
begin;
|
|
8
|
+
create extension if not exists pgtap with schema extensions;
|
|
9
|
+
select plan(17);
|
|
10
|
+
|
|
11
|
+
insert into auth.users (id, aud, role, email, instance_id)
|
|
12
|
+
select ('00000000-0000-4000-8000-00000000c6' || n)::uuid, 'authenticated', 'authenticated', 'genesis-chat-6-' || n || '@example.test', '00000000-0000-0000-0000-000000000000'
|
|
13
|
+
from unnest(array['a1', 'b2']) n;
|
|
14
|
+
|
|
15
|
+
create schema if not exists private;
|
|
16
|
+
create or replace function private.genesis_viewer_people(viewer uuid)
|
|
17
|
+
returns table (tenant_id uuid, person_id uuid) language sql stable set search_path = '' as $$
|
|
18
|
+
select '00000000-0000-4000-8000-0000000000f6'::uuid, viewer
|
|
19
|
+
$$;
|
|
20
|
+
|
|
21
|
+
create function pg_temp.person(n text) returns uuid language sql immutable as $$ select ('00000000-0000-4000-8000-00000000c6' || n)::uuid $$;
|
|
22
|
+
create function pg_temp.sign_in(n text) returns void language plpgsql as $$
|
|
23
|
+
begin
|
|
24
|
+
perform set_config('request.jwt.claims', json_build_object('sub', pg_temp.person(n), 'role', 'authenticated')::text, true);
|
|
25
|
+
perform set_config('request.jwt.claim.sub', pg_temp.person(n)::text, true);
|
|
26
|
+
perform set_config('role', 'authenticated', true);
|
|
27
|
+
end $$;
|
|
28
|
+
grant execute on function pg_temp.person(text), pg_temp.sign_in(text) to authenticated;
|
|
29
|
+
|
|
30
|
+
create temp table t (k text primary key, v uuid);
|
|
31
|
+
grant select, insert, update on t to authenticated;
|
|
32
|
+
create function pg_temp.v(k_ text) returns uuid language sql stable as $$ select v from t where k = k_ $$;
|
|
33
|
+
create function pg_temp.read_at(n text) returns timestamptz language sql stable as $$
|
|
34
|
+
select last_read_at from genesis_chat.members where conversation_id = pg_temp.v('ab') and user_id = pg_temp.person(n)
|
|
35
|
+
$$;
|
|
36
|
+
grant execute on function pg_temp.v(text), pg_temp.read_at(text) to authenticated;
|
|
37
|
+
|
|
38
|
+
create function public.genesis_chat_test6_may_start(member_ids uuid[], subject_type text, subject_id text, user_id uuid)
|
|
39
|
+
returns boolean language sql stable set search_path = '' as $$ select true $$;
|
|
40
|
+
select genesis_chat.register_kind('direct', 'Direct message', p_max_members => 2,
|
|
41
|
+
p_start_check => 'public.genesis_chat_test6_may_start(uuid[], text, text, uuid)');
|
|
42
|
+
|
|
43
|
+
select pg_temp.sign_in('a1');
|
|
44
|
+
insert into t select 'ab', genesis_chat.start_conversation('direct', array[pg_temp.person('b2')]);
|
|
45
|
+
select genesis_chat.send_message(pg_temp.v('ab'), gen_random_uuid(), 'hello');
|
|
46
|
+
|
|
47
|
+
select is(pg_temp.read_at('a1'), null, 'posting moves your read place past your own message only: no read time');
|
|
48
|
+
select is(pg_temp.read_at('b2'), null, 'nobody has read it yet');
|
|
49
|
+
|
|
50
|
+
select pg_temp.sign_in('b2');
|
|
51
|
+
select genesis_chat.mark_read(pg_temp.v('ab'));
|
|
52
|
+
select isnt(pg_temp.read_at('b2'), null, 'reading someone else''s message records when');
|
|
53
|
+
|
|
54
|
+
-- A fixed earlier time, so "unchanged" is visible within one transaction (now() doesn't move).
|
|
55
|
+
reset role;
|
|
56
|
+
update genesis_chat.members set last_read_at = '2000-01-01T00:00:00Z' where conversation_id = pg_temp.v('ab');
|
|
57
|
+
|
|
58
|
+
select pg_temp.sign_in('b2');
|
|
59
|
+
select genesis_chat.mark_read(pg_temp.v('ab'));
|
|
60
|
+
select is(pg_temp.read_at('b2'), '2000-01-01T00:00:00Z'::timestamptz, 'reading again with nothing new keeps the time');
|
|
61
|
+
|
|
62
|
+
select genesis_chat.send_message(pg_temp.v('ab'), gen_random_uuid(), 'hi back');
|
|
63
|
+
select is(pg_temp.read_at('b2'), '2000-01-01T00:00:00Z'::timestamptz, 'replying moves the place past your own message: the time stays');
|
|
64
|
+
|
|
65
|
+
select pg_temp.sign_in('a1');
|
|
66
|
+
select is(pg_temp.read_at('b2'), '2000-01-01T00:00:00Z'::timestamptz, 'the other member sees the read time');
|
|
67
|
+
select genesis_chat.send_message(pg_temp.v('ab'), gen_random_uuid(), 'and again');
|
|
68
|
+
select isnt(pg_temp.read_at('a1'), '2000-01-01T00:00:00Z'::timestamptz, 'posting past a message you hadn''t read counts as reading it');
|
|
69
|
+
|
|
70
|
+
-- An observer's place moving records nothing.
|
|
71
|
+
reset role;
|
|
72
|
+
update genesis_chat.members set role = 'observer', last_read_at = null where conversation_id = pg_temp.v('ab') and user_id = pg_temp.person('b2');
|
|
73
|
+
update genesis_chat.members set last_read_seq = last_read_seq + 1 where conversation_id = pg_temp.v('ab') and user_id = pg_temp.person('b2');
|
|
74
|
+
select is(pg_temp.read_at('b2'), null, 'an observer gets no read time');
|
|
75
|
+
|
|
76
|
+
select has_column('genesis_chat', 'members', 'last_read_at', 'members carry last_read_at');
|
|
77
|
+
|
|
78
|
+
-- A voice note (a message with attachments and no text) is read like any other.
|
|
79
|
+
reset role;
|
|
80
|
+
update genesis_chat.members set role = 'member', last_read_at = '2000-01-01T00:00:00Z' where conversation_id = pg_temp.v('ab') and user_id = pg_temp.person('b2');
|
|
81
|
+
insert into genesis_chat.messages (conversation_id, seq, sender_id, sender_role, body) values (pg_temp.v('ab'), 0, pg_temp.person('a1'), 'member', '');
|
|
82
|
+
select pg_temp.sign_in('b2');
|
|
83
|
+
select genesis_chat.mark_read(pg_temp.v('ab'));
|
|
84
|
+
select isnt(pg_temp.read_at('b2'), '2000-01-01T00:00:00Z'::timestamptz, 'reading past a message with no text (a voice note) records when');
|
|
85
|
+
|
|
86
|
+
-- Reading twice in one transaction (now() fixed, so last_read_at unchanged) still sends the hint:
|
|
87
|
+
-- the hint follows the read place, not the time.
|
|
88
|
+
reset role;
|
|
89
|
+
select ok(genesis_chat.read_passed(pg_temp.v('ab'), pg_temp.person('b2'), 0, 1), 'a read place moving past someone else''s message counts, whatever the time');
|
|
90
|
+
|
|
91
|
+
-- A hidden (moderated) or deleted message isn't read: no read time for it.
|
|
92
|
+
update genesis_chat.members set role = 'member', last_read_at = null where conversation_id = pg_temp.v('ab') and user_id = pg_temp.person('b2');
|
|
93
|
+
select pg_temp.sign_in('a1');
|
|
94
|
+
select genesis_chat.send_message(pg_temp.v('ab'), gen_random_uuid(), 'hidden one');
|
|
95
|
+
reset role;
|
|
96
|
+
update genesis_chat.messages set moderation = 'hidden'
|
|
97
|
+
where conversation_id = pg_temp.v('ab') and seq = (select last_seq from genesis_chat.conversations where id = pg_temp.v('ab'));
|
|
98
|
+
select pg_temp.sign_in('b2');
|
|
99
|
+
select genesis_chat.mark_read(pg_temp.v('ab'));
|
|
100
|
+
select is(pg_temp.read_at('b2'), null, 'reading past a hidden message records no read time');
|
|
101
|
+
|
|
102
|
+
select pg_temp.sign_in('a1');
|
|
103
|
+
select genesis_chat.send_message(pg_temp.v('ab'), gen_random_uuid(), 'deleted one');
|
|
104
|
+
reset role;
|
|
105
|
+
update genesis_chat.messages set deleted_at = now()
|
|
106
|
+
where conversation_id = pg_temp.v('ab') and seq = (select last_seq from genesis_chat.conversations where id = pg_temp.v('ab'));
|
|
107
|
+
select pg_temp.sign_in('b2');
|
|
108
|
+
select genesis_chat.mark_read(pg_temp.v('ab'));
|
|
109
|
+
select is(pg_temp.read_at('b2'), null, 'reading past a deleted message records no read time');
|
|
110
|
+
|
|
111
|
+
-- Clients send only client events on a conversation's topic: never a read (or message) hint.
|
|
112
|
+
reset role;
|
|
113
|
+
grant insert on realtime.messages to authenticated;
|
|
114
|
+
grant usage on all sequences in schema realtime to authenticated;
|
|
115
|
+
select pg_temp.sign_in('a1');
|
|
116
|
+
select set_config('realtime.topic', 'genesis-chat:conv:' || pg_temp.v('ab'), true);
|
|
117
|
+
select throws_ok(
|
|
118
|
+
$$ insert into realtime.messages (topic, extension, event, payload) values (realtime.topic(), 'broadcast', 'read', jsonb_build_object('user_id', pg_temp.person('b2'), 'seq', 1000000)) $$,
|
|
119
|
+
'42501', null, 'a member can''t broadcast a read hint (a forged receipt)');
|
|
120
|
+
select throws_ok(
|
|
121
|
+
$$ insert into realtime.messages (topic, extension, event, payload) values (realtime.topic(), 'broadcast', 'message', '{}'::jsonb) $$,
|
|
122
|
+
'42501', null, 'nor a message hint');
|
|
123
|
+
select lives_ok(
|
|
124
|
+
$$ insert into realtime.messages (topic, extension, event, payload) values (realtime.topic(), 'broadcast', 'activity', '{"activity":"typing"}'::jsonb) $$,
|
|
125
|
+
'a member can still say they are typing');
|
|
126
|
+
select lives_ok(
|
|
127
|
+
$$ insert into realtime.messages (topic, extension, event, payload) values (realtime.topic(), 'presence', 'track', '{}'::jsonb) $$,
|
|
128
|
+
'and use presence');
|
|
129
|
+
|
|
130
|
+
select * from finish();
|
|
131
|
+
rollback;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"README.md"
|
|
87
87
|
],
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@marktiderman/genesis-config": "^0.
|
|
89
|
+
"@marktiderman/genesis-config": "^0.13.0",
|
|
90
90
|
"frimousse": "0.4.0"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
@@ -176,9 +176,9 @@
|
|
|
176
176
|
"@ai-sdk/anthropic": "4.0.102",
|
|
177
177
|
"@marktiderman/genesis-ai": "^0.3.1",
|
|
178
178
|
"@marktiderman/genesis-core": "^2.20.0",
|
|
179
|
-
"@marktiderman/genesis-notifications": "^0.4.
|
|
180
|
-
"@marktiderman/genesis-ui": "^3.2.
|
|
181
|
-
"@marktiderman/genesis-ui-native": "^3.
|
|
179
|
+
"@marktiderman/genesis-notifications": "^0.4.7",
|
|
180
|
+
"@marktiderman/genesis-ui": "^3.2.2",
|
|
181
|
+
"@marktiderman/genesis-ui-native": "^3.16.0",
|
|
182
182
|
"@supabase/supabase-js": "^2.118.0",
|
|
183
183
|
"@tanstack/react-query": "^5.105.0",
|
|
184
184
|
"@testing-library/react": "^16.3.2",
|
|
@@ -251,6 +251,10 @@
|
|
|
251
251
|
{
|
|
252
252
|
"file": "migrations/0005_genesis_chat_attachment_paths.sql",
|
|
253
253
|
"test": "migrations/tests/0005_genesis_chat_attachment_paths.test.sql"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"file": "migrations/0006_genesis_chat_read_receipts.sql",
|
|
257
|
+
"test": "migrations/tests/0006_genesis_chat_read_receipts.test.sql"
|
|
254
258
|
}
|
|
255
259
|
],
|
|
256
260
|
"install": [
|
package/src/core/client.ts
CHANGED
|
@@ -298,6 +298,8 @@ export interface ConversationHandlers {
|
|
|
298
298
|
onJoin?: () => void;
|
|
299
299
|
/** Re-joins only. Prefer `onJoin`. */
|
|
300
300
|
onReconnect?: () => void;
|
|
301
|
+
/** Whether the channel is live, as it changes: true once joined, false when it errors, times out or closes. */
|
|
302
|
+
onLive?: (live: boolean) => void;
|
|
301
303
|
}
|
|
302
304
|
|
|
303
305
|
export interface ConversationChannel extends Subscription {
|
|
@@ -399,6 +401,7 @@ export function createChatClient(supabase: ChatSupabase, options: ChatClientOpti
|
|
|
399
401
|
userId: String(r.user_id),
|
|
400
402
|
role: r.role as ChatRole,
|
|
401
403
|
lastReadSeq: Number(r.last_read_seq ?? 0),
|
|
404
|
+
lastReadAt: r.last_read_at ? String(r.last_read_at) : null,
|
|
402
405
|
joinedAt: String(r.joined_at),
|
|
403
406
|
}));
|
|
404
407
|
},
|
|
@@ -737,6 +740,11 @@ export function createChatClient(supabase: ChatSupabase, options: ChatClientOpti
|
|
|
737
740
|
handlers.onSignal({ type: "reaction", conversationId, messageId: String(payload?.message_id) }),
|
|
738
741
|
)
|
|
739
742
|
.on("broadcast", { event: "members" }, () => handlers.onSignal({ type: "members", conversationId }))
|
|
743
|
+
.on("broadcast", { event: "read" }, ({ payload }) => {
|
|
744
|
+
if (payload?.user_id && payload.user_id !== me) {
|
|
745
|
+
handlers.onSignal({ type: "read", conversationId, userId: String(payload.user_id), seq: Number(payload.seq ?? 0), at: payload.at ? String(payload.at) : null });
|
|
746
|
+
}
|
|
747
|
+
})
|
|
740
748
|
.on("broadcast", { event: "conversation" }, () => handlers.onSignal({ type: "conversation", conversationId }))
|
|
741
749
|
.on("broadcast", { event: "activity" }, ({ payload }) => {
|
|
742
750
|
if (payload?.userId && payload.userId !== me) handlers.onActivity?.({ userId: payload.userId, activity: payload.activity, at: Date.now() });
|
|
@@ -746,6 +754,7 @@ export function createChatClient(supabase: ChatSupabase, options: ChatClientOpti
|
|
|
746
754
|
let joined = false;
|
|
747
755
|
const leave = join(channel, (status) => {
|
|
748
756
|
joined = status === "SUBSCRIBED";
|
|
757
|
+
handlers.onLive?.(joined);
|
|
749
758
|
if (status === "SUBSCRIBED") {
|
|
750
759
|
handlers.onJoin?.();
|
|
751
760
|
if (joinedOnce) handlers.onReconnect?.();
|
package/src/core/types.ts
CHANGED
|
@@ -113,6 +113,11 @@ export interface ChatMember {
|
|
|
113
113
|
userId: string;
|
|
114
114
|
role: ChatRole;
|
|
115
115
|
lastReadSeq: number;
|
|
116
|
+
/**
|
|
117
|
+
* When their read place last moved past someone else's message (migration 0006): a direct
|
|
118
|
+
* conversation's "Read 9:41". Null before they have, or on a database without 0006.
|
|
119
|
+
*/
|
|
120
|
+
lastReadAt?: string | null;
|
|
116
121
|
joinedAt: string;
|
|
117
122
|
}
|
|
118
123
|
|
|
@@ -242,6 +247,8 @@ export type ChatSignal =
|
|
|
242
247
|
| { type: "message"; conversationId: string; id: string; seq?: number; op: "insert" | "update" }
|
|
243
248
|
| { type: "reaction"; conversationId: string; messageId: string }
|
|
244
249
|
| { type: "members"; conversationId: string }
|
|
250
|
+
/** A member's read place moved (migration 0006): carries it, so nothing is fetched. */
|
|
251
|
+
| { type: "read"; conversationId: string; userId: string; seq: number; at: string | null }
|
|
245
252
|
| { type: "conversation"; conversationId: string }
|
|
246
253
|
| { type: "inbox"; conversationId: string; seq?: number };
|
|
247
254
|
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
// @feat:chat
|
|
3
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
4
|
+
import { createElement, type ReactNode } from "react";
|
|
5
|
+
import { Animated, View } from "react-native";
|
|
6
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { GenesisModulesProvider } from "@marktiderman/genesis-ui-native/components";
|
|
8
|
+
import type { ChatMessage, PendingMessage } from "../../core/types";
|
|
9
|
+
import { bubbleCorners, bubblePosition, MessageBubble } from "../message-bubble";
|
|
10
|
+
import { buildThreadRows, type ThreadRow } from "../rows";
|
|
11
|
+
import { ChatTimesProvider, startsTimeReveal, timeRevealFor, TIME_REVEAL_WIDTH } from "../thread-times";
|
|
12
|
+
|
|
13
|
+
vi.mock("react-native", async (original) => ({ ...(await original<object>()), useWindowDimensions: () => ({ width: 390, height: 844, scale: 3, fontScale: 1 }) }));
|
|
14
|
+
|
|
15
|
+
afterEach(cleanup);
|
|
16
|
+
|
|
17
|
+
const ME = "11111111-1111-4111-8111-111111111111";
|
|
18
|
+
const SAM = "22222222-2222-4222-8222-222222222222";
|
|
19
|
+
type MessageRow = Extract<ThreadRow, { type: "message" }>;
|
|
20
|
+
|
|
21
|
+
function message(seq: number, senderId: string): ChatMessage {
|
|
22
|
+
return {
|
|
23
|
+
id: `m${seq}`, conversationId: "conv", seq, clientId: `c${seq}`, senderId, senderRole: "member", kind: "text", body: `body ${seq}`,
|
|
24
|
+
mentions: [], replyToId: null, threadRootId: null, threadCount: 0, threadLastAt: null, topic: null, visibility: "everyone",
|
|
25
|
+
silent: false, meta: {}, createdAt: `2026-10-25T10:0${seq}:00Z`, editedAt: null, deletedAt: null, attachments: [], reactions: [],
|
|
26
|
+
} as unknown as ChatMessage;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const rowsOf = (messages: ChatMessage[]) => buildThreadRows(messages.map((m) => ({ type: "message" as const, message: m })), { me: ME, group: false }).filter((r): r is MessageRow => r.type === "message");
|
|
30
|
+
|
|
31
|
+
describe("bubble shape", () => {
|
|
32
|
+
it("knows its place in a run", () => {
|
|
33
|
+
const run = rowsOf([message(1, SAM), message(2, SAM), message(3, SAM), message(4, ME)]);
|
|
34
|
+
expect(run.map(bubblePosition)).toEqual(["first", "middle", "last", "single"]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("tightens the corners where bubbles of a run meet, on the sender's side, and gives the last one a tail", () => {
|
|
38
|
+
expect(bubbleCorners("first", true)).toMatchObject({ borderTopRightRadius: 18, borderBottomRightRadius: 5, borderTopLeftRadius: 18, borderBottomLeftRadius: 18, tail: false });
|
|
39
|
+
expect(bubbleCorners("middle", true)).toMatchObject({ borderTopRightRadius: 5, borderBottomRightRadius: 5, tail: false });
|
|
40
|
+
expect(bubbleCorners("last", true)).toMatchObject({ borderTopRightRadius: 5, borderBottomRightRadius: 18, tail: true });
|
|
41
|
+
expect(bubbleCorners("middle", false)).toMatchObject({ borderTopLeftRadius: 5, borderBottomLeftRadius: 5, borderTopRightRadius: 18, borderBottomRightRadius: 18 });
|
|
42
|
+
expect(bubbleCorners("single", false).tail).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("draws the tail on the last of a run only, hidden from VoiceOver, and not over a highlighted row", () => {
|
|
46
|
+
const [first, , last] = rowsOf([message(1, SAM), message(2, SAM), message(3, SAM)]);
|
|
47
|
+
render(
|
|
48
|
+
<>
|
|
49
|
+
<MessageBubble row={first!} me={ME} urls={{}} group={false} reducedMotion testID="first" />
|
|
50
|
+
<MessageBubble row={last!} me={ME} urls={{}} group={false} reducedMotion testID="last" />
|
|
51
|
+
<MessageBubble row={last!} me={ME} urls={{}} group={false} reducedMotion highlighted testID="lit" />
|
|
52
|
+
</>,
|
|
53
|
+
);
|
|
54
|
+
expect(screen.queryByTestId("first-tail")).toBeNull();
|
|
55
|
+
expect(screen.getByTestId("last-tail").getAttribute("aria-hidden")).toBe("true");
|
|
56
|
+
expect(screen.queryByTestId("lit-tail")).toBeNull();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("timestamps on demand", () => {
|
|
61
|
+
it("starts on a leftward, mostly sideways drag, and pulls at most the time's width", () => {
|
|
62
|
+
expect(startsTimeReveal(-20, 3)).toBe(true);
|
|
63
|
+
expect(startsTimeReveal(20, 3)).toBe(false);
|
|
64
|
+
expect(startsTimeReveal(-20, 15)).toBe(false);
|
|
65
|
+
expect(timeRevealFor(-30)).toBe(30);
|
|
66
|
+
expect(timeRevealFor(-300)).toBe(TIME_REVEAL_WIDTH);
|
|
67
|
+
expect(timeRevealFor(40)).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("puts every message's time beside it, hidden from VoiceOver (the bubble's label already says it), while the group-end time stays", () => {
|
|
71
|
+
const [first, last] = rowsOf([message(1, SAM), message(2, SAM)]);
|
|
72
|
+
render(
|
|
73
|
+
<ChatTimesProvider value={new Animated.Value(0)}>
|
|
74
|
+
<MessageBubble row={first!} me={ME} urls={{}} group={false} reducedMotion testID="a" />
|
|
75
|
+
<MessageBubble row={last!} me={ME} urls={{}} group={false} reducedMotion testID="b" />
|
|
76
|
+
</ChatTimesProvider>,
|
|
77
|
+
);
|
|
78
|
+
const reveal = screen.getByTestId("a-time-reveal");
|
|
79
|
+
expect(reveal.getAttribute("aria-hidden")).toBe("true");
|
|
80
|
+
expect(reveal.textContent).toMatch(/\d/);
|
|
81
|
+
expect(screen.getByTestId("b-time-reveal")).toBeTruthy();
|
|
82
|
+
expect(screen.getByTestId("a-bubble").getAttribute("aria-label")).toContain(reveal.textContent!);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("swipe to reply on gesture-handler", () => {
|
|
87
|
+
it("uses the app's ReanimatedSwipeable when given: past the threshold it replies, taps, and closes", () => {
|
|
88
|
+
const close = vi.fn();
|
|
89
|
+
const seen: Record<string, unknown>[] = [];
|
|
90
|
+
function Swipeable(props: Record<string, unknown> & { children?: ReactNode; ref?: unknown }) {
|
|
91
|
+
seen.push(props);
|
|
92
|
+
const ref = props.ref as { current: unknown } | undefined;
|
|
93
|
+
if (ref) ref.current = { close };
|
|
94
|
+
return createElement(View, { testID: props.testID as string }, props.children as ReactNode);
|
|
95
|
+
}
|
|
96
|
+
const onReply = vi.fn();
|
|
97
|
+
const onSwipeReply = vi.fn();
|
|
98
|
+
const [row] = rowsOf([message(1, SAM)]);
|
|
99
|
+
render(
|
|
100
|
+
<GenesisModulesProvider modules={{ swipeable: Swipeable as never }}>
|
|
101
|
+
<MessageBubble row={row!} me={ME} urls={{}} group={false} reducedMotion onReply={onReply} onSwipeReply={onSwipeReply} testID="s" />
|
|
102
|
+
</GenesisModulesProvider>,
|
|
103
|
+
);
|
|
104
|
+
expect(screen.getByTestId("s-swipe")).toBeTruthy();
|
|
105
|
+
const props = seen.at(-1)!;
|
|
106
|
+
expect(props.leftThreshold).toBe(56);
|
|
107
|
+
// Leftward drags stay the thread's (the times).
|
|
108
|
+
expect(props.dragOffsetFromRightEdge).toBeGreaterThan(1000);
|
|
109
|
+
(props.onSwipeableWillOpen as () => void)();
|
|
110
|
+
expect(onReply).toHaveBeenCalledWith(expect.objectContaining({ id: "m1" }));
|
|
111
|
+
expect(onSwipeReply).toHaveBeenCalled();
|
|
112
|
+
expect(close).toHaveBeenCalled();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("the send animation", () => {
|
|
117
|
+
function pendingRow(createdAt: string): MessageRow {
|
|
118
|
+
const pending: PendingMessage = { clientId: "p1", input: { conversationId: "conv", clientId: "p1", body: "hi" }, senderId: ME, createdAt, status: "sending" };
|
|
119
|
+
return buildThreadRows([{ type: "pending", pending }], { me: ME, group: false }).find((r): r is MessageRow => r.type === "message")!;
|
|
120
|
+
}
|
|
121
|
+
function reanimated() {
|
|
122
|
+
const entered: unknown[] = [];
|
|
123
|
+
const animation = { duration: vi.fn(() => animation), reduceMotion: vi.fn(() => animation) };
|
|
124
|
+
function AnimatedView(props: Record<string, unknown> & { children?: ReactNode }) {
|
|
125
|
+
entered.push(props.entering);
|
|
126
|
+
const { entering: _e, ...rest } = props;
|
|
127
|
+
return createElement(View, rest, props.children);
|
|
128
|
+
}
|
|
129
|
+
return { module: { default: { View: AnimatedView }, FadeInDown: animation, ReduceMotion: { System: "system", Always: "always", Never: "never" } }, entered, animation };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
it("raises a message you just sent from the composer, with Reanimated's own Reduce Motion check", () => {
|
|
133
|
+
const r = reanimated();
|
|
134
|
+
render(
|
|
135
|
+
<GenesisModulesProvider modules={{ reanimated: r.module as never }}>
|
|
136
|
+
<MessageBubble row={pendingRow(new Date().toISOString())} me={ME} urls={{}} group={false} reducedMotion={false} testID="p" />
|
|
137
|
+
</GenesisModulesProvider>,
|
|
138
|
+
);
|
|
139
|
+
expect(r.entered[0]).toBe(r.animation);
|
|
140
|
+
expect(r.animation.reduceMotion).toHaveBeenCalledWith("system");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("doesn't animate with Reduce Motion, nor an old pending message (a relaunch's outbox)", () => {
|
|
144
|
+
const r = reanimated();
|
|
145
|
+
render(
|
|
146
|
+
<GenesisModulesProvider modules={{ reanimated: r.module as never }}>
|
|
147
|
+
<MessageBubble row={pendingRow(new Date().toISOString())} me={ME} urls={{}} group={false} reducedMotion testID="p" />
|
|
148
|
+
<MessageBubble row={pendingRow("2026-10-25T10:00:00Z")} me={ME} urls={{}} group={false} reducedMotion={false} testID="q" />
|
|
149
|
+
</GenesisModulesProvider>,
|
|
150
|
+
);
|
|
151
|
+
expect(r.entered.every((e) => e === undefined)).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
});
|