@marktiderman/genesis-cli 1.7.0 → 1.9.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 +26 -4
- package/dist/cli.js +933 -319
- package/dist/cli.js.map +1 -1
- package/dist/{config-CrZbM3jD.d.ts → config-QC_Ewwwp.d.ts} +27 -3
- package/dist/doctor.d.ts +68 -4
- package/dist/doctor.js +654 -87
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +164 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +666 -101
- package/dist/index.js.map +1 -1
- package/dist/starter/.env.example +3 -0
- package/dist/starter/README.md +7 -0
- package/dist/starter/__tests__/app-config.test.ts +27 -0
- package/dist/starter/__tests__/chat-outboxes.test.ts +64 -0
- package/dist/starter/__tests__/check-in-photos.test.ts +5 -3
- package/dist/starter/__tests__/components/fake-supabase.ts +8 -0
- package/dist/starter/__tests__/components/messages.test.tsx +33 -0
- package/dist/starter/__tests__/components/settings.test.tsx +34 -0
- package/dist/starter/__tests__/components/setup.ts +13 -0
- package/dist/starter/__tests__/components/tabs-feature-off.test.tsx +1 -1
- package/dist/starter/__tests__/components/tabs.test.tsx +2 -2
- package/dist/starter/__tests__/inline-copy.ts +1 -1
- package/dist/starter/__tests__/starter.test.ts +117 -3
- package/dist/starter/app.config.ts +19 -2
- package/dist/starter/genesis.config.json +2 -2
- package/dist/starter/jest.config.js +2 -1
- package/dist/starter/metro.config.js +1 -1
- package/dist/starter/package.json +9 -0
- package/dist/starter/src/app/(app)/(home)/check-in.tsx +4 -38
- package/dist/starter/src/app/(app)/_layout.tsx +25 -3
- package/dist/starter/src/app/(app)/messages/[id].tsx +63 -0
- package/dist/starter/src/app/(app)/messages/_layout.tsx +11 -0
- package/dist/starter/src/app/(app)/messages/check-in.tsx +9 -0
- package/dist/starter/src/app/(app)/messages/index.tsx +38 -0
- package/dist/starter/src/app/(app)/messages/search.tsx +39 -0
- package/dist/starter/src/app/(app)/notifications/index.tsx +7 -13
- package/dist/starter/src/app/(app)/settings/availability.tsx +16 -0
- package/dist/starter/src/app/(app)/settings/index.tsx +8 -3
- package/dist/starter/src/app/(app)/settings/notifications.tsx +6 -3
- package/dist/starter/src/copy.ts +19 -0
- package/dist/starter/src/lib/chat-outboxes.ts +50 -0
- package/dist/starter/src/lib/chat-video.ts +57 -0
- package/dist/starter/src/lib/chat.tsx +319 -0
- package/dist/starter/src/lib/check-in-screen.tsx +43 -0
- package/dist/starter/src/lib/define-starter.ts +9 -0
- package/dist/starter/src/lib/env.ts +4 -0
- package/dist/starter/src/lib/links.ts +2 -0
- package/dist/starter/src/lib/notifications.ts +30 -12
- package/dist/starter/src/lib/push.ts +21 -5
- package/dist/starter/starter.config.ts +1 -0
- package/dist/starter/supabase/config.toml +5 -0
- package/dist/starter/supabase/migrations/20261025000000_genesis_chat.sql +1836 -0
- package/dist/starter/supabase/migrations/20261025000050_genesis_chat_coaching.sql +934 -0
- package/dist/starter/supabase/migrations/20261025000060_genesis_chat_search_threads.sql +85 -0
- package/dist/starter/supabase/migrations/20261025000100_genesis_notifications.sql +2057 -0
- package/dist/starter/supabase/migrations/20261026000000_chat_people.sql +57 -0
- package/dist/starter/supabase/tests/database/chat_people.test.sql +112 -0
- package/dist/starter/supabase/tests/database/genesis_chat.test.sql +254 -0
- package/dist/starter/supabase/tests/database/genesis_chat_coaching.test.sql +269 -0
- package/dist/starter/supabase/tests/database/genesis_chat_search_threads.test.sql +50 -0
- package/dist/starter/supabase/tests/database/genesis_notifications.test.sql +473 -0
- package/dist/vite.js +651 -86
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
- package/dist/starter/supabase/tests/database/genesis_push.test.sql +0 -407
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat (`features.chat`): the chat client on the app's Supabase, the native
|
|
3
|
+
* modules the chat screens use, resumable uploads, unsent messages kept on
|
|
4
|
+
* the phone, and the push glue (the `messages` category's Reply and Mark read).
|
|
5
|
+
* `src/app/(app)/_layout.tsx` mounts `ChatRoot` over the signed-in tabs (the
|
|
6
|
+
* Messages tab and Settings → Availability share it); `push.ts` adds the
|
|
7
|
+
* category and the reply handler.
|
|
8
|
+
*
|
|
9
|
+
* Names and avatars: genesis-chat stores user ids only. The starter reads them
|
|
10
|
+
* with `loadChatPeople`, through `public.chat_people` (migration
|
|
11
|
+
* `20261026000000_chat_people.sql`): the `name` and `avatar_url` a login's
|
|
12
|
+
* auth metadata carries, for people who share a conversation with you. An app
|
|
13
|
+
* with its own profiles passes its own `loadPeople` to `ChatRoot` instead.
|
|
14
|
+
*
|
|
15
|
+
* Unsent messages are retried when the app comes back to the front and when
|
|
16
|
+
* the connection comes back (`ChatAutoRetry`, with NetInfo), and forgotten on
|
|
17
|
+
* sign-out with the person's drafts.
|
|
18
|
+
*/
|
|
19
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
20
|
+
import NetInfo from "@react-native-community/netinfo";
|
|
21
|
+
import * as Audio from "expo-audio";
|
|
22
|
+
import * as Camera from "expo-camera";
|
|
23
|
+
import * as Clipboard from "expo-clipboard";
|
|
24
|
+
import * as ExpoCrypto from "expo-crypto";
|
|
25
|
+
import { Directory, File, FileMode, Paths } from "expo-file-system";
|
|
26
|
+
import * as Haptics from "expo-haptics";
|
|
27
|
+
import * as ImagePicker from "expo-image-picker";
|
|
28
|
+
import * as Sharing from "expo-sharing";
|
|
29
|
+
import * as Notifications from "expo-notifications";
|
|
30
|
+
import * as Video from "expo-video";
|
|
31
|
+
import * as WebBrowser from "expo-web-browser";
|
|
32
|
+
import { useEffect, type ReactNode } from "react";
|
|
33
|
+
import { KeyboardAvoidingView } from "react-native-keyboard-controller";
|
|
34
|
+
import { createChatClient, type LocalFile, type Outbox, type OutboxStore, type QueuedMessage } from "@marktiderman/genesis-chat";
|
|
35
|
+
import { ChatProvider, useChat, type ChatProviderProps } from "@marktiderman/genesis-chat/react";
|
|
36
|
+
import {
|
|
37
|
+
ChatAutoRetry,
|
|
38
|
+
ChatNativeProvider,
|
|
39
|
+
clearDrafts,
|
|
40
|
+
forgetRecentEmoji,
|
|
41
|
+
createTusUpload,
|
|
42
|
+
handleChatPushResponse,
|
|
43
|
+
videoUploads,
|
|
44
|
+
registerChatNotificationActions,
|
|
45
|
+
type ChatCardContext,
|
|
46
|
+
type ChatNativeModules,
|
|
47
|
+
} from "@marktiderman/genesis-chat/native";
|
|
48
|
+
import { useSession } from "@marktiderman/genesis-native";
|
|
49
|
+
import starter from "../../starter.config";
|
|
50
|
+
import { copy } from "@/copy";
|
|
51
|
+
import { createChatOutboxes, outboxKey } from "./chat-outboxes";
|
|
52
|
+
import { chatVideoUpload } from "./chat-video";
|
|
53
|
+
import { env } from "./env";
|
|
54
|
+
import { supabase } from "./supabase";
|
|
55
|
+
|
|
56
|
+
export const chatClient = createChatClient(supabase);
|
|
57
|
+
|
|
58
|
+
// Genesis describes each module by what it calls, so the packages' own (wider) types are cast once here.
|
|
59
|
+
// Photos copied from their signed links to share them, in one folder cleared on sign-out.
|
|
60
|
+
const SHARED_DIR = "genesis-chat-shared";
|
|
61
|
+
// Pasted pictures kept for an unsent message (`persistFile`), named with this prefix.
|
|
62
|
+
const PERSISTED_PREFIX = "genesis-chat-";
|
|
63
|
+
|
|
64
|
+
const outboxes = createChatOutboxes(AsyncStorage);
|
|
65
|
+
|
|
66
|
+
const modules: ChatNativeModules = {
|
|
67
|
+
audio: Audio as unknown as ChatNativeModules["audio"],
|
|
68
|
+
// The library only (add `launchCameraAsync` for "Take a photo"; the camera sentence is already in
|
|
69
|
+
// app.config.ts for video messages).
|
|
70
|
+
imagePicker: { launchImageLibraryAsync: ImagePicker.launchImageLibraryAsync } as unknown as ChatNativeModules["imagePicker"],
|
|
71
|
+
haptics: Haptics as unknown as ChatNativeModules["haptics"],
|
|
72
|
+
clipboard: Clipboard as unknown as ChatNativeModules["clipboard"],
|
|
73
|
+
keyboardAvoidingView: starter.features.keyboardScroll ? (KeyboardAvoidingView as unknown as ChatNativeModules["keyboardAvoidingView"]) : undefined,
|
|
74
|
+
drafts: AsyncStorage as unknown as ChatNativeModules["drafts"],
|
|
75
|
+
// Share in the photo viewer, from a copy in the cache. (Save to Photos needs expo-media-library
|
|
76
|
+
// and a photo-library-add permission sentence in app.config.ts: pass it as `mediaLibrary`.)
|
|
77
|
+
sharing: Sharing as unknown as ChatNativeModules["sharing"],
|
|
78
|
+
downloadFile: async (url) => {
|
|
79
|
+
const dir = new Directory(Paths.cache, SHARED_DIR);
|
|
80
|
+
dir.create({ idempotent: true });
|
|
81
|
+
return (await File.downloadFileAsync(url, dir, { idempotent: true })).uri;
|
|
82
|
+
},
|
|
83
|
+
netInfo: NetInfo as unknown as ChatNativeModules["netInfo"],
|
|
84
|
+
// Video messages: record in the thread (camera and microphone sentences in app.config.ts), play
|
|
85
|
+
// HLS and files in the bubble; link previews open in an in-app browser.
|
|
86
|
+
camera: Camera as unknown as ChatNativeModules["camera"],
|
|
87
|
+
video: Video as unknown as ChatNativeModules["video"],
|
|
88
|
+
webBrowser: WebBrowser as unknown as ChatNativeModules["webBrowser"],
|
|
89
|
+
openFile: (uri: string) => openFile(uri),
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Mux when the app has an upload handler, else storage (src/lib/chat-video.ts).
|
|
93
|
+
const videoUpload = chatVideoUpload();
|
|
94
|
+
|
|
95
|
+
// The app's own attachment kinds, drawn as cards in the thread (and named by their title in the
|
|
96
|
+
// inbox's preview). A check-in sent in a conversation opens the check-in screen
|
|
97
|
+
// (`onOpenAttachment` in messages/[id].tsx); its sender sees "Sent" instead of Answer
|
|
98
|
+
// (genesis-chat's native cards pass `{ mine }`).
|
|
99
|
+
export const attachmentKinds: NonNullable<ChatProviderProps["attachmentKinds"]> = {
|
|
100
|
+
check_in: {
|
|
101
|
+
title: () => copy.messages.checkInCard,
|
|
102
|
+
subtitle: (a, ctx?: ChatCardContext) => {
|
|
103
|
+
const title = typeof a.ref.title === "string" ? a.ref.title : null;
|
|
104
|
+
return ctx?.mine ? [copy.messages.checkInSent, title].filter(Boolean).join(" · ") : title;
|
|
105
|
+
},
|
|
106
|
+
action: (_a, ctx?: ChatCardContext) => (starter.features.checkIn && !ctx?.mine ? { label: copy.messages.checkInAnswer } : null),
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** Whether a conversation's kind can have topics: any kind for more than two people (not a direct one). */
|
|
111
|
+
export function kindAllowsTopics(rules: { maxMembers: number | null } | null | undefined): boolean {
|
|
112
|
+
return Boolean(rules) && rules!.maxMembers !== 2;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Unsent messages wait here between launches (per signed-in person). */
|
|
116
|
+
function outboxStore(userId: string): OutboxStore {
|
|
117
|
+
const key = outboxKey(userId);
|
|
118
|
+
return {
|
|
119
|
+
load: async () => {
|
|
120
|
+
try {
|
|
121
|
+
return JSON.parse((await AsyncStorage.getItem(key)) ?? "[]") as QueuedMessage[];
|
|
122
|
+
} catch {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
save: async (queue) => {
|
|
127
|
+
await AsyncStorage.setItem(key, JSON.stringify(queue)).catch(() => undefined);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const accessToken = async () => (await supabase.auth.getSession()).data.session?.access_token;
|
|
133
|
+
|
|
134
|
+
/** A picked file opened for reading a chunk at a time, so a long video is never read whole into memory. */
|
|
135
|
+
function openFile(uri: string) {
|
|
136
|
+
const handle = new File(uri).open(FileMode.ReadOnly);
|
|
137
|
+
return {
|
|
138
|
+
size: handle.size ?? 0,
|
|
139
|
+
read: async (offset: number, length: number) => {
|
|
140
|
+
handle.offset = offset;
|
|
141
|
+
return handle.readBytes(length);
|
|
142
|
+
},
|
|
143
|
+
close: () => handle.close(),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A file held as bytes (a pasted picture) copied into the cache directory, so an unsent message
|
|
149
|
+
* keeps it across a relaunch. The outbox only calls this for bytes; picked files are already URIs.
|
|
150
|
+
*/
|
|
151
|
+
async function persistFile(file: LocalFile): Promise<string> {
|
|
152
|
+
const data = file.data;
|
|
153
|
+
const bytes = data instanceof ArrayBuffer ? data : typeof data === "object" && typeof data.arrayBuffer === "function" ? await data.arrayBuffer() : null;
|
|
154
|
+
if (!bytes) throw new Error(`[chat] can't keep ${file.name}: no bytes to write`);
|
|
155
|
+
const safe = file.name.replace(/[^\w.-]+/g, "_").slice(-80) || "file";
|
|
156
|
+
const out = new File(Paths.cache, `genesis-chat-${ExpoCrypto.randomUUID()}-${safe}`);
|
|
157
|
+
out.create({ overwrite: true });
|
|
158
|
+
await out.write(new Uint8Array(bytes));
|
|
159
|
+
return out.uri;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
type LoadPeople = NonNullable<ChatProviderProps["loadPeople"]>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Names and avatars from `public.chat_people`: only people who share a conversation with you
|
|
166
|
+
* (and you), only their name and avatar. Someone with no name in their metadata stays unnamed.
|
|
167
|
+
*/
|
|
168
|
+
export const loadChatPeople: LoadPeople = async (userIds) => {
|
|
169
|
+
// The starter's client has no generated Database types, so rpc() types its arguments as none.
|
|
170
|
+
const { data, error } = await supabase.rpc("chat_people", { p_user_ids: userIds } as never);
|
|
171
|
+
if (error) throw error;
|
|
172
|
+
const out: Awaited<ReturnType<LoadPeople>> = {};
|
|
173
|
+
for (const row of (data ?? []) as { user_id: string; name: string | null; avatar_url: string | null }[]) {
|
|
174
|
+
if (row.name) out[row.user_id] = { name: row.name, avatarUrl: row.avatar_url };
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The providers the chat screens read: the signed-in person's chat, with its uploads and drafts.
|
|
181
|
+
* Before the session is known its children render without it (the Messages stack waits for a
|
|
182
|
+
* person itself).
|
|
183
|
+
*/
|
|
184
|
+
export function ChatRoot({ children, loadPeople = loadChatPeople }: { children: ReactNode; loadPeople?: LoadPeople }) {
|
|
185
|
+
const { userId } = useSession();
|
|
186
|
+
if (!userId) return <>{children}</>;
|
|
187
|
+
return (
|
|
188
|
+
<ChatForUser userId={userId} loadPeople={loadPeople}>
|
|
189
|
+
{children}
|
|
190
|
+
</ChatForUser>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const stores = new Map<string, { store: OutboxStore; upload: ReturnType<typeof createTusUpload> }>();
|
|
195
|
+
function forUser(userId: string) {
|
|
196
|
+
let s = stores.get(userId);
|
|
197
|
+
if (!s) {
|
|
198
|
+
s = {
|
|
199
|
+
store: outboxStore(userId),
|
|
200
|
+
upload: createTusUpload({ supabaseUrl: env.supabaseUrl, apikey: env.supabasePublishableKey, userId, getAccessToken: accessToken, openFile, newId: ExpoCrypto.randomUUID }),
|
|
201
|
+
};
|
|
202
|
+
stores.set(userId, s);
|
|
203
|
+
}
|
|
204
|
+
return s;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function ChatForUser({ userId, loadPeople, children }: { userId: string; loadPeople?: LoadPeople; children: ReactNode }) {
|
|
208
|
+
const { store, upload } = forUser(userId);
|
|
209
|
+
return (
|
|
210
|
+
<ChatProvider client={chatClient} userId={userId} outboxStore={store} upload={upload} newId={ExpoCrypto.randomUUID} persistFile={persistFile} loadPeople={loadPeople} videoUpload={videoUpload} attachmentKinds={attachmentKinds}>
|
|
211
|
+
<ShareOutbox userId={userId} />
|
|
212
|
+
<ChatNativeProvider modules={modules} copy={copy.chat}>
|
|
213
|
+
<ChatAutoRetry />
|
|
214
|
+
{children}
|
|
215
|
+
</ChatNativeProvider>
|
|
216
|
+
</ChatProvider>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// The outbox the Messages screens are using, per person, so a reply from a notification queues
|
|
221
|
+
// in it (and shows in the open thread) instead of writing the saved copy behind its back.
|
|
222
|
+
const liveOutboxes = new Map<string, Outbox>();
|
|
223
|
+
function ShareOutbox({ userId }: { userId: string }) {
|
|
224
|
+
const { outbox, clearOutbox } = useChat();
|
|
225
|
+
// Kept past the Messages screens' unmount: signing out unmounts them before the layout sees it.
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
outboxes.register(userId, clearOutbox);
|
|
228
|
+
}, [userId, clearOutbox]);
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
liveOutboxes.set(userId, outbox);
|
|
231
|
+
return () => {
|
|
232
|
+
if (liveOutboxes.get(userId) === outbox) liveOutboxes.delete(userId);
|
|
233
|
+
};
|
|
234
|
+
}, [userId, outbox]);
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Who was signed in last, kept outside React: the layout that sees the sign-out may be a new instance.
|
|
239
|
+
let lastChatUser: string | null = null;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Who was signed in last, forgotten as it is read. A function on purpose: the React Compiler
|
|
243
|
+
* folded `const who = lastChatUser; lastChatUser = null;` in the hook below into reads of
|
|
244
|
+
* `lastChatUser` after the reset, so sign-out cleared the drafts, unsent messages and recent
|
|
245
|
+
* emoji of `null` instead of the person's.
|
|
246
|
+
*/
|
|
247
|
+
function takeLastChatUser(): string | null {
|
|
248
|
+
const who = lastChatUser;
|
|
249
|
+
lastChatUser = null;
|
|
250
|
+
return who;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Chat's copies of pictures in the cache: shared photos and pasted ones kept for unsent messages. */
|
|
254
|
+
function clearChatFiles() {
|
|
255
|
+
for (const entry of new Directory(Paths.cache).list()) {
|
|
256
|
+
if (entry.name === SHARED_DIR || entry.name.startsWith(PERSISTED_PREFIX)) entry.delete();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Chat drafts, unsent messages, recent emoji and copied pictures never outlive the person who
|
|
262
|
+
* wrote them on this phone: signing out (Settings, account deletion) clears theirs, and signing in clears everyone else's, which covers a session
|
|
263
|
+
* that ended while the app was closed and a switch from one person to another. Mounted once, in
|
|
264
|
+
* the signed-in layout.
|
|
265
|
+
*/
|
|
266
|
+
export function useClearChatOnSignOut() {
|
|
267
|
+
const { status, userId } = useSession();
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
if (!starter.features.chat) return;
|
|
270
|
+
const onError = (e: unknown) => console.warn("[chat] clearing drafts:", e);
|
|
271
|
+
if (status === "signedIn" && userId) {
|
|
272
|
+
if (lastChatUser !== userId) {
|
|
273
|
+
void clearDrafts(modules.drafts!, { except: userId }, onError);
|
|
274
|
+
void outboxes.clearOthers(userId).catch(onError);
|
|
275
|
+
}
|
|
276
|
+
lastChatUser = userId;
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (status !== "signedOut") return;
|
|
280
|
+
const who = takeLastChatUser();
|
|
281
|
+
if (!who) return;
|
|
282
|
+
void clearDrafts(modules.drafts!, who, onError);
|
|
283
|
+
// Videos still uploading were theirs: they stop, and nothing is sent after sign-out.
|
|
284
|
+
videoUploads.cancelAll();
|
|
285
|
+
void outboxes.clear(who).catch(onError);
|
|
286
|
+
forgetRecentEmoji(who);
|
|
287
|
+
try {
|
|
288
|
+
clearChatFiles();
|
|
289
|
+
} catch (e) {
|
|
290
|
+
onError(e);
|
|
291
|
+
}
|
|
292
|
+
}, [status, userId]);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* For createPush's `onResponse`: Reply and Mark read from a message's notification. A reply goes
|
|
297
|
+
* through the outbox: the live one when Messages is open, else one that can't be sent now is kept
|
|
298
|
+
* in the saved outbox, failed, and shows in its thread with Retry.
|
|
299
|
+
*/
|
|
300
|
+
export function onChatPushResponse(response: Parameters<typeof handleChatPushResponse>[0]) {
|
|
301
|
+
if (!starter.features.chat) return;
|
|
302
|
+
const onError = (e: unknown) => console.warn("[chat] push reply:", e);
|
|
303
|
+
void (async () => {
|
|
304
|
+
const userId = (await supabase.auth.getSession()).data.session?.user.id ?? null;
|
|
305
|
+
await handleChatPushResponse(response, {
|
|
306
|
+
client: chatClient,
|
|
307
|
+
notifications: Notifications,
|
|
308
|
+
onError,
|
|
309
|
+
outbox: userId ? () => liveOutboxes.get(userId) : null,
|
|
310
|
+
store: userId ? forUser(userId).store : null,
|
|
311
|
+
userId,
|
|
312
|
+
});
|
|
313
|
+
})().catch(onError);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// The Reply and Mark read buttons on a message's notification, registered once at start.
|
|
317
|
+
if (starter.features.chat && starter.features.push) {
|
|
318
|
+
void registerChatNotificationActions(Notifications, undefined, (error) => console.warn("[chat] notification actions:", error));
|
|
319
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Redirect, Stack, router, useLocalSearchParams } from "expo-router";
|
|
2
|
+
import type { Session } from "@supabase/supabase-js";
|
|
3
|
+
import { useSession } from "@marktiderman/genesis-native";
|
|
4
|
+
import { FormFocus, Button } from "@marktiderman/genesis-forms-native";
|
|
5
|
+
import { useFormDraft } from "@marktiderman/genesis-forms-react";
|
|
6
|
+
import { ScreenContainer } from "@marktiderman/genesis-ui-native";
|
|
7
|
+
import starter from "../../starter.config";
|
|
8
|
+
import { copy } from "@/copy";
|
|
9
|
+
import { checkInDrafts, checkInForm, checkInHaptics, checkInHostOptions, checkInKey, checkInOutbox, checkInPhotos } from "@/lib/check-in";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The check-in example (`features.checkIn`): one question per screen, the title in the native
|
|
13
|
+
* header, a draft per signed-in user and the offline outbox. Open it with a link to fill in the
|
|
14
|
+
* gym: `genesis-starter://check-in?gym=hilltop`. The Home tab shows it at `/check-in`; a check-in
|
|
15
|
+
* card in a conversation opens it in the Messages stack (`/messages/check-in`), so Back returns
|
|
16
|
+
* to the conversation. `backTitle` names the screen under it (left out, iOS uses that screen's title).
|
|
17
|
+
*/
|
|
18
|
+
export function CheckInScreen({ backTitle }: { backTitle?: string }) {
|
|
19
|
+
const params = useLocalSearchParams<{ gym?: string }>();
|
|
20
|
+
const { session } = useSession<Session>();
|
|
21
|
+
const draft = useFormDraft(checkInForm, {
|
|
22
|
+
store: checkInDrafts,
|
|
23
|
+
respondent: session?.user.id ?? "signed-out",
|
|
24
|
+
hostOptions: checkInHostOptions,
|
|
25
|
+
linkParams: params.gym ? { gym: params.gym } : undefined,
|
|
26
|
+
});
|
|
27
|
+
if (!starter.features.checkIn) return <Redirect href="/" />;
|
|
28
|
+
return (
|
|
29
|
+
<ScreenContainer testID="check-in">
|
|
30
|
+
<FormFocus
|
|
31
|
+
draft={draft}
|
|
32
|
+
outbox={checkInOutbox}
|
|
33
|
+
createKey={checkInKey}
|
|
34
|
+
haptics={checkInHaptics}
|
|
35
|
+
photos={checkInPhotos}
|
|
36
|
+
screen={Stack.Screen}
|
|
37
|
+
headerOptions={{ headerBackTitle: backTitle }}
|
|
38
|
+
testID="check-in-form"
|
|
39
|
+
slotProps={{ ending: { actions: <Button onPress={() => router.back()} testID="check-in-done">{copy.checkIn.done}</Button> } }}
|
|
40
|
+
/>
|
|
41
|
+
</ScreenContainer>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -92,6 +92,15 @@ export interface StarterFeatures {
|
|
|
92
92
|
* the form in `src/forms/check-in.json`, or turn it off. JavaScript only.
|
|
93
93
|
*/
|
|
94
94
|
checkIn: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Chat (`@marktiderman/genesis-chat`): the Messages tab with your conversations and a thread
|
|
97
|
+
* screen (photos, voice notes, reactions, replies), on the `genesis_chat` migration, and the
|
|
98
|
+
* `messages` push category with Reply and Mark read when `push` is on. Conversations are started
|
|
99
|
+
* by your server (`genesis_chat.ensure_conversation`) until you register a start check for a
|
|
100
|
+
* kind (the genesis-chat README, Kinds and rules). JavaScript only: expo-audio, expo-image-picker
|
|
101
|
+
* and expo-clipboard stay in the build either way.
|
|
102
|
+
*/
|
|
103
|
+
chat: boolean;
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
export interface StarterConfig {
|
|
@@ -14,6 +14,9 @@ const values = {
|
|
|
14
14
|
EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY: process.env.EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY,
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
/** Optional: chat's hosted video uploads (`src/lib/chat-video.ts`). */
|
|
18
|
+
const chatVideoUploadUrl = process.env.EXPO_PUBLIC_CHAT_VIDEO_UPLOAD_URL || null;
|
|
19
|
+
|
|
17
20
|
/** The names of the settings that aren't set. */
|
|
18
21
|
export const missingEnv = Object.entries(values)
|
|
19
22
|
.filter(([, value]) => !value)
|
|
@@ -30,4 +33,5 @@ export const env = {
|
|
|
30
33
|
// A placeholder keeps the client constructible until the boot step reports the missing value.
|
|
31
34
|
supabaseUrl: values.EXPO_PUBLIC_SUPABASE_URL || "https://missing-supabase-url.invalid",
|
|
32
35
|
supabasePublishableKey: values.EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY || "missing-publishable-key",
|
|
36
|
+
chatVideoUploadUrl,
|
|
33
37
|
};
|
|
@@ -31,6 +31,8 @@ export const links: LinkOptions = {
|
|
|
31
31
|
...(starter.features.notifications ? { "/notifications": "/notifications" } : {}),
|
|
32
32
|
// The check-in example's link (`genesis-starter://check-in?gym=hilltop` fills in the gym; `genesis-starter-dev://` in a development build).
|
|
33
33
|
...(starter.features.checkIn ? { "/check-in": "/check-in" } : {}),
|
|
34
|
+
// A message's push opens its thread (`data.url` = `/messages/<conversation>`).
|
|
35
|
+
...(starter.features.chat ? { "/messages": "/messages", "/messages/:id": "/messages/:id" } : {}),
|
|
34
36
|
"/settings": "/settings",
|
|
35
37
|
...(starter.features.push ? { "/settings/notifications": "/settings/notifications" } : {}),
|
|
36
38
|
},
|
|
@@ -1,15 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* the
|
|
2
|
+
* What the app notifies people about (`features.notifications`), on
|
|
3
|
+
* @marktiderman/genesis-notifications: one list the app, the server and the
|
|
4
|
+
* sender function share. The feed (the Notifications tab) reads it to say
|
|
5
|
+
* what each row is; the push block takes its categories and action buttons;
|
|
6
|
+
* Settings → Notifications shows a switch per category and channel.
|
|
7
|
+
*
|
|
8
|
+
* Add your types here, then send them from your server with `notify()` from
|
|
9
|
+
* `@marktiderman/genesis-notifications/server` (never from the app).
|
|
6
10
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
11
|
+
import { GENESIS_TEST_CATEGORY, GENESIS_TEST_TYPE, MESSAGE_ACTIONS, defineNotifications } from "@marktiderman/genesis-notifications";
|
|
12
|
+
import { copy } from "@/copy";
|
|
9
13
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
14
|
+
export const notifications = defineNotifications({
|
|
15
|
+
categories: {
|
|
16
|
+
activity: { label: copy.push.activityTitle, description: copy.push.activityDescription },
|
|
17
|
+
...GENESIS_TEST_CATEGORY,
|
|
18
|
+
},
|
|
19
|
+
actions: { message: MESSAGE_ACTIONS },
|
|
20
|
+
types: {
|
|
21
|
+
// An example: something in the app needs the person. Rename or replace it.
|
|
22
|
+
"starter.activity": {
|
|
23
|
+
category: "activity",
|
|
24
|
+
channels: { in_app: true, push: true, email: false },
|
|
25
|
+
render: (data) => ({
|
|
26
|
+
title: typeof data.title === "string" ? data.title : copy.push.activityTitle,
|
|
27
|
+
...(typeof data.body === "string" ? { body: data.body } : {}),
|
|
28
|
+
...(typeof data.url === "string" ? { url: data.url } : {}),
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
...GENESIS_TEST_TYPE,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -14,17 +14,30 @@
|
|
|
14
14
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
15
15
|
import * as Application from "expo-application";
|
|
16
16
|
import Constants from "expo-constants";
|
|
17
|
+
import * as Crypto from "expo-crypto";
|
|
17
18
|
import * as Notifications from "expo-notifications";
|
|
18
19
|
import { router, type Href } from "expo-router";
|
|
19
20
|
import { AppState, Linking, Platform } from "react-native";
|
|
20
|
-
import { createPush
|
|
21
|
+
import { createPush } from "@marktiderman/genesis-native/push";
|
|
22
|
+
import { notificationsPushBackend, pushOptionsFrom } from "@marktiderman/genesis-notifications/native";
|
|
21
23
|
import starter from "../../starter.config";
|
|
24
|
+
import { chatPushCategory } from "@marktiderman/genesis-chat/native";
|
|
22
25
|
import { copy } from "@/copy";
|
|
26
|
+
import { onChatPushResponse } from "./chat";
|
|
23
27
|
import { linkHold, links } from "./links";
|
|
28
|
+
import { notifications } from "./notifications";
|
|
24
29
|
import { supabase } from "./supabase";
|
|
25
30
|
|
|
26
|
-
/**
|
|
27
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The kinds of notification the app sends (an Android channel each) and the action buttons, from
|
|
33
|
+
* the registry, plus chat's when it's on: its notifications carry Reply and Mark read (`chat.tsx`
|
|
34
|
+
* registers them).
|
|
35
|
+
*/
|
|
36
|
+
const fromRegistry = pushOptionsFrom(notifications);
|
|
37
|
+
export const pushOptions = {
|
|
38
|
+
...fromRegistry,
|
|
39
|
+
categories: [...(fromRegistry.categories ?? []), ...(starter.features.chat ? [chatPushCategory()] : [])],
|
|
40
|
+
};
|
|
28
41
|
|
|
29
42
|
export function createStarterPush() {
|
|
30
43
|
return createPush({
|
|
@@ -32,8 +45,11 @@ export function createStarterPush() {
|
|
|
32
45
|
platform: Platform.OS,
|
|
33
46
|
projectId: (Constants.expoConfig?.extra?.eas?.projectId as string | undefined) ?? Constants.easConfig?.projectId ?? null,
|
|
34
47
|
appVersion: Application.nativeApplicationVersion,
|
|
35
|
-
backend:
|
|
36
|
-
|
|
48
|
+
backend: notificationsPushBackend(supabase),
|
|
49
|
+
...pushOptions,
|
|
50
|
+
onResponse: onChatPushResponse,
|
|
51
|
+
// This install's id: a token moves to another login only from this phone. Hermes has no crypto.randomUUID.
|
|
52
|
+
randomUUID: Crypto.randomUUID,
|
|
37
53
|
storage: AsyncStorage,
|
|
38
54
|
appState: AppState,
|
|
39
55
|
openSettings: Linking.openSettings,
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
# CLI's defaults. See https://supabase.com/docs/guides/local-development/cli/config
|
|
3
3
|
project_id = "genesis-rn-starter"
|
|
4
4
|
|
|
5
|
+
# The API serves `genesis_chat` too (features.chat): its tables under row level security and its
|
|
6
|
+
# functions, which are the chat client's only writes.
|
|
7
|
+
[api]
|
|
8
|
+
schemas = ["public", "graphql_public", "genesis_chat"]
|
|
9
|
+
|
|
5
10
|
# Sign-up asks the person to confirm their email. The link confirms it on Supabase's side and
|
|
6
11
|
# then opens `site_url`, not the app; the app's copy says to come back and sign in. (Opening the
|
|
7
12
|
# app from the link needs `emailRedirectTo`, a redirect URL here and a screen that exchanges the
|