@marktiderman/genesis-chat 0.11.4 → 0.13.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 +162 -4
- package/dist/{chunk-ZQFREERR.js → chunk-3UNYTK62.js} +3 -3
- package/dist/{chunk-ZQFREERR.js.map → chunk-3UNYTK62.js.map} +1 -1
- package/dist/{chunk-5XYDVUPS.js → chunk-GEEJMKQF.js} +29 -4
- package/dist/chunk-GEEJMKQF.js.map +1 -0
- package/dist/{chunk-D4RPOYB7.js → chunk-H4BRVJJ7.js} +193 -30
- package/dist/chunk-H4BRVJJ7.js.map +1 -0
- package/dist/{chunk-O2QSBRSH.js → chunk-SEMN3S6Q.js} +3 -3
- package/dist/{chunk-O2QSBRSH.js.map → chunk-SEMN3S6Q.js.map} +1 -1
- package/dist/{client-DP7rhJ1U.d.ts → client-DXWyDJ2u.d.ts} +29 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/native.d.ts +355 -145
- package/dist/native.js +701 -217
- package/dist/native.js.map +1 -1
- package/dist/{outbox-C4LnqpKT.d.ts → outbox-Ctngv6Yz.d.ts} +1 -1
- package/dist/push.d.ts +2 -2
- package/dist/react.d.ts +83 -6
- 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-mZsRiIGz.d.ts} +1 -1
- package/dist/web.d.ts +24 -7
- package/dist/web.js +140 -67
- package/dist/web.js.map +1 -1
- package/migrations/0006_genesis_chat_read_receipts.sql +110 -0
- package/migrations/0007_genesis_chat_unread_and_delete_for_me.sql +455 -0
- package/migrations/tests/0006_genesis_chat_read_receipts.test.sql +131 -0
- package/migrations/tests/0007_genesis_chat_unread_and_delete_for_me.test.sql +178 -0
- package/package.json +17 -9
- package/src/__tests__/inbox-row-actions.test.tsx +251 -0
- package/src/__tests__/unread-delete-for-me.test.ts +84 -0
- package/src/__tests__/web.test.tsx +5 -2
- package/src/core/client.ts +30 -1
- 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__/inbox-screen-actions.test.tsx +131 -0
- package/src/native/__tests__/inbox-screen.test.tsx +29 -1
- 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-layout.test.ts +2 -2
- 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 +47 -10
- package/src/native/emoji-picker.tsx +1 -1
- package/src/native/inbox-screen.tsx +52 -27
- package/src/native/index.ts +7 -2
- 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/inbox-actions.ts +121 -0
- package/src/react/index.tsx +172 -23
- package/src/web/inbox.tsx +120 -11
- package/src/web/index.ts +1 -1
- package/src/web/memory-client.ts +40 -7
- package/dist/chunk-5XYDVUPS.js.map +0 -1
- package/dist/chunk-D4RPOYB7.js.map +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** @feat:chat */
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { createChatClient, type ChatSupabase } from "../core/client";
|
|
4
|
+
import { createMemoryChatClient } from "../web/memory-client";
|
|
5
|
+
|
|
6
|
+
/** A supabase-js stand-in that records every rpc. */
|
|
7
|
+
function fakeSupabase() {
|
|
8
|
+
const calls: { name: string; args: unknown }[] = [];
|
|
9
|
+
const supabase = {
|
|
10
|
+
schema: () => ({
|
|
11
|
+
rpc: async (name: string, args: unknown) => {
|
|
12
|
+
calls.push({ name, args });
|
|
13
|
+
return { data: null, error: null };
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
} as unknown as ChatSupabase;
|
|
17
|
+
return { supabase, calls };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("Mark as Unread and Delete for me (0007) on the core client", () => {
|
|
21
|
+
it("sends the place you saw when you give one, and nothing extra when you don't", async () => {
|
|
22
|
+
const { supabase, calls } = fakeSupabase();
|
|
23
|
+
const chat = createChatClient(supabase);
|
|
24
|
+
await chat.deleteConversationForMe("c", 7);
|
|
25
|
+
await chat.deleteConversationForMe("c");
|
|
26
|
+
expect(calls).toEqual([
|
|
27
|
+
{ name: "delete_conversation_for_me", args: { p_conversation_id: "c", p_seq: 7 } },
|
|
28
|
+
{ name: "delete_conversation_for_me", args: { p_conversation_id: "c" } },
|
|
29
|
+
]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("sends markedUnread only when given, and clears a mute with mutedUntil: null", async () => {
|
|
33
|
+
const { supabase, calls } = fakeSupabase();
|
|
34
|
+
const chat = createChatClient(supabase);
|
|
35
|
+
await chat.setMySettings("c", { markedUnread: true });
|
|
36
|
+
await chat.setMySettings("c", { mutedUntil: null });
|
|
37
|
+
expect(calls[0]!.args).toMatchObject({ p_conversation_id: "c", p_marked_unread: true });
|
|
38
|
+
expect(calls[1]!.args).toMatchObject({ p_clear_mute: true });
|
|
39
|
+
expect(calls[1]!.args).not.toHaveProperty("p_marked_unread");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("Delete for me on the memory client, as the database does it", () => {
|
|
44
|
+
const ME = "me";
|
|
45
|
+
const LEE = "lee";
|
|
46
|
+
const make = () =>
|
|
47
|
+
createMemoryChatClient({
|
|
48
|
+
me: ME,
|
|
49
|
+
conversations: [
|
|
50
|
+
{
|
|
51
|
+
id: "c1",
|
|
52
|
+
members: [{ userId: ME, lastReadSeq: 2 }, { userId: LEE }],
|
|
53
|
+
messages: [
|
|
54
|
+
{ id: "m1", seq: 1, senderId: LEE, body: "hi" },
|
|
55
|
+
{ id: "m2", seq: 2, senderId: LEE, body: "how are you?" },
|
|
56
|
+
],
|
|
57
|
+
pins: ["m1"],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("leaves the inbox and the pins until a message you can read arrives", async () => {
|
|
63
|
+
const chat = make();
|
|
64
|
+
await chat.deleteConversationForMe("c1");
|
|
65
|
+
expect(await chat.inbox()).toHaveLength(0);
|
|
66
|
+
expect(await chat.pins("c1")).toEqual([]);
|
|
67
|
+
chat.receive("c1", LEE, "a reply in the old thread", { threadRootId: "m1" });
|
|
68
|
+
expect(await chat.inbox()).toHaveLength(0);
|
|
69
|
+
chat.receive("c1", LEE, "are you there?");
|
|
70
|
+
const inbox = await chat.inbox();
|
|
71
|
+
expect(inbox).toHaveLength(1);
|
|
72
|
+
expect(inbox[0]!.unread).toBe(1);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("keeps a message that came in after what you saw", async () => {
|
|
76
|
+
const chat = make();
|
|
77
|
+
chat.receive("c1", LEE, "sent while you looked");
|
|
78
|
+
await chat.deleteConversationForMe("c1", 2);
|
|
79
|
+
expect(await chat.inbox()).toHaveLength(1);
|
|
80
|
+
expect((await chat.messages("c1")).messages.map((m) => m.body)).toEqual(["sent while you looked"]);
|
|
81
|
+
await chat.deleteConversationForMe("c1", 1);
|
|
82
|
+
expect((await chat.messages("c1")).messages).toHaveLength(1);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -387,10 +387,13 @@ describe("ChatInbox", () => {
|
|
|
387
387
|
expect(row.textContent).toContain("Sam");
|
|
388
388
|
expect(row.textContent).toContain("You: See you soon");
|
|
389
389
|
expect(row.getAttribute("aria-current")).toBe("true");
|
|
390
|
-
expect(row.getAttribute("aria-label")).toMatch(/
|
|
390
|
+
expect(row.getAttribute("aria-label")).toMatch(/Sam, Pinned, /);
|
|
391
|
+
expect(screen.getByTestId("genesis-chat-inbox-row-d1-pinned")).toBeTruthy();
|
|
391
392
|
const groupRow = screen.getByTestId("genesis-chat-inbox-row-c1");
|
|
392
393
|
expect(groupRow.textContent).toContain("Morning crew");
|
|
393
|
-
expect(groupRow.getAttribute("aria-label")).toMatch(/2 unread.*
|
|
394
|
+
expect(groupRow.getAttribute("aria-label")).toMatch(/2 unread.*Alerts off/);
|
|
395
|
+
// Beside the time, as on the phone, not on the preview line.
|
|
396
|
+
expect(screen.getByTestId("genesis-chat-inbox-row-c1-muted").nextElementSibling?.textContent).toMatch(/\d/);
|
|
394
397
|
fireEvent.click(groupRow);
|
|
395
398
|
expect(picked).toEqual(["c1"]);
|
|
396
399
|
row.focus();
|
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
|
},
|
|
@@ -477,9 +480,15 @@ export function createChatClient(supabase: ChatSupabase, options: ChatClientOpti
|
|
|
477
480
|
return rpc<number>("mark_read", { p_conversation_id: conversationId, p_seq: seq ?? null });
|
|
478
481
|
},
|
|
479
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Your own settings for a conversation. `markedUnread` (migration 0007) marks it unread for you
|
|
485
|
+
* only, as Messages' Mark as Unread: it counts as one unread until you read it, and your read
|
|
486
|
+
* place (what senders see as "Read") never moves back. It's sent only when given, so an app
|
|
487
|
+
* whose database predates 0007 keeps working.
|
|
488
|
+
*/
|
|
480
489
|
async setMySettings(
|
|
481
490
|
conversationId: string,
|
|
482
|
-
s: { mutedUntil?: string | null; notify?: "all" | "mentions" | "none"; archived?: boolean; pinned?: boolean },
|
|
491
|
+
s: { mutedUntil?: string | null; notify?: "all" | "mentions" | "none"; archived?: boolean; pinned?: boolean; markedUnread?: boolean },
|
|
483
492
|
) {
|
|
484
493
|
await rpc("set_my_settings", {
|
|
485
494
|
p_conversation_id: conversationId,
|
|
@@ -488,6 +497,20 @@ export function createChatClient(supabase: ChatSupabase, options: ChatClientOpti
|
|
|
488
497
|
p_archived: s.archived ?? null,
|
|
489
498
|
p_pinned: s.pinned ?? null,
|
|
490
499
|
p_clear_mute: s.mutedUntil === null,
|
|
500
|
+
...(s.markedUnread === undefined ? {} : { p_marked_unread: s.markedUnread }),
|
|
501
|
+
});
|
|
502
|
+
},
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Delete for me (migration 0007): the conversation leaves your inbox, and its history your
|
|
506
|
+
* thread, until a new message you can read arrives. Nobody else's inbox, thread or read
|
|
507
|
+
* receipts change. `seq` is the latest message you saw (the inbox row's `lastSeq`): a message
|
|
508
|
+
* that came in after it isn't deleted unseen. Without it, everything up to the latest goes.
|
|
509
|
+
*/
|
|
510
|
+
async deleteConversationForMe(conversationId: string, seq?: number) {
|
|
511
|
+
await rpc("delete_conversation_for_me", {
|
|
512
|
+
p_conversation_id: conversationId,
|
|
513
|
+
...(seq === undefined ? {} : { p_seq: seq }),
|
|
491
514
|
});
|
|
492
515
|
},
|
|
493
516
|
|
|
@@ -737,6 +760,11 @@ export function createChatClient(supabase: ChatSupabase, options: ChatClientOpti
|
|
|
737
760
|
handlers.onSignal({ type: "reaction", conversationId, messageId: String(payload?.message_id) }),
|
|
738
761
|
)
|
|
739
762
|
.on("broadcast", { event: "members" }, () => handlers.onSignal({ type: "members", conversationId }))
|
|
763
|
+
.on("broadcast", { event: "read" }, ({ payload }) => {
|
|
764
|
+
if (payload?.user_id && payload.user_id !== me) {
|
|
765
|
+
handlers.onSignal({ type: "read", conversationId, userId: String(payload.user_id), seq: Number(payload.seq ?? 0), at: payload.at ? String(payload.at) : null });
|
|
766
|
+
}
|
|
767
|
+
})
|
|
740
768
|
.on("broadcast", { event: "conversation" }, () => handlers.onSignal({ type: "conversation", conversationId }))
|
|
741
769
|
.on("broadcast", { event: "activity" }, ({ payload }) => {
|
|
742
770
|
if (payload?.userId && payload.userId !== me) handlers.onActivity?.({ userId: payload.userId, activity: payload.activity, at: Date.now() });
|
|
@@ -746,6 +774,7 @@ export function createChatClient(supabase: ChatSupabase, options: ChatClientOpti
|
|
|
746
774
|
let joined = false;
|
|
747
775
|
const leave = join(channel, (status) => {
|
|
748
776
|
joined = status === "SUBSCRIBED";
|
|
777
|
+
handlers.onLive?.(joined);
|
|
749
778
|
if (status === "SUBSCRIBED") {
|
|
750
779
|
handlers.onJoin?.();
|
|
751
780
|
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
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
// @feat:chat
|
|
3
|
+
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { ChatComposer, micOffset } from "../composer";
|
|
6
|
+
import { ChatNativeProvider } from "../context";
|
|
7
|
+
import type { ChatNativeModules } from "../modules";
|
|
8
|
+
import { useChatComposer } from "../use-composer";
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
cleanup();
|
|
12
|
+
vi.useRealTimers();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function Harness() {
|
|
16
|
+
const composer = useChatComposer("c1", null, "u1");
|
|
17
|
+
return <ChatComposer composer={composer} canPost disabledReason={null} role="member" onSend={vi.fn()} testID="cmp" />;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("the composer's + button", () => {
|
|
21
|
+
it("opens a menu that fits its actions, and the picker opens as soon as the menu has gone, with no fixed wait", async () => {
|
|
22
|
+
vi.useFakeTimers();
|
|
23
|
+
const launchImageLibraryAsync = vi.fn(async () => ({ canceled: true, assets: null }));
|
|
24
|
+
const launchCameraAsync = vi.fn(async () => ({ canceled: true, assets: null }));
|
|
25
|
+
render(
|
|
26
|
+
<ChatNativeProvider modules={{ imagePicker: { launchImageLibraryAsync, launchCameraAsync } } as unknown as ChatNativeModules}>
|
|
27
|
+
<Harness />
|
|
28
|
+
</ChatNativeProvider>,
|
|
29
|
+
);
|
|
30
|
+
await act(async () => fireEvent.click(screen.getByTestId("cmp-attach")));
|
|
31
|
+
await act(async () => void (await vi.advanceTimersByTimeAsync(0)));
|
|
32
|
+
expect(screen.getByTestId("cmp-attach-sheet-action-library")).toBeTruthy();
|
|
33
|
+
expect(screen.getByTestId("cmp-attach-sheet-action-camera")).toBeTruthy();
|
|
34
|
+
expect(screen.getByTestId("cmp-attach-sheet-cancel")).toBeTruthy();
|
|
35
|
+
await act(async () => fireEvent.click(screen.getByTestId("cmp-attach-sheet-action-library")));
|
|
36
|
+
await act(async () => void (await vi.advanceTimersByTimeAsync(10)));
|
|
37
|
+
expect(launchImageLibraryAsync).toHaveBeenCalledTimes(1);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("the mic while held", () => {
|
|
42
|
+
it("follows the finger left toward cancel and up toward the lock, within bounds, never right or down", () => {
|
|
43
|
+
expect(micOffset(-40, -20)).toEqual({ x: -40, y: -20 });
|
|
44
|
+
expect(micOffset(30, 25)).toEqual({ x: 0, y: 0 });
|
|
45
|
+
expect(micOffset(-500, -500)).toEqual({ x: -120, y: -72 });
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
// @feat:chat
|
|
3
|
+
// The inbox row's actions, as Messages has them: Unread (or Read) and Pin to the right, Hide Alerts
|
|
4
|
+
// and Delete to the left, Archive in the menu only. Delete asks first, then deletes for you only.
|
|
5
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
6
|
+
import { cleanup, render, waitFor } from "@testing-library/react";
|
|
7
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
8
|
+
import type { InboxItem } from "@marktiderman/genesis-ui-native/layouts";
|
|
9
|
+
import type { ChatClient } from "../../core/client";
|
|
10
|
+
import { ChatProvider } from "../../react/index";
|
|
11
|
+
import { ChatNativeProvider } from "../context";
|
|
12
|
+
|
|
13
|
+
const seen: { items: InboxItem[] } = { items: [] };
|
|
14
|
+
vi.mock("@marktiderman/genesis-ui-native/layouts", () => ({
|
|
15
|
+
InboxPage: (props: { items: InboxItem[] }) => {
|
|
16
|
+
seen.items = props.items;
|
|
17
|
+
return null;
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
const alerts: { title: string; body?: string; buttons: { text: string; onPress?: () => void }[] }[] = [];
|
|
21
|
+
vi.mock("react-native", async (original) => ({
|
|
22
|
+
...(await original<object>()),
|
|
23
|
+
Alert: {
|
|
24
|
+
alert: (title: string, body?: string, buttons: { text: string; onPress?: () => void }[] = []) => alerts.push({ title, body, buttons }),
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line import/first
|
|
29
|
+
import { ChatInboxScreen } from "../inbox-screen";
|
|
30
|
+
|
|
31
|
+
afterEach(cleanup);
|
|
32
|
+
|
|
33
|
+
const ME = "11111111-1111-4111-8111-111111111111";
|
|
34
|
+
const C = "22222222-2222-4222-8222-222222222222";
|
|
35
|
+
|
|
36
|
+
function row(unread: number, muted = false) {
|
|
37
|
+
return {
|
|
38
|
+
conversationId: C, kind: "direct", title: "Sam", subjectType: null, subjectId: null, status: null, role: "member",
|
|
39
|
+
otherUserId: null, memberCount: 2, lastSeq: 3, lastReadSeq: 3 - unread, unread, mentioned: false, muted, pinned: false,
|
|
40
|
+
archived: false, lastMessageAt: new Date().toISOString(), lastMessage: null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function renderWith(item: ReturnType<typeof row>, over: Record<string, unknown> = {}) {
|
|
45
|
+
const client = {
|
|
46
|
+
inbox: vi.fn(async () => [item]),
|
|
47
|
+
subscribeInbox: vi.fn(() => ({ unsubscribe: vi.fn() })),
|
|
48
|
+
unreadTotal: vi.fn(async () => 0),
|
|
49
|
+
markRead: vi.fn(async () => 3),
|
|
50
|
+
setMySettings: vi.fn(async () => {}),
|
|
51
|
+
deleteConversationForMe: vi.fn(async () => {}),
|
|
52
|
+
...over,
|
|
53
|
+
} as unknown as ChatClient & Record<string, ReturnType<typeof vi.fn>>;
|
|
54
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
55
|
+
// A thread this device opened before: Delete for me must not leave its history cached.
|
|
56
|
+
qc.setQueryData(["genesis-chat", "conversation", C, "messages", null, null], { pages: [{ messages: [{ id: "old" }] }] });
|
|
57
|
+
qc.setQueryData(["genesis-chat", "pins", C], ["old"]);
|
|
58
|
+
render(
|
|
59
|
+
<QueryClientProvider client={qc}>
|
|
60
|
+
<ChatProvider client={client} userId={ME}>
|
|
61
|
+
<ChatNativeProvider>
|
|
62
|
+
<ChatInboxScreen onOpen={() => {}} />
|
|
63
|
+
</ChatNativeProvider>
|
|
64
|
+
</ChatProvider>
|
|
65
|
+
</QueryClientProvider>,
|
|
66
|
+
);
|
|
67
|
+
await waitFor(() => expect(seen.items.length).toBe(1));
|
|
68
|
+
const actions = seen.items[0]!.swipeActions ?? [];
|
|
69
|
+
return { client, qc, actions, byId: (id: string) => actions.find((a) => a.id === id)! };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe("ChatInboxScreen's row actions", () => {
|
|
73
|
+
it("are Messages': Unread and Pin leading, Hide Alerts and Delete trailing, Archive in the menu only", async () => {
|
|
74
|
+
const { actions, byId } = await renderWith(row(0));
|
|
75
|
+
expect(actions.map((a) => a.id)).toEqual(["unread", "pin", "alerts", "delete", "archive"]);
|
|
76
|
+
expect(byId("unread")).toMatchObject({ swipe: { side: "leading", full: true }, tone: "info", icon: "message-unread" });
|
|
77
|
+
expect(byId("pin")).toMatchObject({ swipe: { side: "leading" }, accent: "orange" });
|
|
78
|
+
expect(byId("alerts")).toMatchObject({ swipe: { side: "trailing" }, accent: "purple", icon: "bell-off", label: "Hide Alerts" });
|
|
79
|
+
expect(byId("delete")).toMatchObject({ swipe: { side: "trailing", full: true }, destructive: true, confirms: true });
|
|
80
|
+
expect(byId("archive")).toMatchObject({ swipe: false });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("Mark as Unread sets the mark for you; an unread row offers Read instead", async () => {
|
|
84
|
+
const first = await renderWith(row(0));
|
|
85
|
+
first.byId("unread").onPress();
|
|
86
|
+
await waitFor(() => expect(first.client.setMySettings).toHaveBeenCalledWith(C, { markedUnread: true }));
|
|
87
|
+
cleanup();
|
|
88
|
+
const second = await renderWith(row(2));
|
|
89
|
+
expect(second.actions.map((a) => a.id)).toContain("read");
|
|
90
|
+
second.byId("read").onPress();
|
|
91
|
+
await waitFor(() => expect(second.client.markRead).toHaveBeenCalledWith(C));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("Delete asks first, then deletes for you only, up to the last message the row showed", async () => {
|
|
95
|
+
const { client, qc, byId } = await renderWith(row(0));
|
|
96
|
+
byId("delete").onPress();
|
|
97
|
+
expect(client.deleteConversationForMe).not.toHaveBeenCalled();
|
|
98
|
+
expect(alerts.at(-1)!.body).toMatch(/removed for you/);
|
|
99
|
+
const confirm = alerts.at(-1)!.buttons.find((b) => b.text === "Delete")!;
|
|
100
|
+
confirm.onPress!();
|
|
101
|
+
await waitFor(() => expect(client.deleteConversationForMe).toHaveBeenCalledWith(C, 3));
|
|
102
|
+
// The thread this device had cached is gone, so a new message can't bring the history back here.
|
|
103
|
+
await waitFor(() => expect(qc.getQueryData(["genesis-chat", "conversation", C, "messages", null, null])).toBeUndefined());
|
|
104
|
+
expect(qc.getQueryData(["genesis-chat", "pins", C])).toBeUndefined();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("says so when an action fails, instead of doing nothing", async () => {
|
|
108
|
+
const failing = await renderWith(row(0), {
|
|
109
|
+
setMySettings: vi.fn(async () => {
|
|
110
|
+
throw new Error("You aren't in this conversation");
|
|
111
|
+
}),
|
|
112
|
+
deleteConversationForMe: vi.fn(async () => {
|
|
113
|
+
throw new Error("Offline");
|
|
114
|
+
}),
|
|
115
|
+
});
|
|
116
|
+
failing.byId("unread").onPress();
|
|
117
|
+
await waitFor(() => expect(alerts.at(-1)).toMatchObject({ title: "That didn't work", body: "You aren't in this conversation" }));
|
|
118
|
+
failing.byId("delete").onPress();
|
|
119
|
+
alerts.at(-1)!.buttons.find((b) => b.text === "Delete")!.onPress!();
|
|
120
|
+
await waitFor(() => expect(alerts.at(-1)).toMatchObject({ title: "That didn't work", body: "Offline" }));
|
|
121
|
+
// A failed delete leaves the cached thread alone.
|
|
122
|
+
expect(failing.qc.getQueryData(["genesis-chat", "pins", C])).toEqual(["old"]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("a muted row offers Show Alerts, which clears the mute", async () => {
|
|
126
|
+
const { client, byId } = await renderWith(row(0, true));
|
|
127
|
+
expect(byId("alerts")).toMatchObject({ label: "Show Alerts", icon: "bell" });
|
|
128
|
+
byId("alerts").onPress();
|
|
129
|
+
await waitFor(() => expect(client.setMySettings).toHaveBeenCalledWith(C, { mutedUntil: null }));
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -7,7 +7,9 @@ import { GenesisModulesProvider, NativeToastProvider } from "@marktiderman/genes
|
|
|
7
7
|
import type { ChatClient } from "../../core/client";
|
|
8
8
|
import { ChatProvider } from "../../react/index";
|
|
9
9
|
import { ChatNativeProvider } from "../context";
|
|
10
|
-
import { ChatInboxScreen } from "../inbox-screen";
|
|
10
|
+
import { ChatInboxScreen, inboxRow } from "../inbox-screen";
|
|
11
|
+
import { chatNativeCopy } from "../copy";
|
|
12
|
+
import type { ChatInboxItem } from "../../core/types";
|
|
11
13
|
|
|
12
14
|
vi.mock("react-native", async (original) => ({ ...(await original<object>()), useWindowDimensions: () => ({ width: 390, height: 844, scale: 3, fontScale: 1 }) }));
|
|
13
15
|
|
|
@@ -45,4 +47,30 @@ describe("ChatInboxScreen", () => {
|
|
|
45
47
|
await waitFor(() => expect(inbox).toHaveBeenCalled());
|
|
46
48
|
expect(inbox.mock.calls[0]![0]).toMatchObject({ kinds: ["direct", "group"], excludeKinds: ["support"] });
|
|
47
49
|
});
|
|
50
|
+
|
|
51
|
+
it("carries a conversation's muted and pinned onto its row, for the bell-slash and the pin", () => {
|
|
52
|
+
const item: ChatInboxItem = {
|
|
53
|
+
conversationId: "c",
|
|
54
|
+
kind: "direct",
|
|
55
|
+
title: "Ben",
|
|
56
|
+
subjectType: null,
|
|
57
|
+
subjectId: null,
|
|
58
|
+
status: "open",
|
|
59
|
+
role: "member",
|
|
60
|
+
otherUserId: null,
|
|
61
|
+
memberCount: 2,
|
|
62
|
+
lastSeq: 1,
|
|
63
|
+
lastReadSeq: 0,
|
|
64
|
+
unread: 1,
|
|
65
|
+
mentioned: false,
|
|
66
|
+
muted: true,
|
|
67
|
+
pinned: true,
|
|
68
|
+
archived: false,
|
|
69
|
+
lastMessageAt: null,
|
|
70
|
+
lastMessage: null,
|
|
71
|
+
};
|
|
72
|
+
const ctx = { me: ME, copy: chatNativeCopy, person: () => undefined };
|
|
73
|
+
expect(inboxRow(item, ctx)).toMatchObject({ muted: true, pinned: true });
|
|
74
|
+
expect(inboxRow({ ...item, muted: false, pinned: false }, ctx)).toMatchObject({ muted: false, pinned: false });
|
|
75
|
+
});
|
|
48
76
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
// @feat:chat
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import type { ChatAttachment } from "../../core/types";
|
|
5
|
+
import { fromServer } from "../media";
|
|
6
|
+
|
|
7
|
+
const photo = { id: "a1", kind: "image", provider: "storage", path: "conv/1/photo.jpg", url: null, name: "photo.jpg" } as unknown as ChatAttachment;
|
|
8
|
+
|
|
9
|
+
describe("a photo's cache key", () => {
|
|
10
|
+
it("is its storage path, so a re-signed link hits expo-image's disk cache instead of downloading again", () => {
|
|
11
|
+
const first = fromServer(photo, { "conv/1/photo.jpg": "https://x/photo.jpg?token=1" });
|
|
12
|
+
const resigned = fromServer(photo, { "conv/1/photo.jpg": "https://x/photo.jpg?token=2" });
|
|
13
|
+
expect(first.uri).not.toBe(resigned.uri);
|
|
14
|
+
expect(first.cacheKey).toBe("conv/1/photo.jpg");
|
|
15
|
+
expect(resigned.cacheKey).toBe(first.cacheKey);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("is left to the URL for a file that isn't in storage", () => {
|
|
19
|
+
expect(fromServer({ ...photo, provider: "mux", path: null, url: "https://x/v.jpg" } as unknown as ChatAttachment, {}).cacheKey).toBeNull();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -143,6 +143,8 @@ describe("ChatThreadScreen scheduled send", () => {
|
|
|
143
143
|
fireEvent.click(await screen.findByTestId("t-scheduled"));
|
|
144
144
|
expect(screen.getByTestId("t-scheduled").getAttribute("aria-label")).toBe("1 scheduled message");
|
|
145
145
|
const list = await screen.findByTestId("t-scheduled-sheet");
|
|
146
|
+
// In a scroll view: past the sheet's 90% cap the later ones (and their Cancel) are still reachable.
|
|
147
|
+
expect(within(screen.getByTestId("t-scheduled-scroll")).getByTestId("t-scheduled-list")).toBeTruthy();
|
|
146
148
|
const cancel = within(list).getByText("Cancel");
|
|
147
149
|
fireEvent.click(cancel.closest("button")!);
|
|
148
150
|
await waitFor(() => expect(called(client, "cancelScheduled")).toHaveLength(1));
|