@zean-chat/react-native 0.1.14 → 0.1.15

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.js CHANGED
@@ -28,7 +28,7 @@ __export(index_exports, {
28
28
  module.exports = __toCommonJS(index_exports);
29
29
 
30
30
  // src/components/ZeanChat.tsx
31
- var import_react17 = require("react");
31
+ var import_react18 = require("react");
32
32
 
33
33
  // ../shared/src/constants/app.ts
34
34
  var APP_NAME = "Zean";
@@ -40,6 +40,8 @@ var SUPPORTED_LOCALES = ["fr", "en"];
40
40
  var DEFAULT_LOCALE = "fr";
41
41
 
42
42
  // ../shared/src/constants/conversations.ts
43
+ var CONVERSATION_STATUSES = ["open", "resolved"];
44
+ var INBOX_TABS = [...CONVERSATION_STATUSES, "spam"];
43
45
  var INBOX_FILTERS = ["all", "mine", "unassigned"];
44
46
  var INBOX_VIEWS = [...INBOX_FILTERS, "unread"];
45
47
  var CONTACT_ID_MAX_LENGTH = 200;
@@ -67,7 +69,11 @@ var RESERVED_CONTACT_ATTRIBUTES = [
67
69
  ];
68
70
  var MISSED_REPLY_DELAY_MS = 60 * 6e4;
69
71
  var MAX_MESSAGE_LENGTH = 5e3;
72
+ var EDIT_WINDOW_MS = 30 * 6e4;
73
+ var DELETE_WINDOW_MS = 60 * 6e4;
74
+ var DRAFT_TTL_MS = 30 * 24 * 60 * 6e4;
70
75
  var TEST_DEVICE_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
76
+ var QUOTE_HIGHLIGHT_MS = 1600;
71
77
 
72
78
  // ../shared/src/constants/widget.ts
73
79
  var EXPO_GO_BUNDLE_ID = "host.exp.exponent";
@@ -229,6 +235,7 @@ function createChatStore(backend, options) {
229
235
  const outboxKey = `zean:${options.appKey}:outbox`;
230
236
  const attributesKey = `zean:${options.appKey}:attributes`;
231
237
  const keptKey = `zean:${options.appKey}:conversation`;
238
+ const draftKey = `zean:${options.appKey}:draft`;
232
239
  const keep = options.keep === true;
233
240
  const listeners2 = /* @__PURE__ */ new Set();
234
241
  const stops = [];
@@ -245,6 +252,7 @@ function createChatStore(backend, options) {
245
252
  let keptHasOlder = false;
246
253
  let keptHistory = null;
247
254
  let askedAfter;
255
+ let syncedAt;
248
256
  let windowed = false;
249
257
  let open2 = false;
250
258
  let liveTimer = null;
@@ -253,9 +261,12 @@ function createChatStore(backend, options) {
253
261
  let lastTypingSignal = 0;
254
262
  let connected = false;
255
263
  let outbox = [];
264
+ let draft2 = null;
265
+ let people = 0;
256
266
  let heldAttributes = {};
257
267
  let started = false;
258
268
  let reported = false;
269
+ let shared = null;
259
270
  let user = null;
260
271
  let idCode = null;
261
272
  let idCodeDismissed = false;
@@ -309,6 +320,7 @@ function createChatStore(backend, options) {
309
320
  useSecret(secret);
310
321
  outbox = await loadOutbox();
311
322
  heldAttributes = { ...await loadAttributes(), ...heldAttributes };
323
+ draft2 = await loadDraft();
312
324
  if (keep) await loadKept();
313
325
  if (destroyed) return;
314
326
  emit2();
@@ -366,8 +378,7 @@ function createChatStore(backend, options) {
366
378
  function serverMessages() {
367
379
  if (kept.length === 0) return page.messages;
368
380
  if (page.messages.length === 0) return kept;
369
- const keptIds = new Set(kept.map((message) => message.id));
370
- return [...kept, ...page.messages.filter((message) => !keptIds.has(message.id))];
381
+ return [...kept, ...page.messages];
371
382
  }
372
383
  function serverHasOlder() {
373
384
  return kept.length > 0 ? keptHasOlder : page.hasOlder;
@@ -405,6 +416,7 @@ function createChatStore(backend, options) {
405
416
  session = result;
406
417
  failedToLoad = false;
407
418
  if (keep) checkKept(result);
419
+ checkDraft(result);
408
420
  emit2();
409
421
  if ("report" in result && result.report && !reported) {
410
422
  reported = true;
@@ -455,7 +467,7 @@ function createChatStore(backend, options) {
455
467
  }
456
468
  function watchMessages() {
457
469
  stopMessages?.();
458
- const after = !windowed && kept.length > 0 ? kept.at(-1).createdAt : void 0;
470
+ const after = !windowed && kept.length > 0 ? rereadFrom(kept.at(-1).createdAt, syncedAt) : void 0;
459
471
  askedAfter = after;
460
472
  stopMessages = backend.watch(
461
473
  "messages",
@@ -465,8 +477,10 @@ function createChatStore(backend, options) {
465
477
  if (after === void 0 || windowed) {
466
478
  kept = [];
467
479
  keptHasOlder = false;
468
- }
480
+ } else kept = kept.filter((message) => message.createdAt <= after);
469
481
  page = result;
482
+ const now = Date.now();
483
+ syncedAt = now;
470
484
  pageLoaded = true;
471
485
  loadingOlder = false;
472
486
  const stored = new Set(result.messages.map((message) => message.clientId));
@@ -474,7 +488,8 @@ function createChatStore(backend, options) {
474
488
  outbox = outbox.filter((entry) => !stored.has(entry.clientId));
475
489
  saveOutbox();
476
490
  }
477
- if (after !== void 0 && !windowed && result.messages.length >= ADVANCE_AFTER) {
491
+ const settled = result.messages.filter((message) => message.createdAt <= now - DELETE_WINDOW_MS);
492
+ if (after !== void 0 && !windowed && settled.length >= ADVANCE_AFTER) {
478
493
  kept = serverMessages();
479
494
  page = { messages: [], hasOlder: false, seen: result.seen };
480
495
  watchMessages();
@@ -546,22 +561,24 @@ function createChatStore(backend, options) {
546
561
  const verified = session !== null && "identity" in session && session.identity === "verified";
547
562
  const shown = serverMessages();
548
563
  const hasOlder = serverHasOlder();
549
- const stored = new Set(shown.map((message) => message.clientId));
550
- const pending = outbox.filter((entry) => !stored.has(entry.clientId)).map(fromOutbox);
564
+ const previous = shared;
565
+ const messages = previous && previous.kept === kept && previous.pageMessages === page.messages && previous.outbox === outbox ? previous.messages : derivedMessages(shown);
566
+ const appState = previous && previous.sessionApp === app ? previous.app : app ? {
567
+ name: app.name,
568
+ color: app.color,
569
+ logoUrl: app.logoUrl,
570
+ launcher: app.launcher,
571
+ showBadge: app.showBadge,
572
+ hiddenPages: app.hiddenPages
573
+ } : null;
574
+ shared = { sessionApp: app, app: appState, kept, pageMessages: page.messages, outbox, messages };
551
575
  return {
552
576
  status,
553
- app: app ? {
554
- name: app.name,
555
- color: app.color,
556
- logoUrl: app.logoUrl,
557
- launcher: app.launcher,
558
- showBadge: app.showBadge,
559
- hiddenPages: app.hiddenPages
560
- } : null,
577
+ app: appState,
561
578
  locale,
562
579
  texts: { header: textOf("header"), welcome: textOf("welcome"), away: textOf("away") },
563
580
  online: app ? app.teamOnline && isWithinBusinessHours(app.hours, /* @__PURE__ */ new Date()) : false,
564
- messages: [...shown.map(fromServer), ...pending],
581
+ messages,
565
582
  // Past the most the widget holds, older messages stay in the dashboard.
566
583
  hasOlder: hasOlder && Math.max(limit, shown.length) < WIDGET_MAX_MESSAGES,
567
584
  atStart: !hasOlder,
@@ -575,9 +592,16 @@ function createChatStore(backend, options) {
575
592
  emailGiven,
576
593
  verified,
577
594
  contactCode: codeOffer(verified),
578
- connected
595
+ connected,
596
+ personKey: people
579
597
  };
580
598
  }
599
+ function derivedMessages(shown) {
600
+ const stored = new Set(shown.map((message) => message.clientId));
601
+ const shownIds = new Map(shown.map((message) => [message.id, message.clientId ?? message.id]));
602
+ const pending = outbox.filter((entry) => !stored.has(entry.clientId)).map(fromOutbox);
603
+ return [...shown.map((message) => fromServer(message, shownIds)), ...pending];
604
+ }
581
605
  function codeOffer(verified) {
582
606
  if (idCode && !verified) return idCodeDismissed ? null : { kind: "id", ...idCode };
583
607
  const offer = session && "emailCode" in session ? session.emailCode : null;
@@ -585,7 +609,7 @@ function createChatStore(backend, options) {
585
609
  return { ...offer, sent: emailKey(offer) === emailCodeSent };
586
610
  }
587
611
  function checkKept(result) {
588
- const history = "contact" in result ? result.contact?.historyKey ?? null : null;
612
+ const history = historyOf(result);
589
613
  if (history !== keptHistory) {
590
614
  keptHistory = history;
591
615
  dropKept();
@@ -596,6 +620,12 @@ function createChatStore(backend, options) {
596
620
  stopLiveLater();
597
621
  } else saveKept();
598
622
  }
623
+ function checkDraft(result) {
624
+ if (!draft2) return;
625
+ const history = historyOf(result);
626
+ if (draft2.history === history) return;
627
+ writeDraft(draft2.history === null ? { ...draft2, history } : null);
628
+ }
599
629
  async function loadKept() {
600
630
  try {
601
631
  const saved = JSON.parse(await options.storage.getItem(keptKey) || "null");
@@ -604,6 +634,7 @@ function createChatStore(backend, options) {
604
634
  kept = saved.messages;
605
635
  keptHasOlder = saved.hasOlder;
606
636
  keptHistory = saved.session.contact?.historyKey ?? null;
637
+ syncedAt = saved.syncedAt;
607
638
  page = { messages: [], hasOlder: false, seen: saved.seen };
608
639
  pageLoaded = kept.length > 0 || !saved.session.contact?.historyKey;
609
640
  } catch {
@@ -619,7 +650,8 @@ function createChatStore(backend, options) {
619
650
  session: { ...current, report: false },
620
651
  messages: shown.slice(-KEPT_MESSAGES),
621
652
  hasOlder: shown.length > KEPT_MESSAGES || serverHasOlder(),
622
- seen: page.seen
653
+ seen: page.seen,
654
+ ...syncedAt === void 0 ? {} : { syncedAt }
623
655
  };
624
656
  quietly(() => options.storage.setItem(keptKey, JSON.stringify(value)));
625
657
  }
@@ -682,8 +714,36 @@ function createChatStore(backend, options) {
682
714
  function saveAttributes() {
683
715
  void options.storage.setItem(attributesKey, JSON.stringify(heldAttributes));
684
716
  }
717
+ async function loadDraft() {
718
+ try {
719
+ const saved = JSON.parse(await options.storage.getItem(draftKey) || "null");
720
+ if (typeof saved?.text !== "string" || !Array.isArray(saved.files) || typeof saved.updatedAt !== "number") return null;
721
+ return saved.updatedAt > Date.now() - DRAFT_TTL_MS ? saved : null;
722
+ } catch {
723
+ return null;
724
+ }
725
+ }
726
+ function forgetDraft() {
727
+ writeDraft(null);
728
+ people += 1;
729
+ }
730
+ function writeDraft(next) {
731
+ draft2 = next;
732
+ quietly(() => options.storage.setItem(draftKey, next ? JSON.stringify(next) : ""));
733
+ }
685
734
  return {
686
735
  getState: () => state,
736
+ draft: () => draft2 ? { text: draft2.text, files: draft2.files } : null,
737
+ saveDraft(given) {
738
+ const text = given.text;
739
+ const files = given.files.map((file) => file.uri && /^https?:/i.test(file.uri) ? { ...file, uri: null } : file);
740
+ if (!text.trim() && files.length === 0) {
741
+ writeDraft(null);
742
+ return;
743
+ }
744
+ if (draft2 && JSON.stringify({ text, files }) === JSON.stringify({ text: draft2.text, files: draft2.files })) return;
745
+ writeDraft({ text, files, history: session ? historyOf(session) : null, updatedAt: Date.now() });
746
+ },
687
747
  subscribe(listener) {
688
748
  listeners2.add(listener);
689
749
  return () => listeners2.delete(listener);
@@ -700,6 +760,7 @@ function createChatStore(backend, options) {
700
760
  };
701
761
  outbox = [...outbox, entry];
702
762
  saveOutbox();
763
+ writeDraft(null);
703
764
  wroteHere = true;
704
765
  emit2();
705
766
  if (started) deliver(entry);
@@ -788,6 +849,7 @@ function createChatStore(backend, options) {
788
849
  heldAttributes = {};
789
850
  saveAttributes();
790
851
  forgetKept();
852
+ forgetDraft();
791
853
  emit2();
792
854
  }
793
855
  if (user?.id !== person.id) {
@@ -871,6 +933,7 @@ function createChatStore(backend, options) {
871
933
  watchers = [];
872
934
  stopLive();
873
935
  forgetKept();
936
+ forgetDraft();
874
937
  keepLive();
875
938
  deviceSecret = null;
876
939
  outbox = [];
@@ -916,6 +979,9 @@ function createChatStore(backend, options) {
916
979
  }
917
980
  };
918
981
  }
982
+ function rereadFrom(newest, syncedAt = newest) {
983
+ return Math.min(newest, syncedAt - DELETE_WINDOW_MS);
984
+ }
919
985
  function localeOf(languages, fallback) {
920
986
  for (const language of languages) {
921
987
  const base = language.slice(0, 2).toLowerCase();
@@ -924,8 +990,15 @@ function localeOf(languages, fallback) {
924
990
  }
925
991
  return fallback;
926
992
  }
927
- function fromServer({ clientId, ...message }) {
928
- return { ...message, id: clientId ?? message.id, status: "sent", error: null };
993
+ function fromServer({ clientId, replyTo, ...message }, shownIds) {
994
+ return {
995
+ ...message,
996
+ id: clientId ?? message.id,
997
+ status: "sent",
998
+ error: null,
999
+ // Kept on the device before quotes came: none.
1000
+ replyTo: replyTo ? { ...replyTo, id: shownIds.get(replyTo.id) ?? replyTo.id, loaded: shownIds.has(replyTo.id) } : null
1001
+ };
929
1002
  }
930
1003
  function fromOutbox(entry) {
931
1004
  return {
@@ -936,7 +1009,8 @@ function fromOutbox(entry) {
936
1009
  attachments: entry.attachments ?? [],
937
1010
  createdAt: entry.createdAt,
938
1011
  status: entry.error === null ? "sending" : "failed",
939
- error: entry.error
1012
+ error: entry.error,
1013
+ replyTo: null
940
1014
  };
941
1015
  }
942
1016
  function bundleWarning(bundle) {
@@ -945,6 +1019,9 @@ function bundleWarning(bundle) {
945
1019
  const field = bundle.os === "ios" ? "Bundle ID" : "Package name";
946
1020
  return `${APP_NAME}: ${bundle.id} is not the App's ${field}. Set it in the App settings.`;
947
1021
  }
1022
+ function historyOf(result) {
1023
+ return "contact" in result ? result.contact?.historyKey ?? null : null;
1024
+ }
948
1025
  function hidesChat(result) {
949
1026
  return result.state === "not_found" || result.state === "domain_not_allowed" || result.state === "bundle_id_not_allowed";
950
1027
  }
@@ -6302,6 +6379,18 @@ function withCode(error) {
6302
6379
  return Object.assign(error instanceof Error ? error : new Error(String(error)), { code: code2 });
6303
6380
  }
6304
6381
 
6382
+ // ../sdk-core/src/quotes.ts
6383
+ function quoteAuthorOf(quote, you, appName) {
6384
+ return quote.from === "contact" ? you : quote.sender?.name ?? appName;
6385
+ }
6386
+ function quoteStepOf(state, replyId) {
6387
+ const quote = state.messages.find((message) => message.id === replyId)?.replyTo;
6388
+ if (!quote || quote.deleted) return { kind: "none" };
6389
+ if (quote.loaded) return { kind: "go", id: quote.id };
6390
+ if (state.loadingOlder) return { kind: "wait" };
6391
+ return state.hasOlder ? { kind: "older" } : { kind: "none" };
6392
+ }
6393
+
6305
6394
  // ../sdk-core/src/index.ts
6306
6395
  function createChat(options) {
6307
6396
  return createChatStore(convexBackend(options.backendUrl), options);
@@ -6715,8 +6804,8 @@ function subscribeChatView(listener) {
6715
6804
  }
6716
6805
 
6717
6806
  // src/components/ChatModal.tsx
6718
- var import_react16 = require("react");
6719
- var import_react_native23 = require("react-native");
6807
+ var import_react17 = require("react");
6808
+ var import_react_native24 = require("react-native");
6720
6809
 
6721
6810
  // src/hooks/use-app-active.ts
6722
6811
  var import_react = require("react");
@@ -6755,6 +6844,10 @@ var en = {
6755
6844
  seen: "Seen",
6756
6845
  not_sent: "Not sent.",
6757
6846
  rate_limited: "Too many messages at once. Wait a moment.",
6847
+ you: "You",
6848
+ photo: "Photo",
6849
+ message_deleted: "Message deleted",
6850
+ show_quoted: "Show the quoted message",
6758
6851
  retry: "Retry",
6759
6852
  team: "The team",
6760
6853
  typing: "{name} is typing\u2026",
@@ -6811,6 +6904,10 @@ var fr = {
6811
6904
  seen: "Vu",
6812
6905
  not_sent: "Non envoy\xE9.",
6813
6906
  rate_limited: "Trop de messages \xE0 la fois. Patientez un instant.",
6907
+ you: "Vous",
6908
+ photo: "Photo",
6909
+ message_deleted: "Message supprim\xE9",
6910
+ show_quoted: "Voir le message cit\xE9",
6814
6911
  retry: "R\xE9essayer",
6815
6912
  team: "L'\xE9quipe",
6816
6913
  typing: "{name} \xE9crit\u2026",
@@ -6948,8 +7045,8 @@ var styles = import_react_native4.StyleSheet.create({
6948
7045
  });
6949
7046
 
6950
7047
  // src/components/ChatScreen.tsx
6951
- var import_react15 = require("react");
6952
- var import_react_native22 = require("react-native");
7048
+ var import_react16 = require("react");
7049
+ var import_react_native23 = require("react-native");
6953
7050
 
6954
7051
  // src/hooks/use-connection-lost.ts
6955
7052
  var import_react4 = require("react");
@@ -7214,11 +7311,96 @@ function isImage(type) {
7214
7311
  return IMAGE_TYPES.includes(type);
7215
7312
  }
7216
7313
 
7314
+ // src/models/conversation.utils.ts
7315
+ function authorOf(message) {
7316
+ if (message.from === "contact") return "contact";
7317
+ return `team:${message.sender?.name ?? ""}:${message.sender?.image ?? ""}`;
7318
+ }
7319
+ function startOfDay(timestamp) {
7320
+ const day = new Date(timestamp);
7321
+ day.setHours(0, 0, 0, 0);
7322
+ return day.getTime();
7323
+ }
7324
+ function sameDay(left, right) {
7325
+ return startOfDay(left) === startOfDay(right);
7326
+ }
7327
+ function joins(older, newer) {
7328
+ return older.status !== "failed" && authorOf(older) === authorOf(newer) && newer.createdAt - older.createdAt < RUN_GAP_MS && sameDay(older.createdAt, newer.createdAt);
7329
+ }
7330
+ function conversationRows(messages, seen, welcome) {
7331
+ const all = welcome ? [welcome, ...messages] : [...messages];
7332
+ const lastReply = all.findLastIndex((message) => message.from === "team" && message.sender !== null);
7333
+ return all.map((message, index) => {
7334
+ const older = all[index - 1];
7335
+ const newer = all[index + 1];
7336
+ const isWelcome = message === welcome;
7337
+ return {
7338
+ message,
7339
+ startsRun: !older || !joins(older, message),
7340
+ endsRun: !newer || !joins(message, newer),
7341
+ // Alone, the welcome has no day: there is nothing to date.
7342
+ startsDay: isWelcome ? messages.length > 0 : !older || !sameDay(older.createdAt, message.createdAt),
7343
+ receipt: receiptOf(message, seen || index < lastReply),
7344
+ welcome: isWelcome
7345
+ };
7346
+ });
7347
+ }
7348
+ function receiptOf(message, seen) {
7349
+ if (message.from === "team" || message.status === "failed") return null;
7350
+ if (message.status === "sending") return "sending";
7351
+ return seen ? "seen" : "sent";
7352
+ }
7353
+ var DATE_STYLES = {
7354
+ time: { hour: "2-digit", minute: "2-digit" },
7355
+ weekday: { weekday: "long" },
7356
+ day: { day: "numeric", month: "short" },
7357
+ dayYear: { day: "numeric", month: "short", year: "numeric" }
7358
+ };
7359
+ var formats = /* @__PURE__ */ new Map();
7360
+ function formatDate(timestamp, locale, style) {
7361
+ const key = `${locale}:${style}`;
7362
+ let format2 = formats.get(key);
7363
+ if (!format2) {
7364
+ format2 = new Intl.DateTimeFormat(locale, DATE_STYLES[style]);
7365
+ formats.set(key, format2);
7366
+ }
7367
+ return format2.format(timestamp);
7368
+ }
7369
+ function messageTime(timestamp, locale) {
7370
+ return formatDate(timestamp, locale, "time");
7371
+ }
7372
+ function dayLabel(timestamp, now, locale, t) {
7373
+ const today = startOfDay(now);
7374
+ const day = startOfDay(timestamp);
7375
+ if (day === today) return t.today;
7376
+ if (day === startOfDay(today - 1)) return t.yesterday;
7377
+ const weekAgo = new Date(today);
7378
+ weekAgo.setDate(weekAgo.getDate() - 6);
7379
+ if (day >= weekAgo.getTime()) return formatDate(timestamp, locale, "weekday");
7380
+ const sameYear = new Date(timestamp).getFullYear() === new Date(now).getFullYear();
7381
+ return formatDate(timestamp, locale, sameYear ? "day" : "dayYear");
7382
+ }
7383
+ function pendingPhotosOfDraft(files, newId) {
7384
+ return files.flatMap(
7385
+ ({ uri, name, type, width, height, attachment }) => uri ? [{ id: newId(), uri, name, type, width, height, status: attachment ? "ready" : "picked", attachment }] : []
7386
+ );
7387
+ }
7388
+ function draftFilesOf(photos) {
7389
+ return photos.map(({ name, type, attachment, uri, width, height }) => ({
7390
+ name,
7391
+ type,
7392
+ attachment,
7393
+ uri,
7394
+ ...width && height ? { width, height } : {}
7395
+ }));
7396
+ }
7397
+
7217
7398
  // src/hooks/use-pending-photos.ts
7218
7399
  var lastId = 0;
7400
+ var nextId = () => `photo_${++lastId}`;
7219
7401
  function usePendingPhotos() {
7220
7402
  const { chat: chat2, t, maxPhotos } = useChatContext();
7221
- const [photos, setPhotos] = (0, import_react7.useState)([]);
7403
+ const [photos, setPhotos] = (0, import_react7.useState)(() => pendingPhotosOfDraft(chat2.draft()?.files ?? [], nextId));
7222
7404
  const [problem, setProblem] = (0, import_react7.useState)(null);
7223
7405
  const [sending, setSending] = (0, import_react7.useState)(false);
7224
7406
  const tooMany = maxPhotos === 1 ? t.too_many_one : format(t.too_many, { count: maxPhotos });
@@ -7263,9 +7445,8 @@ function usePendingPhotos() {
7263
7445
  setProblem(format(t.photo_size, { name: photo.name }));
7264
7446
  continue;
7265
7447
  }
7266
- lastId += 1;
7267
7448
  const { uri, name, type, width, height } = photo;
7268
- added.push({ id: `photo_${lastId}`, uri, name, type, width, height, status: "picked", attachment: null });
7449
+ added.push({ id: nextId(), uri, name, type, width, height, status: "picked", attachment: null });
7269
7450
  }
7270
7451
  setPhotos((current) => [...current, ...added]);
7271
7452
  };
@@ -7279,8 +7460,10 @@ function usePendingPhotos() {
7279
7460
  setPhotos([]);
7280
7461
  return attachments;
7281
7462
  };
7463
+ const draftFiles = (0, import_react7.useMemo)(() => draftFilesOf(photos), [photos]);
7282
7464
  return {
7283
7465
  photos,
7466
+ draftFiles,
7284
7467
  problem,
7285
7468
  /** Photos that still fit in the message. */
7286
7469
  room: maxPhotos - photos.length,
@@ -7422,8 +7605,8 @@ var styles6 = import_react_native10.StyleSheet.create({
7422
7605
  var import_jsx_runtime8 = require("react/jsx-runtime");
7423
7606
  function Composer() {
7424
7607
  const { chat: chat2, t, colors } = useChatContext();
7425
- const [text, setText] = (0, import_react8.useState)("");
7426
- const typed = (0, import_react8.useRef)("");
7608
+ const [text, setText] = (0, import_react8.useState)(() => chat2.draft()?.text ?? "");
7609
+ const typed = (0, import_react8.useRef)(text);
7427
7610
  const pending = usePendingPhotos();
7428
7611
  const picker = photoPicker();
7429
7612
  const canSend = !pending.sending && (text.trim().length > 0 || pending.photos.length > 0);
@@ -7437,6 +7620,9 @@ function Composer() {
7437
7620
  changeText(draft2);
7438
7621
  clearDraft();
7439
7622
  }, [draft2]);
7623
+ (0, import_react8.useEffect)(() => {
7624
+ chat2.saveDraft({ text, files: pending.draftFiles });
7625
+ }, [chat2, text, pending.draftFiles]);
7440
7626
  const handleSend = async () => {
7441
7627
  const attachments = pending.photos.length > 0 ? await pending.send() : [];
7442
7628
  if (!attachments) return;
@@ -7533,78 +7719,8 @@ var styles7 = import_react_native11.StyleSheet.create({
7533
7719
  });
7534
7720
 
7535
7721
  // src/components/MessageList.tsx
7536
- var import_react14 = require("react");
7537
- var import_react_native20 = require("react-native");
7538
-
7539
- // src/models/conversation.utils.ts
7540
- function authorOf(message) {
7541
- if (message.from === "contact") return "contact";
7542
- return `team:${message.sender?.name ?? ""}:${message.sender?.image ?? ""}`;
7543
- }
7544
- function startOfDay(timestamp) {
7545
- const day = new Date(timestamp);
7546
- day.setHours(0, 0, 0, 0);
7547
- return day.getTime();
7548
- }
7549
- function sameDay(left, right) {
7550
- return startOfDay(left) === startOfDay(right);
7551
- }
7552
- function joins(older, newer) {
7553
- return older.status !== "failed" && authorOf(older) === authorOf(newer) && newer.createdAt - older.createdAt < RUN_GAP_MS && sameDay(older.createdAt, newer.createdAt);
7554
- }
7555
- function conversationRows(messages, seen, welcome) {
7556
- const all = welcome ? [welcome, ...messages] : [...messages];
7557
- const lastReply = all.findLastIndex((message) => message.from === "team" && message.sender !== null);
7558
- return all.map((message, index) => {
7559
- const older = all[index - 1];
7560
- const newer = all[index + 1];
7561
- const isWelcome = message === welcome;
7562
- return {
7563
- message,
7564
- startsRun: !older || !joins(older, message),
7565
- endsRun: !newer || !joins(message, newer),
7566
- // Alone, the welcome has no day: there is nothing to date.
7567
- startsDay: isWelcome ? messages.length > 0 : !older || !sameDay(older.createdAt, message.createdAt),
7568
- receipt: receiptOf(message, seen || index < lastReply),
7569
- welcome: isWelcome
7570
- };
7571
- });
7572
- }
7573
- function receiptOf(message, seen) {
7574
- if (message.from === "team" || message.status === "failed") return null;
7575
- if (message.status === "sending") return "sending";
7576
- return seen ? "seen" : "sent";
7577
- }
7578
- var DATE_STYLES = {
7579
- time: { hour: "2-digit", minute: "2-digit" },
7580
- weekday: { weekday: "long" },
7581
- day: { day: "numeric", month: "short" },
7582
- dayYear: { day: "numeric", month: "short", year: "numeric" }
7583
- };
7584
- var formats = /* @__PURE__ */ new Map();
7585
- function formatDate(timestamp, locale, style) {
7586
- const key = `${locale}:${style}`;
7587
- let format2 = formats.get(key);
7588
- if (!format2) {
7589
- format2 = new Intl.DateTimeFormat(locale, DATE_STYLES[style]);
7590
- formats.set(key, format2);
7591
- }
7592
- return format2.format(timestamp);
7593
- }
7594
- function messageTime(timestamp, locale) {
7595
- return formatDate(timestamp, locale, "time");
7596
- }
7597
- function dayLabel(timestamp, now, locale, t) {
7598
- const today = startOfDay(now);
7599
- const day = startOfDay(timestamp);
7600
- if (day === today) return t.today;
7601
- if (day === startOfDay(today - 1)) return t.yesterday;
7602
- const weekAgo = new Date(today);
7603
- weekAgo.setDate(weekAgo.getDate() - 6);
7604
- if (day >= weekAgo.getTime()) return formatDate(timestamp, locale, "weekday");
7605
- const sameYear = new Date(timestamp).getFullYear() === new Date(now).getFullYear();
7606
- return formatDate(timestamp, locale, sameYear ? "day" : "dayYear");
7607
- }
7722
+ var import_react15 = require("react");
7723
+ var import_react_native21 = require("react-native");
7608
7724
 
7609
7725
  // src/components/EmailForm.tsx
7610
7726
  var import_react9 = require("react");
@@ -7677,7 +7793,8 @@ var styles8 = import_react_native12.StyleSheet.create({
7677
7793
  });
7678
7794
 
7679
7795
  // src/components/MessageBubble.tsx
7680
- var import_react_native18 = require("react-native");
7796
+ var import_react13 = require("react");
7797
+ var import_react_native19 = require("react-native");
7681
7798
 
7682
7799
  // src/hooks/use-rise-in.ts
7683
7800
  var import_react10 = require("react");
@@ -7710,6 +7827,8 @@ var signed = /* @__PURE__ */ new Map();
7710
7827
  function useAttachmentLinks(chat2, keys, stored) {
7711
7828
  const [links, setLinks] = (0, import_react11.useState)(() => cachedLinks(keys));
7712
7829
  const [attempt, setAttempt] = (0, import_react11.useState)(0);
7830
+ const connected = (0, import_react11.useSyncExternalStore)(chat2.subscribe, () => chat2.getState().connected);
7831
+ const failed = (0, import_react11.useRef)(false);
7713
7832
  const wanted = keys.join("|");
7714
7833
  (0, import_react11.useEffect)(() => {
7715
7834
  if (!stored) return;
@@ -7721,19 +7840,27 @@ function useAttachmentLinks(chat2, keys, stored) {
7721
7840
  }
7722
7841
  let cancelled = false;
7723
7842
  let retry;
7843
+ const askAgain = () => {
7844
+ if (!cancelled && attempt < LINK_RETRIES) retry = setTimeout(() => setAttempt(attempt + 1), LINK_RETRY_MS);
7845
+ };
7724
7846
  chat2.attachmentLinks(missing).then((fresh) => {
7847
+ failed.current = false;
7725
7848
  for (const link of fresh) signed.set(link.key, { url: link.url, until: Date.now() + LINK_LIFETIME_MS });
7726
7849
  if (cancelled) return;
7727
7850
  setLinks(cachedLinks(list));
7728
- if (fresh.length < missing.length && attempt < LINK_RETRIES)
7729
- retry = setTimeout(() => setAttempt(attempt + 1), LINK_RETRY_MS);
7851
+ if (fresh.length < missing.length) askAgain();
7730
7852
  }).catch(() => {
7853
+ failed.current = true;
7854
+ askAgain();
7731
7855
  });
7732
7856
  return () => {
7733
7857
  cancelled = true;
7734
7858
  clearTimeout(retry);
7735
7859
  };
7736
7860
  }, [chat2, wanted, attempt, stored]);
7861
+ (0, import_react11.useEffect)(() => {
7862
+ if (connected && failed.current) setAttempt((current) => current + 1);
7863
+ }, [connected]);
7737
7864
  return links;
7738
7865
  }
7739
7866
  function cachedLinks(keys) {
@@ -7885,37 +8012,104 @@ var styles10 = import_react_native16.StyleSheet.create({
7885
8012
  retry: { fontWeight: "600", textDecorationLine: "underline" }
7886
8013
  });
7887
8014
 
7888
- // src/components/TeamAvatar.tsx
8015
+ // src/components/MessageQuote.tsx
7889
8016
  var import_react_native17 = require("react-native");
8017
+
8018
+ // ../shared/src/utils/quotes.ts
8019
+ function quoteImageOf(quote) {
8020
+ return !quote.deleted && quote.attachment && isImage(quote.attachment.type) ? quote.attachment : null;
8021
+ }
8022
+ function quoteLineOf(quote, labels) {
8023
+ if (quote.deleted) return labels.deleted;
8024
+ if (quote.text) return quote.text;
8025
+ if (!quote.attachment) return "";
8026
+ return quoteImageOf(quote) ? labels.photo : quote.attachment.name;
8027
+ }
8028
+
8029
+ // src/components/MessageQuote.tsx
7890
8030
  var import_jsx_runtime13 = require("react/jsx-runtime");
8031
+ function MessageQuote({ quote, app, onQuote }) {
8032
+ const { chat: chat2, t, colors } = useChatContext();
8033
+ const image = quoteImageOf(quote);
8034
+ const links = useAttachmentLinks(chat2, image ? [image.key] : [], true);
8035
+ const url = image && links.get(image.key);
8036
+ const text = quoteLineOf(quote, { deleted: t.message_deleted, photo: t.photo });
8037
+ const { deleted } = quote;
8038
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
8039
+ import_react_native17.Pressable,
8040
+ {
8041
+ disabled: deleted,
8042
+ onPress: onQuote,
8043
+ accessibilityRole: "button",
8044
+ accessibilityLabel: t.show_quoted,
8045
+ accessibilityState: { disabled: deleted },
8046
+ style: ({ pressed }) => [
8047
+ styles11.quote,
8048
+ { backgroundColor: colors.background, borderLeftColor: colors.primary },
8049
+ pressed && styles11.pressed
8050
+ ],
8051
+ children: [
8052
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_react_native17.View, { style: styles11.lines, children: [
8053
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native17.Text, { style: [styles11.name, { color: colors.primaryText }], numberOfLines: 1, children: quoteAuthorOf(quote, t.you, app.name) }),
8054
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native17.Text, { style: [styles11.text, { color: colors.muted }, quote.deleted && styles11.deleted], numberOfLines: 1, children: text })
8055
+ ] }),
8056
+ image && (url ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native17.Image, { source: { uri: url }, style: [styles11.thumb, { borderColor: colors.border }], accessibilityIgnoresInvertColors: true }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Skeleton, { style: [styles11.thumb, { borderColor: colors.border }] }))
8057
+ ]
8058
+ }
8059
+ );
8060
+ }
8061
+ var THUMB = 36;
8062
+ var styles11 = import_react_native17.StyleSheet.create({
8063
+ quote: {
8064
+ flexDirection: "row",
8065
+ alignItems: "center",
8066
+ gap: 8,
8067
+ alignSelf: "stretch",
8068
+ borderRadius: 10,
8069
+ borderLeftWidth: 3,
8070
+ paddingVertical: 6,
8071
+ paddingLeft: 8,
8072
+ paddingRight: 6
8073
+ },
8074
+ pressed: { opacity: 0.6 },
8075
+ lines: { flexShrink: 1, flexGrow: 1 },
8076
+ name: { fontSize: 13, fontWeight: "600" },
8077
+ text: { fontSize: 13, lineHeight: 18 },
8078
+ deleted: { fontStyle: "italic" },
8079
+ thumb: { width: THUMB, height: THUMB, borderRadius: 6, borderWidth: 1 }
8080
+ });
8081
+
8082
+ // src/components/TeamAvatar.tsx
8083
+ var import_react_native18 = require("react-native");
8084
+ var import_jsx_runtime14 = require("react/jsx-runtime");
7891
8085
  function TeamAvatar({ app, sender, ai = false }) {
7892
8086
  const { colors } = useChatContext();
7893
8087
  if (ai) {
7894
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
7895
- import_react_native17.View,
8088
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
8089
+ import_react_native18.View,
7896
8090
  {
7897
- style: [styles11.avatar, { backgroundColor: colors.primaryTint }],
8091
+ style: [styles12.avatar, { backgroundColor: colors.primaryTint }],
7898
8092
  accessibilityElementsHidden: true,
7899
8093
  importantForAccessibility: "no-hide-descendants",
7900
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Icon, { name: "sparkles", color: colors.primaryText, size: 14 })
8094
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "sparkles", color: colors.primaryText, size: 14 })
7901
8095
  }
7902
8096
  );
7903
8097
  }
7904
8098
  const image = sender ? sender.image : app.logoUrl;
7905
8099
  if (image) {
7906
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native17.Image, { source: { uri: image }, style: [styles11.avatar, { borderColor: colors.border }], accessibilityIgnoresInvertColors: true });
8100
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Image, { source: { uri: image }, style: [styles12.avatar, { borderColor: colors.border }], accessibilityIgnoresInvertColors: true });
7907
8101
  }
7908
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
7909
- import_react_native17.View,
8102
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
8103
+ import_react_native18.View,
7910
8104
  {
7911
- style: [styles11.avatar, { backgroundColor: sender ? colors.primaryTint : colors.primary }],
8105
+ style: [styles12.avatar, { backgroundColor: sender ? colors.primaryTint : colors.primary }],
7912
8106
  accessibilityElementsHidden: true,
7913
8107
  importantForAccessibility: "no-hide-descendants",
7914
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native17.Text, { style: [styles11.initials, { color: sender ? colors.primaryText : colors.primaryForeground }], children: initialsOf(sender?.name ?? app.name) })
8108
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Text, { style: [styles12.initials, { color: sender ? colors.primaryText : colors.primaryForeground }], children: initialsOf(sender?.name ?? app.name) })
7915
8109
  }
7916
8110
  );
7917
8111
  }
7918
- var styles11 = import_react_native17.StyleSheet.create({
8112
+ var styles12 = import_react_native18.StyleSheet.create({
7919
8113
  avatar: {
7920
8114
  width: 28,
7921
8115
  height: 28,
@@ -7930,57 +8124,80 @@ var styles11 = import_react_native17.StyleSheet.create({
7930
8124
  });
7931
8125
 
7932
8126
  // src/components/MessageBubble.tsx
7933
- var import_jsx_runtime14 = require("react/jsx-runtime");
7934
- function MessageBubble({ row, app, onRetry }) {
8127
+ var import_jsx_runtime15 = require("react/jsx-runtime");
8128
+ var MessageBubble = (0, import_react13.memo)(function MessageBubble2({ row, app, onRetry, onQuote, highlighted }) {
7935
8129
  const { chat: chat2, t, locale, colors, openedAt } = useChatContext();
7936
8130
  const { message, startsRun, endsRun, startsDay } = row;
7937
8131
  const own = message.from === "contact";
8132
+ const handleRetry = () => onRetry(message.id);
7938
8133
  const rise = useRiseIn(message.createdAt > openedAt && (!own || message.status === "sending"));
7939
8134
  const corner = startsRun ? RADII.group : RADII.inner;
7940
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.Animated.View, { style: [styles12.row, { paddingTop: startsRun ? 14 : 3 }, rise], children: [
7941
- startsDay && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Text, { style: [styles12.day, { backgroundColor: colors.surface, color: colors.muted }], accessibilityRole: "header", children: dayLabel(message.createdAt, openedAt, locale, t) }),
7942
- own ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.own, children: [
7943
- message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
7944
- import_react_native18.Text,
7945
- {
7946
- selectable: true,
7947
- style: [
7948
- styles12.bubble,
7949
- { borderTopRightRadius: corner, borderBottomRightRadius: RADII.inner },
7950
- { backgroundColor: colors.primary, color: colors.primaryForeground }
7951
- ],
7952
- children: message.body
7953
- }
7954
- ),
7955
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageFiles, { attachments: message.attachments, own: true, stored: message.status === "sent" }),
7956
- endsRun && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageMeta, { row, onRetry })
7957
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.team, children: [
7958
- (startsRun || message.ai) && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Text, { style: [styles12.name, { color: colors.muted }], numberOfLines: 1, children: message.ai ? t.ai : message.sender?.name ?? app.name }),
7959
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.teamRow, children: [
7960
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.View, { style: styles12.avatar, children: endsRun && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TeamAvatar, { app, sender: message.sender, ai: message.ai }) }),
7961
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.teamColumn, children: [
7962
- message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
7963
- import_react_native18.Text,
8135
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
8136
+ import_react_native19.Animated.View,
8137
+ {
8138
+ style: [styles13.row, { paddingTop: startsRun ? 14 : 3 }, highlighted && { backgroundColor: colors.primaryTint }, rise],
8139
+ children: [
8140
+ startsDay && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native19.Text, { style: [styles13.day, { backgroundColor: colors.surface, color: colors.muted }], accessibilityRole: "header", children: dayLabel(message.createdAt, openedAt, locale, t) }),
8141
+ own ? /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native19.View, { style: styles13.own, children: [
8142
+ message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
8143
+ import_react_native19.Text,
7964
8144
  {
7965
8145
  selectable: true,
7966
8146
  style: [
7967
- styles12.bubble,
7968
- { borderTopLeftRadius: corner, borderBottomLeftRadius: RADII.inner },
7969
- { backgroundColor: colors.surface, color: colors.text }
8147
+ styles13.bubble,
8148
+ styles13.text,
8149
+ { borderTopRightRadius: corner, borderBottomRightRadius: RADII.inner },
8150
+ { backgroundColor: colors.primary, color: colors.primaryForeground }
7970
8151
  ],
7971
8152
  children: message.body
7972
8153
  }
7973
8154
  ),
7974
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageFiles, { attachments: message.attachments, own: false, stored: true })
8155
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(MessageFiles, { attachments: message.attachments, own: true, stored: message.status === "sent" }),
8156
+ endsRun && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(MessageMeta, { row, onRetry: handleRetry })
8157
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native19.View, { style: styles13.team, children: [
8158
+ (startsRun || message.ai) && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native19.Text, { style: [styles13.name, { color: colors.muted }], numberOfLines: 1, children: message.ai ? t.ai : message.sender?.name ?? app.name }),
8159
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native19.View, { style: styles13.teamRow, children: [
8160
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native19.View, { style: styles13.avatar, children: endsRun && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(TeamAvatar, { app, sender: message.sender, ai: message.ai }) }),
8161
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native19.View, { style: styles13.teamColumn, children: [
8162
+ message.replyTo ? /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
8163
+ import_react_native19.View,
8164
+ {
8165
+ style: [
8166
+ styles13.bubble,
8167
+ styles13.quoted,
8168
+ { borderTopLeftRadius: corner, borderBottomLeftRadius: RADII.inner },
8169
+ { backgroundColor: colors.surface }
8170
+ ],
8171
+ children: [
8172
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(MessageQuote, { quote: message.replyTo, app, onQuote: () => onQuote(message.id) }),
8173
+ message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native19.Text, { selectable: true, style: [styles13.text, styles13.quotedText, { color: colors.text }], children: message.body })
8174
+ ]
8175
+ }
8176
+ ) : message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
8177
+ import_react_native19.Text,
8178
+ {
8179
+ selectable: true,
8180
+ style: [
8181
+ styles13.bubble,
8182
+ styles13.text,
8183
+ { borderTopLeftRadius: corner, borderBottomLeftRadius: RADII.inner },
8184
+ { backgroundColor: colors.surface, color: colors.text }
8185
+ ],
8186
+ children: message.body
8187
+ }
8188
+ ),
8189
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(MessageFiles, { attachments: message.attachments, own: false, stored: true })
8190
+ ] })
8191
+ ] }),
8192
+ message.ai && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native19.Pressable, { accessibilityRole: "button", onPress: () => chat2.send(t.request_human), hitSlop: 8, style: styles13.teamMeta, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native19.Text, { style: [styles13.human, { color: colors.primaryText }], children: t.request_human }) }),
8193
+ endsRun && !row.welcome && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native19.View, { style: styles13.teamMeta, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(MessageMeta, { row, onRetry: handleRetry }) })
7975
8194
  ] })
7976
- ] }),
7977
- message.ai && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Pressable, { accessibilityRole: "button", onPress: () => chat2.send(t.request_human), hitSlop: 8, style: styles12.teamMeta, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Text, { style: [styles12.human, { color: colors.primaryText }], children: t.request_human }) }),
7978
- endsRun && !row.welcome && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.View, { style: styles12.teamMeta, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageMeta, { row, onRetry }) })
7979
- ] })
7980
- ] });
7981
- }
8195
+ ]
8196
+ }
8197
+ );
8198
+ });
7982
8199
  var AVATAR = 28;
7983
- var styles12 = import_react_native18.StyleSheet.create({
8200
+ var styles13 = import_react_native19.StyleSheet.create({
7984
8201
  row: { paddingHorizontal: 12 },
7985
8202
  day: {
7986
8203
  alignSelf: "center",
@@ -8006,29 +8223,31 @@ var styles12 = import_react_native18.StyleSheet.create({
8006
8223
  borderRadius: RADII.group,
8007
8224
  paddingHorizontal: 14,
8008
8225
  paddingVertical: 10,
8009
- fontSize: 16,
8010
- lineHeight: 22,
8011
8226
  overflow: "hidden"
8012
- }
8227
+ },
8228
+ text: { fontSize: 16, lineHeight: 22 },
8229
+ // A reply with its quote: the quote above the text, inside the bubble.
8230
+ quoted: { gap: 6, paddingTop: 8, paddingHorizontal: 8 },
8231
+ quotedText: { paddingHorizontal: 6 }
8013
8232
  });
8014
8233
 
8015
8234
  // src/components/TypingBubble.tsx
8016
- var import_react13 = require("react");
8017
- var import_react_native19 = require("react-native");
8018
- var import_jsx_runtime15 = require("react/jsx-runtime");
8235
+ var import_react14 = require("react");
8236
+ var import_react_native20 = require("react-native");
8237
+ var import_jsx_runtime16 = require("react/jsx-runtime");
8019
8238
  function TypingBubble({ app, sender }) {
8020
8239
  const { t, colors } = useChatContext();
8021
8240
  const rise = useRiseIn(true);
8022
- const dots = (0, import_react13.useRef)([0, 1, 2].map(() => new import_react_native19.Animated.Value(0))).current;
8023
- (0, import_react13.useEffect)(() => {
8024
- const bounce = import_react_native19.Animated.loop(
8025
- import_react_native19.Animated.stagger(
8241
+ const dots = (0, import_react14.useRef)([0, 1, 2].map(() => new import_react_native20.Animated.Value(0))).current;
8242
+ (0, import_react14.useEffect)(() => {
8243
+ const bounce = import_react_native20.Animated.loop(
8244
+ import_react_native20.Animated.stagger(
8026
8245
  150,
8027
8246
  dots.map(
8028
- (dot) => import_react_native19.Animated.sequence([
8029
- import_react_native19.Animated.timing(dot, { toValue: 1, duration: 300, useNativeDriver: true }),
8030
- import_react_native19.Animated.timing(dot, { toValue: 0, duration: 300, useNativeDriver: true }),
8031
- import_react_native19.Animated.delay(300)
8247
+ (dot) => import_react_native20.Animated.sequence([
8248
+ import_react_native20.Animated.timing(dot, { toValue: 1, duration: 300, useNativeDriver: true }),
8249
+ import_react_native20.Animated.timing(dot, { toValue: 0, duration: 300, useNativeDriver: true }),
8250
+ import_react_native20.Animated.delay(300)
8032
8251
  ])
8033
8252
  )
8034
8253
  )
@@ -8036,13 +8255,13 @@ function TypingBubble({ app, sender }) {
8036
8255
  bounce.start();
8037
8256
  return () => bounce.stop();
8038
8257
  }, [dots]);
8039
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native19.Animated.View, { style: [styles13.row, rise], accessible: true, accessibilityLabel: format(t.typing, { name: sender?.name ?? t.team }), children: [
8040
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(TeamAvatar, { app, sender }),
8041
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native19.View, { style: [styles13.bubble, { backgroundColor: colors.surface }], children: dots.map((dot, index) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
8042
- import_react_native19.Animated.View,
8258
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_react_native20.Animated.View, { style: [styles14.row, rise], accessible: true, accessibilityLabel: format(t.typing, { name: sender?.name ?? t.team }), children: [
8259
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(TeamAvatar, { app, sender }),
8260
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native20.View, { style: [styles14.bubble, { backgroundColor: colors.surface }], children: dots.map((dot, index) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
8261
+ import_react_native20.Animated.View,
8043
8262
  {
8044
8263
  style: [
8045
- styles13.dot,
8264
+ styles14.dot,
8046
8265
  {
8047
8266
  backgroundColor: colors.muted,
8048
8267
  opacity: dot.interpolate({ inputRange: [0, 1], outputRange: [0.35, 1] }),
@@ -8054,7 +8273,7 @@ function TypingBubble({ app, sender }) {
8054
8273
  )) })
8055
8274
  ] });
8056
8275
  }
8057
- var styles13 = import_react_native19.StyleSheet.create({
8276
+ var styles14 = import_react_native20.StyleSheet.create({
8058
8277
  row: { flexDirection: "row", alignItems: "flex-end", gap: 8, paddingHorizontal: 12, paddingTop: 14 },
8059
8278
  bubble: {
8060
8279
  flexDirection: "row",
@@ -8069,15 +8288,17 @@ var styles13 = import_react_native19.StyleSheet.create({
8069
8288
  });
8070
8289
 
8071
8290
  // src/components/MessageList.tsx
8072
- var import_jsx_runtime16 = require("react/jsx-runtime");
8291
+ var import_jsx_runtime17 = require("react/jsx-runtime");
8073
8292
  function MessageList({ state }) {
8074
8293
  const { chat: chat2, t, colors, openedAt } = useChatContext();
8075
- const listRef = (0, import_react14.useRef)(null);
8076
- const [scrolledUp, setScrolledUp] = (0, import_react14.useState)(false);
8294
+ const listRef = (0, import_react15.useRef)(null);
8295
+ const [scrolledUp, setScrolledUp] = (0, import_react15.useState)(false);
8296
+ const [highlighted, setHighlighted] = (0, import_react15.useState)(null);
8297
+ const [seeking, setSeeking] = (0, import_react15.useState)(null);
8077
8298
  const app = state.app;
8078
8299
  const { messages, seen, atStart } = state;
8079
8300
  const welcomeText = state.texts.welcome;
8080
- const rows = (0, import_react14.useMemo)(() => {
8301
+ const rows = (0, import_react15.useMemo)(() => {
8081
8302
  const welcome = atStart ? {
8082
8303
  id: "welcome",
8083
8304
  from: "team",
@@ -8086,65 +8307,95 @@ function MessageList({ state }) {
8086
8307
  attachments: [],
8087
8308
  createdAt: messages[0]?.createdAt ?? openedAt,
8088
8309
  status: "sent",
8089
- error: null
8310
+ error: null,
8311
+ replyTo: null
8090
8312
  } : null;
8091
8313
  return conversationRows(messages, seen, welcome).reverse();
8092
8314
  }, [messages, seen, atStart, welcomeText, openedAt]);
8093
8315
  const newest = rows.at(0)?.message;
8094
8316
  const sending = newest?.from === "contact" && newest.status === "sending" ? newest.id : null;
8095
- (0, import_react14.useEffect)(() => {
8317
+ (0, import_react15.useEffect)(() => {
8096
8318
  if (sending) listRef.current?.scrollToOffset({ offset: 0, animated: true });
8097
8319
  }, [sending]);
8098
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_react_native20.View, { style: styles14.list, children: [
8099
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
8100
- import_react_native20.FlatList,
8320
+ (0, import_react15.useEffect)(() => {
8321
+ if (!highlighted) return;
8322
+ const timer = setTimeout(() => setHighlighted(null), QUOTE_HIGHLIGHT_MS);
8323
+ return () => clearTimeout(timer);
8324
+ }, [highlighted]);
8325
+ (0, import_react15.useEffect)(() => {
8326
+ if (!seeking) return;
8327
+ const step = quoteStepOf(state, seeking);
8328
+ if (step.kind === "older") chat2.loadOlder();
8329
+ if (step.kind === "older" || step.kind === "wait") return;
8330
+ setSeeking(null);
8331
+ if (step.kind === "none") return;
8332
+ const index = rows.findIndex((row) => row.message.id === step.id);
8333
+ listRef.current?.scrollToIndex({ index, animated: true, viewPosition: 0.5 });
8334
+ setHighlighted(step.id);
8335
+ }, [seeking, state, chat2, rows]);
8336
+ const handleQuote = (0, import_react15.useCallback)((replyId) => setSeeking(replyId), []);
8337
+ const handleRetry = (0, import_react15.useCallback)((messageId) => chat2.retry(messageId), [chat2]);
8338
+ const renderItem = (0, import_react15.useCallback)(
8339
+ ({ item }) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(MessageBubble, { row: item, app, onRetry: handleRetry, onQuote: handleQuote, highlighted: highlighted === item.message.id }),
8340
+ [app, handleRetry, handleQuote, highlighted]
8341
+ );
8342
+ const handleScrollToIndexFailed = ({ index, averageItemLength }) => {
8343
+ listRef.current?.scrollToOffset({ offset: index * averageItemLength, animated: false });
8344
+ setTimeout(() => listRef.current?.scrollToIndex({ index, animated: true, viewPosition: 0.5 }), RETRY_SCROLL_MS);
8345
+ };
8346
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_react_native21.View, { style: styles15.list, children: [
8347
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
8348
+ import_react_native21.FlatList,
8101
8349
  {
8102
8350
  ref: listRef,
8103
8351
  testID: "zean-conversation",
8104
8352
  inverted: true,
8105
8353
  data: rows,
8106
8354
  keyExtractor: (row) => row.message.id,
8107
- renderItem: ({ item }) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessageBubble, { row: item, app, onRetry: () => chat2.retry(item.message.id) }),
8108
- ListHeaderComponent: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_react_native20.View, { style: styles14.below, children: [
8109
- state.teamTyping && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(TypingBubble, { app, sender: state.teamTyping.sender }),
8110
- state.askEmail && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(EmailForm, { onSubmit: chat2.setEmail }),
8111
- state.email && (!state.online || state.emailGiven) && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native20.Text, { style: [styles14.saved, { color: colors.muted }], children: format(t.email_saved, { email: state.email }) })
8355
+ extraData: highlighted,
8356
+ renderItem,
8357
+ onScrollToIndexFailed: handleScrollToIndexFailed,
8358
+ ListHeaderComponent: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_react_native21.View, { style: styles15.below, children: [
8359
+ state.teamTyping && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(TypingBubble, { app, sender: state.teamTyping.sender }),
8360
+ state.askEmail && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(EmailForm, { onSubmit: chat2.setEmail }),
8361
+ state.email && (!state.online || state.emailGiven) && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_native21.Text, { style: [styles15.saved, { color: colors.muted }], children: format(t.email_saved, { email: state.email }) })
8112
8362
  ] }),
8113
- ListFooterComponent: state.hasOlder ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native20.View, { style: styles14.above, children: state.loadingOlder ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Skeleton, { style: [styles14.bone, styles14.olderBone] }) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
8114
- import_react_native20.Pressable,
8363
+ ListFooterComponent: state.hasOlder ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_native21.View, { style: styles15.above, children: state.loadingOlder ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Skeleton, { style: [styles15.bone, styles15.olderBone] }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
8364
+ import_react_native21.Pressable,
8115
8365
  {
8116
8366
  onPress: chat2.loadOlder,
8117
8367
  accessibilityRole: "button",
8118
- style: ({ pressed }) => [styles14.earlier, { backgroundColor: colors.surface }, pressed && styles14.pressed],
8119
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_native20.Text, { style: [styles14.earlierText, { color: colors.muted }], children: t.earlier })
8368
+ style: ({ pressed }) => [styles15.earlier, { backgroundColor: colors.surface }, pressed && styles15.pressed],
8369
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_native21.Text, { style: [styles15.earlierText, { color: colors.muted }], children: t.earlier })
8120
8370
  }
8121
8371
  ) }) : void 0,
8122
8372
  onScroll: (event) => setScrolledUp(event.nativeEvent.contentOffset.y > NEWEST_BUTTON_OFFSET),
8123
8373
  scrollEventThrottle: 64,
8124
8374
  maintainVisibleContentPosition: scrolledUp ? { minIndexForVisible: 0 } : void 0,
8125
- contentContainerStyle: styles14.content,
8375
+ contentContainerStyle: styles15.content,
8126
8376
  keyboardShouldPersistTaps: "handled",
8127
8377
  keyboardDismissMode: "on-drag",
8128
- style: styles14.list
8378
+ style: styles15.list
8129
8379
  }
8130
8380
  ),
8131
- scrolledUp && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
8132
- import_react_native20.Pressable,
8381
+ scrolledUp && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
8382
+ import_react_native21.Pressable,
8133
8383
  {
8134
8384
  onPress: () => listRef.current?.scrollToOffset({ offset: 0, animated: true }),
8135
8385
  accessibilityRole: "button",
8136
8386
  accessibilityLabel: t.newest,
8137
8387
  style: ({ pressed }) => [
8138
- styles14.newest,
8388
+ styles15.newest,
8139
8389
  { backgroundColor: colors.surface, borderColor: colors.border },
8140
- pressed && styles14.pressed
8390
+ pressed && styles15.pressed
8141
8391
  ],
8142
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Icon, { name: "down", color: colors.text, size: 20 })
8392
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Icon, { name: "down", color: colors.text, size: 20 })
8143
8393
  }
8144
8394
  )
8145
8395
  ] });
8146
8396
  }
8147
- var styles14 = import_react_native20.StyleSheet.create({
8397
+ var RETRY_SCROLL_MS = 250;
8398
+ var styles15 = import_react_native21.StyleSheet.create({
8148
8399
  list: { flex: 1 },
8149
8400
  // Inverted, `flex-end` is the top: a short Conversation starts under the header, as in the web widget.
8150
8401
  content: { flexGrow: 1, justifyContent: "flex-end", paddingBottom: 12, paddingTop: 4 },
@@ -8163,7 +8414,7 @@ var styles14 = import_react_native20.StyleSheet.create({
8163
8414
  width: COMPOSER_BUTTON,
8164
8415
  height: COMPOSER_BUTTON,
8165
8416
  borderRadius: COMPOSER_BUTTON / 2,
8166
- borderWidth: import_react_native20.StyleSheet.hairlineWidth,
8417
+ borderWidth: import_react_native21.StyleSheet.hairlineWidth,
8167
8418
  alignItems: "center",
8168
8419
  justifyContent: "center",
8169
8420
  shadowColor: "#000000",
@@ -8175,26 +8426,26 @@ var styles14 = import_react_native20.StyleSheet.create({
8175
8426
  });
8176
8427
 
8177
8428
  // src/components/PoweredBy.tsx
8178
- var import_react_native21 = require("react-native");
8179
- var import_jsx_runtime17 = require("react/jsx-runtime");
8429
+ var import_react_native22 = require("react-native");
8430
+ var import_jsx_runtime18 = require("react/jsx-runtime");
8180
8431
  function PoweredBy() {
8181
8432
  const { t, colors } = useChatContext();
8182
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
8183
- import_react_native21.Pressable,
8433
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
8434
+ import_react_native22.Pressable,
8184
8435
  {
8185
- style: ({ pressed }) => [styles15.row, pressed && styles15.pressed],
8436
+ style: ({ pressed }) => [styles16.row, pressed && styles16.pressed],
8186
8437
  accessibilityRole: "link",
8187
8438
  accessibilityLabel: `${t.powered_by} ${APP_NAME}`,
8188
- onPress: () => void import_react_native21.Linking.openURL(APP_URL),
8439
+ onPress: () => void import_react_native22.Linking.openURL(APP_URL),
8189
8440
  children: [
8190
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_native21.Text, { style: [styles15.text, { color: colors.muted }], children: t.powered_by }),
8191
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Icon, { name: "mark", color: ZEAN_ACCENT_HEX, size: 14 }),
8192
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_native21.Text, { style: [styles15.text, styles15.name, { color: colors.muted }], children: APP_NAME })
8441
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_native22.Text, { style: [styles16.text, { color: colors.muted }], children: t.powered_by }),
8442
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Icon, { name: "mark", color: ZEAN_ACCENT_HEX, size: 14 }),
8443
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_native22.Text, { style: [styles16.text, styles16.name, { color: colors.muted }], children: APP_NAME })
8193
8444
  ]
8194
8445
  }
8195
8446
  );
8196
8447
  }
8197
- var styles15 = import_react_native21.StyleSheet.create({
8448
+ var styles16 = import_react_native22.StyleSheet.create({
8198
8449
  row: { flexDirection: "row", alignItems: "center", justifyContent: "center", alignSelf: "center", gap: 4 },
8199
8450
  pressed: { opacity: 0.6 },
8200
8451
  text: { fontSize: 12 },
@@ -8202,46 +8453,49 @@ var styles15 = import_react_native21.StyleSheet.create({
8202
8453
  });
8203
8454
 
8204
8455
  // src/components/ChatScreen.tsx
8205
- var import_jsx_runtime18 = require("react/jsx-runtime");
8456
+ var import_jsx_runtime19 = require("react/jsx-runtime");
8206
8457
  function ChatScreen({ state, insets, onClose }) {
8207
8458
  const { chat: chat2, t, colors } = useChatContext();
8208
- const rootRef = (0, import_react15.useRef)(null);
8459
+ const rootRef = (0, import_react16.useRef)(null);
8209
8460
  const keyboard = useKeyboardOverlap(rootRef);
8210
8461
  const connectionLost = useConnectionLost(state.connected);
8211
8462
  const app = state.app;
8212
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_react_native22.View, { ref: rootRef, style: [styles16.screen, { backgroundColor: colors.background, paddingBottom: keyboard }], children: [
8213
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatHeader, { app, online: state.online, topInset: insets.top, onClose }),
8214
- connectionLost && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_native22.View, { style: styles16.notice, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatNotice, { children: t.reconnecting }) }),
8215
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(MessageList, { state }),
8216
- /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_react_native22.View, { style: [styles16.footer, { paddingBottom: 8 + (keyboard > 0 ? 0 : insets.bottom) }], children: [
8217
- state.contactCode && state.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ContactCodeCard, { code: state.contactCode, onDismiss: chat2.dismissCode }),
8218
- state.status === "blocked" ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatNotice, { children: t.blocked }) : state.status === "unavailable" ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatNotice, { children: t.unavailable }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Composer, {}),
8219
- app.showBadge && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PoweredBy, {})
8463
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_react_native23.View, { ref: rootRef, style: [styles17.screen, { backgroundColor: colors.background, paddingBottom: keyboard }], children: [
8464
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ChatHeader, { app, online: state.online, topInset: insets.top, onClose }),
8465
+ connectionLost && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_react_native23.View, { style: styles17.notice, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ChatNotice, { children: t.reconnecting }) }),
8466
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(MessageList, { state }),
8467
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_react_native23.View, { style: [styles17.footer, { paddingBottom: 8 + (keyboard > 0 ? 0 : insets.bottom) }], children: [
8468
+ state.contactCode && state.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ContactCodeCard, { code: state.contactCode, onDismiss: chat2.dismissCode }),
8469
+ state.status === "blocked" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ChatNotice, { children: t.blocked }) : state.status === "unavailable" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ChatNotice, { children: t.unavailable }) : (
8470
+ // Another person on the device starts it over: what it held was the previous one's.
8471
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Composer, {}, state.personKey)
8472
+ ),
8473
+ app.showBadge && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(PoweredBy, {})
8220
8474
  ] })
8221
8475
  ] });
8222
8476
  }
8223
- var styles16 = import_react_native22.StyleSheet.create({
8477
+ var styles17 = import_react_native23.StyleSheet.create({
8224
8478
  screen: { flex: 1 },
8225
8479
  notice: { paddingHorizontal: 12, paddingTop: 12 },
8226
8480
  footer: { gap: 8, paddingHorizontal: 10, paddingTop: 6 }
8227
8481
  });
8228
8482
 
8229
8483
  // src/components/ChatModal.tsx
8230
- var import_jsx_runtime19 = require("react/jsx-runtime");
8484
+ var import_jsx_runtime20 = require("react/jsx-runtime");
8231
8485
  var STRINGS = { fr, en };
8232
8486
  function ChatModal({ chat: chat2, colorScheme, maxPhotos }) {
8233
- const state = (0, import_react16.useSyncExternalStore)(chat2.subscribe, chat2.getState);
8234
- const { open: open2 } = (0, import_react16.useSyncExternalStore)(subscribeChatView, chatView);
8235
- const deviceScheme = (0, import_react_native23.useColorScheme)();
8487
+ const state = (0, import_react17.useSyncExternalStore)(chat2.subscribe, chat2.getState);
8488
+ const { open: open2 } = (0, import_react17.useSyncExternalStore)(subscribeChatView, chatView);
8489
+ const deviceScheme = (0, import_react_native24.useColorScheme)();
8236
8490
  const scheme = colorScheme ?? (deviceScheme === "dark" ? "dark" : "light");
8237
8491
  const active = useAppActive();
8238
- const dimensions = (0, import_react_native23.useWindowDimensions)();
8239
- const [gallery, setGallery] = (0, import_react16.useState)(null);
8240
- const [openedAt, setOpenedAt] = (0, import_react16.useState)(Date.now);
8492
+ const dimensions = (0, import_react_native24.useWindowDimensions)();
8493
+ const [gallery, setGallery] = (0, import_react17.useState)(null);
8494
+ const [openedAt, setOpenedAt] = (0, import_react17.useState)(Date.now);
8241
8495
  const app = state.app;
8242
8496
  const visible = open2 && app !== null && state.status !== "loading" && state.status !== "hidden";
8243
8497
  const color = app?.color ?? ZEAN_ACCENT_HEX;
8244
- const context = (0, import_react16.useMemo)(
8498
+ const context = (0, import_react17.useMemo)(
8245
8499
  () => ({
8246
8500
  chat: chat2,
8247
8501
  t: STRINGS[state.locale],
@@ -8253,35 +8507,35 @@ function ChatModal({ chat: chat2, colorScheme, maxPhotos }) {
8253
8507
  }),
8254
8508
  [chat2, state.locale, color, scheme, openedAt, maxPhotos]
8255
8509
  );
8256
- const insets = (0, import_react16.useMemo)(screenInsets, [dimensions.width, dimensions.height]);
8257
- (0, import_react16.useEffect)(() => chat2.setOpen(open2 && active), [chat2, open2, active]);
8258
- (0, import_react16.useEffect)(() => {
8510
+ const insets = (0, import_react17.useMemo)(screenInsets, [dimensions.width, dimensions.height]);
8511
+ (0, import_react17.useEffect)(() => chat2.setOpen(open2 && active), [chat2, open2, active]);
8512
+ (0, import_react17.useEffect)(() => {
8259
8513
  if (visible && active && state.unread > 0) chat2.markRead();
8260
8514
  }, [chat2, visible, active, state.unread]);
8261
- (0, import_react16.useEffect)(() => {
8515
+ (0, import_react17.useEffect)(() => {
8262
8516
  if (visible) setOpenedAt(Date.now());
8263
8517
  else setGallery(null);
8264
8518
  }, [visible]);
8265
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
8266
- import_react_native23.Modal,
8519
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
8520
+ import_react_native24.Modal,
8267
8521
  {
8268
8522
  testID: "zean-chat",
8269
8523
  visible,
8270
8524
  animationType: "slide",
8271
- presentationStyle: import_react_native23.Platform.OS === "ios" && !import_react_native23.Platform.isPad ? "pageSheet" : "fullScreen",
8525
+ presentationStyle: import_react_native24.Platform.OS === "ios" && !import_react_native24.Platform.isPad ? "pageSheet" : "fullScreen",
8272
8526
  statusBarTranslucent: true,
8273
8527
  navigationBarTranslucent: true,
8274
- onRequestClose: () => import_react_native23.Platform.OS === "android" && gallery ? setGallery(null) : zean.close(),
8275
- children: app && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(ChatContext, { value: context, children: [
8276
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ChatScreen, { state, insets, onClose: zean.close }),
8277
- gallery && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ImageViewer, { gallery, topInset: insets.top, onClose: () => setGallery(null) })
8528
+ onRequestClose: () => import_react_native24.Platform.OS === "android" && gallery ? setGallery(null) : zean.close(),
8529
+ children: app && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(ChatContext, { value: context, children: [
8530
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ChatScreen, { state, insets, onClose: zean.close }),
8531
+ gallery && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ImageViewer, { gallery, topInset: insets.top, onClose: () => setGallery(null) })
8278
8532
  ] })
8279
8533
  }
8280
8534
  );
8281
8535
  }
8282
8536
 
8283
8537
  // src/components/ZeanChat.tsx
8284
- var import_jsx_runtime20 = require("react/jsx-runtime");
8538
+ var import_jsx_runtime21 = require("react/jsx-runtime");
8285
8539
  function ZeanChat({
8286
8540
  appKey,
8287
8541
  storage,
@@ -8292,12 +8546,12 @@ function ZeanChat({
8292
8546
  maxPhotos,
8293
8547
  backendUrl = backendUrlFor(appKey)
8294
8548
  }) {
8295
- const [chat2, setChat] = (0, import_react17.useState)(null);
8296
- const storageRef = (0, import_react17.useRef)(storage);
8549
+ const [chat2, setChat] = (0, import_react18.useState)(null);
8550
+ const storageRef = (0, import_react18.useRef)(storage);
8297
8551
  const userKey = user ? JSON.stringify(user) : null;
8298
- const identified = (0, import_react17.useRef)(false);
8552
+ const identified = (0, import_react18.useRef)(false);
8299
8553
  const attributesKey = attributes2 ? JSON.stringify(attributes2) : null;
8300
- (0, import_react17.useEffect)(() => {
8554
+ (0, import_react18.useEffect)(() => {
8301
8555
  const started = createChat({
8302
8556
  appKey,
8303
8557
  backendUrl,
@@ -8320,20 +8574,20 @@ function ZeanChat({
8320
8574
  started.destroy();
8321
8575
  };
8322
8576
  }, [appKey, backendUrl, locale]);
8323
- (0, import_react17.useEffect)(() => {
8577
+ (0, import_react18.useEffect)(() => {
8324
8578
  if (userKey) zean.identify(JSON.parse(userKey));
8325
8579
  else if (identified.current) zean.signOut();
8326
8580
  identified.current = userKey !== null;
8327
8581
  }, [userKey]);
8328
- (0, import_react17.useEffect)(() => {
8582
+ (0, import_react18.useEffect)(() => {
8329
8583
  if (attributesKey) zean.setAttributes(JSON.parse(attributesKey));
8330
- }, [attributesKey]);
8331
- return chat2 ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ChatModal, { chat: chat2, colorScheme, maxPhotos }) : null;
8584
+ }, [attributesKey, userKey]);
8585
+ return chat2 ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ChatModal, { chat: chat2, colorScheme, maxPhotos }) : null;
8332
8586
  }
8333
8587
 
8334
8588
  // src/hooks/use-zean.ts
8335
- var import_react18 = require("react");
8589
+ var import_react19 = require("react");
8336
8590
  function useZean() {
8337
- const { unread } = (0, import_react18.useSyncExternalStore)(subscribeChatView, chatView);
8591
+ const { unread } = (0, import_react19.useSyncExternalStore)(subscribeChatView, chatView);
8338
8592
  return { ...zean, unreadCount: unread };
8339
8593
  }