@poolse/react-native 3.10.1 → 3.10.3

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/dist/index.cjs CHANGED
@@ -851,6 +851,7 @@ function Avatar({
851
851
  const theme = useTheme();
852
852
  const dim = SIZES[size];
853
853
  const initials = computeInitials(name);
854
+ const [failedSrc, setFailedSrc] = react.useState(null);
854
855
  const tint = seed ? userColor(seed) : theme.colors.accent;
855
856
  const fontSize = size === "xs" ? 9 : size === "sm" ? 11 : size === "lg" ? 22 : 15;
856
857
  const badgeSize = Math.max(8, Math.round(dim * 0.32));
@@ -872,10 +873,11 @@ function Avatar({
872
873
  accessibilityRole: "image",
873
874
  accessibilityLabel: agent ? `${name ?? "Agent"} (agent)` : name ?? "avatar",
874
875
  children: [
875
- src ? /* @__PURE__ */ jsxRuntime.jsx(
876
+ src && failedSrc !== src ? /* @__PURE__ */ jsxRuntime.jsx(
876
877
  reactNative.Image,
877
878
  {
878
879
  source: { uri: src },
880
+ onError: () => setFailedSrc(src),
879
881
  style: { width: dim, height: dim, borderRadius: radius },
880
882
  accessible: false
881
883
  }
@@ -905,7 +907,7 @@ function Avatar({
905
907
  ]
906
908
  }
907
909
  ) : null,
908
- lookupId ? /* @__PURE__ */ jsxRuntime.jsx(LivePresenceBadge, { id: lookupId, size: badgeSize, style: badgeStyle }) : presence && presence !== true ? /* @__PURE__ */ jsxRuntime.jsx(
910
+ lookupId ? /* @__PURE__ */ jsxRuntime.jsx(OptionalLivePresenceBadge, { id: lookupId, size: badgeSize, style: badgeStyle }) : presence && presence !== true ? /* @__PURE__ */ jsxRuntime.jsx(
909
911
  PresenceBadge,
910
912
  {
911
913
  state: presence,
@@ -932,6 +934,9 @@ function Avatar({
932
934
  }
933
935
  );
934
936
  }
937
+ function OptionalLivePresenceBadge(props) {
938
+ return react$1.useOptionalPoolse() ? /* @__PURE__ */ jsxRuntime.jsx(LivePresenceBadge, { ...props }) : null;
939
+ }
935
940
  function LivePresenceBadge({
936
941
  id,
937
942
  size,
@@ -3253,7 +3258,9 @@ var MessageComposer = react.forwardRef(
3253
3258
  emojiPicker = true,
3254
3259
  accessory,
3255
3260
  formattingToolbar = false,
3256
- commands
3261
+ commands,
3262
+ onMic,
3263
+ recordingBar
3257
3264
  }, ref) {
3258
3265
  const theme = useTheme();
3259
3266
  const inputRef = react.useRef(null);
@@ -3295,6 +3302,17 @@ var MessageComposer = react.forwardRef(
3295
3302
  if (!controlled) setInnerValue("");
3296
3303
  onChangeTextRef.current?.("");
3297
3304
  },
3305
+ getText: () => valueRef.current,
3306
+ setText: (text) => setValueRef.current(text),
3307
+ insertText: (text) => {
3308
+ const now = valueRef.current;
3309
+ const sel = selectionRef.current ?? { start: now.length, end: now.length };
3310
+ const caret = sel.start + text.length;
3311
+ applyTextRef.current(now.slice(0, sel.start) + text + now.slice(sel.end), {
3312
+ start: caret,
3313
+ end: caret
3314
+ });
3315
+ },
3298
3316
  setSelection: (start, end) => {
3299
3317
  selectionRef.current = { start, end };
3300
3318
  inputRef.current?.setSelection?.(start, end);
@@ -3329,14 +3347,19 @@ var MessageComposer = react.forwardRef(
3329
3347
  const replyId = replyingTo?.id;
3330
3348
  const attachmentIds = readyAttachmentIds;
3331
3349
  setDraft("");
3332
- upload.reset();
3333
3350
  const opts = {
3334
3351
  ...replyId ? { quoted_message_id: replyId } : {},
3335
3352
  ...attachmentIds.length > 0 ? { attachment_ids: attachmentIds } : {}
3336
3353
  };
3337
3354
  try {
3338
- await onSend(body, opts);
3355
+ if (await onSend(body, opts) === false) {
3356
+ if (!controlled) setInnerValue((now) => now ? now : body);
3357
+ else onChangeTextRef.current?.(body);
3358
+ return;
3359
+ }
3360
+ upload.reset();
3339
3361
  } catch (err) {
3362
+ upload.reset();
3340
3363
  const outcome = react$1.readDlpError(err);
3341
3364
  if (outcome) setDlp({ outcome, body, opts });
3342
3365
  if (!controlled) setInnerValue((now) => now ? now : body);
@@ -3357,6 +3380,12 @@ var MessageComposer = react.forwardRef(
3357
3380
  setCursor(sel.end);
3358
3381
  setTimeout(() => inputRef.current?.setSelection?.(sel.start, sel.end), 0);
3359
3382
  };
3383
+ const valueRef = react.useRef(value);
3384
+ valueRef.current = value;
3385
+ const setValueRef = react.useRef(setValue);
3386
+ setValueRef.current = setValue;
3387
+ const applyTextRef = react.useRef(applyText);
3388
+ applyTextRef.current = applyText;
3360
3389
  const format2 = (kind) => {
3361
3390
  const sel = selectionRef.current ?? { start: value.length, end: value.length };
3362
3391
  const r = react$1.applyFormat(value, sel, kind);
@@ -3426,7 +3455,7 @@ var MessageComposer = react.forwardRef(
3426
3455
  ...Array.isArray(formattingToolbar) ? { actions: formattingToolbar } : {}
3427
3456
  }
3428
3457
  ) : null,
3429
- /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles15.row, children: [
3458
+ recordingBar ? recordingBar : /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles15.row, children: [
3430
3459
  attachments && onAttachPress ? /* @__PURE__ */ jsxRuntime.jsx(
3431
3460
  reactNative.Pressable,
3432
3461
  {
@@ -3480,7 +3509,18 @@ var MessageComposer = react.forwardRef(
3480
3509
  ]
3481
3510
  }
3482
3511
  ),
3483
- /* @__PURE__ */ jsxRuntime.jsx(
3512
+ onMic && !isEditing && value.trim().length === 0 && readyAttachmentIds.length === 0 && !isUploading ? /* @__PURE__ */ jsxRuntime.jsx(
3513
+ reactNative.Pressable,
3514
+ {
3515
+ onPress: onMic,
3516
+ disabled,
3517
+ hitSlop: 8,
3518
+ style: [styles15.sendBtn, { backgroundColor: theme.colors.accent }],
3519
+ accessibilityRole: "button",
3520
+ accessibilityLabel: "Record a voice message",
3521
+ children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "mic", size: 18, color: theme.colors.accentText, label: null })
3522
+ }
3523
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
3484
3524
  reactNative.Pressable,
3485
3525
  {
3486
3526
  onPress: handleSend,
@@ -3645,129 +3685,146 @@ var styles15 = reactNative.StyleSheet.create({
3645
3685
  padding: 6
3646
3686
  }
3647
3687
  });
3648
- function MentionInput({
3649
- conversationId,
3650
- onSend,
3651
- maxSuggestions = 6,
3652
- labelFor,
3653
- value: valueProp,
3654
- onChangeText,
3655
- onSelectionChange,
3656
- groups,
3657
- ...composerProps
3658
- }) {
3659
- const theme = useTheme();
3660
- const chat = react$1.usePoolse();
3661
- const { me } = react$1.useMe();
3662
- const { members } = react$1.useMembers(conversationId);
3663
- const composerRef = react.useRef(null);
3664
- const [innerText, setInnerText] = react.useState("");
3665
- const text = valueProp ?? innerText;
3666
- const [cursor, setCursor] = react.useState(0);
3667
- const [dismissedAt, setDismissedAt] = react.useState(null);
3668
- const pickedRef = react.useRef([]);
3669
- const setText = (next) => {
3670
- if (valueProp === void 0) setInnerText(next);
3671
- onChangeText?.(next);
3672
- };
3673
- const query = react.useMemo(() => {
3674
- const q = activeMentionQuery(text, cursor);
3675
- return q && q.start !== dismissedAt ? q : null;
3676
- }, [text, cursor, dismissedAt]);
3677
- const candidates = react.useMemo(() => {
3678
- if (!query) return [];
3679
- const all = members.filter((m) => m.user_id !== me?.id).map((m) => ({
3680
- member: m,
3681
- externalId: m.external_id,
3682
- label: labelFor?.(m.external_id) ?? chat.users.peek(m.external_id)?.displayName ?? m.external_id
3683
- }));
3684
- return filterMentionCandidates(all, query.query, maxSuggestions);
3685
- }, [query, members, me?.id, labelFor, chat, maxSuggestions]);
3686
- const groupMatches = react.useMemo(
3687
- () => query && groups ? react$1.rankMentionGroups(groups, query.query, Math.max(0, maxSuggestions - candidates.length)) : [],
3688
- [query, groups, maxSuggestions, candidates.length]
3689
- );
3690
- const pickGroup = (g) => {
3691
- if (!query) return;
3692
- const next = insertMention(text, query.start, cursor, g.handle);
3693
- setText(next.text);
3694
- setCursor(next.cursor);
3695
- setTimeout(() => composerRef.current?.setSelection(next.cursor, next.cursor), 0);
3696
- };
3697
- const pick = (c) => {
3698
- if (!query) return;
3699
- const next = insertMention(text, query.start, cursor, c.label);
3700
- pickedRef.current = [...pickedRef.current, { userId: c.member.user_id, label: c.label }];
3701
- setText(next.text);
3702
- setCursor(next.cursor);
3703
- setTimeout(() => composerRef.current?.setSelection(next.cursor, next.cursor), 0);
3704
- };
3705
- const handleSend = async (body, opts) => {
3706
- const mentions = mentionedUserIds(body, pickedRef.current);
3707
- await onSend(body, { ...opts, ...mentions.length > 0 ? { mentions } : {} });
3708
- pickedRef.current = [];
3709
- };
3710
- const suggestions = query && candidates.length + groupMatches.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(
3711
- reactNative.View,
3712
- {
3713
- style: [
3714
- styles16.suggestions,
3715
- {
3716
- backgroundColor: theme.colors.surface,
3717
- borderColor: theme.colors.border,
3718
- borderRadius: theme.radii.md
3719
- },
3720
- theme.shadows.md
3721
- ],
3722
- accessibilityRole: "menu",
3723
- accessibilityLabel: "Mention suggestions",
3724
- children: [
3725
- /* @__PURE__ */ jsxRuntime.jsxs(reactNative.ScrollView, { keyboardShouldPersistTaps: "always", style: styles16.suggestionScroll, children: [
3726
- candidates.map((c) => /* @__PURE__ */ jsxRuntime.jsx(
3727
- MentionRow,
3728
- {
3729
- externalId: c.externalId,
3730
- label: c.label,
3731
- onPress: () => pick(c)
3732
- },
3733
- c.member.user_id
3734
- )),
3735
- groupMatches.map((g) => /* @__PURE__ */ jsxRuntime.jsx(GroupRow, { group: g, onPress: () => pickGroup(g) }, `group:${g.handle}`))
3736
- ] }),
3737
- /* @__PURE__ */ jsxRuntime.jsx(
3738
- reactNative.Pressable,
3688
+ var MentionInput = react.forwardRef(
3689
+ function MentionInput2({
3690
+ conversationId,
3691
+ onSend,
3692
+ maxSuggestions = 6,
3693
+ labelFor,
3694
+ value: valueProp,
3695
+ onChangeText,
3696
+ onSelectionChange,
3697
+ groups,
3698
+ ...composerProps
3699
+ }, ref) {
3700
+ const theme = useTheme();
3701
+ const chat = react$1.usePoolse();
3702
+ const { me } = react$1.useMe();
3703
+ const { members } = react$1.useMembers(conversationId);
3704
+ const composerRef = react.useRef(null);
3705
+ react.useImperativeHandle(
3706
+ ref,
3707
+ () => ({
3708
+ addFiles: (inputs) => composerRef.current?.addFiles(inputs),
3709
+ focus: () => composerRef.current?.focus(),
3710
+ clear: () => composerRef.current?.clear(),
3711
+ getText: () => composerRef.current?.getText() ?? "",
3712
+ setText: (t) => composerRef.current?.setText(t),
3713
+ insertText: (t) => composerRef.current?.insertText(t),
3714
+ setSelection: (start, end) => composerRef.current?.setSelection(start, end)
3715
+ }),
3716
+ []
3717
+ );
3718
+ const [innerText, setInnerText] = react.useState("");
3719
+ const text = valueProp ?? innerText;
3720
+ const [cursor, setCursor] = react.useState(0);
3721
+ const [dismissedAt, setDismissedAt] = react.useState(null);
3722
+ const pickedRef = react.useRef([]);
3723
+ const setText = (next) => {
3724
+ if (valueProp === void 0) setInnerText(next);
3725
+ onChangeText?.(next);
3726
+ };
3727
+ const query = react.useMemo(() => {
3728
+ const q = activeMentionQuery(text, cursor);
3729
+ return q && q.start !== dismissedAt ? q : null;
3730
+ }, [text, cursor, dismissedAt]);
3731
+ const candidates = react.useMemo(() => {
3732
+ if (!query) return [];
3733
+ const all = members.filter((m) => m.user_id !== me?.id).map((m) => ({
3734
+ member: m,
3735
+ externalId: m.external_id,
3736
+ label: labelFor?.(m.external_id) ?? chat.users.peek(m.external_id)?.displayName ?? m.external_id
3737
+ }));
3738
+ return filterMentionCandidates(all, query.query, maxSuggestions);
3739
+ }, [query, members, me?.id, labelFor, chat, maxSuggestions]);
3740
+ const groupMatches = react.useMemo(
3741
+ () => query && groups ? react$1.rankMentionGroups(groups, query.query, Math.max(0, maxSuggestions - candidates.length)) : [],
3742
+ [query, groups, maxSuggestions, candidates.length]
3743
+ );
3744
+ const pickGroup = (g) => {
3745
+ if (!query) return;
3746
+ const next = insertMention(text, query.start, cursor, g.handle);
3747
+ setText(next.text);
3748
+ setCursor(next.cursor);
3749
+ setTimeout(() => composerRef.current?.setSelection(next.cursor, next.cursor), 0);
3750
+ };
3751
+ const pick = (c) => {
3752
+ if (!query) return;
3753
+ const next = insertMention(text, query.start, cursor, c.label);
3754
+ pickedRef.current = [...pickedRef.current, { userId: c.member.user_id, label: c.label }];
3755
+ setText(next.text);
3756
+ setCursor(next.cursor);
3757
+ setTimeout(() => composerRef.current?.setSelection(next.cursor, next.cursor), 0);
3758
+ };
3759
+ const handleSend = async (body, opts) => {
3760
+ const mentions = mentionedUserIds(body, pickedRef.current);
3761
+ const result = await onSend(body, { ...opts, ...mentions.length > 0 ? { mentions } : {} });
3762
+ if (result === false) return false;
3763
+ pickedRef.current = [];
3764
+ return void 0;
3765
+ };
3766
+ const suggestions = query && candidates.length + groupMatches.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(
3767
+ reactNative.View,
3768
+ {
3769
+ style: [
3770
+ styles16.suggestions,
3739
3771
  {
3740
- onPress: () => setDismissedAt(query.start),
3741
- style: styles16.dismiss,
3742
- accessibilityRole: "button",
3743
- accessibilityLabel: "Dismiss suggestions",
3744
- hitSlop: 6,
3745
- children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "close", size: 14, color: theme.colors.textSubtle, label: null })
3746
- }
3747
- )
3748
- ]
3749
- }
3750
- ) : null;
3751
- return /* @__PURE__ */ jsxRuntime.jsx(
3752
- MessageComposer,
3753
- {
3754
- ref: composerRef,
3755
- ...composerProps,
3756
- ...labelFor ? { labelFor } : {},
3757
- value: text,
3758
- onChangeText: (next) => {
3759
- setText(next);
3760
- if (dismissedAt !== null && !next.includes("@", dismissedAt)) setDismissedAt(null);
3761
- },
3762
- onSelectionChange: (sel) => {
3763
- setCursor(sel.end);
3764
- onSelectionChange?.(sel);
3765
- },
3766
- onSend: handleSend,
3767
- accessory: suggestions
3768
- }
3769
- );
3770
- }
3772
+ backgroundColor: theme.colors.surface,
3773
+ borderColor: theme.colors.border,
3774
+ borderRadius: theme.radii.md
3775
+ },
3776
+ theme.shadows.md
3777
+ ],
3778
+ accessibilityRole: "menu",
3779
+ accessibilityLabel: "Mention suggestions",
3780
+ children: [
3781
+ /* @__PURE__ */ jsxRuntime.jsxs(reactNative.ScrollView, { keyboardShouldPersistTaps: "always", style: styles16.suggestionScroll, children: [
3782
+ candidates.map((c) => /* @__PURE__ */ jsxRuntime.jsx(
3783
+ MentionRow,
3784
+ {
3785
+ externalId: c.externalId,
3786
+ label: c.label,
3787
+ onPress: () => pick(c)
3788
+ },
3789
+ c.member.user_id
3790
+ )),
3791
+ groupMatches.map((g) => /* @__PURE__ */ jsxRuntime.jsx(GroupRow, { group: g, onPress: () => pickGroup(g) }, `group:${g.handle}`))
3792
+ ] }),
3793
+ /* @__PURE__ */ jsxRuntime.jsx(
3794
+ reactNative.Pressable,
3795
+ {
3796
+ onPress: () => setDismissedAt(query.start),
3797
+ style: styles16.dismiss,
3798
+ accessibilityRole: "button",
3799
+ accessibilityLabel: "Dismiss suggestions",
3800
+ hitSlop: 6,
3801
+ children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "close", size: 14, color: theme.colors.textSubtle, label: null })
3802
+ }
3803
+ )
3804
+ ]
3805
+ }
3806
+ ) : null;
3807
+ return /* @__PURE__ */ jsxRuntime.jsx(
3808
+ MessageComposer,
3809
+ {
3810
+ ref: composerRef,
3811
+ ...composerProps,
3812
+ ...labelFor ? { labelFor } : {},
3813
+ value: text,
3814
+ onChangeText: (next) => {
3815
+ setText(next);
3816
+ if (dismissedAt !== null && !next.includes("@", dismissedAt)) setDismissedAt(null);
3817
+ },
3818
+ onSelectionChange: (sel) => {
3819
+ setCursor(sel.end);
3820
+ onSelectionChange?.(sel);
3821
+ },
3822
+ onSend: handleSend,
3823
+ accessory: suggestions
3824
+ }
3825
+ );
3826
+ }
3827
+ );
3771
3828
  function MentionRow({
3772
3829
  externalId,
3773
3830
  label,
@@ -3884,6 +3941,23 @@ var styles16 = reactNative.StyleSheet.create({
3884
3941
  right: 8
3885
3942
  }
3886
3943
  });
3944
+ var alertConfirmDelete = () => new Promise((resolve) => {
3945
+ reactNative.Alert.alert(
3946
+ "Delete message?",
3947
+ "It will be deleted for everyone.",
3948
+ [
3949
+ { text: "Cancel", style: "cancel", onPress: () => resolve(false) },
3950
+ { text: "Delete", style: "destructive", onPress: () => resolve(true) }
3951
+ ],
3952
+ { cancelable: true, onDismiss: () => resolve(false) }
3953
+ );
3954
+ });
3955
+
3956
+ // src/internal/confirmDelete.ts
3957
+ async function confirmThenDelete(msg, confirm, remove) {
3958
+ if (!await confirm(msg)) return;
3959
+ await remove(msg.id).catch(() => void 0);
3960
+ }
3887
3961
 
3888
3962
  // src/internal/messageFocus.ts
3889
3963
  function latestMarkableId(messages) {
@@ -7312,6 +7386,7 @@ function FlatMessageRow({
7312
7386
  isEditing = false,
7313
7387
  onStartEdit,
7314
7388
  onDelete,
7389
+ extraActions,
7315
7390
  onOpenThread,
7316
7391
  onQuote,
7317
7392
  labelFor,
@@ -7573,7 +7648,8 @@ function FlatMessageRow({
7573
7648
  onQuote,
7574
7649
  onMarkUnread,
7575
7650
  onRemoveLinkPreview,
7576
- linkPreviews
7651
+ linkPreviews,
7652
+ extraActions
7577
7653
  }
7578
7654
  ) : null;
7579
7655
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -7750,7 +7826,8 @@ function MessageActions({
7750
7826
  pinned = false,
7751
7827
  onForward,
7752
7828
  onTranslate,
7753
- translated = false
7829
+ translated = false,
7830
+ extraActions = []
7754
7831
  }) {
7755
7832
  const theme = useTheme();
7756
7833
  const insets = useSafeInsets();
@@ -7780,6 +7857,14 @@ function MessageActions({
7780
7857
  });
7781
7858
  }
7782
7859
  }
7860
+ for (const a of extraActions) {
7861
+ items.push({
7862
+ label: a.label,
7863
+ icon: a.icon ?? "more-h",
7864
+ onPress: a.onPress,
7865
+ ...a.danger ? { danger: true } : {}
7866
+ });
7867
+ }
7783
7868
  if (isSelf && onEdit) items.push({ label: "Edit", icon: "edit", onPress: onEdit });
7784
7869
  if (isSelf && onDelete)
7785
7870
  items.push({ label: "Delete", icon: "trash", onPress: onDelete, danger: true });
@@ -7939,7 +8024,8 @@ function RowActionsSheet({
7939
8024
  onQuote,
7940
8025
  onMarkUnread,
7941
8026
  onRemoveLinkPreview,
7942
- linkPreviews
8027
+ linkPreviews,
8028
+ extraActions
7943
8029
  }) {
7944
8030
  const then = (fn) => () => {
7945
8031
  close();
@@ -7959,6 +8045,7 @@ function RowActionsSheet({
7959
8045
  ...threads && onOpenThread ? { onReplyInThread: then(onOpenThread) } : {},
7960
8046
  ...quotations && onQuote ? { onQuote: then(onQuote) } : {},
7961
8047
  ...onMarkUnread ? { onMarkUnread: then(onMarkUnread) } : {},
8048
+ ...extraActions && extraActions.length > 0 ? { extraActions: extraActions.map((a) => ({ ...a, onPress: then(a.onPress) })) } : {},
7962
8049
  ...onRemoveLinkPreview && previewUrls.length > 0 ? {
7963
8050
  previewUrls,
7964
8051
  onRemovePreview: (url) => {
@@ -8060,7 +8147,8 @@ function BubbleMessageRow({
8060
8147
  onMarkUnread,
8061
8148
  editHistory = true,
8062
8149
  onRetrySend,
8063
- onDiscardSend
8150
+ onDiscardSend,
8151
+ extraActions
8064
8152
  }) {
8065
8153
  const theme = useTheme();
8066
8154
  const isSelf = meId !== null && msg.sender_id === meId;
@@ -8317,7 +8405,8 @@ function BubbleMessageRow({
8317
8405
  onQuote,
8318
8406
  onMarkUnread,
8319
8407
  onRemoveLinkPreview,
8320
- linkPreviews
8408
+ linkPreviews,
8409
+ extraActions
8321
8410
  }
8322
8411
  ) : null
8323
8412
  ),
@@ -8443,7 +8532,8 @@ function ThreadView({
8443
8532
  showPresence = false,
8444
8533
  linkPreviews = true,
8445
8534
  follow = true,
8446
- alsoSendToChannel = true
8535
+ alsoSendToChannel = true,
8536
+ ...hooks
8447
8537
  }) {
8448
8538
  return /* @__PURE__ */ jsxRuntime.jsx(
8449
8539
  reactNative.Modal,
@@ -8467,7 +8557,8 @@ function ThreadView({
8467
8557
  showPresence,
8468
8558
  linkPreviews,
8469
8559
  follow,
8470
- alsoSendToChannel
8560
+ alsoSendToChannel,
8561
+ hooks
8471
8562
  }
8472
8563
  ) })
8473
8564
  }
@@ -8485,7 +8576,8 @@ function ThreadSheet({
8485
8576
  showPresence,
8486
8577
  linkPreviews,
8487
8578
  follow,
8488
- alsoSendToChannel
8579
+ alsoSendToChannel,
8580
+ hooks
8489
8581
  }) {
8490
8582
  const theme = useTheme();
8491
8583
  const followState = react$1.useThreadFollow(follow ? rootMessage.id : null);
@@ -8529,9 +8621,8 @@ function ThreadSheet({
8529
8621
  quotations: false,
8530
8622
  isEditing: editingId === msg.id,
8531
8623
  ...canEdit ? { onStartEdit: () => setEditingId(msg.id) } : {},
8532
- onDelete: () => {
8533
- void deleteReply(msg.id);
8534
- },
8624
+ onDelete: () => void confirmThenDelete(msg, hooks.confirmDelete ?? alertConfirmDelete, deleteReply),
8625
+ ...hooks.extraActions ? { extraActions: hooks.extraActions(msg) } : {},
8535
8626
  ...labelFor ? { labelFor } : {},
8536
8627
  ...avatarFor ? { avatarFor } : {},
8537
8628
  ...layout ? { layout } : {},
@@ -8549,6 +8640,7 @@ function ThreadSheet({
8549
8640
  meId,
8550
8641
  editingId,
8551
8642
  deleteReply,
8643
+ hooks,
8552
8644
  labelFor,
8553
8645
  avatarFor,
8554
8646
  layout,
@@ -8694,20 +8786,30 @@ function ThreadSheet({
8694
8786
  }
8695
8787
  )
8696
8788
  ] }) : null,
8789
+ hooks.composerAccessory,
8697
8790
  /* @__PURE__ */ jsxRuntime.jsx(
8698
8791
  MessageComposer,
8699
8792
  {
8793
+ ref: hooks.composerHandle ?? null,
8700
8794
  onSend: async (body, opts) => {
8701
- await sendReply({
8795
+ let draft = {
8702
8796
  body,
8703
8797
  ...opts,
8704
8798
  ...alsoSendToChannel && alsoToChannel ? { also_send_to_channel: true } : {}
8705
- });
8799
+ };
8800
+ if (hooks.beforeSend) {
8801
+ const changed = await hooks.beforeSend(draft);
8802
+ if (changed === false) return false;
8803
+ draft = changed;
8804
+ }
8805
+ await sendReply(draft);
8706
8806
  setAlsoToChannel(false);
8807
+ return void 0;
8707
8808
  },
8708
8809
  placeholder: "Reply to thread\u2026",
8709
8810
  attachments: true,
8710
8811
  onAttachPress: () => setPickerOpen(true),
8812
+ ...hooks.composerProps,
8711
8813
  editingMessage,
8712
8814
  onCancelEdit: () => setEditingId(null),
8713
8815
  onSaveEdit: async (body) => {
@@ -9128,7 +9230,13 @@ function ConversationView({
9128
9230
  maxFileSize,
9129
9231
  acceptedFileTypes,
9130
9232
  markUnread = true,
9131
- onMarkedUnread
9233
+ onMarkedUnread,
9234
+ composerProps: appComposerProps,
9235
+ composerAccessory,
9236
+ composerHandle,
9237
+ beforeSend,
9238
+ extraActions,
9239
+ confirmDelete = alertConfirmDelete
9132
9240
  }) {
9133
9241
  const theme = useTheme();
9134
9242
  const chat = react$1.usePoolse();
@@ -9204,6 +9312,20 @@ function ConversationView({
9204
9312
  );
9205
9313
  const [draftFor, setDraftFor] = react.useState(conversationId);
9206
9314
  const [draftText, setDraftText] = react.useState(() => drafts.peek(conversationId)?.text ?? "");
9315
+ const composerRef = react.useRef(null);
9316
+ react.useImperativeHandle(
9317
+ composerHandle,
9318
+ () => ({
9319
+ addFiles: (inputs) => composerRef.current?.addFiles(inputs),
9320
+ focus: () => composerRef.current?.focus(),
9321
+ clear: () => composerRef.current?.clear(),
9322
+ getText: () => composerRef.current?.getText() ?? "",
9323
+ setText: (t) => composerRef.current?.setText(t),
9324
+ insertText: (t) => composerRef.current?.insertText(t),
9325
+ setSelection: (start, end) => composerRef.current?.setSelection(start, end)
9326
+ }),
9327
+ []
9328
+ );
9207
9329
  const [replyingTo, setReplyingTo] = react.useState(
9208
9330
  () => drafts.peek(conversationId)?.quote ?? null
9209
9331
  );
@@ -9466,7 +9588,8 @@ function ConversationView({
9466
9588
  ...readState ? { readState } : {},
9467
9589
  isEditing: editingId === msg.id,
9468
9590
  ...canEdit ? { onStartEdit: () => setEditingId(msg.id) } : {},
9469
- onDelete: () => deleteMsg(msg.id),
9591
+ onDelete: () => void confirmThenDelete(msg, confirmDelete, deleteMsg),
9592
+ ...extraActions ? { extraActions: extraActions(msg) } : {},
9470
9593
  ...threads ? { onOpenThread: () => setThreadRoot(msg) } : {},
9471
9594
  ...canQuote && !tombstone ? { onQuote: () => setReplyingTo(msg) } : {},
9472
9595
  onQuotedClick,
@@ -9508,6 +9631,8 @@ function ConversationView({
9508
9631
  threads,
9509
9632
  editingId,
9510
9633
  deleteMsg,
9634
+ confirmDelete,
9635
+ extraActions,
9511
9636
  labelFor,
9512
9637
  avatarFor,
9513
9638
  showSenderLabels,
@@ -9567,9 +9692,15 @@ function ConversationView({
9567
9692
  const composerProps = react.useMemo(
9568
9693
  () => ({
9569
9694
  onSend: async (body, opts) => {
9570
- const id = sdk.safeUuid();
9695
+ let draft = { body, ...opts };
9696
+ if (beforeSend) {
9697
+ const changed = await beforeSend(draft);
9698
+ if (changed === false) return false;
9699
+ draft = changed;
9700
+ }
9701
+ const id = draft.id ?? sdk.safeUuid();
9571
9702
  try {
9572
- await send({ body, ...opts, id });
9703
+ await send({ ...draft, id });
9573
9704
  } catch (err) {
9574
9705
  const kept = err instanceof sdk.MessageQueuedError || chat.outboxEnabled && !isQuoteGone(err);
9575
9706
  if (kept) {
@@ -9586,6 +9717,7 @@ function ConversationView({
9586
9717
  setReplyingTo(null);
9587
9718
  setAutoReadPaused(false);
9588
9719
  onSent?.(conversationId);
9720
+ return void 0;
9589
9721
  },
9590
9722
  value: draftText,
9591
9723
  onChangeText: (text) => {
@@ -9593,7 +9725,11 @@ function ConversationView({
9593
9725
  setDraftText(text);
9594
9726
  },
9595
9727
  emojiPicker,
9596
- onTyping: signalTyping,
9728
+ ...appComposerProps,
9729
+ onTyping: () => {
9730
+ signalTyping();
9731
+ appComposerProps?.onTyping?.();
9732
+ },
9597
9733
  ...attachments ? { onAttachPress: () => setPickerOpen(true) } : {},
9598
9734
  ...replyingTo ? { replyingTo } : {},
9599
9735
  onCancelReply: () => setReplyingTo(null),
@@ -9623,7 +9759,9 @@ function ConversationView({
9623
9759
  editingId,
9624
9760
  edit,
9625
9761
  draftText,
9626
- emojiPicker
9762
+ emojiPicker,
9763
+ beforeSend,
9764
+ appComposerProps
9627
9765
  ]
9628
9766
  );
9629
9767
  const headerNode = header === false ? null : header === true ? /* @__PURE__ */ jsxRuntime.jsx(
@@ -9763,7 +9901,8 @@ function ConversationView({
9763
9901
  }
9764
9902
  ) : null
9765
9903
  ] }),
9766
- !showComposer ? null : mentions ? /* @__PURE__ */ jsxRuntime.jsx(MentionInput, { conversationId, ...composerProps }) : /* @__PURE__ */ jsxRuntime.jsx(MessageComposer, { ...composerProps }),
9904
+ showComposer ? composerAccessory : null,
9905
+ !showComposer ? null : mentions ? /* @__PURE__ */ jsxRuntime.jsx(MentionInput, { ref: composerRef, conversationId, ...composerProps }) : /* @__PURE__ */ jsxRuntime.jsx(MessageComposer, { ref: composerRef, ...composerProps }),
9767
9906
  canAttach ? /* @__PURE__ */ jsxRuntime.jsx(
9768
9907
  AttachmentPicker,
9769
9908
  {
@@ -9787,7 +9926,11 @@ function ConversationView({
9787
9926
  ...timeFormat ? { timeFormat } : {},
9788
9927
  density,
9789
9928
  showPresence,
9790
- linkPreviews
9929
+ linkPreviews,
9930
+ confirmDelete,
9931
+ ...appComposerProps ? { composerProps: appComposerProps } : {},
9932
+ ...beforeSend ? { beforeSend } : {},
9933
+ ...extraActions ? { extraActions } : {}
9791
9934
  }
9792
9935
  ) : null
9793
9936
  ]