@zean-chat/react-native 0.1.13 → 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/README.md +2 -0
- package/dist/components/Composer.d.ts +1 -1
- package/dist/components/MessageBubble.d.ts +3 -2
- package/dist/components/MessageQuote.d.ts +3 -0
- package/dist/hooks/use-pending-photos.d.ts +5 -1
- package/dist/i18n/en.d.ts +4 -0
- package/dist/i18n/fr.d.ts +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +537 -256
- package/dist/interfaces.d.ts +10 -1
- package/dist/models/conversation.utils.d.ts +6 -2
- package/dist/models/sdk.interface.d.ts +18 -2
- package/dist/models/sdk.store.d.ts +4 -0
- package/package.json +1 -1
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
550
|
-
const
|
|
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:
|
|
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
|
|
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 =
|
|
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 {
|
|
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);
|
|
@@ -6631,19 +6720,34 @@ var identity = null;
|
|
|
6631
6720
|
var signOutWaiting = false;
|
|
6632
6721
|
var attributes = {};
|
|
6633
6722
|
var pushToken;
|
|
6723
|
+
var draft = null;
|
|
6724
|
+
var notify = () => {
|
|
6725
|
+
for (const listener of listeners) listener();
|
|
6726
|
+
};
|
|
6634
6727
|
var emit = () => {
|
|
6635
6728
|
const unread = chat?.getState().unread ?? 0;
|
|
6636
6729
|
if (view.open === open && view.unread === unread) return;
|
|
6637
6730
|
view = { open, unread };
|
|
6638
|
-
|
|
6731
|
+
notify();
|
|
6732
|
+
};
|
|
6733
|
+
var setDraft = (next) => {
|
|
6734
|
+
draft = next;
|
|
6735
|
+
notify();
|
|
6639
6736
|
};
|
|
6640
6737
|
var setOpen = (next) => {
|
|
6641
6738
|
open = next;
|
|
6642
6739
|
emit();
|
|
6643
6740
|
};
|
|
6644
6741
|
var zean = {
|
|
6645
|
-
open
|
|
6646
|
-
|
|
6742
|
+
open(options) {
|
|
6743
|
+
const message = options?.message;
|
|
6744
|
+
if (typeof message === "string" && message.trim() !== "") setDraft(message.slice(0, MAX_MESSAGE_LENGTH));
|
|
6745
|
+
setOpen(true);
|
|
6746
|
+
},
|
|
6747
|
+
close() {
|
|
6748
|
+
setDraft(null);
|
|
6749
|
+
setOpen(false);
|
|
6750
|
+
},
|
|
6647
6751
|
toggle: () => setOpen(!open),
|
|
6648
6752
|
identify(user) {
|
|
6649
6753
|
identity = user;
|
|
@@ -6688,14 +6792,20 @@ function attachChat(next) {
|
|
|
6688
6792
|
function chatView() {
|
|
6689
6793
|
return view;
|
|
6690
6794
|
}
|
|
6795
|
+
function chatDraft() {
|
|
6796
|
+
return draft;
|
|
6797
|
+
}
|
|
6798
|
+
function clearDraft() {
|
|
6799
|
+
setDraft(null);
|
|
6800
|
+
}
|
|
6691
6801
|
function subscribeChatView(listener) {
|
|
6692
6802
|
listeners.add(listener);
|
|
6693
6803
|
return () => listeners.delete(listener);
|
|
6694
6804
|
}
|
|
6695
6805
|
|
|
6696
6806
|
// src/components/ChatModal.tsx
|
|
6697
|
-
var
|
|
6698
|
-
var
|
|
6807
|
+
var import_react17 = require("react");
|
|
6808
|
+
var import_react_native24 = require("react-native");
|
|
6699
6809
|
|
|
6700
6810
|
// src/hooks/use-app-active.ts
|
|
6701
6811
|
var import_react = require("react");
|
|
@@ -6734,6 +6844,10 @@ var en = {
|
|
|
6734
6844
|
seen: "Seen",
|
|
6735
6845
|
not_sent: "Not sent.",
|
|
6736
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",
|
|
6737
6851
|
retry: "Retry",
|
|
6738
6852
|
team: "The team",
|
|
6739
6853
|
typing: "{name} is typing\u2026",
|
|
@@ -6790,6 +6904,10 @@ var fr = {
|
|
|
6790
6904
|
seen: "Vu",
|
|
6791
6905
|
not_sent: "Non envoy\xE9.",
|
|
6792
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",
|
|
6793
6911
|
retry: "R\xE9essayer",
|
|
6794
6912
|
team: "L'\xE9quipe",
|
|
6795
6913
|
typing: "{name} \xE9crit\u2026",
|
|
@@ -6927,8 +7045,8 @@ var styles = import_react_native4.StyleSheet.create({
|
|
|
6927
7045
|
});
|
|
6928
7046
|
|
|
6929
7047
|
// src/components/ChatScreen.tsx
|
|
6930
|
-
var
|
|
6931
|
-
var
|
|
7048
|
+
var import_react16 = require("react");
|
|
7049
|
+
var import_react_native23 = require("react-native");
|
|
6932
7050
|
|
|
6933
7051
|
// src/hooks/use-connection-lost.ts
|
|
6934
7052
|
var import_react4 = require("react");
|
|
@@ -7193,11 +7311,96 @@ function isImage(type) {
|
|
|
7193
7311
|
return IMAGE_TYPES.includes(type);
|
|
7194
7312
|
}
|
|
7195
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
|
+
|
|
7196
7398
|
// src/hooks/use-pending-photos.ts
|
|
7197
7399
|
var lastId = 0;
|
|
7400
|
+
var nextId = () => `photo_${++lastId}`;
|
|
7198
7401
|
function usePendingPhotos() {
|
|
7199
7402
|
const { chat: chat2, t, maxPhotos } = useChatContext();
|
|
7200
|
-
const [photos, setPhotos] = (0, import_react7.useState)([]);
|
|
7403
|
+
const [photos, setPhotos] = (0, import_react7.useState)(() => pendingPhotosOfDraft(chat2.draft()?.files ?? [], nextId));
|
|
7201
7404
|
const [problem, setProblem] = (0, import_react7.useState)(null);
|
|
7202
7405
|
const [sending, setSending] = (0, import_react7.useState)(false);
|
|
7203
7406
|
const tooMany = maxPhotos === 1 ? t.too_many_one : format(t.too_many, { count: maxPhotos });
|
|
@@ -7242,9 +7445,8 @@ function usePendingPhotos() {
|
|
|
7242
7445
|
setProblem(format(t.photo_size, { name: photo.name }));
|
|
7243
7446
|
continue;
|
|
7244
7447
|
}
|
|
7245
|
-
lastId += 1;
|
|
7246
7448
|
const { uri, name, type, width, height } = photo;
|
|
7247
|
-
added.push({ id:
|
|
7449
|
+
added.push({ id: nextId(), uri, name, type, width, height, status: "picked", attachment: null });
|
|
7248
7450
|
}
|
|
7249
7451
|
setPhotos((current) => [...current, ...added]);
|
|
7250
7452
|
};
|
|
@@ -7258,8 +7460,10 @@ function usePendingPhotos() {
|
|
|
7258
7460
|
setPhotos([]);
|
|
7259
7461
|
return attachments;
|
|
7260
7462
|
};
|
|
7463
|
+
const draftFiles = (0, import_react7.useMemo)(() => draftFilesOf(photos), [photos]);
|
|
7261
7464
|
return {
|
|
7262
7465
|
photos,
|
|
7466
|
+
draftFiles,
|
|
7263
7467
|
problem,
|
|
7264
7468
|
/** Photos that still fit in the message. */
|
|
7265
7469
|
room: maxPhotos - photos.length,
|
|
@@ -7401,15 +7605,24 @@ var styles6 = import_react_native10.StyleSheet.create({
|
|
|
7401
7605
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
7402
7606
|
function Composer() {
|
|
7403
7607
|
const { chat: chat2, t, colors } = useChatContext();
|
|
7404
|
-
const [text, setText] = (0, import_react8.useState)("");
|
|
7405
|
-
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);
|
|
7406
7610
|
const pending = usePendingPhotos();
|
|
7407
7611
|
const picker = photoPicker();
|
|
7408
7612
|
const canSend = !pending.sending && (text.trim().length > 0 || pending.photos.length > 0);
|
|
7613
|
+
const draft2 = (0, import_react8.useSyncExternalStore)(subscribeChatView, chatDraft);
|
|
7409
7614
|
const changeText = (value) => {
|
|
7410
7615
|
typed.current = value;
|
|
7411
7616
|
setText(value);
|
|
7412
7617
|
};
|
|
7618
|
+
(0, import_react8.useEffect)(() => {
|
|
7619
|
+
if (draft2 === null) return;
|
|
7620
|
+
changeText(draft2);
|
|
7621
|
+
clearDraft();
|
|
7622
|
+
}, [draft2]);
|
|
7623
|
+
(0, import_react8.useEffect)(() => {
|
|
7624
|
+
chat2.saveDraft({ text, files: pending.draftFiles });
|
|
7625
|
+
}, [chat2, text, pending.draftFiles]);
|
|
7413
7626
|
const handleSend = async () => {
|
|
7414
7627
|
const attachments = pending.photos.length > 0 ? await pending.send() : [];
|
|
7415
7628
|
if (!attachments) return;
|
|
@@ -7506,78 +7719,8 @@ var styles7 = import_react_native11.StyleSheet.create({
|
|
|
7506
7719
|
});
|
|
7507
7720
|
|
|
7508
7721
|
// src/components/MessageList.tsx
|
|
7509
|
-
var
|
|
7510
|
-
var
|
|
7511
|
-
|
|
7512
|
-
// src/models/conversation.utils.ts
|
|
7513
|
-
function authorOf(message) {
|
|
7514
|
-
if (message.from === "contact") return "contact";
|
|
7515
|
-
return `team:${message.sender?.name ?? ""}:${message.sender?.image ?? ""}`;
|
|
7516
|
-
}
|
|
7517
|
-
function startOfDay(timestamp) {
|
|
7518
|
-
const day = new Date(timestamp);
|
|
7519
|
-
day.setHours(0, 0, 0, 0);
|
|
7520
|
-
return day.getTime();
|
|
7521
|
-
}
|
|
7522
|
-
function sameDay(left, right) {
|
|
7523
|
-
return startOfDay(left) === startOfDay(right);
|
|
7524
|
-
}
|
|
7525
|
-
function joins(older, newer) {
|
|
7526
|
-
return older.status !== "failed" && authorOf(older) === authorOf(newer) && newer.createdAt - older.createdAt < RUN_GAP_MS && sameDay(older.createdAt, newer.createdAt);
|
|
7527
|
-
}
|
|
7528
|
-
function conversationRows(messages, seen, welcome) {
|
|
7529
|
-
const all = welcome ? [welcome, ...messages] : [...messages];
|
|
7530
|
-
const lastReply = all.findLastIndex((message) => message.from === "team" && message.sender !== null);
|
|
7531
|
-
return all.map((message, index) => {
|
|
7532
|
-
const older = all[index - 1];
|
|
7533
|
-
const newer = all[index + 1];
|
|
7534
|
-
const isWelcome = message === welcome;
|
|
7535
|
-
return {
|
|
7536
|
-
message,
|
|
7537
|
-
startsRun: !older || !joins(older, message),
|
|
7538
|
-
endsRun: !newer || !joins(message, newer),
|
|
7539
|
-
// Alone, the welcome has no day: there is nothing to date.
|
|
7540
|
-
startsDay: isWelcome ? messages.length > 0 : !older || !sameDay(older.createdAt, message.createdAt),
|
|
7541
|
-
receipt: receiptOf(message, seen || index < lastReply),
|
|
7542
|
-
welcome: isWelcome
|
|
7543
|
-
};
|
|
7544
|
-
});
|
|
7545
|
-
}
|
|
7546
|
-
function receiptOf(message, seen) {
|
|
7547
|
-
if (message.from === "team" || message.status === "failed") return null;
|
|
7548
|
-
if (message.status === "sending") return "sending";
|
|
7549
|
-
return seen ? "seen" : "sent";
|
|
7550
|
-
}
|
|
7551
|
-
var DATE_STYLES = {
|
|
7552
|
-
time: { hour: "2-digit", minute: "2-digit" },
|
|
7553
|
-
weekday: { weekday: "long" },
|
|
7554
|
-
day: { day: "numeric", month: "short" },
|
|
7555
|
-
dayYear: { day: "numeric", month: "short", year: "numeric" }
|
|
7556
|
-
};
|
|
7557
|
-
var formats = /* @__PURE__ */ new Map();
|
|
7558
|
-
function formatDate(timestamp, locale, style) {
|
|
7559
|
-
const key = `${locale}:${style}`;
|
|
7560
|
-
let format2 = formats.get(key);
|
|
7561
|
-
if (!format2) {
|
|
7562
|
-
format2 = new Intl.DateTimeFormat(locale, DATE_STYLES[style]);
|
|
7563
|
-
formats.set(key, format2);
|
|
7564
|
-
}
|
|
7565
|
-
return format2.format(timestamp);
|
|
7566
|
-
}
|
|
7567
|
-
function messageTime(timestamp, locale) {
|
|
7568
|
-
return formatDate(timestamp, locale, "time");
|
|
7569
|
-
}
|
|
7570
|
-
function dayLabel(timestamp, now, locale, t) {
|
|
7571
|
-
const today = startOfDay(now);
|
|
7572
|
-
const day = startOfDay(timestamp);
|
|
7573
|
-
if (day === today) return t.today;
|
|
7574
|
-
if (day === startOfDay(today - 1)) return t.yesterday;
|
|
7575
|
-
const weekAgo = new Date(today);
|
|
7576
|
-
weekAgo.setDate(weekAgo.getDate() - 6);
|
|
7577
|
-
if (day >= weekAgo.getTime()) return formatDate(timestamp, locale, "weekday");
|
|
7578
|
-
const sameYear = new Date(timestamp).getFullYear() === new Date(now).getFullYear();
|
|
7579
|
-
return formatDate(timestamp, locale, sameYear ? "day" : "dayYear");
|
|
7580
|
-
}
|
|
7722
|
+
var import_react15 = require("react");
|
|
7723
|
+
var import_react_native21 = require("react-native");
|
|
7581
7724
|
|
|
7582
7725
|
// src/components/EmailForm.tsx
|
|
7583
7726
|
var import_react9 = require("react");
|
|
@@ -7650,7 +7793,8 @@ var styles8 = import_react_native12.StyleSheet.create({
|
|
|
7650
7793
|
});
|
|
7651
7794
|
|
|
7652
7795
|
// src/components/MessageBubble.tsx
|
|
7653
|
-
var
|
|
7796
|
+
var import_react13 = require("react");
|
|
7797
|
+
var import_react_native19 = require("react-native");
|
|
7654
7798
|
|
|
7655
7799
|
// src/hooks/use-rise-in.ts
|
|
7656
7800
|
var import_react10 = require("react");
|
|
@@ -7683,6 +7827,8 @@ var signed = /* @__PURE__ */ new Map();
|
|
|
7683
7827
|
function useAttachmentLinks(chat2, keys, stored) {
|
|
7684
7828
|
const [links, setLinks] = (0, import_react11.useState)(() => cachedLinks(keys));
|
|
7685
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);
|
|
7686
7832
|
const wanted = keys.join("|");
|
|
7687
7833
|
(0, import_react11.useEffect)(() => {
|
|
7688
7834
|
if (!stored) return;
|
|
@@ -7694,19 +7840,27 @@ function useAttachmentLinks(chat2, keys, stored) {
|
|
|
7694
7840
|
}
|
|
7695
7841
|
let cancelled = false;
|
|
7696
7842
|
let retry;
|
|
7843
|
+
const askAgain = () => {
|
|
7844
|
+
if (!cancelled && attempt < LINK_RETRIES) retry = setTimeout(() => setAttempt(attempt + 1), LINK_RETRY_MS);
|
|
7845
|
+
};
|
|
7697
7846
|
chat2.attachmentLinks(missing).then((fresh) => {
|
|
7847
|
+
failed.current = false;
|
|
7698
7848
|
for (const link of fresh) signed.set(link.key, { url: link.url, until: Date.now() + LINK_LIFETIME_MS });
|
|
7699
7849
|
if (cancelled) return;
|
|
7700
7850
|
setLinks(cachedLinks(list));
|
|
7701
|
-
if (fresh.length < missing.length
|
|
7702
|
-
retry = setTimeout(() => setAttempt(attempt + 1), LINK_RETRY_MS);
|
|
7851
|
+
if (fresh.length < missing.length) askAgain();
|
|
7703
7852
|
}).catch(() => {
|
|
7853
|
+
failed.current = true;
|
|
7854
|
+
askAgain();
|
|
7704
7855
|
});
|
|
7705
7856
|
return () => {
|
|
7706
7857
|
cancelled = true;
|
|
7707
7858
|
clearTimeout(retry);
|
|
7708
7859
|
};
|
|
7709
7860
|
}, [chat2, wanted, attempt, stored]);
|
|
7861
|
+
(0, import_react11.useEffect)(() => {
|
|
7862
|
+
if (connected && failed.current) setAttempt((current) => current + 1);
|
|
7863
|
+
}, [connected]);
|
|
7710
7864
|
return links;
|
|
7711
7865
|
}
|
|
7712
7866
|
function cachedLinks(keys) {
|
|
@@ -7858,37 +8012,104 @@ var styles10 = import_react_native16.StyleSheet.create({
|
|
|
7858
8012
|
retry: { fontWeight: "600", textDecorationLine: "underline" }
|
|
7859
8013
|
});
|
|
7860
8014
|
|
|
7861
|
-
// src/components/
|
|
8015
|
+
// src/components/MessageQuote.tsx
|
|
7862
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
|
|
7863
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");
|
|
7864
8085
|
function TeamAvatar({ app, sender, ai = false }) {
|
|
7865
8086
|
const { colors } = useChatContext();
|
|
7866
8087
|
if (ai) {
|
|
7867
|
-
return /* @__PURE__ */ (0,
|
|
7868
|
-
|
|
8088
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
8089
|
+
import_react_native18.View,
|
|
7869
8090
|
{
|
|
7870
|
-
style: [
|
|
8091
|
+
style: [styles12.avatar, { backgroundColor: colors.primaryTint }],
|
|
7871
8092
|
accessibilityElementsHidden: true,
|
|
7872
8093
|
importantForAccessibility: "no-hide-descendants",
|
|
7873
|
-
children: /* @__PURE__ */ (0,
|
|
8094
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "sparkles", color: colors.primaryText, size: 14 })
|
|
7874
8095
|
}
|
|
7875
8096
|
);
|
|
7876
8097
|
}
|
|
7877
8098
|
const image = sender ? sender.image : app.logoUrl;
|
|
7878
8099
|
if (image) {
|
|
7879
|
-
return /* @__PURE__ */ (0,
|
|
8100
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Image, { source: { uri: image }, style: [styles12.avatar, { borderColor: colors.border }], accessibilityIgnoresInvertColors: true });
|
|
7880
8101
|
}
|
|
7881
|
-
return /* @__PURE__ */ (0,
|
|
7882
|
-
|
|
8102
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
8103
|
+
import_react_native18.View,
|
|
7883
8104
|
{
|
|
7884
|
-
style: [
|
|
8105
|
+
style: [styles12.avatar, { backgroundColor: sender ? colors.primaryTint : colors.primary }],
|
|
7885
8106
|
accessibilityElementsHidden: true,
|
|
7886
8107
|
importantForAccessibility: "no-hide-descendants",
|
|
7887
|
-
children: /* @__PURE__ */ (0,
|
|
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) })
|
|
7888
8109
|
}
|
|
7889
8110
|
);
|
|
7890
8111
|
}
|
|
7891
|
-
var
|
|
8112
|
+
var styles12 = import_react_native18.StyleSheet.create({
|
|
7892
8113
|
avatar: {
|
|
7893
8114
|
width: 28,
|
|
7894
8115
|
height: 28,
|
|
@@ -7903,57 +8124,80 @@ var styles11 = import_react_native17.StyleSheet.create({
|
|
|
7903
8124
|
});
|
|
7904
8125
|
|
|
7905
8126
|
// src/components/MessageBubble.tsx
|
|
7906
|
-
var
|
|
7907
|
-
|
|
8127
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
8128
|
+
var MessageBubble = (0, import_react13.memo)(function MessageBubble2({ row, app, onRetry, onQuote, highlighted }) {
|
|
7908
8129
|
const { chat: chat2, t, locale, colors, openedAt } = useChatContext();
|
|
7909
8130
|
const { message, startsRun, endsRun, startsDay } = row;
|
|
7910
8131
|
const own = message.from === "contact";
|
|
8132
|
+
const handleRetry = () => onRetry(message.id);
|
|
7911
8133
|
const rise = useRiseIn(message.createdAt > openedAt && (!own || message.status === "sending"));
|
|
7912
8134
|
const corner = startsRun ? RADII.group : RADII.inner;
|
|
7913
|
-
return /* @__PURE__ */ (0,
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
{
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
{ borderTopRightRadius: corner, borderBottomRightRadius: RADII.inner },
|
|
7923
|
-
{ backgroundColor: colors.primary, color: colors.primaryForeground }
|
|
7924
|
-
],
|
|
7925
|
-
children: message.body
|
|
7926
|
-
}
|
|
7927
|
-
),
|
|
7928
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageFiles, { attachments: message.attachments, own: true, stored: message.status === "sent" }),
|
|
7929
|
-
endsRun && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageMeta, { row, onRetry })
|
|
7930
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.team, children: [
|
|
7931
|
-
(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 }),
|
|
7932
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.teamRow, children: [
|
|
7933
|
-
/* @__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 }) }),
|
|
7934
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.teamColumn, children: [
|
|
7935
|
-
message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7936
|
-
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,
|
|
7937
8144
|
{
|
|
7938
8145
|
selectable: true,
|
|
7939
8146
|
style: [
|
|
7940
|
-
|
|
7941
|
-
|
|
7942
|
-
{
|
|
8147
|
+
styles13.bubble,
|
|
8148
|
+
styles13.text,
|
|
8149
|
+
{ borderTopRightRadius: corner, borderBottomRightRadius: RADII.inner },
|
|
8150
|
+
{ backgroundColor: colors.primary, color: colors.primaryForeground }
|
|
7943
8151
|
],
|
|
7944
8152
|
children: message.body
|
|
7945
8153
|
}
|
|
7946
8154
|
),
|
|
7947
|
-
/* @__PURE__ */ (0,
|
|
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 }) })
|
|
7948
8194
|
] })
|
|
7949
|
-
]
|
|
7950
|
-
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
] });
|
|
7954
|
-
}
|
|
8195
|
+
]
|
|
8196
|
+
}
|
|
8197
|
+
);
|
|
8198
|
+
});
|
|
7955
8199
|
var AVATAR = 28;
|
|
7956
|
-
var
|
|
8200
|
+
var styles13 = import_react_native19.StyleSheet.create({
|
|
7957
8201
|
row: { paddingHorizontal: 12 },
|
|
7958
8202
|
day: {
|
|
7959
8203
|
alignSelf: "center",
|
|
@@ -7979,29 +8223,31 @@ var styles12 = import_react_native18.StyleSheet.create({
|
|
|
7979
8223
|
borderRadius: RADII.group,
|
|
7980
8224
|
paddingHorizontal: 14,
|
|
7981
8225
|
paddingVertical: 10,
|
|
7982
|
-
fontSize: 16,
|
|
7983
|
-
lineHeight: 22,
|
|
7984
8226
|
overflow: "hidden"
|
|
7985
|
-
}
|
|
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 }
|
|
7986
8232
|
});
|
|
7987
8233
|
|
|
7988
8234
|
// src/components/TypingBubble.tsx
|
|
7989
|
-
var
|
|
7990
|
-
var
|
|
7991
|
-
var
|
|
8235
|
+
var import_react14 = require("react");
|
|
8236
|
+
var import_react_native20 = require("react-native");
|
|
8237
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
7992
8238
|
function TypingBubble({ app, sender }) {
|
|
7993
8239
|
const { t, colors } = useChatContext();
|
|
7994
8240
|
const rise = useRiseIn(true);
|
|
7995
|
-
const dots = (0,
|
|
7996
|
-
(0,
|
|
7997
|
-
const bounce =
|
|
7998
|
-
|
|
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(
|
|
7999
8245
|
150,
|
|
8000
8246
|
dots.map(
|
|
8001
|
-
(dot) =>
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
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)
|
|
8005
8251
|
])
|
|
8006
8252
|
)
|
|
8007
8253
|
)
|
|
@@ -8009,13 +8255,13 @@ function TypingBubble({ app, sender }) {
|
|
|
8009
8255
|
bounce.start();
|
|
8010
8256
|
return () => bounce.stop();
|
|
8011
8257
|
}, [dots]);
|
|
8012
|
-
return /* @__PURE__ */ (0,
|
|
8013
|
-
/* @__PURE__ */ (0,
|
|
8014
|
-
/* @__PURE__ */ (0,
|
|
8015
|
-
|
|
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,
|
|
8016
8262
|
{
|
|
8017
8263
|
style: [
|
|
8018
|
-
|
|
8264
|
+
styles14.dot,
|
|
8019
8265
|
{
|
|
8020
8266
|
backgroundColor: colors.muted,
|
|
8021
8267
|
opacity: dot.interpolate({ inputRange: [0, 1], outputRange: [0.35, 1] }),
|
|
@@ -8027,7 +8273,7 @@ function TypingBubble({ app, sender }) {
|
|
|
8027
8273
|
)) })
|
|
8028
8274
|
] });
|
|
8029
8275
|
}
|
|
8030
|
-
var
|
|
8276
|
+
var styles14 = import_react_native20.StyleSheet.create({
|
|
8031
8277
|
row: { flexDirection: "row", alignItems: "flex-end", gap: 8, paddingHorizontal: 12, paddingTop: 14 },
|
|
8032
8278
|
bubble: {
|
|
8033
8279
|
flexDirection: "row",
|
|
@@ -8042,15 +8288,17 @@ var styles13 = import_react_native19.StyleSheet.create({
|
|
|
8042
8288
|
});
|
|
8043
8289
|
|
|
8044
8290
|
// src/components/MessageList.tsx
|
|
8045
|
-
var
|
|
8291
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
8046
8292
|
function MessageList({ state }) {
|
|
8047
8293
|
const { chat: chat2, t, colors, openedAt } = useChatContext();
|
|
8048
|
-
const listRef = (0,
|
|
8049
|
-
const [scrolledUp, setScrolledUp] = (0,
|
|
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);
|
|
8050
8298
|
const app = state.app;
|
|
8051
8299
|
const { messages, seen, atStart } = state;
|
|
8052
8300
|
const welcomeText = state.texts.welcome;
|
|
8053
|
-
const rows = (0,
|
|
8301
|
+
const rows = (0, import_react15.useMemo)(() => {
|
|
8054
8302
|
const welcome = atStart ? {
|
|
8055
8303
|
id: "welcome",
|
|
8056
8304
|
from: "team",
|
|
@@ -8059,65 +8307,95 @@ function MessageList({ state }) {
|
|
|
8059
8307
|
attachments: [],
|
|
8060
8308
|
createdAt: messages[0]?.createdAt ?? openedAt,
|
|
8061
8309
|
status: "sent",
|
|
8062
|
-
error: null
|
|
8310
|
+
error: null,
|
|
8311
|
+
replyTo: null
|
|
8063
8312
|
} : null;
|
|
8064
8313
|
return conversationRows(messages, seen, welcome).reverse();
|
|
8065
8314
|
}, [messages, seen, atStart, welcomeText, openedAt]);
|
|
8066
8315
|
const newest = rows.at(0)?.message;
|
|
8067
8316
|
const sending = newest?.from === "contact" && newest.status === "sending" ? newest.id : null;
|
|
8068
|
-
(0,
|
|
8317
|
+
(0, import_react15.useEffect)(() => {
|
|
8069
8318
|
if (sending) listRef.current?.scrollToOffset({ offset: 0, animated: true });
|
|
8070
8319
|
}, [sending]);
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
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,
|
|
8074
8349
|
{
|
|
8075
8350
|
ref: listRef,
|
|
8076
8351
|
testID: "zean-conversation",
|
|
8077
8352
|
inverted: true,
|
|
8078
8353
|
data: rows,
|
|
8079
8354
|
keyExtractor: (row) => row.message.id,
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
state.
|
|
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 }) })
|
|
8085
8362
|
] }),
|
|
8086
|
-
ListFooterComponent: state.hasOlder ? /* @__PURE__ */ (0,
|
|
8087
|
-
|
|
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,
|
|
8088
8365
|
{
|
|
8089
8366
|
onPress: chat2.loadOlder,
|
|
8090
8367
|
accessibilityRole: "button",
|
|
8091
|
-
style: ({ pressed }) => [
|
|
8092
|
-
children: /* @__PURE__ */ (0,
|
|
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 })
|
|
8093
8370
|
}
|
|
8094
8371
|
) }) : void 0,
|
|
8095
8372
|
onScroll: (event) => setScrolledUp(event.nativeEvent.contentOffset.y > NEWEST_BUTTON_OFFSET),
|
|
8096
8373
|
scrollEventThrottle: 64,
|
|
8097
8374
|
maintainVisibleContentPosition: scrolledUp ? { minIndexForVisible: 0 } : void 0,
|
|
8098
|
-
contentContainerStyle:
|
|
8375
|
+
contentContainerStyle: styles15.content,
|
|
8099
8376
|
keyboardShouldPersistTaps: "handled",
|
|
8100
8377
|
keyboardDismissMode: "on-drag",
|
|
8101
|
-
style:
|
|
8378
|
+
style: styles15.list
|
|
8102
8379
|
}
|
|
8103
8380
|
),
|
|
8104
|
-
scrolledUp && /* @__PURE__ */ (0,
|
|
8105
|
-
|
|
8381
|
+
scrolledUp && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
8382
|
+
import_react_native21.Pressable,
|
|
8106
8383
|
{
|
|
8107
8384
|
onPress: () => listRef.current?.scrollToOffset({ offset: 0, animated: true }),
|
|
8108
8385
|
accessibilityRole: "button",
|
|
8109
8386
|
accessibilityLabel: t.newest,
|
|
8110
8387
|
style: ({ pressed }) => [
|
|
8111
|
-
|
|
8388
|
+
styles15.newest,
|
|
8112
8389
|
{ backgroundColor: colors.surface, borderColor: colors.border },
|
|
8113
|
-
pressed &&
|
|
8390
|
+
pressed && styles15.pressed
|
|
8114
8391
|
],
|
|
8115
|
-
children: /* @__PURE__ */ (0,
|
|
8392
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Icon, { name: "down", color: colors.text, size: 20 })
|
|
8116
8393
|
}
|
|
8117
8394
|
)
|
|
8118
8395
|
] });
|
|
8119
8396
|
}
|
|
8120
|
-
var
|
|
8397
|
+
var RETRY_SCROLL_MS = 250;
|
|
8398
|
+
var styles15 = import_react_native21.StyleSheet.create({
|
|
8121
8399
|
list: { flex: 1 },
|
|
8122
8400
|
// Inverted, `flex-end` is the top: a short Conversation starts under the header, as in the web widget.
|
|
8123
8401
|
content: { flexGrow: 1, justifyContent: "flex-end", paddingBottom: 12, paddingTop: 4 },
|
|
@@ -8136,7 +8414,7 @@ var styles14 = import_react_native20.StyleSheet.create({
|
|
|
8136
8414
|
width: COMPOSER_BUTTON,
|
|
8137
8415
|
height: COMPOSER_BUTTON,
|
|
8138
8416
|
borderRadius: COMPOSER_BUTTON / 2,
|
|
8139
|
-
borderWidth:
|
|
8417
|
+
borderWidth: import_react_native21.StyleSheet.hairlineWidth,
|
|
8140
8418
|
alignItems: "center",
|
|
8141
8419
|
justifyContent: "center",
|
|
8142
8420
|
shadowColor: "#000000",
|
|
@@ -8148,26 +8426,26 @@ var styles14 = import_react_native20.StyleSheet.create({
|
|
|
8148
8426
|
});
|
|
8149
8427
|
|
|
8150
8428
|
// src/components/PoweredBy.tsx
|
|
8151
|
-
var
|
|
8152
|
-
var
|
|
8429
|
+
var import_react_native22 = require("react-native");
|
|
8430
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
8153
8431
|
function PoweredBy() {
|
|
8154
8432
|
const { t, colors } = useChatContext();
|
|
8155
|
-
return /* @__PURE__ */ (0,
|
|
8156
|
-
|
|
8433
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
8434
|
+
import_react_native22.Pressable,
|
|
8157
8435
|
{
|
|
8158
|
-
style: ({ pressed }) => [
|
|
8436
|
+
style: ({ pressed }) => [styles16.row, pressed && styles16.pressed],
|
|
8159
8437
|
accessibilityRole: "link",
|
|
8160
8438
|
accessibilityLabel: `${t.powered_by} ${APP_NAME}`,
|
|
8161
|
-
onPress: () => void
|
|
8439
|
+
onPress: () => void import_react_native22.Linking.openURL(APP_URL),
|
|
8162
8440
|
children: [
|
|
8163
|
-
/* @__PURE__ */ (0,
|
|
8164
|
-
/* @__PURE__ */ (0,
|
|
8165
|
-
/* @__PURE__ */ (0,
|
|
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 })
|
|
8166
8444
|
]
|
|
8167
8445
|
}
|
|
8168
8446
|
);
|
|
8169
8447
|
}
|
|
8170
|
-
var
|
|
8448
|
+
var styles16 = import_react_native22.StyleSheet.create({
|
|
8171
8449
|
row: { flexDirection: "row", alignItems: "center", justifyContent: "center", alignSelf: "center", gap: 4 },
|
|
8172
8450
|
pressed: { opacity: 0.6 },
|
|
8173
8451
|
text: { fontSize: 12 },
|
|
@@ -8175,46 +8453,49 @@ var styles15 = import_react_native21.StyleSheet.create({
|
|
|
8175
8453
|
});
|
|
8176
8454
|
|
|
8177
8455
|
// src/components/ChatScreen.tsx
|
|
8178
|
-
var
|
|
8456
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
8179
8457
|
function ChatScreen({ state, insets, onClose }) {
|
|
8180
8458
|
const { chat: chat2, t, colors } = useChatContext();
|
|
8181
|
-
const rootRef = (0,
|
|
8459
|
+
const rootRef = (0, import_react16.useRef)(null);
|
|
8182
8460
|
const keyboard = useKeyboardOverlap(rootRef);
|
|
8183
8461
|
const connectionLost = useConnectionLost(state.connected);
|
|
8184
8462
|
const app = state.app;
|
|
8185
|
-
return /* @__PURE__ */ (0,
|
|
8186
|
-
/* @__PURE__ */ (0,
|
|
8187
|
-
connectionLost && /* @__PURE__ */ (0,
|
|
8188
|
-
/* @__PURE__ */ (0,
|
|
8189
|
-
/* @__PURE__ */ (0,
|
|
8190
|
-
state.contactCode && state.status === "ready" && /* @__PURE__ */ (0,
|
|
8191
|
-
state.status === "blocked" ? /* @__PURE__ */ (0,
|
|
8192
|
-
|
|
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, {})
|
|
8193
8474
|
] })
|
|
8194
8475
|
] });
|
|
8195
8476
|
}
|
|
8196
|
-
var
|
|
8477
|
+
var styles17 = import_react_native23.StyleSheet.create({
|
|
8197
8478
|
screen: { flex: 1 },
|
|
8198
8479
|
notice: { paddingHorizontal: 12, paddingTop: 12 },
|
|
8199
8480
|
footer: { gap: 8, paddingHorizontal: 10, paddingTop: 6 }
|
|
8200
8481
|
});
|
|
8201
8482
|
|
|
8202
8483
|
// src/components/ChatModal.tsx
|
|
8203
|
-
var
|
|
8484
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
8204
8485
|
var STRINGS = { fr, en };
|
|
8205
8486
|
function ChatModal({ chat: chat2, colorScheme, maxPhotos }) {
|
|
8206
|
-
const state = (0,
|
|
8207
|
-
const { open: open2 } = (0,
|
|
8208
|
-
const deviceScheme = (0,
|
|
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)();
|
|
8209
8490
|
const scheme = colorScheme ?? (deviceScheme === "dark" ? "dark" : "light");
|
|
8210
8491
|
const active = useAppActive();
|
|
8211
|
-
const dimensions = (0,
|
|
8212
|
-
const [gallery, setGallery] = (0,
|
|
8213
|
-
const [openedAt, setOpenedAt] = (0,
|
|
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);
|
|
8214
8495
|
const app = state.app;
|
|
8215
8496
|
const visible = open2 && app !== null && state.status !== "loading" && state.status !== "hidden";
|
|
8216
8497
|
const color = app?.color ?? ZEAN_ACCENT_HEX;
|
|
8217
|
-
const context = (0,
|
|
8498
|
+
const context = (0, import_react17.useMemo)(
|
|
8218
8499
|
() => ({
|
|
8219
8500
|
chat: chat2,
|
|
8220
8501
|
t: STRINGS[state.locale],
|
|
@@ -8226,35 +8507,35 @@ function ChatModal({ chat: chat2, colorScheme, maxPhotos }) {
|
|
|
8226
8507
|
}),
|
|
8227
8508
|
[chat2, state.locale, color, scheme, openedAt, maxPhotos]
|
|
8228
8509
|
);
|
|
8229
|
-
const insets = (0,
|
|
8230
|
-
(0,
|
|
8231
|
-
(0,
|
|
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)(() => {
|
|
8232
8513
|
if (visible && active && state.unread > 0) chat2.markRead();
|
|
8233
8514
|
}, [chat2, visible, active, state.unread]);
|
|
8234
|
-
(0,
|
|
8515
|
+
(0, import_react17.useEffect)(() => {
|
|
8235
8516
|
if (visible) setOpenedAt(Date.now());
|
|
8236
8517
|
else setGallery(null);
|
|
8237
8518
|
}, [visible]);
|
|
8238
|
-
return /* @__PURE__ */ (0,
|
|
8239
|
-
|
|
8519
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
8520
|
+
import_react_native24.Modal,
|
|
8240
8521
|
{
|
|
8241
8522
|
testID: "zean-chat",
|
|
8242
8523
|
visible,
|
|
8243
8524
|
animationType: "slide",
|
|
8244
|
-
presentationStyle:
|
|
8525
|
+
presentationStyle: import_react_native24.Platform.OS === "ios" && !import_react_native24.Platform.isPad ? "pageSheet" : "fullScreen",
|
|
8245
8526
|
statusBarTranslucent: true,
|
|
8246
8527
|
navigationBarTranslucent: true,
|
|
8247
|
-
onRequestClose: () =>
|
|
8248
|
-
children: app && /* @__PURE__ */ (0,
|
|
8249
|
-
/* @__PURE__ */ (0,
|
|
8250
|
-
gallery && /* @__PURE__ */ (0,
|
|
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) })
|
|
8251
8532
|
] })
|
|
8252
8533
|
}
|
|
8253
8534
|
);
|
|
8254
8535
|
}
|
|
8255
8536
|
|
|
8256
8537
|
// src/components/ZeanChat.tsx
|
|
8257
|
-
var
|
|
8538
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
8258
8539
|
function ZeanChat({
|
|
8259
8540
|
appKey,
|
|
8260
8541
|
storage,
|
|
@@ -8265,12 +8546,12 @@ function ZeanChat({
|
|
|
8265
8546
|
maxPhotos,
|
|
8266
8547
|
backendUrl = backendUrlFor(appKey)
|
|
8267
8548
|
}) {
|
|
8268
|
-
const [chat2, setChat] = (0,
|
|
8269
|
-
const storageRef = (0,
|
|
8549
|
+
const [chat2, setChat] = (0, import_react18.useState)(null);
|
|
8550
|
+
const storageRef = (0, import_react18.useRef)(storage);
|
|
8270
8551
|
const userKey = user ? JSON.stringify(user) : null;
|
|
8271
|
-
const identified = (0,
|
|
8552
|
+
const identified = (0, import_react18.useRef)(false);
|
|
8272
8553
|
const attributesKey = attributes2 ? JSON.stringify(attributes2) : null;
|
|
8273
|
-
(0,
|
|
8554
|
+
(0, import_react18.useEffect)(() => {
|
|
8274
8555
|
const started = createChat({
|
|
8275
8556
|
appKey,
|
|
8276
8557
|
backendUrl,
|
|
@@ -8293,20 +8574,20 @@ function ZeanChat({
|
|
|
8293
8574
|
started.destroy();
|
|
8294
8575
|
};
|
|
8295
8576
|
}, [appKey, backendUrl, locale]);
|
|
8296
|
-
(0,
|
|
8577
|
+
(0, import_react18.useEffect)(() => {
|
|
8297
8578
|
if (userKey) zean.identify(JSON.parse(userKey));
|
|
8298
8579
|
else if (identified.current) zean.signOut();
|
|
8299
8580
|
identified.current = userKey !== null;
|
|
8300
8581
|
}, [userKey]);
|
|
8301
|
-
(0,
|
|
8582
|
+
(0, import_react18.useEffect)(() => {
|
|
8302
8583
|
if (attributesKey) zean.setAttributes(JSON.parse(attributesKey));
|
|
8303
|
-
}, [attributesKey]);
|
|
8304
|
-
return chat2 ? /* @__PURE__ */ (0,
|
|
8584
|
+
}, [attributesKey, userKey]);
|
|
8585
|
+
return chat2 ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ChatModal, { chat: chat2, colorScheme, maxPhotos }) : null;
|
|
8305
8586
|
}
|
|
8306
8587
|
|
|
8307
8588
|
// src/hooks/use-zean.ts
|
|
8308
|
-
var
|
|
8589
|
+
var import_react19 = require("react");
|
|
8309
8590
|
function useZean() {
|
|
8310
|
-
const { unread } = (0,
|
|
8591
|
+
const { unread } = (0, import_react19.useSyncExternalStore)(subscribeChatView, chatView);
|
|
8311
8592
|
return { ...zean, unreadCount: unread };
|
|
8312
8593
|
}
|