@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 CHANGED
@@ -11,7 +11,7 @@ replies, threads, reactions, read state, live updates and push.
11
11
  | `/web` | Renderers on genesis-ui: inbox, thread, composer (text, photos, voice, video, emoji, scheduled send), media, topics, search, availability, broadcast, and the chat dock. |
12
12
  | `/native` | Beta: screens and parts on genesis-ui-native (inbox, thread, search, availability), voice notes, photos and video, and the push block's glue. See "On native" below. |
13
13
  | `/server` | `createChatRunner`: works the outbox (push, transcripts, storage cleanup). |
14
- | `migrations/0001_genesis_chat.sql` … `0004_genesis_chat_tenants.sql` | The schema, copied into your app by `genesis add chat` in order, each with its pgTAP test. 0003 makes `search_messages` return a hit's `thread_root_id`; 0004 puts every conversation in a tenant (see Tenants). |
14
+ | `migrations/0001_genesis_chat.sql` … `0005_genesis_chat_attachment_paths.sql` | The schema, copied into your app by `genesis add chat` in order, each with its pgTAP test. 0003 makes `search_messages` return a hit's `thread_root_id`; 0004 puts every conversation in a tenant (see Tenants). |
15
15
 
16
16
  ## On the web
17
17
 
package/dist/native.d.ts CHANGED
@@ -36,6 +36,8 @@ interface ChatOrganiseCopy {
36
36
  topicClosedDone: string;
37
37
  topicReopenedDone: string;
38
38
  schedule: string;
39
+ /** The hint on Send when it can schedule. */
40
+ scheduleHoldHint: string;
39
41
  scheduleTitle: string;
40
42
  scheduleHint: string;
41
43
  schedulePick: string;
@@ -285,7 +287,7 @@ declare function fill(text: string, values: Record<string, string | number>): st
285
287
  *
286
288
  * import * as Audio from "expo-audio"; // voice notes
287
289
  * import * as ImagePicker from "expo-image-picker"; // photos and videos
288
- * import * as Haptics from "expo-haptics"; // send and record
290
+ * import * as Haptics from "expo-haptics"; // send and record (Genesis's module is used when this is left out)
289
291
  * import * as Clipboard from "expo-clipboard"; // copy, paste a picture
290
292
  * import { KeyboardAvoidingView } from "react-native-keyboard-controller";
291
293
  * import AsyncStorage from "@react-native-async-storage/async-storage"; // drafts
package/dist/native.js CHANGED
@@ -6,10 +6,10 @@ import { summarizeReactions, parseMentions, startsDay, dayLabel, itemTime, itemS
6
6
  import { formatDuration, nextPlaybackRate, ChatError, CHAT_LIMITS, fileExtension, isAllowedExtension, attachmentKindFor, awaySummary, WEEKDAYS, minutesOf, waveformFromMetering, recordingLimitMs, CHAT_BUCKET, randomId } from './chunk-5XYDVUPS.js';
7
7
  export { CHAT_MARK_READ_ACTION, CHAT_PUSH_CATEGORY, CHAT_REPLY_ACTION, PUSH_REPLY_WAIT_MS, chatNotificationActions, chatPath, chatPushCategory, chatPushCopy, chatPushPayload, chatThreadMatch, conversationIdFromData, failedReply, handleChatPushResponse, registerChatNotificationActions, replyClientId, replyClientIdFor } from './chunk-BTG4JWLF.js';
8
8
  import { createContext, memo, useMemo, useState, useCallback, useRef, useContext, useSyncExternalStore, useLayoutEffect, useEffect, useReducer } from 'react';
9
- import { NativeText, NativeAvatar, NativeImage, NativeIcon, NativeButton, LIGHTBOX_DISMISS_DISTANCE, LIGHTBOX_DISMISS_VELOCITY, LIGHTBOX_MAX_ZOOM, lightboxPanLimit, lightboxPinchScale, lightboxShouldDismiss, NativeProgress, useToast, NativeSheet, NativeDatePicker, NativeTimePicker, NativeListItem, NativeSkeleton, NativeEmptyState, NativeTextarea, NativeSwitch, NativeCombobox, NativeChipGroup, NativeChip, NativeInput, NativeSearchBar, NativeInlineAlert, NativeLightbox, useGenesisModules, NativeThreadList, NativeSheetScrollView, NativeCheckbox, NativeBadge } from '@marktiderman/genesis-ui-native/components';
9
+ import { NativeText, NativeAvatar, NativeImage, NativeIcon, NativeButton, LIGHTBOX_DISMISS_DISTANCE, LIGHTBOX_DISMISS_VELOCITY, LIGHTBOX_MAX_ZOOM, lightboxPanLimit, lightboxPinchScale, lightboxShouldDismiss, useGenesisModules, NativeProgress, useToast, NativeSheet, NativeDatePicker, NativeTimePicker, NativeListItem, NativeSkeleton, NativeEmptyState, NativeTextarea, NativeSwitch, NativeCombobox, NativeChipGroup, NativeChip, NativeInput, NativeSearchBar, NativeComposerBar, NativeInlineAlert, NativeLightbox, NativeThreadList, NativeSheetScrollView, NativeCheckbox, NativeBadge } from '@marktiderman/genesis-ui-native/components';
10
10
  import { InboxPage, SettingsSubPage, getThreadPageStackOptions, formatInboxTime } from '@marktiderman/genesis-ui-native/layouts';
11
- import { Pressable, Animated, PanResponder, View, Linking, useWindowDimensions, ActivityIndicator, AppState, Modal, AccessibilityInfo, ScrollView, FlatList, TextInput, Platform, KeyboardAvoidingView, Alert } from 'react-native';
12
- import { useThemeRoles, useReducedMotion } from '@marktiderman/genesis-ui-native/hooks';
11
+ import { Pressable, Animated, PanResponder, View, Linking, useWindowDimensions, ActivityIndicator, AppState, Modal, AccessibilityInfo, ScrollView, FlatList, Platform, KeyboardAvoidingView, Alert } from 'react-native';
12
+ import { useThemeRoles, sentBubbleColor, playHaptic, useReducedMotion } from '@marktiderman/genesis-ui-native/hooks';
13
13
  import { reportError } from '@marktiderman/genesis-core/errors';
14
14
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
15
15
  import { useQueryClient } from '@tanstack/react-query';
@@ -35,6 +35,7 @@ var chatOrganiseCopy = {
35
35
  topicClosedDone: "Closed {name}",
36
36
  topicReopenedDone: "Reopened {name}",
37
37
  schedule: "Schedule message",
38
+ scheduleHoldHint: "Touch and hold to schedule",
38
39
  scheduleTitle: "Schedule message",
39
40
  scheduleHint: "It sends at this time, in your time zone, as if you'd sent it then.",
40
41
  schedulePick: "Pick a date and time",
@@ -256,9 +257,15 @@ var EMPTY_MODULES = Object.freeze({});
256
257
  var DEFAULT = { modules: EMPTY_MODULES, copy: resolveChatCopy(), person: () => void 0 };
257
258
  var Context = createContext(DEFAULT);
258
259
  function ChatNativeProvider({ modules = EMPTY_MODULES, copy, getPerson, children }) {
260
+ const { haptics: genesisHaptics } = useGenesisModules();
259
261
  const value = useMemo(
260
- () => ({ modules, copy: resolveChatCopy(copy), person: (id) => id && getPerson ? getPerson(id) : void 0 }),
261
- [modules, copy, getPerson]
262
+ () => ({
263
+ // Chat's own haptics module, else the one the app gave Genesis, so it's passed once.
264
+ modules: modules.haptics || !genesisHaptics ? modules : { ...modules, haptics: genesisHaptics },
265
+ copy: resolveChatCopy(copy),
266
+ person: (id) => id && getPerson ? getPerson(id) : void 0
267
+ }),
268
+ [modules, genesisHaptics, copy, getPerson]
262
269
  );
263
270
  return /* @__PURE__ */ jsx(Context.Provider, { value, children });
264
271
  }
@@ -1389,7 +1396,7 @@ function MessageBubbleImpl(props) {
1389
1396
  const quote = message?.replyToId ?? pending?.input.replyToId ?? null;
1390
1397
  const quoted = quote && repliedTo ? repliedTo : null;
1391
1398
  const invisible = Boolean(message && !message.deletedAt && !body && !attachments.length && !preview && !quote && !moderation && cards.length && !shownCards.length);
1392
- const bubbleColor = mine ? colors.tint : colors.surface;
1399
+ const bubbleColor = mine ? sentBubbleColor(colors) : colors.surface;
1393
1400
  const fg = mine ? "text-primary-foreground" : void 0;
1394
1401
  const textStyle = mine ? { fontSize: 17, lineHeight: 22 } : { fontSize: 17, lineHeight: 22, color: colors.label };
1395
1402
  return /* @__PURE__ */ jsxs(
@@ -1576,18 +1583,16 @@ function ChatInboxScreen({ onOpen, onStart, kind, kinds, excludeKinds, archived,
1576
1583
  }
1577
1584
  );
1578
1585
  }
1579
-
1580
- // src/native/modules.ts
1586
+ var HAPTIC_KIND = {
1587
+ send: "light",
1588
+ "record-lock": "light",
1589
+ "record-start": "medium",
1590
+ select: "select",
1591
+ error: "error",
1592
+ "record-cancel": "warning"
1593
+ };
1581
1594
  function haptic(haptics, event) {
1582
- if (!haptics) return;
1583
- try {
1584
- const style = (s) => s;
1585
- const p = event === "send" || event === "record-lock" ? haptics.impactAsync(style(haptics.ImpactFeedbackStyle.Light)) : event === "record-start" ? haptics.impactAsync(style(haptics.ImpactFeedbackStyle.Medium)) : event === "select" ? haptics.selectionAsync() : haptics.notificationAsync(
1586
- style(event === "error" ? haptics.NotificationFeedbackType.Error : haptics.NotificationFeedbackType.Warning)
1587
- );
1588
- void p?.catch?.(() => void 0);
1589
- } catch {
1590
- }
1595
+ playHaptic(haptics, HAPTIC_KIND[event]);
1591
1596
  }
1592
1597
 
1593
1598
  // src/native/video-recorder-state.ts
@@ -3483,6 +3488,7 @@ function ComposerWithVoice(props) {
3483
3488
  function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo, onSchedule, placeholder, voice, userId, testID = "chat-composer" }) {
3484
3489
  const { modules, copy } = useChatNative();
3485
3490
  const colors = useThemeRoles();
3491
+ const genesis = useGenesisModules();
3486
3492
  const { state, dispatch } = composer;
3487
3493
  const [attachOpen, setAttachOpen] = useState(false);
3488
3494
  const [canPaste, setCanPaste] = useState(false);
@@ -3506,7 +3512,7 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
3506
3512
  if (!sendable) return;
3507
3513
  const payload = composer.take();
3508
3514
  if (!payload) return;
3509
- haptic(modules.haptics, "send");
3515
+ if (!genesis.haptics) haptic(modules.haptics, "send");
3510
3516
  onSend(payload);
3511
3517
  };
3512
3518
  const openAttach = async () => {
@@ -3550,9 +3556,9 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
3550
3556
  haptic(modules.haptics, "error");
3551
3557
  }
3552
3558
  };
3553
- return /* @__PURE__ */ jsxs(View, { testID, style: { backgroundColor: colors.groupedBackground, paddingHorizontal: 8, paddingTop: 6, paddingBottom: 6, gap: 6 }, children: [
3554
- notice ? /* @__PURE__ */ jsx(NativeText, { testID: `${testID}-notice`, accessibilityLiveRegion: "polite", preset: "caption", style: { color: colors.destructive, paddingHorizontal: 8 }, children: notice }) : null,
3555
- state.replyTo ? /* @__PURE__ */ jsxs(View, { testID: `${testID}-reply`, style: { flexDirection: "row", alignItems: "center", paddingLeft: 12, borderLeftWidth: 3, borderLeftColor: colors.tint, marginHorizontal: 4 }, children: [
3559
+ const above = /* @__PURE__ */ jsxs(Fragment, { children: [
3560
+ notice ? /* @__PURE__ */ jsx(NativeText, { testID: `${testID}-notice`, accessibilityLiveRegion: "polite", preset: "caption", style: { color: colors.destructive, paddingHorizontal: 4 }, children: notice }) : null,
3561
+ state.replyTo ? /* @__PURE__ */ jsxs(View, { testID: `${testID}-reply`, style: { flexDirection: "row", alignItems: "center", paddingLeft: 12, borderLeftWidth: 3, borderLeftColor: colors.tint }, children: [
3556
3562
  /* @__PURE__ */ jsxs(View, { style: { flex: 1 }, children: [
3557
3563
  /* @__PURE__ */ jsx(NativeText, { preset: "caption", style: { color: colors.tint, fontWeight: "600" }, children: fill(copy.replyingTo, { name: state.replyTo.name }) }),
3558
3564
  /* @__PURE__ */ jsx(NativeText, { preset: "caption", numberOfLines: 1, style: { color: colors.secondaryLabel }, children: state.replyTo.preview })
@@ -3573,47 +3579,40 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
3573
3579
  children: /* @__PURE__ */ jsx(NativeIcon, { name: "close", size: 14, color: colors.surface })
3574
3580
  }
3575
3581
  )
3576
- ] }, a.key)) }) : null,
3577
- /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "flex-end", gap: 4 }, children: [
3578
- recording && voice ? /* @__PURE__ */ jsx(RecordingBar, { voice, testID }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3579
- modules.imagePicker || modules.clipboard?.getImageAsync ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-attach`, icon: "plus", label: copy.attach, onPress: () => void openAttach(), color: colors.tint, disabled: !ready }) : null,
3580
- onRecordVideo ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-video`, icon: "video", label: copy.recordVideo, onPress: onRecordVideo, color: colors.tint, disabled: !ready }) : null,
3581
- /* @__PURE__ */ jsx(
3582
- TextInput,
3583
- {
3584
- testID: `${testID}-input`,
3585
- value: state.text,
3586
- onChangeText: (text) => {
3587
- dispatch({ type: "text", text });
3588
- if (text) signalTyping?.();
3589
- },
3590
- onSelectionChange: (e) => {
3591
- selection.current = e.nativeEvent.selection;
3592
- },
3593
- placeholder: placeholder ?? copy.placeholder,
3594
- placeholderTextColor: colors.tertiaryLabel,
3595
- accessibilityLabel: placeholder ?? copy.placeholder,
3596
- editable: ready,
3597
- multiline: true,
3598
- maxLength: CHAT_LIMITS.bodyChars,
3599
- style: {
3600
- flex: 1,
3601
- minHeight: 40,
3602
- maxHeight: 140,
3603
- paddingHorizontal: 14,
3604
- paddingTop: 10,
3605
- paddingBottom: 10,
3606
- borderRadius: 20,
3607
- fontSize: 17,
3608
- color: colors.label,
3609
- backgroundColor: colors.surface
3610
- }
3611
- }
3612
- ),
3613
- /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-emoji`, icon: "smile", label: copy.addEmoji, onPress: () => setEmojiOpen(true), color: colors.secondaryLabel, disabled: !ready })
3614
- ] }),
3615
- sendable && !recording ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-send`, icon: "arrow-up", label: copy.send, onPress: send, onLongPress: onSchedule, longPressLabel: onSchedule ? copy.schedule : void 0, filled: true, color: colors.tint }) : voice ? /* @__PURE__ */ jsx(MicButton, { voice, testID, disabled: !ready }) : /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-send`, icon: "arrow-up", label: copy.send, onPress: send, filled: true, color: colors.tint, disabled: true })
3616
- ] }),
3582
+ ] }, a.key)) }) : null
3583
+ ] });
3584
+ const canAttach = Boolean(modules.imagePicker || modules.clipboard?.getImageAsync);
3585
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3586
+ /* @__PURE__ */ jsx(
3587
+ NativeComposerBar,
3588
+ {
3589
+ testID,
3590
+ value: state.text,
3591
+ onChangeText: (text) => {
3592
+ dispatch({ type: "text", text });
3593
+ if (text) signalTyping?.();
3594
+ },
3595
+ onSelectionChange: (e) => {
3596
+ selection.current = e.nativeEvent.selection;
3597
+ },
3598
+ onSend: send,
3599
+ hasContent: sendable && !recording,
3600
+ editable: ready,
3601
+ placeholder: placeholder ?? copy.placeholder,
3602
+ sendLabel: copy.send,
3603
+ maxLength: CHAT_LIMITS.bodyChars,
3604
+ sendActions: onSchedule ? [{ id: "schedule", label: copy.schedule, onPress: onSchedule }] : void 0,
3605
+ sendActionsHint: copy.scheduleHoldHint,
3606
+ above,
3607
+ leading: canAttach || onRecordVideo ? /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row" }, children: [
3608
+ canAttach ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-attach`, icon: "plus", label: copy.attach, onPress: () => void openAttach(), color: colors.tint, disabled: !ready }) : null,
3609
+ onRecordVideo ? /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-video`, icon: "video", label: copy.recordVideo, onPress: onRecordVideo, color: colors.tint, disabled: !ready }) : null
3610
+ ] }) : null,
3611
+ trailing: recording ? null : /* @__PURE__ */ jsx(IconButton, { testID: `${testID}-emoji`, icon: "smile", label: copy.addEmoji, onPress: () => setEmojiOpen(true), color: colors.secondaryLabel, disabled: !ready }),
3612
+ idleAction: voice ? /* @__PURE__ */ jsx(MicButton, { voice, testID, disabled: !ready }) : null,
3613
+ replaceInput: recording && voice ? /* @__PURE__ */ jsx(RecordingBar, { voice, testID }) : null
3614
+ }
3615
+ ),
3617
3616
  /* @__PURE__ */ jsx(ChatEmojiPickerSheet, { open: emojiOpen, onClose: () => setEmojiOpen(false), onSelect: insertEmoji, userId, testID: `${testID}-emoji-sheet` }),
3618
3617
  /* @__PURE__ */ jsx(NativeSheet, { open: attachOpen, onOpenChange: setAttachOpen, testID: `${testID}-attach-sheet`, children: /* @__PURE__ */ jsxs(View, { children: [
3619
3618
  modules.imagePicker ? /* @__PURE__ */ jsx(NativeListItem, { testID: `${testID}-attach-library`, title: copy.attachLibrary, leading: /* @__PURE__ */ jsx(NativeIcon, { name: "image" }), onPress: () => void pick("library") }) : null,
@@ -3627,13 +3626,9 @@ function IconButton({
3627
3626
  label,
3628
3627
  onPress,
3629
3628
  color,
3630
- filled = false,
3631
3629
  disabled = false,
3632
- onLongPress,
3633
- longPressLabel,
3634
3630
  testID
3635
3631
  }) {
3636
- const colors = useThemeRoles();
3637
3632
  return /* @__PURE__ */ jsx(
3638
3633
  Pressable,
3639
3634
  {
@@ -3643,12 +3638,8 @@ function IconButton({
3643
3638
  accessibilityState: { disabled },
3644
3639
  disabled,
3645
3640
  onPress,
3646
- onLongPress,
3647
- delayLongPress: onLongPress ? 400 : void 0,
3648
- accessibilityActions: onLongPress && longPressLabel ? [{ name: "longpress", label: longPressLabel }] : void 0,
3649
- onAccessibilityAction: onLongPress ? (e) => e.nativeEvent.actionName === "longpress" && onLongPress() : void 0,
3650
3641
  style: { width: 44, height: 44, alignItems: "center", justifyContent: "center", opacity: disabled ? 0.4 : 1 },
3651
- children: filled ? /* @__PURE__ */ jsx(View, { style: { width: 34, height: 34, borderRadius: 17, backgroundColor: color, alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ jsx(NativeIcon, { name: icon, size: 18, color: colors.surface, weight: "semibold" }) }) : /* @__PURE__ */ jsx(NativeIcon, { name: icon, size: 24, color })
3642
+ children: /* @__PURE__ */ jsx(NativeIcon, { name: icon, size: 24, color })
3652
3643
  }
3653
3644
  );
3654
3645
  }
@@ -4187,11 +4178,19 @@ function ChatThreadScreen(props) {
4187
4178
  const observer = conv.role === "observer";
4188
4179
  const { loadUntil } = conv;
4189
4180
  const jumpSeq = jumpTo?.seq;
4190
- const jumpMessageId = jumpTo?.messageId ?? null;
4181
+ const firstPageFailed = Boolean(conv.error) && conv.messages.length === 0;
4182
+ const jumpMessageId = firstPageFailed ? null : jumpTo?.messageId ?? null;
4183
+ const jumpBlocked = firstPageFailed && Boolean(jumpTo);
4184
+ useEffect(() => {
4185
+ if (jumpBlocked) fail();
4186
+ }, [jumpBlocked, fail]);
4187
+ const jumpLoadFailed = useRef(false);
4191
4188
  const onLoadUntil = useCallback(
4192
4189
  (id) => {
4190
+ jumpLoadFailed.current = false;
4193
4191
  if (id !== jumpMessageId || jumpSeq == null) return Promise.resolve(false);
4194
4192
  return loadUntil(jumpSeq).catch(() => {
4193
+ jumpLoadFailed.current = true;
4195
4194
  fail();
4196
4195
  return false;
4197
4196
  });
@@ -4205,7 +4204,10 @@ function ChatThreadScreen(props) {
4205
4204
  },
4206
4205
  [copy.jumpedTo, nameOf, attachmentKinds]
4207
4206
  );
4208
- const onJumpFailed = useCallback(() => toast.show({ title: copy.messageGone }), [toast, copy.messageGone]);
4207
+ const onJumpFailed = useCallback(() => {
4208
+ if (jumpLoadFailed.current) jumpLoadFailed.current = false;
4209
+ else toast.show({ title: copy.messageGone });
4210
+ }, [toast, copy.messageGone]);
4209
4211
  const reattachable = useCallback((files) => files.every((f) => !f.lost || f.kind === "image" || f.kind === "video"), []);
4210
4212
  const renderItem = useCallback(
4211
4213
  (row, { highlighted }) => {