@marktiderman/genesis-chat 0.9.0 → 0.10.1
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 +3 -1
- package/dist/native.js +75 -73
- package/dist/native.js.map +1 -1
- package/dist/web.d.ts +7 -3
- package/dist/web.js +277 -273
- 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 +65 -1
- package/src/native/composer.tsx +53 -79
- package/src/native/context.tsx +9 -2
- package/src/native/message-bubble.tsx +2 -2
- package/src/native/modules.ts +13 -18
- package/src/native/organise-copy.ts +3 -0
- package/src/native/thread-screen.tsx +17 -2
- package/src/web/attachments.tsx +16 -3
- package/src/web/bubble.tsx +5 -3
- package/src/web/cards.tsx +1 -1
- package/src/web/composer.tsx +3 -5
- package/src/web/dock.tsx +3 -3
- package/src/web/inbox.tsx +82 -90
- package/src/web/markdown.tsx +3 -3
- package/src/web/thread.tsx +250 -261
- package/src/web/voice-note.tsx +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
// @feat:chat
|
|
3
3
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
4
|
-
import { act, cleanup, render, screen, waitFor } from "@testing-library/react";
|
|
4
|
+
import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
5
5
|
import { forwardRef, useImperativeHandle, type ReactNode } from "react";
|
|
6
6
|
import { AccessibilityInfo } from "react-native";
|
|
7
7
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
@@ -9,6 +9,7 @@ import { GenesisModulesProvider, NativeToastProvider } from "@marktiderman/genes
|
|
|
9
9
|
import type { ChatClient } from "../../core/client";
|
|
10
10
|
import type { ChatMessage } from "../../core/types";
|
|
11
11
|
import { ChatProvider } from "../../react/index";
|
|
12
|
+
import { chatNativeCopy } from "../copy";
|
|
12
13
|
import { ChatNativeProvider } from "../context";
|
|
13
14
|
import type { ThreadRow } from "../rows";
|
|
14
15
|
import { nearBottom, ChatThreadScreen, threadListMode } from "../thread-screen";
|
|
@@ -138,6 +139,69 @@ describe("ChatThreadScreen's jump to a message", () => {
|
|
|
138
139
|
});
|
|
139
140
|
});
|
|
140
141
|
|
|
142
|
+
describe("ChatThreadScreen's jump when it can't load back", () => {
|
|
143
|
+
it("says the load failed, not that the message is gone", async () => {
|
|
144
|
+
const list = scrollingList();
|
|
145
|
+
const client = fakeClient([msg(5, SAM, "2026-10-24T10:00:00Z")], 5);
|
|
146
|
+
(client.messages as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ messages: [msg(5, SAM, "2026-10-24T10:00:00Z")], hasEarlier: true }).mockRejectedValue(new Error("offline"));
|
|
147
|
+
render(wrap(client, list.List, <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2", seq: 2 }} />));
|
|
148
|
+
expect(await screen.findByText(chatNativeCopy.actionFailed, {}, { timeout: 2000 })).toBeTruthy();
|
|
149
|
+
await act(async () => void (await new Promise((r) => setTimeout(r, 600))));
|
|
150
|
+
expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("with a deep link and a first page that failed: says the read failed, never gone, and goes there once rows come", async () => {
|
|
154
|
+
const list = scrollingList();
|
|
155
|
+
const client = fakeClient([msg(1, SAM, "2026-10-24T10:00:00Z"), msg(2, ME, "2026-10-24T10:01:00Z")], 3);
|
|
156
|
+
(client.messages as ReturnType<typeof vi.fn>).mockRejectedValueOnce(new Error("offline"));
|
|
157
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
158
|
+
render(
|
|
159
|
+
<QueryClientProvider client={qc}>
|
|
160
|
+
<GenesisModulesProvider modules={{ list: list.List as never }}>
|
|
161
|
+
<ChatProvider client={client} userId={ME}>
|
|
162
|
+
<NativeToastProvider>
|
|
163
|
+
<ChatNativeProvider>
|
|
164
|
+
<ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2" }} />
|
|
165
|
+
</ChatNativeProvider>
|
|
166
|
+
</NativeToastProvider>
|
|
167
|
+
</ChatProvider>
|
|
168
|
+
</GenesisModulesProvider>
|
|
169
|
+
</QueryClientProvider>,
|
|
170
|
+
);
|
|
171
|
+
expect(await screen.findByText(chatNativeCopy.actionFailed, {}, { timeout: 2000 })).toBeTruthy();
|
|
172
|
+
await act(async () => void (await new Promise((r) => setTimeout(r, 600))));
|
|
173
|
+
expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
|
|
174
|
+
expect(list.scrollToIndex).not.toHaveBeenCalled();
|
|
175
|
+
await act(async () => void (await qc.refetchQueries()));
|
|
176
|
+
await waitFor(() => expect(list.scrollToIndex).toHaveBeenCalled());
|
|
177
|
+
expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("keeps a deep link through a failed first page even with a message of yours waiting to send", async () => {
|
|
181
|
+
const list = scrollingList();
|
|
182
|
+
const client = fakeClient([msg(1, SAM, "2026-10-24T10:00:00Z"), msg(2, ME, "2026-10-24T10:01:00Z")], 3);
|
|
183
|
+
(client.messages as ReturnType<typeof vi.fn>).mockRejectedValueOnce(new Error("offline"));
|
|
184
|
+
(client as unknown as { send: unknown }).send = vi.fn(() => new Promise(() => undefined));
|
|
185
|
+
render(wrap(client, list.List, <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2" }} testID="t" />));
|
|
186
|
+
await screen.findByText(chatNativeCopy.actionFailed, {}, { timeout: 2000 });
|
|
187
|
+
const input = await screen.findByTestId("t-composer-input");
|
|
188
|
+
await waitFor(() => expect(input.hasAttribute("disabled")).toBe(false));
|
|
189
|
+
fireEvent.change(input, { target: { value: "Still here" } });
|
|
190
|
+
fireEvent.click(screen.getByTestId("t-composer-send"));
|
|
191
|
+
await waitFor(() => expect((list.last().data as ThreadRow[] | undefined)?.some((r) => r.type === "message")).toBe(true));
|
|
192
|
+
await act(async () => void (await new Promise((r) => setTimeout(r, 600))));
|
|
193
|
+
expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("finds a deleted message: its tombstone is a row", async () => {
|
|
197
|
+
const list = scrollingList();
|
|
198
|
+
const deleted = { ...msg(2, SAM, "2026-10-24T10:01:00Z"), deletedAt: "2026-10-24T11:00:00Z" } as ChatMessage;
|
|
199
|
+
render(wrap(fakeClient([msg(1, SAM, "2026-10-24T10:00:00Z"), deleted], 3), list.List, <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2", seq: 2 }} />));
|
|
200
|
+
await waitFor(() => expect(list.scrollToIndex).toHaveBeenCalled());
|
|
201
|
+
expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
141
205
|
describe("threadListMode", () => {
|
|
142
206
|
it("follows new rows by hand only on FlatList, which keeps its place for earlier rows", () => {
|
|
143
207
|
expect(threadListMode(true, false)).toMatchObject({ followsByHand: false });
|
package/src/native/composer.tsx
CHANGED
|
@@ -7,10 +7,13 @@
|
|
|
7
7
|
* The emoji button opens the full picker, which types where the cursor is.
|
|
8
8
|
* With `onRecordVideo`, a camera button opens the video recorder. When the
|
|
9
9
|
* person can't post, it says why instead of taking input.
|
|
10
|
+
*
|
|
11
|
+
* The bar is genesis-ui-native's `NativeComposerBar`; this adds what's chat's: the draft, the
|
|
12
|
+
* attachments and reply above it, the mic in Send's place and the recording in the input's.
|
|
10
13
|
*/
|
|
11
14
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
12
|
-
import { PanResponder, Pressable, ScrollView,
|
|
13
|
-
import { NativeIcon, NativeImage, NativeListItem, NativeSheet, NativeText } from "@marktiderman/genesis-ui-native/components";
|
|
15
|
+
import { PanResponder, Pressable, ScrollView, View } from "react-native";
|
|
16
|
+
import { NativeComposerBar, NativeIcon, NativeImage, NativeListItem, NativeSheet, NativeText, useGenesisModules } from "@marktiderman/genesis-ui-native/components";
|
|
14
17
|
import { useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
|
|
15
18
|
import { CHAT_LIMITS, formatDuration, recordingLimitMs } from "../core/media";
|
|
16
19
|
import type { LocalFile } from "../core/outbox";
|
|
@@ -94,6 +97,7 @@ function ComposerWithVoice(props: ChatComposerProps & { audio: ExpoAudioLike })
|
|
|
94
97
|
function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo, onSchedule, placeholder, voice, userId, testID = "chat-composer" }: ChatComposerProps & { voice: Voice | null }) {
|
|
95
98
|
const { modules, copy } = useChatNative();
|
|
96
99
|
const colors = useThemeRoles();
|
|
100
|
+
const genesis = useGenesisModules();
|
|
97
101
|
const { state, dispatch } = composer;
|
|
98
102
|
const [attachOpen, setAttachOpen] = useState(false);
|
|
99
103
|
const [canPaste, setCanPaste] = useState(false);
|
|
@@ -122,7 +126,8 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
|
|
|
122
126
|
if (!sendable) return;
|
|
123
127
|
const payload = composer.take();
|
|
124
128
|
if (!payload) return;
|
|
125
|
-
|
|
129
|
+
// The bar taps when the app gave Genesis the module; chat's own covers an app that gave only chat.
|
|
130
|
+
if (!genesis.haptics) haptic(modules.haptics, "send");
|
|
126
131
|
onSend(payload);
|
|
127
132
|
};
|
|
128
133
|
|
|
@@ -175,15 +180,15 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
|
|
|
175
180
|
}
|
|
176
181
|
};
|
|
177
182
|
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
const above = (
|
|
184
|
+
<>
|
|
180
185
|
{notice ? (
|
|
181
|
-
<NativeText testID={`${testID}-notice`} accessibilityLiveRegion="polite" preset="caption" style={{ color: colors.destructive, paddingHorizontal:
|
|
186
|
+
<NativeText testID={`${testID}-notice`} accessibilityLiveRegion="polite" preset="caption" style={{ color: colors.destructive, paddingHorizontal: 4 }}>
|
|
182
187
|
{notice}
|
|
183
188
|
</NativeText>
|
|
184
189
|
) : null}
|
|
185
190
|
{state.replyTo ? (
|
|
186
|
-
<View testID={`${testID}-reply`} style={{ flexDirection: "row", alignItems: "center", paddingLeft: 12, borderLeftWidth: 3, borderLeftColor: colors.tint
|
|
191
|
+
<View testID={`${testID}-reply`} style={{ flexDirection: "row", alignItems: "center", paddingLeft: 12, borderLeftWidth: 3, borderLeftColor: colors.tint }}>
|
|
187
192
|
<View style={{ flex: 1 }}>
|
|
188
193
|
<NativeText preset="caption" style={{ color: colors.tint, fontWeight: "600" }}>
|
|
189
194
|
{fill(copy.replyingTo, { name: state.replyTo.name })}
|
|
@@ -220,57 +225,44 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
|
|
|
220
225
|
))}
|
|
221
226
|
</ScrollView>
|
|
222
227
|
) : null}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}}
|
|
262
|
-
/>
|
|
263
|
-
<IconButton testID={`${testID}-emoji`} icon="smile" label={copy.addEmoji} onPress={() => setEmojiOpen(true)} color={colors.secondaryLabel} disabled={!ready} />
|
|
264
|
-
</>
|
|
265
|
-
)}
|
|
266
|
-
{sendable && !recording ? (
|
|
267
|
-
<IconButton testID={`${testID}-send`} icon="arrow-up" label={copy.send} onPress={send} onLongPress={onSchedule} longPressLabel={onSchedule ? copy.schedule : undefined} filled color={colors.tint} />
|
|
268
|
-
) : voice ? (
|
|
269
|
-
<MicButton voice={voice} testID={testID} disabled={!ready} />
|
|
270
|
-
) : (
|
|
271
|
-
<IconButton testID={`${testID}-send`} icon="arrow-up" label={copy.send} onPress={send} filled color={colors.tint} disabled />
|
|
272
|
-
)}
|
|
273
|
-
</View>
|
|
228
|
+
</>
|
|
229
|
+
);
|
|
230
|
+
const canAttach = Boolean(modules.imagePicker || modules.clipboard?.getImageAsync);
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<>
|
|
234
|
+
<NativeComposerBar
|
|
235
|
+
testID={testID}
|
|
236
|
+
value={state.text}
|
|
237
|
+
onChangeText={(text) => {
|
|
238
|
+
dispatch({ type: "text", text });
|
|
239
|
+
if (text) signalTyping?.();
|
|
240
|
+
}}
|
|
241
|
+
onSelectionChange={(e) => {
|
|
242
|
+
selection.current = e.nativeEvent.selection;
|
|
243
|
+
}}
|
|
244
|
+
onSend={send}
|
|
245
|
+
// A recording sends itself: until it ends, the mic keeps Send's place, even over a written draft.
|
|
246
|
+
hasContent={sendable && !recording}
|
|
247
|
+
editable={ready}
|
|
248
|
+
placeholder={placeholder ?? copy.placeholder}
|
|
249
|
+
sendLabel={copy.send}
|
|
250
|
+
maxLength={CHAT_LIMITS.bodyChars}
|
|
251
|
+
sendActions={onSchedule ? [{ id: "schedule", label: copy.schedule, onPress: onSchedule }] : undefined}
|
|
252
|
+
sendActionsHint={copy.scheduleHoldHint}
|
|
253
|
+
above={above}
|
|
254
|
+
leading={
|
|
255
|
+
canAttach || onRecordVideo ? (
|
|
256
|
+
<View style={{ flexDirection: "row" }}>
|
|
257
|
+
{canAttach ? <IconButton testID={`${testID}-attach`} icon="plus" label={copy.attach} onPress={() => void openAttach()} color={colors.tint} disabled={!ready} /> : null}
|
|
258
|
+
{onRecordVideo ? <IconButton testID={`${testID}-video`} icon="video" label={copy.recordVideo} onPress={onRecordVideo} color={colors.tint} disabled={!ready} /> : null}
|
|
259
|
+
</View>
|
|
260
|
+
) : null
|
|
261
|
+
}
|
|
262
|
+
trailing={recording ? null : <IconButton testID={`${testID}-emoji`} icon="smile" label={copy.addEmoji} onPress={() => setEmojiOpen(true)} color={colors.secondaryLabel} disabled={!ready} />}
|
|
263
|
+
idleAction={voice ? <MicButton voice={voice} testID={testID} disabled={!ready} /> : null}
|
|
264
|
+
replaceInput={recording && voice ? <RecordingBar voice={voice} testID={testID} /> : null}
|
|
265
|
+
/>
|
|
274
266
|
<ChatEmojiPickerSheet open={emojiOpen} onClose={() => setEmojiOpen(false)} onSelect={insertEmoji} userId={userId} testID={`${testID}-emoji-sheet`} />
|
|
275
267
|
<NativeSheet open={attachOpen} onOpenChange={setAttachOpen} testID={`${testID}-attach-sheet`}>
|
|
276
268
|
<View>
|
|
@@ -285,7 +277,7 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
|
|
|
285
277
|
) : null}
|
|
286
278
|
</View>
|
|
287
279
|
</NativeSheet>
|
|
288
|
-
|
|
280
|
+
</>
|
|
289
281
|
);
|
|
290
282
|
}
|
|
291
283
|
|
|
@@ -294,24 +286,16 @@ function IconButton({
|
|
|
294
286
|
label,
|
|
295
287
|
onPress,
|
|
296
288
|
color,
|
|
297
|
-
filled = false,
|
|
298
289
|
disabled = false,
|
|
299
|
-
onLongPress,
|
|
300
|
-
longPressLabel,
|
|
301
290
|
testID,
|
|
302
291
|
}: {
|
|
303
|
-
icon: "plus" | "
|
|
292
|
+
icon: "plus" | "close" | "trash" | "video" | "smile";
|
|
304
293
|
label: string;
|
|
305
294
|
onPress: () => void;
|
|
306
|
-
onLongPress?: () => void;
|
|
307
|
-
/** The long press as a VoiceOver / TalkBack action. */
|
|
308
|
-
longPressLabel?: string;
|
|
309
295
|
color: unknown;
|
|
310
|
-
filled?: boolean;
|
|
311
296
|
disabled?: boolean;
|
|
312
297
|
testID: string;
|
|
313
298
|
}) {
|
|
314
|
-
const colors = useThemeRoles();
|
|
315
299
|
return (
|
|
316
300
|
<Pressable
|
|
317
301
|
testID={testID}
|
|
@@ -320,19 +304,9 @@ function IconButton({
|
|
|
320
304
|
accessibilityState={{ disabled }}
|
|
321
305
|
disabled={disabled}
|
|
322
306
|
onPress={onPress}
|
|
323
|
-
onLongPress={onLongPress}
|
|
324
|
-
delayLongPress={onLongPress ? 400 : undefined}
|
|
325
|
-
accessibilityActions={onLongPress && longPressLabel ? [{ name: "longpress", label: longPressLabel }] : undefined}
|
|
326
|
-
onAccessibilityAction={onLongPress ? (e) => e.nativeEvent.actionName === "longpress" && onLongPress() : undefined}
|
|
327
307
|
style={{ width: 44, height: 44, alignItems: "center", justifyContent: "center", opacity: disabled ? 0.4 : 1 }}
|
|
328
308
|
>
|
|
329
|
-
{
|
|
330
|
-
<View style={{ width: 34, height: 34, borderRadius: 17, backgroundColor: color as string, alignItems: "center", justifyContent: "center" }}>
|
|
331
|
-
<NativeIcon name={icon} size={18} color={colors.surface} weight="semibold" />
|
|
332
|
-
</View>
|
|
333
|
-
) : (
|
|
334
|
-
<NativeIcon name={icon} size={24} color={color as string} />
|
|
335
|
-
)}
|
|
309
|
+
<NativeIcon name={icon} size={24} color={color as string} />
|
|
336
310
|
</Pressable>
|
|
337
311
|
);
|
|
338
312
|
}
|
package/src/native/context.tsx
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { createContext, useContext, useMemo, type ReactNode } from "react";
|
|
9
9
|
import { usePeople } from "../react/index";
|
|
10
10
|
import { resolveChatCopy, type ChatNativeCopy, type ChatNativeCopyOverrides } from "./copy";
|
|
11
|
+
import { useGenesisModules } from "@marktiderman/genesis-ui-native/components";
|
|
11
12
|
import type { ChatNativeModules } from "./modules";
|
|
12
13
|
|
|
13
14
|
export interface ChatPerson {
|
|
@@ -37,9 +38,15 @@ export interface ChatNativeProviderProps {
|
|
|
37
38
|
|
|
38
39
|
/** Inside `ChatProvider` (from `/react`). Optional: without it there are no native extras and people are "Someone". */
|
|
39
40
|
export function ChatNativeProvider({ modules = EMPTY_MODULES, copy, getPerson, children }: ChatNativeProviderProps) {
|
|
41
|
+
const { haptics: genesisHaptics } = useGenesisModules();
|
|
40
42
|
const value = useMemo<ChatNativeContextValue>(
|
|
41
|
-
() => ({
|
|
42
|
-
|
|
43
|
+
() => ({
|
|
44
|
+
// Chat's own haptics module, else the one the app gave Genesis, so it's passed once.
|
|
45
|
+
modules: modules.haptics || !genesisHaptics ? modules : { ...modules, haptics: genesisHaptics },
|
|
46
|
+
copy: resolveChatCopy(copy),
|
|
47
|
+
person: (id) => (id && getPerson ? getPerson(id) : undefined),
|
|
48
|
+
}),
|
|
49
|
+
[modules, genesisHaptics, copy, getPerson],
|
|
43
50
|
);
|
|
44
51
|
return <Context.Provider value={value}>{children}</Context.Provider>;
|
|
45
52
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { memo, useCallback, useMemo, useRef, useState } from "react";
|
|
17
17
|
import { Animated, PanResponder, Pressable, View } from "react-native";
|
|
18
18
|
import { NativeAvatar, NativeText } from "@marktiderman/genesis-ui-native/components";
|
|
19
|
-
import { useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
|
|
19
|
+
import { sentBubbleColor, useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
|
|
20
20
|
import { summarizeReactions } from "../core/thread";
|
|
21
21
|
import type { ChatLinkPreview, ChatMessage, PendingFile } from "../core/types";
|
|
22
22
|
import type { ChatAttachmentKind } from "../react/index";
|
|
@@ -269,7 +269,7 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
|
|
|
269
269
|
const quoted = quote && repliedTo ? repliedTo : null;
|
|
270
270
|
// A message that is only app attachments the slot drew nothing for has nothing to show or read.
|
|
271
271
|
const invisible = Boolean(message && !message.deletedAt && !body && !attachments.length && !preview && !quote && !moderation && cards.length && !shownCards.length);
|
|
272
|
-
const bubbleColor = mine ? colors
|
|
272
|
+
const bubbleColor = mine ? sentBubbleColor(colors) : colors.surface;
|
|
273
273
|
const fg = mine ? "text-primary-foreground" : undefined;
|
|
274
274
|
const textStyle = mine ? { fontSize: 17, lineHeight: 22 } : { fontSize: 17, lineHeight: 22, color: colors.label };
|
|
275
275
|
|
package/src/native/modules.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* import * as Audio from "expo-audio"; // voice notes
|
|
8
8
|
* import * as ImagePicker from "expo-image-picker"; // photos and videos
|
|
9
|
-
* import * as Haptics from "expo-haptics"; // send and record
|
|
9
|
+
* import * as Haptics from "expo-haptics"; // send and record (Genesis's module is used when this is left out)
|
|
10
10
|
* import * as Clipboard from "expo-clipboard"; // copy, paste a picture
|
|
11
11
|
* import { KeyboardAvoidingView } from "react-native-keyboard-controller";
|
|
12
12
|
* import AsyncStorage from "@react-native-async-storage/async-storage"; // drafts
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* The shapes follow the SDK 58 packages' own type declarations.
|
|
23
23
|
*/
|
|
24
24
|
import type { ComponentType, ReactNode } from "react";
|
|
25
|
+
import { playHaptic, type HapticKind } from "@marktiderman/genesis-ui-native/hooks";
|
|
25
26
|
|
|
26
27
|
/** `RecorderState` from expo-audio (`recorder.getStatus()`). */
|
|
27
28
|
export interface RecorderStateLike {
|
|
@@ -255,23 +256,17 @@ export interface ChatNativeModules {
|
|
|
255
256
|
|
|
256
257
|
export type HapticEvent = "send" | "record-start" | "record-lock" | "record-cancel" | "select" | "error";
|
|
257
258
|
|
|
259
|
+
/** What each of chat's moments plays, in genesis-ui-native's vocabulary. */
|
|
260
|
+
const HAPTIC_KIND: Record<HapticEvent, HapticKind> = {
|
|
261
|
+
send: "light",
|
|
262
|
+
"record-lock": "light",
|
|
263
|
+
"record-start": "medium",
|
|
264
|
+
select: "select",
|
|
265
|
+
error: "error",
|
|
266
|
+
"record-cancel": "warning",
|
|
267
|
+
};
|
|
268
|
+
|
|
258
269
|
/** Plays a haptic when the app gave expo-haptics; never throws. */
|
|
259
270
|
export function haptic(haptics: HapticsLike | undefined, event: HapticEvent): void {
|
|
260
|
-
|
|
261
|
-
try {
|
|
262
|
-
const style = (s: unknown) => s as never;
|
|
263
|
-
const p =
|
|
264
|
-
event === "send" || event === "record-lock"
|
|
265
|
-
? haptics.impactAsync(style(haptics.ImpactFeedbackStyle.Light))
|
|
266
|
-
: event === "record-start"
|
|
267
|
-
? haptics.impactAsync(style(haptics.ImpactFeedbackStyle.Medium))
|
|
268
|
-
: event === "select"
|
|
269
|
-
? haptics.selectionAsync()
|
|
270
|
-
: haptics.notificationAsync(
|
|
271
|
-
style(event === "error" ? haptics.NotificationFeedbackType.Error : haptics.NotificationFeedbackType.Warning),
|
|
272
|
-
);
|
|
273
|
-
void p?.catch?.(() => undefined);
|
|
274
|
-
} catch {
|
|
275
|
-
// A haptic is never worth an error.
|
|
276
|
-
}
|
|
271
|
+
playHaptic(haptics, HAPTIC_KIND[event]);
|
|
277
272
|
}
|
|
@@ -25,6 +25,8 @@ export interface ChatOrganiseCopy {
|
|
|
25
25
|
topicReopenedDone: string;
|
|
26
26
|
// Scheduled send
|
|
27
27
|
schedule: string;
|
|
28
|
+
/** The hint on Send when it can schedule. */
|
|
29
|
+
scheduleHoldHint: string;
|
|
28
30
|
scheduleTitle: string;
|
|
29
31
|
scheduleHint: string;
|
|
30
32
|
schedulePick: string;
|
|
@@ -122,6 +124,7 @@ export const chatOrganiseCopy: ChatOrganiseCopy = {
|
|
|
122
124
|
topicClosedDone: "Closed {name}",
|
|
123
125
|
topicReopenedDone: "Reopened {name}",
|
|
124
126
|
schedule: "Schedule message",
|
|
127
|
+
scheduleHoldHint: "Touch and hold to schedule",
|
|
125
128
|
scheduleTitle: "Schedule message",
|
|
126
129
|
scheduleHint: "It sends at this time, in your time zone, as if you'd sent it then.",
|
|
127
130
|
schedulePick: "Pick a date and time",
|
|
@@ -298,11 +298,23 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
|
|
|
298
298
|
const { loadUntil } = conv;
|
|
299
299
|
// A jump names the server's message id; its seq says how far back to load.
|
|
300
300
|
const jumpSeq = jumpTo?.seq;
|
|
301
|
-
|
|
301
|
+
// Not while the first page has failed: there's nothing to look in, so the message isn't known to be
|
|
302
|
+
// gone. The reader hears the read failed, and the jump goes ahead when the rows come. Messages, not
|
|
303
|
+
// rows: a saved outbox row is drawn even when nothing could be read.
|
|
304
|
+
const firstPageFailed = Boolean(conv.error) && conv.messages.length === 0;
|
|
305
|
+
const jumpMessageId = firstPageFailed ? null : (jumpTo?.messageId ?? null);
|
|
306
|
+
const jumpBlocked = firstPageFailed && Boolean(jumpTo);
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
if (jumpBlocked) fail();
|
|
309
|
+
}, [jumpBlocked, fail]);
|
|
310
|
+
// A load that failed has said so: the message isn't known to be gone.
|
|
311
|
+
const jumpLoadFailed = useRef(false);
|
|
302
312
|
const onLoadUntil = useCallback(
|
|
303
313
|
(id: string) => {
|
|
314
|
+
jumpLoadFailed.current = false;
|
|
304
315
|
if (id !== jumpMessageId || jumpSeq == null) return Promise.resolve(false);
|
|
305
316
|
return loadUntil(jumpSeq).catch(() => {
|
|
317
|
+
jumpLoadFailed.current = true;
|
|
306
318
|
fail();
|
|
307
319
|
return false;
|
|
308
320
|
});
|
|
@@ -316,7 +328,10 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
|
|
|
316
328
|
},
|
|
317
329
|
[copy.jumpedTo, nameOf, attachmentKinds],
|
|
318
330
|
);
|
|
319
|
-
const onJumpFailed = useCallback(() =>
|
|
331
|
+
const onJumpFailed = useCallback(() => {
|
|
332
|
+
if (jumpLoadFailed.current) jumpLoadFailed.current = false;
|
|
333
|
+
else toast.show({ title: copy.messageGone });
|
|
334
|
+
}, [toast, copy.messageGone]);
|
|
320
335
|
const reattachable = useCallback((files: readonly PendingFile[]) => files.every((f) => !f.lost || f.kind === "image" || f.kind === "video"), []);
|
|
321
336
|
|
|
322
337
|
const renderItem = useCallback(
|
package/src/web/attachments.tsx
CHANGED
|
@@ -50,13 +50,26 @@ export interface ChatAttachmentSlotProps {
|
|
|
50
50
|
|
|
51
51
|
export const BUILT_IN_KINDS = new Set(["image", "voice", "video", "file", "link"]);
|
|
52
52
|
|
|
53
|
+
const hostOf = (url: string | null): string => {
|
|
54
|
+
try {
|
|
55
|
+
return url ? new URL(url).host : "";
|
|
56
|
+
} catch {
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
53
61
|
export function toAttachmentView(a: ChatAttachment, urls: Record<string, string>): AttachmentView {
|
|
62
|
+
const signed = a.path ? (urls[a.path] ?? null) : null;
|
|
63
|
+
const url = a.path ? signed : a.provider === "external" || a.kind === "link" ? a.url : null;
|
|
64
|
+
// Media from outside storage is a link naming its host: whoever sent it chose that address, so a
|
|
65
|
+
// reader's browser loads nothing until they ask.
|
|
66
|
+
const outsideMedia = (a.kind === "image" || a.kind === "video" || a.kind === "voice") && !a.path && Boolean(url);
|
|
54
67
|
return {
|
|
55
68
|
key: a.id,
|
|
56
|
-
kind: a.kind,
|
|
57
|
-
url
|
|
69
|
+
kind: outsideMedia ? "file" : a.kind,
|
|
70
|
+
url,
|
|
58
71
|
posterUrl: a.posterPath ? (urls[a.posterPath] ?? null) : null,
|
|
59
|
-
name: a.name,
|
|
72
|
+
name: outsideMedia ? `${a.name ?? "File"} (${hostOf(url)})` : a.name,
|
|
60
73
|
mime: a.mime,
|
|
61
74
|
bytes: a.bytes,
|
|
62
75
|
width: a.width,
|
package/src/web/bubble.tsx
CHANGED
|
@@ -64,6 +64,8 @@ export interface MessageRowProps {
|
|
|
64
64
|
item: ThreadItem;
|
|
65
65
|
/** First of a run from one sender: the name and avatar show (others' messages, in groups). */
|
|
66
66
|
startsGroup: boolean;
|
|
67
|
+
/** A jump just landed here (ThreadPage says so). */
|
|
68
|
+
highlighted?: boolean;
|
|
67
69
|
className?: string;
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -139,7 +141,7 @@ export function plainText(body: string): string {
|
|
|
139
141
|
return body.replace(/@\[([^\]]+)\]\(user:[0-9a-f-]{36}\)/gi, "@$1");
|
|
140
142
|
}
|
|
141
143
|
|
|
142
|
-
export function MessageRow({ item, startsGroup, className }: MessageRowProps) {
|
|
144
|
+
export function MessageRow({ item, startsGroup, highlighted: highlightedProp, className }: MessageRowProps) {
|
|
143
145
|
const ctx = useThreadContext();
|
|
144
146
|
const keepFocus = useRef<(() => void) | null>(null);
|
|
145
147
|
const pending = item.type === "pending" ? item.pending : null;
|
|
@@ -165,7 +167,7 @@ export function MessageRow({ item, startsGroup, className }: MessageRowProps) {
|
|
|
165
167
|
const progress = pending ? pendingProgress(pending) : null;
|
|
166
168
|
const editing = ctx.editingId === message.id;
|
|
167
169
|
const reactions = pending ? [] : summarizeReactions(message, ctx.me);
|
|
168
|
-
const highlighted = ctx.highlightedId === message.id;
|
|
170
|
+
const highlighted = highlightedProp ?? ctx.highlightedId === message.id;
|
|
169
171
|
const actionable = !pending && !deleted;
|
|
170
172
|
const hidden = !deleted && message.moderation === "hidden";
|
|
171
173
|
const flagged = !deleted && message.moderation === "flagged";
|
|
@@ -283,7 +285,7 @@ export function MessageRow({ item, startsGroup, className }: MessageRowProps) {
|
|
|
283
285
|
disabled={!ctx.canPost}
|
|
284
286
|
className={cn(
|
|
285
287
|
"inline-flex h-6 items-center gap-1 rounded-full border bg-background px-2 text-xs shadow-sm transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none",
|
|
286
|
-
r.mine && "border-primary bg-primary/10 text-primary",
|
|
288
|
+
r.mine && "border-primary bg-primary/10 text-primary-text",
|
|
287
289
|
)}
|
|
288
290
|
data-testid={`genesis-chat-reaction-${r.emoji}`}
|
|
289
291
|
>
|
package/src/web/cards.tsx
CHANGED
|
@@ -110,7 +110,7 @@ export function ChatAttachmentCard({ title, subtitle, icon: Icon = ClipboardList
|
|
|
110
110
|
className={cn("flex w-[min(20rem,100%)] items-center gap-3 rounded-lg p-2.5", primary ? "bg-primary-foreground/15" : "border bg-background", className)}
|
|
111
111
|
data-testid="genesis-chat-attachment-card"
|
|
112
112
|
>
|
|
113
|
-
<span className={cn("flex size-10 shrink-0 items-center justify-center rounded-md", primary ? "bg-primary-foreground/20" : "bg-primary/10 text-primary")}>
|
|
113
|
+
<span className={cn("flex size-10 shrink-0 items-center justify-center rounded-md", primary ? "bg-primary-foreground/20" : "bg-primary/10 text-primary-text")}>
|
|
114
114
|
<Icon className="size-5" aria-hidden />
|
|
115
115
|
</span>
|
|
116
116
|
<span className="min-w-0 flex-1">
|
package/src/web/composer.tsx
CHANGED
|
@@ -7,10 +7,8 @@
|
|
|
7
7
|
* camera, emoji, and scheduled send (the arrow beside Send). Where you may not
|
|
8
8
|
* post it says why instead; when who you are couldn't load, it offers a retry.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* wiring (the chat client, realtime, read state) and moves its rendering onto `ComposerBar` with chat's
|
|
13
|
-
* builder; until then fix behaviour in both places.
|
|
10
|
+
* In ChatThread it fills `ThreadPage`'s `composer` slot. Its input isn't on genesis-ui's `ComposerBar`
|
|
11
|
+
* yet: the web bar has no attachments-only send, or a mic in Send's place, as the native one has.
|
|
14
12
|
*/
|
|
15
13
|
import {
|
|
16
14
|
useCallback,
|
|
@@ -372,7 +370,7 @@ export function ChatComposer({
|
|
|
372
370
|
{replyTo ? (
|
|
373
371
|
<div className="flex items-center gap-2 border-b px-3 py-2" data-testid="genesis-chat-reply-banner">
|
|
374
372
|
<div className="min-w-0 flex-1 border-l-4 border-primary pl-2">
|
|
375
|
-
<div className="text-xs font-semibold text-primary">Replying to {replyName}</div>
|
|
373
|
+
<div className="text-xs font-semibold text-primary-text">Replying to {replyName}</div>
|
|
376
374
|
<div className="truncate text-xs text-muted-foreground">{previewText(replyTo.body, replyTo.attachments[0]?.kind ?? null, Boolean(replyTo.deletedAt))}</div>
|
|
377
375
|
</div>
|
|
378
376
|
<Button type="button" variant="ghost" size="icon" className="size-7 shrink-0" onClick={onCancelReply} aria-label="Cancel reply">
|
package/src/web/dock.tsx
CHANGED
|
@@ -76,8 +76,8 @@ export interface ChatDockPanel {
|
|
|
76
76
|
/** Opening the same id again brings that window back rather than adding a second. */
|
|
77
77
|
id: string;
|
|
78
78
|
title: string;
|
|
79
|
-
/** Its body, filling the window under the dock's title bar. */
|
|
80
|
-
render: () => ReactNode;
|
|
79
|
+
/** Its body, filling the window under the dock's title bar. `visible`: it stays mounted when minimized, so pause what mustn't happen out of sight (marking read). */
|
|
80
|
+
render: (state: { visible: boolean }) => ReactNode;
|
|
81
81
|
/** In place of the avatar in the title bar. */
|
|
82
82
|
icon?: ReactNode;
|
|
83
83
|
/** Unread count on the bar and the bubble. */
|
|
@@ -649,7 +649,7 @@ function DockItemView({ item, inbox, resolveUser, threadProps, labels, inSheet,
|
|
|
649
649
|
toggleRef={toggleRef}
|
|
650
650
|
/>
|
|
651
651
|
<div className="flex min-h-0 flex-1 flex-col overflow-y-auto" hidden={!visible} data-testid="genesis-chat-dock-panel">
|
|
652
|
-
{item.render()}
|
|
652
|
+
{item.render({ visible })}
|
|
653
653
|
</div>
|
|
654
654
|
</>
|
|
655
655
|
);
|