@zean-chat/react-native 0.1.0 → 0.1.2
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 -2
- package/dist/components/ContactCodeCard.d.ts +6 -0
- package/dist/components/ZeanChat.d.ts +1 -1
- package/dist/i18n/en.d.ts +9 -0
- package/dist/i18n/fr.d.ts +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +485 -300
- package/dist/interfaces.d.ts +17 -9
- package/dist/models/sdk.interface.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/components/ZeanChat.tsx
|
|
29
|
-
var
|
|
29
|
+
var import_react14 = require("react");
|
|
30
30
|
|
|
31
31
|
// ../shared/src/constants/app.ts
|
|
32
32
|
var APP_NAME = "Zean";
|
|
@@ -35,6 +35,11 @@ var SUPPORTED_LOCALES = ["fr", "en"];
|
|
|
35
35
|
var DEFAULT_LOCALE = "fr";
|
|
36
36
|
|
|
37
37
|
// ../shared/src/constants/conversations.ts
|
|
38
|
+
var CONTACT_ID_MAX_LENGTH = 200;
|
|
39
|
+
var CONTACT_NAME_MAX_LENGTH = 120;
|
|
40
|
+
var CONTACT_PHONE_MAX_LENGTH = 32;
|
|
41
|
+
var LANGUAGE_TAG_PATTERN = /^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{1,8}){0,4}$/;
|
|
42
|
+
var CONTACT_CODE_MAX_AGE_MS = 10 * 6e4;
|
|
38
43
|
var CONTACT_ATTRIBUTES_MAX = 50;
|
|
39
44
|
var CONTACT_ATTRIBUTE_NAME_MAX_LENGTH = 40;
|
|
40
45
|
var CONTACT_ATTRIBUTE_TEXT_MAX_LENGTH = 250;
|
|
@@ -43,6 +48,7 @@ var RESERVED_CONTACT_ATTRIBUTES = [
|
|
|
43
48
|
"id",
|
|
44
49
|
"name",
|
|
45
50
|
"email",
|
|
51
|
+
"phone",
|
|
46
52
|
"user_id",
|
|
47
53
|
"external_id",
|
|
48
54
|
"verified",
|
|
@@ -94,6 +100,65 @@ function isAttributeValue(value) {
|
|
|
94
100
|
return typeof value === "boolean";
|
|
95
101
|
}
|
|
96
102
|
|
|
103
|
+
// ../shared/src/utils/email.ts
|
|
104
|
+
function normaliseEmail(email) {
|
|
105
|
+
return email.trim().toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
function isEmail(value) {
|
|
108
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(value);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ../shared/src/utils/names.ts
|
|
112
|
+
function initialsOf(name) {
|
|
113
|
+
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
114
|
+
if (words.length === 0) return "";
|
|
115
|
+
const letterOf = (word) => Array.from(word)[0] ?? "";
|
|
116
|
+
return (letterOf(words[0]) + (words.length > 1 ? letterOf(words[words.length - 1]) : "")).toUpperCase();
|
|
117
|
+
}
|
|
118
|
+
function squashSpaces(value) {
|
|
119
|
+
return value.trim().replace(/\s+/g, " ");
|
|
120
|
+
}
|
|
121
|
+
var NAME_WORD = String.raw`\p{L}[\p{L}\p{M}]*`;
|
|
122
|
+
var PERSON_NAME = new RegExp(String.raw`^${NAME_WORD}(?:\.?[ '’-]${NAME_WORD})*\.?$`, "u");
|
|
123
|
+
|
|
124
|
+
// ../shared/src/utils/contact-user.ts
|
|
125
|
+
var PHONE_PATTERN = /^\+?[0-9][0-9 ().-]*$/;
|
|
126
|
+
function cleanContactUser(value) {
|
|
127
|
+
const input = typeof value === "object" && value !== null ? value : {};
|
|
128
|
+
const id = typeof input.id === "number" && Number.isFinite(input.id) ? String(input.id) : input.id;
|
|
129
|
+
if (typeof id !== "string" || !id.trim() || id.trim().length > CONTACT_ID_MAX_LENGTH) return { user: null, dropped: [] };
|
|
130
|
+
const user = { id: id.trim() };
|
|
131
|
+
const dropped = [];
|
|
132
|
+
const text = (key) => {
|
|
133
|
+
const raw = input[key];
|
|
134
|
+
if (raw === void 0 || raw === null) return null;
|
|
135
|
+
const cleaned = typeof raw === "string" ? squashSpaces(raw) : "";
|
|
136
|
+
if (!cleaned) dropped.push(key);
|
|
137
|
+
return cleaned || null;
|
|
138
|
+
};
|
|
139
|
+
const name = text("name");
|
|
140
|
+
if (name !== null && name.length <= CONTACT_NAME_MAX_LENGTH) user.name = name;
|
|
141
|
+
else if (name !== null) dropped.push("name");
|
|
142
|
+
const email = text("email");
|
|
143
|
+
if (email !== null && isEmail(normaliseEmail(email))) user.email = normaliseEmail(email);
|
|
144
|
+
else if (email !== null) dropped.push("email");
|
|
145
|
+
const phone = text("phone");
|
|
146
|
+
if (phone !== null && phone.length <= CONTACT_PHONE_MAX_LENGTH && PHONE_PATTERN.test(phone)) user.phone = phone;
|
|
147
|
+
else if (phone !== null) dropped.push("phone");
|
|
148
|
+
const language = text("language");
|
|
149
|
+
if (language !== null && LANGUAGE_TAG_PATTERN.test(language)) user.language = languageTag(language);
|
|
150
|
+
else if (language !== null) dropped.push("language");
|
|
151
|
+
return { user, dropped };
|
|
152
|
+
}
|
|
153
|
+
function languageTag(value) {
|
|
154
|
+
return value.split("-").map((part, index) => {
|
|
155
|
+
if (index === 0) return part.toLowerCase();
|
|
156
|
+
if (part.length === 2) return part.toUpperCase();
|
|
157
|
+
if (part.length === 4) return part[0].toUpperCase() + part.slice(1).toLowerCase();
|
|
158
|
+
return part.toLowerCase();
|
|
159
|
+
}).join("-");
|
|
160
|
+
}
|
|
161
|
+
|
|
97
162
|
// ../shared/src/utils/widget.ts
|
|
98
163
|
var WEEKDAYS = { Mon: 1, Tue: 2, Wed: 3, Thu: 4, Fri: 5, Sat: 6, Sun: 7 };
|
|
99
164
|
function isWithinBusinessHours(hours, at) {
|
|
@@ -132,8 +197,6 @@ function minutesOf(clock) {
|
|
|
132
197
|
var CLOCK_MS = 3e4;
|
|
133
198
|
var TYPING_SIGNAL_MS = 2e3;
|
|
134
199
|
var SECRET_BYTES = 32;
|
|
135
|
-
var REFRESH_AHEAD_MS = 6e4;
|
|
136
|
-
var REFRESH_SPACING_MS = 3e4;
|
|
137
200
|
var SECRET_RETRY_MS = 2e3;
|
|
138
201
|
function createChatStore(backend, options) {
|
|
139
202
|
const secretKey = `zean:${options.appKey}:device`;
|
|
@@ -157,12 +220,12 @@ function createChatStore(backend, options) {
|
|
|
157
220
|
let heldAttributes = {};
|
|
158
221
|
let started = false;
|
|
159
222
|
let reported = false;
|
|
160
|
-
let
|
|
161
|
-
let
|
|
223
|
+
let user = null;
|
|
224
|
+
let contactCode = null;
|
|
162
225
|
let generation = 0;
|
|
163
|
-
let
|
|
164
|
-
let
|
|
165
|
-
let
|
|
226
|
+
let identifying = null;
|
|
227
|
+
let identified = false;
|
|
228
|
+
let identifiedKnown = false;
|
|
166
229
|
let watchers = [];
|
|
167
230
|
let destroyed = false;
|
|
168
231
|
let state = derive();
|
|
@@ -171,8 +234,13 @@ function createChatStore(backend, options) {
|
|
|
171
234
|
for (const listener of listeners2) listener();
|
|
172
235
|
};
|
|
173
236
|
const args = () => ({ appKey: options.appKey, deviceSecret, host: options.host });
|
|
174
|
-
const
|
|
175
|
-
const device = () => ({
|
|
237
|
+
const deviceLanguage = options.deviceLanguage ?? options.languages[0];
|
|
238
|
+
const device = () => ({
|
|
239
|
+
locale: state.locale,
|
|
240
|
+
...deviceLanguage ? { language: deviceLanguage } : {},
|
|
241
|
+
browser: options.browser,
|
|
242
|
+
os: options.os
|
|
243
|
+
});
|
|
176
244
|
const deviceWaiters = [];
|
|
177
245
|
const useSecret = (secret) => {
|
|
178
246
|
deviceSecret = secret;
|
|
@@ -209,48 +277,31 @@ function createChatStore(backend, options) {
|
|
|
209
277
|
];
|
|
210
278
|
watchMessages();
|
|
211
279
|
}
|
|
212
|
-
function
|
|
213
|
-
|
|
214
|
-
if (
|
|
280
|
+
function sendIdentity() {
|
|
281
|
+
const person = user;
|
|
282
|
+
if (!person) return Promise.resolve();
|
|
215
283
|
const mine = generation;
|
|
216
|
-
const
|
|
217
|
-
lastRefresh = Date.now();
|
|
218
|
-
refreshing = (async () => {
|
|
219
|
-
let next = null;
|
|
220
|
-
try {
|
|
221
|
-
next = await source();
|
|
222
|
-
} catch {
|
|
223
|
-
next = null;
|
|
224
|
-
}
|
|
284
|
+
const run = (async () => {
|
|
225
285
|
await deviceKnown();
|
|
226
286
|
if (mine !== generation || destroyed || !deviceSecret) return;
|
|
227
|
-
|
|
228
|
-
scheduleRefresh(next);
|
|
229
|
-
if (!next) return;
|
|
287
|
+
identifiedKnown = state.known;
|
|
230
288
|
try {
|
|
231
|
-
await backend.call("
|
|
289
|
+
const result = await backend.call("identify", { ...args(), user: person, device: device() });
|
|
290
|
+
if (mine !== generation) return;
|
|
291
|
+
contactCode = result.state === "code_available" ? { email: result.email, sent: contactCode?.sent ?? false } : null;
|
|
292
|
+
identified = true;
|
|
293
|
+
emit2();
|
|
232
294
|
} catch (error) {
|
|
233
|
-
if (
|
|
234
|
-
console.warn(
|
|
235
|
-
`${APP_NAME}: the token was refused. Sign it with HS256 and the App's identity secret, with "sub" and "exp".`
|
|
236
|
-
);
|
|
237
|
-
token = null;
|
|
295
|
+
if (codeOf(error) === "invalid_user") console.warn(`${APP_NAME}: the user was refused: it needs an id.`);
|
|
238
296
|
}
|
|
239
|
-
})()
|
|
240
|
-
|
|
297
|
+
})();
|
|
298
|
+
const tracked = run.finally(() => {
|
|
299
|
+
if (identifying === tracked) identifying = null;
|
|
241
300
|
});
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
function scheduleRefresh(value) {
|
|
245
|
-
if (refreshTimer) clearTimeout(refreshTimer);
|
|
246
|
-
refreshTimer = null;
|
|
247
|
-
const expiresAt = value ? expiryOf(value) : null;
|
|
248
|
-
if (expiresAt === null) return;
|
|
249
|
-
refreshTimer = setTimeout(() => void refreshToken(), Math.max(REFRESH_SPACING_MS, expiresAt - Date.now() - REFRESH_AHEAD_MS));
|
|
301
|
+
identifying = tracked;
|
|
302
|
+
return tracked;
|
|
250
303
|
}
|
|
251
304
|
function handleSession(result) {
|
|
252
|
-
const lapsed = "identity" in result && result.identity === "none" && token !== null;
|
|
253
|
-
if (lapsed && Date.now() - lastRefresh > REFRESH_SPACING_MS) void refreshToken();
|
|
254
305
|
if (session?.state !== result.state && result.state === "not_found")
|
|
255
306
|
console.warn(`${APP_NAME}: no App has the key "${options.appKey}". Check the install snippet.`);
|
|
256
307
|
if (session?.state !== result.state && result.state === "domain_not_allowed")
|
|
@@ -266,10 +317,11 @@ function createChatStore(backend, options) {
|
|
|
266
317
|
});
|
|
267
318
|
}
|
|
268
319
|
startOnce();
|
|
320
|
+
if (state.known && !state.verified && !identifiedKnown && user && !identifying) void sendIdentity();
|
|
269
321
|
if (state.known && Object.keys(heldAttributes).length > 0) void sendAttributes();
|
|
270
322
|
}
|
|
271
323
|
async function sendAttributes() {
|
|
272
|
-
if (
|
|
324
|
+
if (identifying) await identifying;
|
|
273
325
|
const attributes2 = heldAttributes;
|
|
274
326
|
if (destroyed || !deviceSecret || Object.keys(attributes2).length === 0) return { ok: true };
|
|
275
327
|
heldAttributes = {};
|
|
@@ -286,7 +338,7 @@ function createChatStore(backend, options) {
|
|
|
286
338
|
function startOnce() {
|
|
287
339
|
if (started || state.status === "loading" || state.status === "hidden") return;
|
|
288
340
|
started = true;
|
|
289
|
-
if (state.known
|
|
341
|
+
if (state.known) backend.call("start", { ...args(), device: device() }).catch(() => {
|
|
290
342
|
});
|
|
291
343
|
for (const entry of outbox) if (entry.error === null) deliver(entry);
|
|
292
344
|
}
|
|
@@ -322,10 +374,8 @@ function createChatStore(backend, options) {
|
|
|
322
374
|
);
|
|
323
375
|
}
|
|
324
376
|
function deliver(entry) {
|
|
325
|
-
const used = token;
|
|
326
377
|
backend.call("send", {
|
|
327
378
|
...args(),
|
|
328
|
-
...signed2(),
|
|
329
379
|
body: entry.body,
|
|
330
380
|
...entry.attachments ? { attachments: entry.attachments } : {},
|
|
331
381
|
clientId: entry.clientId,
|
|
@@ -336,12 +386,7 @@ function createChatStore(backend, options) {
|
|
|
336
386
|
saveOutbox();
|
|
337
387
|
emit2();
|
|
338
388
|
},
|
|
339
|
-
|
|
340
|
-
const refusedToken = codeOf(error) === "identity_expired" || codeOf(error) === "identity_invalid";
|
|
341
|
-
if (refusedToken && getToken) {
|
|
342
|
-
await refreshToken();
|
|
343
|
-
if (token && token !== used) return deliver(entry);
|
|
344
|
-
}
|
|
389
|
+
(error) => {
|
|
345
390
|
outbox = outbox.map((other) => other.clientId === entry.clientId ? { ...other, error: codeOf(error) } : other);
|
|
346
391
|
saveOutbox();
|
|
347
392
|
emit2();
|
|
@@ -355,6 +400,7 @@ function createChatStore(backend, options) {
|
|
|
355
400
|
const locale = localeOf(options.languages, app?.defaultLocale ?? DEFAULT_LOCALE);
|
|
356
401
|
const fallback = DEFAULT_WIDGET_TEXTS;
|
|
357
402
|
const textOf = (key) => pickText(app?.texts[key], locale, app?.defaultLocale ?? DEFAULT_LOCALE, { fr: fallback.fr[key], en: fallback.en[key] });
|
|
403
|
+
const verified = session !== null && "identity" in session && session.identity === "verified";
|
|
358
404
|
const stored = new Set(page.messages.map((message) => message.clientId));
|
|
359
405
|
const pending = outbox.filter((entry) => !stored.has(entry.clientId)).map(fromOutbox);
|
|
360
406
|
return {
|
|
@@ -373,7 +419,8 @@ function createChatStore(backend, options) {
|
|
|
373
419
|
teamTyping: typing && typing.until > Date.now() ? { sender: typing.sender } : null,
|
|
374
420
|
email: contact?.email ?? null,
|
|
375
421
|
known: contact !== null,
|
|
376
|
-
verified
|
|
422
|
+
verified,
|
|
423
|
+
contactCode: verified ? null : contactCode,
|
|
377
424
|
connected
|
|
378
425
|
};
|
|
379
426
|
}
|
|
@@ -498,22 +545,70 @@ function createChatStore(backend, options) {
|
|
|
498
545
|
saveAttributes();
|
|
499
546
|
return state.known ? await sendAttributes() : { ok: true };
|
|
500
547
|
},
|
|
501
|
-
async identify(
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
548
|
+
async identify(given) {
|
|
549
|
+
const { user: person, dropped } = cleanContactUser(given);
|
|
550
|
+
if (!person) {
|
|
551
|
+
console.warn(`${APP_NAME}: the user was left out: it needs an id, text or a number.`);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
if (dropped.length > 0) console.warn(`${APP_NAME}: left out of the user, as they do not fit: ${dropped.join(", ")}.`);
|
|
555
|
+
if (user && JSON.stringify(user) === JSON.stringify(person)) {
|
|
556
|
+
if (identifying) return identifying;
|
|
557
|
+
if (identified) return;
|
|
558
|
+
}
|
|
559
|
+
if (user && user.id !== person.id) {
|
|
560
|
+
outbox = [];
|
|
561
|
+
saveOutbox();
|
|
562
|
+
heldAttributes = {};
|
|
563
|
+
saveAttributes();
|
|
564
|
+
}
|
|
565
|
+
if (user?.id !== person.id) {
|
|
566
|
+
generation += 1;
|
|
567
|
+
contactCode = null;
|
|
568
|
+
}
|
|
569
|
+
user = person;
|
|
570
|
+
identified = false;
|
|
571
|
+
await sendIdentity();
|
|
572
|
+
},
|
|
573
|
+
async requestCode() {
|
|
574
|
+
const person = user;
|
|
575
|
+
if (!person || !deviceSecret || !contactCode) return { ok: false, code: "not_found" };
|
|
576
|
+
try {
|
|
577
|
+
await backend.call("requestCode", { ...args(), userId: person.id });
|
|
578
|
+
const current = contactCode;
|
|
579
|
+
if (current && user === person) contactCode = { ...current, sent: true };
|
|
580
|
+
emit2();
|
|
581
|
+
return { ok: true };
|
|
582
|
+
} catch (error) {
|
|
583
|
+
return { ok: false, code: codeOf(error) };
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
async confirmCode(code2) {
|
|
587
|
+
const person = user;
|
|
588
|
+
if (!person || !deviceSecret) return { ok: false, code: "not_found" };
|
|
589
|
+
try {
|
|
590
|
+
const result = await backend.call("confirmCode", { ...args(), userId: person.id, code: code2 });
|
|
591
|
+
if (!result.ok) return result;
|
|
592
|
+
contactCode = null;
|
|
593
|
+
emit2();
|
|
594
|
+
void sendIdentity();
|
|
595
|
+
return { ok: true };
|
|
596
|
+
} catch (error) {
|
|
597
|
+
return { ok: false, code: codeOf(error) };
|
|
598
|
+
}
|
|
507
599
|
},
|
|
508
600
|
async signOut() {
|
|
509
601
|
generation += 1;
|
|
510
602
|
const mine = generation;
|
|
511
603
|
await starting;
|
|
512
604
|
if (mine !== generation) return;
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
605
|
+
user = null;
|
|
606
|
+
identified = false;
|
|
607
|
+
contactCode = null;
|
|
608
|
+
identifying = null;
|
|
609
|
+
identifiedKnown = false;
|
|
610
|
+
if (deviceSecret) backend.call("signOut", args()).catch(() => {
|
|
611
|
+
});
|
|
517
612
|
for (const stop of watchers) stop();
|
|
518
613
|
watchers = [];
|
|
519
614
|
stopMessages?.();
|
|
@@ -539,7 +634,6 @@ function createChatStore(backend, options) {
|
|
|
539
634
|
destroy() {
|
|
540
635
|
destroyed = true;
|
|
541
636
|
for (const resolve of deviceWaiters.splice(0)) resolve();
|
|
542
|
-
scheduleRefresh(null);
|
|
543
637
|
stopMessages?.();
|
|
544
638
|
for (const stop of watchers) stop();
|
|
545
639
|
for (const stop of stops) stop();
|
|
@@ -576,16 +670,6 @@ function codeOf(error) {
|
|
|
576
670
|
const code2 = error?.code;
|
|
577
671
|
return typeof code2 === "string" ? code2 : "unknown";
|
|
578
672
|
}
|
|
579
|
-
function expiryOf(value) {
|
|
580
|
-
try {
|
|
581
|
-
const payload = value.split(".")[1];
|
|
582
|
-
const json = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
|
|
583
|
-
const exp = JSON.parse(json).exp;
|
|
584
|
-
return typeof exp === "number" ? exp * 1e3 : null;
|
|
585
|
-
} catch {
|
|
586
|
-
return null;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
673
|
function webCrypto() {
|
|
590
674
|
const value = globalThis.crypto;
|
|
591
675
|
return typeof value?.getRandomValues === "function" ? value : null;
|
|
@@ -5948,9 +6032,9 @@ var zean = {
|
|
|
5948
6032
|
open: () => setOpen(true),
|
|
5949
6033
|
close: () => setOpen(false),
|
|
5950
6034
|
toggle: () => setOpen(!open),
|
|
5951
|
-
identify(
|
|
5952
|
-
identity =
|
|
5953
|
-
void chat?.identify(
|
|
6035
|
+
identify(user) {
|
|
6036
|
+
identity = user;
|
|
6037
|
+
void chat?.identify(user);
|
|
5954
6038
|
},
|
|
5955
6039
|
signOut() {
|
|
5956
6040
|
identity = null;
|
|
@@ -6163,8 +6247,8 @@ function hideKeyboard() {
|
|
|
6163
6247
|
}
|
|
6164
6248
|
|
|
6165
6249
|
// src/components/ChatModal.tsx
|
|
6166
|
-
var
|
|
6167
|
-
var
|
|
6250
|
+
var import_react13 = require("react");
|
|
6251
|
+
var import_react_native19 = require("react-native");
|
|
6168
6252
|
|
|
6169
6253
|
// src/hooks/use-app-active.ts
|
|
6170
6254
|
var import_react = require("react");
|
|
@@ -6213,6 +6297,15 @@ var en = {
|
|
|
6213
6297
|
email_invalid: "Enter a valid email address.",
|
|
6214
6298
|
email_saved: "Thanks, we will write to {email}.",
|
|
6215
6299
|
error: "Something went wrong. Try again.",
|
|
6300
|
+
code_prompt: "Chatted with us on another device? Get a code at {email} to see your conversation here.",
|
|
6301
|
+
code_send: "Get the code",
|
|
6302
|
+
code_label: "Enter the 6-digit code sent to {email}.",
|
|
6303
|
+
code_submit: "Confirm",
|
|
6304
|
+
code_resend: "Send a new code",
|
|
6305
|
+
code_invalid: "This code does not match. Check it and try again.",
|
|
6306
|
+
code_expired: "This code no longer works. Ask for a new one.",
|
|
6307
|
+
code_rate_limited: "Too many codes asked for. Try again in an hour.",
|
|
6308
|
+
code_dismiss: "Not now",
|
|
6216
6309
|
attach: "Send a photo",
|
|
6217
6310
|
uploading: "Uploading\u2026",
|
|
6218
6311
|
ready: "Ready",
|
|
@@ -6251,6 +6344,15 @@ var fr = {
|
|
|
6251
6344
|
email_invalid: "Saisissez une adresse e-mail valide.",
|
|
6252
6345
|
email_saved: "Merci, nous vous \xE9crirons \xE0 {email}.",
|
|
6253
6346
|
error: "Une erreur est survenue. R\xE9essayez.",
|
|
6347
|
+
code_prompt: "D\xE9j\xE0 \xE9chang\xE9 avec nous sur un autre appareil ? Recevez un code \xE0 {email} pour retrouver votre conversation ici.",
|
|
6348
|
+
code_send: "Recevoir le code",
|
|
6349
|
+
code_label: "Saisissez le code \xE0 6 chiffres envoy\xE9 \xE0 {email}.",
|
|
6350
|
+
code_submit: "Valider",
|
|
6351
|
+
code_resend: "Envoyer un nouveau code",
|
|
6352
|
+
code_invalid: "Ce code ne correspond pas. V\xE9rifiez-le et r\xE9essayez.",
|
|
6353
|
+
code_expired: "Ce code ne fonctionne plus. Demandez-en un nouveau.",
|
|
6354
|
+
code_rate_limited: "Trop de codes demand\xE9s. R\xE9essayez dans une heure.",
|
|
6355
|
+
code_dismiss: "Plus tard",
|
|
6254
6356
|
attach: "Envoyer une photo",
|
|
6255
6357
|
uploading: "Envoi\u2026",
|
|
6256
6358
|
ready: "Pr\xEAt",
|
|
@@ -6276,8 +6378,8 @@ var styles = import_react_native3.StyleSheet.create({
|
|
|
6276
6378
|
});
|
|
6277
6379
|
|
|
6278
6380
|
// src/components/ChatScreen.tsx
|
|
6279
|
-
var
|
|
6280
|
-
var
|
|
6381
|
+
var import_react12 = require("react");
|
|
6382
|
+
var import_react_native18 = require("react-native");
|
|
6281
6383
|
|
|
6282
6384
|
// src/hooks/use-connection-lost.ts
|
|
6283
6385
|
var import_react3 = require("react");
|
|
@@ -6416,10 +6518,117 @@ var styles4 = import_react_native8.StyleSheet.create({
|
|
|
6416
6518
|
notice: { borderRadius: 8, paddingHorizontal: 12, paddingVertical: 8, textAlign: "center", fontSize: 14, overflow: "hidden" }
|
|
6417
6519
|
});
|
|
6418
6520
|
|
|
6419
|
-
// src/components/
|
|
6420
|
-
var
|
|
6521
|
+
// src/components/ContactCodeCard.tsx
|
|
6522
|
+
var import_react5 = require("react");
|
|
6421
6523
|
var import_react_native9 = require("react-native");
|
|
6422
6524
|
|
|
6525
|
+
// ../shared/src/constants/auth.ts
|
|
6526
|
+
var CODE_LENGTH = 6;
|
|
6527
|
+
var CODE_MAX_AGE_SECONDS = 15 * 60;
|
|
6528
|
+
|
|
6529
|
+
// src/components/ContactCodeCard.tsx
|
|
6530
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
6531
|
+
function ContactCodeCard({ code: code2, onDismiss }) {
|
|
6532
|
+
const { chat: chat2, t, colors } = useChatContext();
|
|
6533
|
+
const [value, setValue] = (0, import_react5.useState)("");
|
|
6534
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
6535
|
+
const [busy, setBusy] = (0, import_react5.useState)(false);
|
|
6536
|
+
const errorOf = (reason) => reason === "contact_code_invalid" ? t.code_invalid : reason === "contact_code_expired" ? t.code_expired : reason === "rate_limited" ? t.code_rate_limited : t.error;
|
|
6537
|
+
const handleSend = async () => {
|
|
6538
|
+
setBusy(true);
|
|
6539
|
+
setError(null);
|
|
6540
|
+
const result = await chat2.requestCode();
|
|
6541
|
+
setBusy(false);
|
|
6542
|
+
setValue("");
|
|
6543
|
+
if (!result.ok) setError(errorOf(result.code));
|
|
6544
|
+
};
|
|
6545
|
+
const handleSubmit = async () => {
|
|
6546
|
+
const typed = value.replace(/\D/g, "");
|
|
6547
|
+
if (typed.length !== CODE_LENGTH) {
|
|
6548
|
+
setError(t.code_invalid);
|
|
6549
|
+
return;
|
|
6550
|
+
}
|
|
6551
|
+
setBusy(true);
|
|
6552
|
+
setError(null);
|
|
6553
|
+
const result = await chat2.confirmCode(typed);
|
|
6554
|
+
setBusy(false);
|
|
6555
|
+
if (!result.ok) setError(errorOf(result.code));
|
|
6556
|
+
};
|
|
6557
|
+
const label = format(code2.sent ? t.code_label : t.code_prompt, { email: code2.email });
|
|
6558
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native9.View, { style: [styles5.card, { borderColor: colors.border }], children: [
|
|
6559
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.prompt, { color: colors.text }], children: label }),
|
|
6560
|
+
code2.sent ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native9.View, { style: styles5.row, children: [
|
|
6561
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
6562
|
+
import_react_native9.TextInput,
|
|
6563
|
+
{
|
|
6564
|
+
value,
|
|
6565
|
+
onChangeText: setValue,
|
|
6566
|
+
onSubmitEditing: () => void handleSubmit(),
|
|
6567
|
+
placeholder: "000000",
|
|
6568
|
+
placeholderTextColor: colors.muted,
|
|
6569
|
+
accessibilityLabel: label,
|
|
6570
|
+
keyboardType: "number-pad",
|
|
6571
|
+
maxLength: CODE_LENGTH,
|
|
6572
|
+
autoComplete: "one-time-code",
|
|
6573
|
+
textContentType: "oneTimeCode",
|
|
6574
|
+
returnKeyType: "done",
|
|
6575
|
+
style: [styles5.input, { borderColor: error ? colors.danger : colors.border, color: colors.text }]
|
|
6576
|
+
}
|
|
6577
|
+
),
|
|
6578
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
6579
|
+
import_react_native9.Pressable,
|
|
6580
|
+
{
|
|
6581
|
+
onPress: () => void handleSubmit(),
|
|
6582
|
+
disabled: busy,
|
|
6583
|
+
accessibilityRole: "button",
|
|
6584
|
+
style: [styles5.submit, { backgroundColor: colors.primary }, busy && styles5.busy],
|
|
6585
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.submitText, { color: colors.primaryForeground }], children: t.code_submit })
|
|
6586
|
+
}
|
|
6587
|
+
)
|
|
6588
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native9.View, { style: styles5.actions, children: [
|
|
6589
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
6590
|
+
import_react_native9.Pressable,
|
|
6591
|
+
{
|
|
6592
|
+
onPress: () => void handleSend(),
|
|
6593
|
+
disabled: busy,
|
|
6594
|
+
accessibilityRole: "button",
|
|
6595
|
+
style: [styles5.send, { backgroundColor: colors.primary }, busy && styles5.busy],
|
|
6596
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.submitText, { color: colors.primaryForeground }], children: t.code_send })
|
|
6597
|
+
}
|
|
6598
|
+
),
|
|
6599
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Pressable, { onPress: onDismiss, accessibilityRole: "button", hitSlop: 8, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.link, { color: colors.muted }], children: t.code_dismiss }) })
|
|
6600
|
+
] }),
|
|
6601
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { accessibilityLiveRegion: "polite", style: [styles5.error, { color: colors.danger }], children: error }),
|
|
6602
|
+
code2.sent && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Pressable, { onPress: () => void handleSend(), disabled: busy, accessibilityRole: "button", hitSlop: 8, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.link, { color: colors.muted }, busy && styles5.busy], children: t.code_resend }) })
|
|
6603
|
+
] });
|
|
6604
|
+
}
|
|
6605
|
+
var styles5 = import_react_native9.StyleSheet.create({
|
|
6606
|
+
card: { gap: 8, padding: 12, borderRadius: 12, borderWidth: import_react_native9.StyleSheet.hairlineWidth },
|
|
6607
|
+
prompt: { fontSize: 14, lineHeight: 20 },
|
|
6608
|
+
row: { flexDirection: "row", gap: 8 },
|
|
6609
|
+
actions: { flexDirection: "row", alignItems: "center", gap: 12 },
|
|
6610
|
+
input: {
|
|
6611
|
+
flex: 1,
|
|
6612
|
+
minWidth: 0,
|
|
6613
|
+
borderWidth: 1,
|
|
6614
|
+
borderRadius: 8,
|
|
6615
|
+
paddingHorizontal: 12,
|
|
6616
|
+
paddingVertical: 8,
|
|
6617
|
+
fontSize: 16,
|
|
6618
|
+
letterSpacing: 4
|
|
6619
|
+
},
|
|
6620
|
+
submit: { justifyContent: "center", paddingHorizontal: 12, borderRadius: 8 },
|
|
6621
|
+
send: { paddingHorizontal: 12, paddingVertical: 8, borderRadius: 8 },
|
|
6622
|
+
busy: { opacity: 0.6 },
|
|
6623
|
+
submitText: { fontSize: 14, fontWeight: "500" },
|
|
6624
|
+
link: { fontSize: 12, fontWeight: "500" },
|
|
6625
|
+
error: { fontSize: 12 }
|
|
6626
|
+
});
|
|
6627
|
+
|
|
6628
|
+
// src/components/Composer.tsx
|
|
6629
|
+
var import_react7 = require("react");
|
|
6630
|
+
var import_react_native10 = require("react-native");
|
|
6631
|
+
|
|
6423
6632
|
// ../shared/src/constants/uploads.ts
|
|
6424
6633
|
var MAX_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
6425
6634
|
var MAX_FILE_BYTES = 10 * 1024 * 1024;
|
|
@@ -6428,7 +6637,7 @@ var MAX_IMAGE_SIDE = 1600;
|
|
|
6428
6637
|
var IMAGE_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
|
6429
6638
|
|
|
6430
6639
|
// src/hooks/use-pending-photos.ts
|
|
6431
|
-
var
|
|
6640
|
+
var import_react6 = require("react");
|
|
6432
6641
|
|
|
6433
6642
|
// ../shared/src/utils/files.ts
|
|
6434
6643
|
function isImage(type) {
|
|
@@ -6439,8 +6648,8 @@ function isImage(type) {
|
|
|
6439
6648
|
var lastId = 0;
|
|
6440
6649
|
function usePendingPhotos() {
|
|
6441
6650
|
const { chat: chat2, t } = useChatContext();
|
|
6442
|
-
const [photos, setPhotos] = (0,
|
|
6443
|
-
const [problem, setProblem] = (0,
|
|
6651
|
+
const [photos, setPhotos] = (0, import_react6.useState)([]);
|
|
6652
|
+
const [problem, setProblem] = (0, import_react6.useState)(null);
|
|
6444
6653
|
const update = (id, patch) => setPhotos((current) => current.map((photo) => photo.id === id ? { ...photo, ...patch } : photo));
|
|
6445
6654
|
const upload = async (id, photo, type) => {
|
|
6446
6655
|
try {
|
|
@@ -6577,11 +6786,11 @@ function photoOf({ uri, fileName, type, width, height, fileSize }) {
|
|
|
6577
6786
|
}
|
|
6578
6787
|
|
|
6579
6788
|
// src/components/Composer.tsx
|
|
6580
|
-
var
|
|
6789
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
6581
6790
|
function Composer() {
|
|
6582
6791
|
const { chat: chat2, t, colors } = useChatContext();
|
|
6583
|
-
const [text, setText] = (0,
|
|
6584
|
-
const [focused, setFocused] = (0,
|
|
6792
|
+
const [text, setText] = (0, import_react7.useState)("");
|
|
6793
|
+
const [focused, setFocused] = (0, import_react7.useState)(false);
|
|
6585
6794
|
const pending = usePendingPhotos();
|
|
6586
6795
|
const picker = photoPicker();
|
|
6587
6796
|
const canSend = !pending.uploading && (text.trim().length > 0 || pending.ready);
|
|
@@ -6603,36 +6812,36 @@ function Composer() {
|
|
|
6603
6812
|
pending.showProblem(t.error);
|
|
6604
6813
|
}
|
|
6605
6814
|
};
|
|
6606
|
-
return /* @__PURE__ */ (0,
|
|
6607
|
-
pending.photos.length > 0 && /* @__PURE__ */ (0,
|
|
6608
|
-
|
|
6815
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react_native10.View, { style: styles6.composer, children: [
|
|
6816
|
+
pending.photos.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_native10.ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, contentContainerStyle: styles6.photos, children: pending.photos.map((photo) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
6817
|
+
import_react_native10.View,
|
|
6609
6818
|
{
|
|
6610
6819
|
style: [
|
|
6611
|
-
|
|
6820
|
+
styles6.photo,
|
|
6612
6821
|
{ borderColor: photo.status === "failed" ? colors.danger : colors.border, backgroundColor: colors.background }
|
|
6613
6822
|
],
|
|
6614
6823
|
children: [
|
|
6615
|
-
/* @__PURE__ */ (0,
|
|
6616
|
-
/* @__PURE__ */ (0,
|
|
6617
|
-
/* @__PURE__ */ (0,
|
|
6618
|
-
|
|
6824
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_native10.Image, { source: { uri: photo.uri }, style: styles6.preview }),
|
|
6825
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_native10.Text, { style: [styles6.photoStatus, { color: photo.status === "failed" ? colors.danger : colors.muted }], children: photo.status === "uploading" ? t.uploading : photo.status === "failed" ? t.not_sent : t.ready }),
|
|
6826
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
6827
|
+
import_react_native10.Pressable,
|
|
6619
6828
|
{
|
|
6620
6829
|
onPress: () => pending.remove(photo.id),
|
|
6621
6830
|
accessibilityRole: "button",
|
|
6622
6831
|
accessibilityLabel: format(t.remove_photo, { name: photo.name }),
|
|
6623
6832
|
hitSlop: 8,
|
|
6624
|
-
style:
|
|
6625
|
-
children: /* @__PURE__ */ (0,
|
|
6833
|
+
style: styles6.remove,
|
|
6834
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "remove", color: colors.muted, size: 14 })
|
|
6626
6835
|
}
|
|
6627
6836
|
)
|
|
6628
6837
|
]
|
|
6629
6838
|
},
|
|
6630
6839
|
photo.id
|
|
6631
6840
|
)) }),
|
|
6632
|
-
pending.problem && /* @__PURE__ */ (0,
|
|
6633
|
-
/* @__PURE__ */ (0,
|
|
6634
|
-
/* @__PURE__ */ (0,
|
|
6635
|
-
|
|
6841
|
+
pending.problem && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_native10.Text, { accessibilityLiveRegion: "polite", style: [styles6.problem, { color: colors.danger }], children: pending.problem }),
|
|
6842
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react_native10.View, { style: [styles6.field, { backgroundColor: colors.background, borderColor: focused ? colors.primary : colors.border }], children: [
|
|
6843
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
6844
|
+
import_react_native10.TextInput,
|
|
6636
6845
|
{
|
|
6637
6846
|
value: text,
|
|
6638
6847
|
onChangeText: (value) => {
|
|
@@ -6646,23 +6855,23 @@ function Composer() {
|
|
|
6646
6855
|
placeholder: t.placeholder,
|
|
6647
6856
|
placeholderTextColor: colors.muted,
|
|
6648
6857
|
accessibilityLabel: t.placeholder,
|
|
6649
|
-
style: [
|
|
6858
|
+
style: [styles6.input, { color: colors.text }]
|
|
6650
6859
|
}
|
|
6651
6860
|
),
|
|
6652
|
-
/* @__PURE__ */ (0,
|
|
6653
|
-
picker && /* @__PURE__ */ (0,
|
|
6654
|
-
|
|
6861
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react_native10.View, { style: styles6.tools, children: [
|
|
6862
|
+
picker && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
6863
|
+
import_react_native10.Pressable,
|
|
6655
6864
|
{
|
|
6656
6865
|
onPress: () => void handlePick(),
|
|
6657
6866
|
accessibilityRole: "button",
|
|
6658
6867
|
accessibilityLabel: t.attach,
|
|
6659
6868
|
hitSlop: 6,
|
|
6660
|
-
style:
|
|
6661
|
-
children: /* @__PURE__ */ (0,
|
|
6869
|
+
style: styles6.tool,
|
|
6870
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "photo", color: colors.muted })
|
|
6662
6871
|
}
|
|
6663
6872
|
),
|
|
6664
|
-
/* @__PURE__ */ (0,
|
|
6665
|
-
|
|
6873
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
6874
|
+
import_react_native10.Pressable,
|
|
6666
6875
|
{
|
|
6667
6876
|
onPress: handleSend,
|
|
6668
6877
|
disabled: !canSend,
|
|
@@ -6670,15 +6879,15 @@ function Composer() {
|
|
|
6670
6879
|
accessibilityLabel: t.send,
|
|
6671
6880
|
accessibilityState: { disabled: !canSend },
|
|
6672
6881
|
hitSlop: 6,
|
|
6673
|
-
style: ({ pressed }) => [
|
|
6674
|
-
children: /* @__PURE__ */ (0,
|
|
6882
|
+
style: ({ pressed }) => [styles6.send, pressed && styles6.pressed],
|
|
6883
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "send", color: canSend ? colors.primary : colors.border, size: 22 })
|
|
6675
6884
|
}
|
|
6676
6885
|
)
|
|
6677
6886
|
] })
|
|
6678
6887
|
] })
|
|
6679
6888
|
] });
|
|
6680
6889
|
}
|
|
6681
|
-
var
|
|
6890
|
+
var styles6 = import_react_native10.StyleSheet.create({
|
|
6682
6891
|
composer: { gap: 8 },
|
|
6683
6892
|
photos: { gap: 6 },
|
|
6684
6893
|
photo: {
|
|
@@ -6704,28 +6913,18 @@ var styles5 = import_react_native9.StyleSheet.create({
|
|
|
6704
6913
|
});
|
|
6705
6914
|
|
|
6706
6915
|
// src/components/MessageList.tsx
|
|
6707
|
-
var
|
|
6708
|
-
var
|
|
6709
|
-
|
|
6710
|
-
// src/components/EmailForm.tsx
|
|
6711
|
-
var import_react7 = require("react");
|
|
6712
|
-
var import_react_native10 = require("react-native");
|
|
6713
|
-
|
|
6714
|
-
// ../shared/src/utils/email.ts
|
|
6715
|
-
function normaliseEmail(email) {
|
|
6716
|
-
return email.trim().toLowerCase();
|
|
6717
|
-
}
|
|
6718
|
-
function isEmail(value) {
|
|
6719
|
-
return /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(value);
|
|
6720
|
-
}
|
|
6916
|
+
var import_react11 = require("react");
|
|
6917
|
+
var import_react_native16 = require("react-native");
|
|
6721
6918
|
|
|
6722
6919
|
// src/components/EmailForm.tsx
|
|
6723
|
-
var
|
|
6920
|
+
var import_react8 = require("react");
|
|
6921
|
+
var import_react_native11 = require("react-native");
|
|
6922
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
6724
6923
|
function EmailForm({ onSubmit }) {
|
|
6725
6924
|
const { t, colors } = useChatContext();
|
|
6726
|
-
const [email, setEmail] = (0,
|
|
6727
|
-
const [error, setError] = (0,
|
|
6728
|
-
const [busy, setBusy] = (0,
|
|
6925
|
+
const [email, setEmail] = (0, import_react8.useState)("");
|
|
6926
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
6927
|
+
const [busy, setBusy] = (0, import_react8.useState)(false);
|
|
6729
6928
|
const handleSubmit = async () => {
|
|
6730
6929
|
const address = normaliseEmail(email);
|
|
6731
6930
|
if (!isEmail(address)) {
|
|
@@ -6738,11 +6937,11 @@ function EmailForm({ onSubmit }) {
|
|
|
6738
6937
|
setBusy(false);
|
|
6739
6938
|
if (!result.ok) setError(result.code === "invalid_email" ? t.email_invalid : t.error);
|
|
6740
6939
|
};
|
|
6741
|
-
return /* @__PURE__ */ (0,
|
|
6742
|
-
/* @__PURE__ */ (0,
|
|
6743
|
-
/* @__PURE__ */ (0,
|
|
6744
|
-
/* @__PURE__ */ (0,
|
|
6745
|
-
|
|
6940
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react_native11.View, { style: [styles7.form, { borderColor: colors.border }], children: [
|
|
6941
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react_native11.Text, { style: [styles7.prompt, { color: colors.text }], children: t.email_prompt }),
|
|
6942
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react_native11.View, { style: styles7.row, children: [
|
|
6943
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
6944
|
+
import_react_native11.TextInput,
|
|
6746
6945
|
{
|
|
6747
6946
|
value: email,
|
|
6748
6947
|
onChangeText: setEmail,
|
|
@@ -6756,25 +6955,25 @@ function EmailForm({ onSubmit }) {
|
|
|
6756
6955
|
autoComplete: "email",
|
|
6757
6956
|
textContentType: "emailAddress",
|
|
6758
6957
|
returnKeyType: "send",
|
|
6759
|
-
style: [
|
|
6958
|
+
style: [styles7.input, { borderColor: error ? colors.danger : colors.border, color: colors.text }]
|
|
6760
6959
|
}
|
|
6761
6960
|
),
|
|
6762
|
-
/* @__PURE__ */ (0,
|
|
6763
|
-
|
|
6961
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
6962
|
+
import_react_native11.Pressable,
|
|
6764
6963
|
{
|
|
6765
6964
|
onPress: () => void handleSubmit(),
|
|
6766
6965
|
disabled: busy,
|
|
6767
6966
|
accessibilityRole: "button",
|
|
6768
|
-
style: [
|
|
6769
|
-
children: /* @__PURE__ */ (0,
|
|
6967
|
+
style: [styles7.submit, { backgroundColor: colors.primary }, busy && styles7.busy],
|
|
6968
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react_native11.Text, { style: [styles7.submitText, { color: colors.primaryForeground }], children: t.email_submit })
|
|
6770
6969
|
}
|
|
6771
6970
|
)
|
|
6772
6971
|
] }),
|
|
6773
|
-
error && /* @__PURE__ */ (0,
|
|
6972
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react_native11.Text, { accessibilityLiveRegion: "polite", style: [styles7.error, { color: colors.danger }], children: error })
|
|
6774
6973
|
] });
|
|
6775
6974
|
}
|
|
6776
|
-
var
|
|
6777
|
-
form: { gap: 8, padding: 12, borderRadius: 12, borderWidth:
|
|
6975
|
+
var styles7 = import_react_native11.StyleSheet.create({
|
|
6976
|
+
form: { gap: 8, padding: 12, borderRadius: 12, borderWidth: import_react_native11.StyleSheet.hairlineWidth },
|
|
6778
6977
|
prompt: { fontSize: 14, lineHeight: 20 },
|
|
6779
6978
|
row: { flexDirection: "row", gap: 8 },
|
|
6780
6979
|
input: { flex: 1, minWidth: 0, borderWidth: 1, borderRadius: 8, paddingHorizontal: 12, paddingVertical: 8, fontSize: 16 },
|
|
@@ -6785,10 +6984,10 @@ var styles6 = import_react_native10.StyleSheet.create({
|
|
|
6785
6984
|
});
|
|
6786
6985
|
|
|
6787
6986
|
// src/components/MessageBubble.tsx
|
|
6788
|
-
var
|
|
6987
|
+
var import_react_native14 = require("react-native");
|
|
6789
6988
|
|
|
6790
6989
|
// src/components/MessageFiles.tsx
|
|
6791
|
-
var
|
|
6990
|
+
var import_react_native12 = require("react-native");
|
|
6792
6991
|
|
|
6793
6992
|
// ../shared/src/utils/file-links.ts
|
|
6794
6993
|
var encoder = new TextEncoder();
|
|
@@ -6801,13 +7000,13 @@ function withFileName(url, name) {
|
|
|
6801
7000
|
}
|
|
6802
7001
|
|
|
6803
7002
|
// src/hooks/use-attachment-links.ts
|
|
6804
|
-
var
|
|
7003
|
+
var import_react9 = require("react");
|
|
6805
7004
|
var signed = /* @__PURE__ */ new Map();
|
|
6806
7005
|
function useAttachmentLinks(chat2, keys, stored) {
|
|
6807
|
-
const [links, setLinks] = (0,
|
|
6808
|
-
const [attempt, setAttempt] = (0,
|
|
7006
|
+
const [links, setLinks] = (0, import_react9.useState)(() => cachedLinks(keys));
|
|
7007
|
+
const [attempt, setAttempt] = (0, import_react9.useState)(0);
|
|
6809
7008
|
const wanted = keys.join("|");
|
|
6810
|
-
(0,
|
|
7009
|
+
(0, import_react9.useEffect)(() => {
|
|
6811
7010
|
if (!stored) return;
|
|
6812
7011
|
const list = wanted ? wanted.split("|") : [];
|
|
6813
7012
|
const missing = list.filter((key) => (signed.get(key)?.until ?? 0) < Date.now());
|
|
@@ -6837,7 +7036,7 @@ function cachedLinks(keys) {
|
|
|
6837
7036
|
}
|
|
6838
7037
|
|
|
6839
7038
|
// src/components/MessageFiles.tsx
|
|
6840
|
-
var
|
|
7039
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
6841
7040
|
var IMAGE_SIDE = 224;
|
|
6842
7041
|
function MessageFiles({ attachments, own, stored }) {
|
|
6843
7042
|
const { chat: chat2, t, colors, openImage } = useChatContext();
|
|
@@ -6847,40 +7046,40 @@ function MessageFiles({ attachments, own, stored }) {
|
|
|
6847
7046
|
stored
|
|
6848
7047
|
);
|
|
6849
7048
|
if (attachments.length === 0) return null;
|
|
6850
|
-
return /* @__PURE__ */ (0,
|
|
7049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_native12.View, { style: [styles8.files, { alignItems: own ? "flex-end" : "flex-start" }], children: attachments.map((attachment) => {
|
|
6851
7050
|
const url = links.get(attachment.key);
|
|
6852
7051
|
if (isImage(attachment.type)) {
|
|
6853
7052
|
const size = imageSize(attachment);
|
|
6854
|
-
return url ? /* @__PURE__ */ (0,
|
|
6855
|
-
|
|
7053
|
+
return url ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
7054
|
+
import_react_native12.Pressable,
|
|
6856
7055
|
{
|
|
6857
7056
|
onPress: () => openImage({ url, name: attachment.name }),
|
|
6858
7057
|
accessibilityRole: "imagebutton",
|
|
6859
7058
|
accessibilityLabel: t.open_image,
|
|
6860
|
-
style: [
|
|
6861
|
-
children: /* @__PURE__ */ (0,
|
|
7059
|
+
style: [styles8.image, { borderColor: colors.border }],
|
|
7060
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_native12.Image, { source: { uri: url }, style: size, resizeMode: "cover", accessibilityLabel: attachment.name })
|
|
6862
7061
|
},
|
|
6863
7062
|
attachment.key
|
|
6864
|
-
) : /* @__PURE__ */ (0,
|
|
6865
|
-
|
|
7063
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
7064
|
+
import_react_native12.View,
|
|
6866
7065
|
{
|
|
6867
|
-
style: [
|
|
7066
|
+
style: [styles8.image, size, { backgroundColor: colors.surface, borderColor: colors.border }]
|
|
6868
7067
|
},
|
|
6869
7068
|
attachment.key
|
|
6870
7069
|
);
|
|
6871
7070
|
}
|
|
6872
|
-
return /* @__PURE__ */ (0,
|
|
6873
|
-
|
|
7071
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
7072
|
+
import_react_native12.Pressable,
|
|
6874
7073
|
{
|
|
6875
7074
|
disabled: !url,
|
|
6876
|
-
onPress: () => url && void
|
|
7075
|
+
onPress: () => url && void import_react_native12.Linking.openURL(withFileName(url, attachment.name)),
|
|
6877
7076
|
accessibilityRole: "link",
|
|
6878
7077
|
accessibilityLabel: format(t.open_file, { name: attachment.name }),
|
|
6879
|
-
style: [
|
|
7078
|
+
style: [styles8.file, { borderColor: colors.border, backgroundColor: colors.background }],
|
|
6880
7079
|
children: [
|
|
6881
|
-
/* @__PURE__ */ (0,
|
|
6882
|
-
/* @__PURE__ */ (0,
|
|
6883
|
-
/* @__PURE__ */ (0,
|
|
7080
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "file", color: colors.muted, size: 16 }),
|
|
7081
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_native12.Text, { style: [styles8.fileName, { color: colors.text }], numberOfLines: 1, children: attachment.name }),
|
|
7082
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "download", color: colors.muted, size: 16 })
|
|
6884
7083
|
]
|
|
6885
7084
|
},
|
|
6886
7085
|
attachment.key
|
|
@@ -6892,9 +7091,9 @@ function imageSize({ width, height }) {
|
|
|
6892
7091
|
const scale = IMAGE_SIDE / Math.max(width, height);
|
|
6893
7092
|
return { width: Math.max(80, Math.round(width * scale)), height: Math.max(80, Math.round(height * scale)) };
|
|
6894
7093
|
}
|
|
6895
|
-
var
|
|
7094
|
+
var styles8 = import_react_native12.StyleSheet.create({
|
|
6896
7095
|
files: { gap: 6 },
|
|
6897
|
-
image: { overflow: "hidden", borderRadius: 12, borderWidth:
|
|
7096
|
+
image: { overflow: "hidden", borderRadius: 12, borderWidth: import_react_native12.StyleSheet.hairlineWidth },
|
|
6898
7097
|
file: {
|
|
6899
7098
|
flexDirection: "row",
|
|
6900
7099
|
alignItems: "center",
|
|
@@ -6902,81 +7101,69 @@ var styles7 = import_react_native11.StyleSheet.create({
|
|
|
6902
7101
|
width: 208,
|
|
6903
7102
|
padding: 8,
|
|
6904
7103
|
borderRadius: 12,
|
|
6905
|
-
borderWidth:
|
|
7104
|
+
borderWidth: import_react_native12.StyleSheet.hairlineWidth
|
|
6906
7105
|
},
|
|
6907
7106
|
fileName: { flex: 1, fontSize: 14 }
|
|
6908
7107
|
});
|
|
6909
7108
|
|
|
6910
7109
|
// src/components/TeamAvatar.tsx
|
|
6911
|
-
var
|
|
6912
|
-
|
|
6913
|
-
// ../shared/src/utils/names.ts
|
|
6914
|
-
function initialsOf(name) {
|
|
6915
|
-
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
6916
|
-
if (words.length === 0) return "";
|
|
6917
|
-
const letterOf = (word) => Array.from(word)[0] ?? "";
|
|
6918
|
-
return (letterOf(words[0]) + (words.length > 1 ? letterOf(words[words.length - 1]) : "")).toUpperCase();
|
|
6919
|
-
}
|
|
6920
|
-
var NAME_WORD = String.raw`\p{L}[\p{L}\p{M}]*`;
|
|
6921
|
-
var PERSON_NAME = new RegExp(String.raw`^${NAME_WORD}(?:\.?[ '’-]${NAME_WORD})*\.?$`, "u");
|
|
6922
|
-
|
|
6923
|
-
// src/components/TeamAvatar.tsx
|
|
6924
|
-
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
7110
|
+
var import_react_native13 = require("react-native");
|
|
7111
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
6925
7112
|
function TeamAvatar({ app, sender }) {
|
|
6926
7113
|
const { colors } = useChatContext();
|
|
6927
7114
|
const image = sender ? sender.image : app.logoUrl;
|
|
6928
|
-
if (image) return /* @__PURE__ */ (0,
|
|
6929
|
-
return /* @__PURE__ */ (0,
|
|
6930
|
-
|
|
7115
|
+
if (image) return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_native13.Image, { source: { uri: image }, style: styles9.avatar, accessibilityIgnoresInvertColors: true });
|
|
7116
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
7117
|
+
import_react_native13.View,
|
|
6931
7118
|
{
|
|
6932
|
-
style: [
|
|
7119
|
+
style: [styles9.avatar, { backgroundColor: sender ? colors.primaryTint : colors.primary }],
|
|
6933
7120
|
accessibilityElementsHidden: true,
|
|
6934
7121
|
importantForAccessibility: "no-hide-descendants",
|
|
6935
|
-
children: /* @__PURE__ */ (0,
|
|
7122
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_native13.Text, { style: [styles9.initials, { color: sender ? colors.primaryText : colors.primaryForeground }], children: initialsOf(sender?.name ?? app.name) })
|
|
6936
7123
|
}
|
|
6937
7124
|
);
|
|
6938
7125
|
}
|
|
6939
|
-
var
|
|
7126
|
+
var styles9 = import_react_native13.StyleSheet.create({
|
|
6940
7127
|
avatar: { width: 26, height: 26, borderRadius: 13, alignItems: "center", justifyContent: "center" },
|
|
6941
7128
|
initials: { fontSize: 10, fontWeight: "600" }
|
|
6942
7129
|
});
|
|
6943
7130
|
|
|
6944
7131
|
// src/components/MessageBubble.tsx
|
|
6945
|
-
var
|
|
7132
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
6946
7133
|
function MessageBubble({ message, app, showName, status, onRetry }) {
|
|
6947
7134
|
const { t, colors } = useChatContext();
|
|
6948
7135
|
if (message.from === "contact") {
|
|
6949
|
-
return /* @__PURE__ */ (0,
|
|
6950
|
-
message.body !== "" && /* @__PURE__ */ (0,
|
|
6951
|
-
|
|
7136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react_native14.View, { style: styles10.own, children: [
|
|
7137
|
+
message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
7138
|
+
import_react_native14.Text,
|
|
6952
7139
|
{
|
|
6953
7140
|
selectable: true,
|
|
6954
7141
|
style: [
|
|
6955
|
-
|
|
6956
|
-
|
|
7142
|
+
styles10.bubble,
|
|
7143
|
+
styles10.ownBubble,
|
|
6957
7144
|
{ backgroundColor: colors.primary, color: colors.primaryForeground },
|
|
6958
|
-
message.status === "sending" &&
|
|
7145
|
+
message.status === "sending" && styles10.sending
|
|
6959
7146
|
],
|
|
6960
7147
|
children: message.body
|
|
6961
7148
|
}
|
|
6962
7149
|
),
|
|
6963
|
-
/* @__PURE__ */ (0,
|
|
6964
|
-
message.status === "failed" ? /* @__PURE__ */ (0,
|
|
6965
|
-
/* @__PURE__ */ (0,
|
|
6966
|
-
/* @__PURE__ */ (0,
|
|
6967
|
-
] }) : status && /* @__PURE__ */ (0,
|
|
7150
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MessageFiles, { attachments: message.attachments, own: true, stored: message.status === "sent" }),
|
|
7151
|
+
message.status === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react_native14.View, { style: styles10.failed, children: [
|
|
7152
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native14.Text, { style: [styles10.meta, { color: colors.danger }], children: message.error === "rate_limited" ? t.rate_limited : t.not_sent }),
|
|
7153
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native14.Pressable, { onPress: onRetry, accessibilityRole: "button", hitSlop: 8, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native14.Text, { style: [styles10.meta, styles10.retry, { color: colors.danger }], children: t.retry }) })
|
|
7154
|
+
] }) : status && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native14.Text, { style: [styles10.meta, { color: colors.muted }], children: status })
|
|
6968
7155
|
] });
|
|
6969
7156
|
}
|
|
6970
|
-
return /* @__PURE__ */ (0,
|
|
6971
|
-
/* @__PURE__ */ (0,
|
|
6972
|
-
/* @__PURE__ */ (0,
|
|
6973
|
-
showName && /* @__PURE__ */ (0,
|
|
6974
|
-
message.body !== "" && /* @__PURE__ */ (0,
|
|
6975
|
-
/* @__PURE__ */ (0,
|
|
7157
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react_native14.View, { style: styles10.team, children: [
|
|
7158
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(TeamAvatar, { app, sender: message.sender }),
|
|
7159
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react_native14.View, { style: styles10.teamColumn, children: [
|
|
7160
|
+
showName && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native14.Text, { style: [styles10.meta, styles10.name, { color: colors.muted }], children: message.sender?.name ?? app.name }),
|
|
7161
|
+
message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native14.Text, { selectable: true, style: [styles10.bubble, styles10.teamBubble, { backgroundColor: colors.surface, color: colors.text }], children: message.body }),
|
|
7162
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MessageFiles, { attachments: message.attachments, own: false, stored: true })
|
|
6976
7163
|
] })
|
|
6977
7164
|
] });
|
|
6978
7165
|
}
|
|
6979
|
-
var
|
|
7166
|
+
var styles10 = import_react_native14.StyleSheet.create({
|
|
6980
7167
|
own: { alignSelf: "flex-end", alignItems: "flex-end", maxWidth: "80%", gap: 4 },
|
|
6981
7168
|
team: { flexDirection: "row", alignItems: "flex-start", gap: 8, maxWidth: "88%" },
|
|
6982
7169
|
teamColumn: { flexShrink: 1, gap: 4 },
|
|
@@ -6991,21 +7178,21 @@ var styles9 = import_react_native13.StyleSheet.create({
|
|
|
6991
7178
|
});
|
|
6992
7179
|
|
|
6993
7180
|
// src/components/TypingBubble.tsx
|
|
6994
|
-
var
|
|
6995
|
-
var
|
|
6996
|
-
var
|
|
7181
|
+
var import_react10 = require("react");
|
|
7182
|
+
var import_react_native15 = require("react-native");
|
|
7183
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
6997
7184
|
function TypingBubble({ app, sender }) {
|
|
6998
7185
|
const { t, colors } = useChatContext();
|
|
6999
|
-
const dots = (0,
|
|
7000
|
-
(0,
|
|
7001
|
-
const pulse =
|
|
7002
|
-
|
|
7186
|
+
const dots = (0, import_react10.useRef)([0, 1, 2].map(() => new import_react_native15.Animated.Value(0.3))).current;
|
|
7187
|
+
(0, import_react10.useEffect)(() => {
|
|
7188
|
+
const pulse = import_react_native15.Animated.loop(
|
|
7189
|
+
import_react_native15.Animated.stagger(
|
|
7003
7190
|
150,
|
|
7004
7191
|
dots.map(
|
|
7005
|
-
(dot) =>
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7192
|
+
(dot) => import_react_native15.Animated.sequence([
|
|
7193
|
+
import_react_native15.Animated.timing(dot, { toValue: 1, duration: 300, useNativeDriver: true }),
|
|
7194
|
+
import_react_native15.Animated.timing(dot, { toValue: 0.3, duration: 300, useNativeDriver: true }),
|
|
7195
|
+
import_react_native15.Animated.delay(300)
|
|
7009
7196
|
])
|
|
7010
7197
|
)
|
|
7011
7198
|
)
|
|
@@ -7013,12 +7200,12 @@ function TypingBubble({ app, sender }) {
|
|
|
7013
7200
|
pulse.start();
|
|
7014
7201
|
return () => pulse.stop();
|
|
7015
7202
|
}, [dots]);
|
|
7016
|
-
return /* @__PURE__ */ (0,
|
|
7017
|
-
/* @__PURE__ */ (0,
|
|
7018
|
-
/* @__PURE__ */ (0,
|
|
7203
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react_native15.View, { style: styles11.row, accessible: true, accessibilityLabel: format(t.typing, { name: sender?.name ?? t.team }), children: [
|
|
7204
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(TeamAvatar, { app, sender }),
|
|
7205
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_native15.View, { style: [styles11.bubble, { backgroundColor: colors.surface }], children: dots.map((opacity, index) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_native15.Animated.View, { style: [styles11.dot, { backgroundColor: colors.muted, opacity }] }, index)) })
|
|
7019
7206
|
] });
|
|
7020
7207
|
}
|
|
7021
|
-
var
|
|
7208
|
+
var styles11 = import_react_native15.StyleSheet.create({
|
|
7022
7209
|
row: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
7023
7210
|
bubble: {
|
|
7024
7211
|
flexDirection: "row",
|
|
@@ -7033,12 +7220,12 @@ var styles10 = import_react_native14.StyleSheet.create({
|
|
|
7033
7220
|
});
|
|
7034
7221
|
|
|
7035
7222
|
// src/components/MessageList.tsx
|
|
7036
|
-
var
|
|
7223
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
7037
7224
|
function MessageList({ state }) {
|
|
7038
7225
|
const { chat: chat2, t, colors } = useChatContext();
|
|
7039
7226
|
const app = state.app;
|
|
7040
7227
|
const { messages } = state;
|
|
7041
|
-
const newestFirst = (0,
|
|
7228
|
+
const newestFirst = (0, import_react11.useMemo)(() => [...messages].reverse(), [messages]);
|
|
7042
7229
|
const lastContactIndex = messages.findLastIndex((message) => message.from === "contact");
|
|
7043
7230
|
const latest = lastContactIndex >= 0 ? messages[lastContactIndex] : void 0;
|
|
7044
7231
|
const status = latest?.status === "sending" ? t.sending : latest?.status === "sent" ? state.seen ? t.seen : t.sent : null;
|
|
@@ -7053,8 +7240,8 @@ function MessageList({ state }) {
|
|
|
7053
7240
|
status: "sent",
|
|
7054
7241
|
error: null
|
|
7055
7242
|
};
|
|
7056
|
-
return /* @__PURE__ */ (0,
|
|
7057
|
-
|
|
7243
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
7244
|
+
import_react_native16.FlatList,
|
|
7058
7245
|
{
|
|
7059
7246
|
inverted: true,
|
|
7060
7247
|
data: newestFirst,
|
|
@@ -7062,7 +7249,7 @@ function MessageList({ state }) {
|
|
|
7062
7249
|
extraData: status,
|
|
7063
7250
|
renderItem: ({ item, index }) => {
|
|
7064
7251
|
const position = messages.length - 1 - index;
|
|
7065
|
-
return /* @__PURE__ */ (0,
|
|
7252
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
7066
7253
|
MessageBubble,
|
|
7067
7254
|
{
|
|
7068
7255
|
message: item,
|
|
@@ -7074,36 +7261,36 @@ function MessageList({ state }) {
|
|
|
7074
7261
|
);
|
|
7075
7262
|
},
|
|
7076
7263
|
ItemSeparatorComponent: Gap,
|
|
7077
|
-
ListHeaderComponent: /* @__PURE__ */ (0,
|
|
7078
|
-
state.teamTyping && /* @__PURE__ */ (0,
|
|
7079
|
-
askEmail && /* @__PURE__ */ (0,
|
|
7080
|
-
state.email && !state.online && /* @__PURE__ */ (0,
|
|
7264
|
+
ListHeaderComponent: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_react_native16.View, { style: styles12.below, children: [
|
|
7265
|
+
state.teamTyping && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(TypingBubble, { app, sender: state.teamTyping.sender }),
|
|
7266
|
+
askEmail && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(EmailForm, { onSubmit: chat2.setEmail }),
|
|
7267
|
+
state.email && !state.online && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native16.Text, { style: [styles12.saved, { color: colors.muted }], children: format(t.email_saved, { email: state.email }) })
|
|
7081
7268
|
] }),
|
|
7082
|
-
ListFooterComponent: /* @__PURE__ */ (0,
|
|
7083
|
-
state.hasOlder && /* @__PURE__ */ (0,
|
|
7084
|
-
|
|
7269
|
+
ListFooterComponent: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_react_native16.View, { style: styles12.above, children: [
|
|
7270
|
+
state.hasOlder && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
7271
|
+
import_react_native16.Pressable,
|
|
7085
7272
|
{
|
|
7086
7273
|
onPress: chat2.loadOlder,
|
|
7087
7274
|
disabled: state.loadingOlder,
|
|
7088
7275
|
accessibilityRole: "button",
|
|
7089
|
-
style: [
|
|
7090
|
-
children: /* @__PURE__ */ (0,
|
|
7276
|
+
style: [styles12.earlier, state.loadingOlder && styles12.loading],
|
|
7277
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native16.Text, { style: [styles12.earlierText, { color: colors.muted }], children: t.earlier })
|
|
7091
7278
|
}
|
|
7092
7279
|
),
|
|
7093
|
-
state.atStart && /* @__PURE__ */ (0,
|
|
7280
|
+
state.atStart && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(MessageBubble, { message: welcome, app, showName: true, status: null, onRetry: () => {
|
|
7094
7281
|
} })
|
|
7095
7282
|
] }),
|
|
7096
|
-
contentContainerStyle:
|
|
7283
|
+
contentContainerStyle: styles12.content,
|
|
7097
7284
|
keyboardShouldPersistTaps: "handled",
|
|
7098
7285
|
keyboardDismissMode: "interactive",
|
|
7099
|
-
style:
|
|
7286
|
+
style: styles12.list
|
|
7100
7287
|
}
|
|
7101
7288
|
);
|
|
7102
7289
|
}
|
|
7103
7290
|
function Gap() {
|
|
7104
|
-
return /* @__PURE__ */ (0,
|
|
7291
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native16.View, { style: styles12.gap });
|
|
7105
7292
|
}
|
|
7106
|
-
var
|
|
7293
|
+
var styles12 = import_react_native16.StyleSheet.create({
|
|
7107
7294
|
list: { flex: 1 },
|
|
7108
7295
|
// Inverted, `flex-end` is the top: a short Conversation starts under the header, as in the web widget.
|
|
7109
7296
|
content: { flexGrow: 1, justifyContent: "flex-end", padding: 14 },
|
|
@@ -7117,32 +7304,33 @@ var styles11 = import_react_native15.StyleSheet.create({
|
|
|
7117
7304
|
});
|
|
7118
7305
|
|
|
7119
7306
|
// src/components/PoweredBy.tsx
|
|
7120
|
-
var
|
|
7121
|
-
var
|
|
7307
|
+
var import_react_native17 = require("react-native");
|
|
7308
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
7122
7309
|
function PoweredBy() {
|
|
7123
7310
|
const { t, colors } = useChatContext();
|
|
7124
|
-
return /* @__PURE__ */ (0,
|
|
7125
|
-
/* @__PURE__ */ (0,
|
|
7126
|
-
/* @__PURE__ */ (0,
|
|
7127
|
-
/* @__PURE__ */ (0,
|
|
7311
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native17.View, { style: styles13.row, accessible: true, accessibilityLabel: `${t.powered_by} ${APP_NAME}`, children: [
|
|
7312
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native17.Text, { style: [styles13.text, { color: colors.muted }], children: t.powered_by }),
|
|
7313
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "mark", color: ZEAN_ACCENT_HEX, size: 14 }),
|
|
7314
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native17.Text, { style: [styles13.text, styles13.name, { color: colors.muted }], children: APP_NAME })
|
|
7128
7315
|
] });
|
|
7129
7316
|
}
|
|
7130
|
-
var
|
|
7317
|
+
var styles13 = import_react_native17.StyleSheet.create({
|
|
7131
7318
|
row: { flexDirection: "row", alignItems: "center", justifyContent: "center", gap: 4 },
|
|
7132
7319
|
text: { fontSize: 12 },
|
|
7133
7320
|
name: { fontWeight: "600" }
|
|
7134
7321
|
});
|
|
7135
7322
|
|
|
7136
7323
|
// src/components/ChatScreen.tsx
|
|
7137
|
-
var
|
|
7324
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
7138
7325
|
function ChatScreen({ state, insets, onClose }) {
|
|
7139
7326
|
const { t, colors } = useChatContext();
|
|
7140
|
-
const rootRef = (0,
|
|
7327
|
+
const rootRef = (0, import_react12.useRef)(null);
|
|
7141
7328
|
const keyboard = useKeyboardOverlap(rootRef);
|
|
7142
7329
|
const connectionLost = useConnectionLost(state.connected);
|
|
7330
|
+
const [codeDismissed, setCodeDismissed] = (0, import_react12.useState)(false);
|
|
7143
7331
|
const app = state.app;
|
|
7144
|
-
return /* @__PURE__ */ (0,
|
|
7145
|
-
/* @__PURE__ */ (0,
|
|
7332
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native18.View, { ref: rootRef, style: [styles14.screen, { backgroundColor: colors.background, paddingBottom: keyboard }], children: [
|
|
7333
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
7146
7334
|
ChatHeader,
|
|
7147
7335
|
{
|
|
7148
7336
|
app,
|
|
@@ -7152,90 +7340,87 @@ function ChatScreen({ state, insets, onClose }) {
|
|
|
7152
7340
|
onClose
|
|
7153
7341
|
}
|
|
7154
7342
|
),
|
|
7155
|
-
connectionLost && /* @__PURE__ */ (0,
|
|
7156
|
-
/* @__PURE__ */ (0,
|
|
7157
|
-
/* @__PURE__ */ (0,
|
|
7158
|
-
state.
|
|
7159
|
-
|
|
7343
|
+
connectionLost && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_native18.View, { style: styles14.notice, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ChatNotice, { children: t.reconnecting }) }),
|
|
7344
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(MessageList, { state }),
|
|
7345
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native18.View, { style: [styles14.footer, { borderTopColor: colors.border, paddingBottom: 8 + (keyboard > 0 ? 0 : insets.bottom) }], children: [
|
|
7346
|
+
state.contactCode && !codeDismissed && state.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ContactCodeCard, { code: state.contactCode, onDismiss: () => setCodeDismissed(true) }),
|
|
7347
|
+
state.status === "blocked" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ChatNotice, { children: t.blocked }) : state.status === "unavailable" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ChatNotice, { children: t.unavailable }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Composer, {}),
|
|
7348
|
+
app.showBadge && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(PoweredBy, {})
|
|
7160
7349
|
] })
|
|
7161
7350
|
] });
|
|
7162
7351
|
}
|
|
7163
|
-
var
|
|
7352
|
+
var styles14 = import_react_native18.StyleSheet.create({
|
|
7164
7353
|
screen: { flex: 1 },
|
|
7165
7354
|
notice: { paddingHorizontal: 14, paddingTop: 12 },
|
|
7166
|
-
footer: { gap: 8, paddingHorizontal: 12, paddingTop: 10, borderTopWidth:
|
|
7355
|
+
footer: { gap: 8, paddingHorizontal: 12, paddingTop: 10, borderTopWidth: import_react_native18.StyleSheet.hairlineWidth }
|
|
7167
7356
|
});
|
|
7168
7357
|
|
|
7169
7358
|
// src/components/ChatModal.tsx
|
|
7170
|
-
var
|
|
7359
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
7171
7360
|
var STRINGS = { fr, en };
|
|
7172
7361
|
function ChatModal({ chat: chat2, colorScheme }) {
|
|
7173
|
-
const state = (0,
|
|
7174
|
-
const { open: open2 } = (0,
|
|
7175
|
-
const deviceScheme = (0,
|
|
7362
|
+
const state = (0, import_react13.useSyncExternalStore)(chat2.subscribe, chat2.getState);
|
|
7363
|
+
const { open: open2 } = (0, import_react13.useSyncExternalStore)(subscribeChatView, chatView);
|
|
7364
|
+
const deviceScheme = (0, import_react_native19.useColorScheme)();
|
|
7176
7365
|
const scheme = colorScheme ?? (deviceScheme === "dark" ? "dark" : "light");
|
|
7177
7366
|
const active = useAppActive();
|
|
7178
|
-
const dimensions = (0,
|
|
7179
|
-
const [image, setImage] = (0,
|
|
7367
|
+
const dimensions = (0, import_react_native19.useWindowDimensions)();
|
|
7368
|
+
const [image, setImage] = (0, import_react13.useState)(null);
|
|
7180
7369
|
const app = state.app;
|
|
7181
7370
|
const visible = open2 && app !== null && state.status !== "loading" && state.status !== "hidden";
|
|
7182
7371
|
const color = app?.color ?? ZEAN_ACCENT_HEX;
|
|
7183
|
-
const context = (0,
|
|
7372
|
+
const context = (0, import_react13.useMemo)(
|
|
7184
7373
|
() => ({ chat: chat2, t: STRINGS[state.locale], colors: chatColors(color, scheme), openImage: setImage }),
|
|
7185
7374
|
[chat2, state.locale, color, scheme]
|
|
7186
7375
|
);
|
|
7187
|
-
const insets = (0,
|
|
7188
|
-
(0,
|
|
7376
|
+
const insets = (0, import_react13.useMemo)(screenInsets, [dimensions.width, dimensions.height]);
|
|
7377
|
+
(0, import_react13.useEffect)(() => {
|
|
7189
7378
|
if (visible && active && state.unread > 0) chat2.markRead();
|
|
7190
7379
|
}, [chat2, visible, active, state.unread]);
|
|
7191
|
-
(0,
|
|
7380
|
+
(0, import_react13.useEffect)(() => {
|
|
7192
7381
|
if (!visible) setImage(null);
|
|
7193
7382
|
}, [visible]);
|
|
7194
|
-
return /* @__PURE__ */ (0,
|
|
7195
|
-
|
|
7383
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
7384
|
+
import_react_native19.Modal,
|
|
7196
7385
|
{
|
|
7197
7386
|
visible,
|
|
7198
7387
|
animationType: "slide",
|
|
7199
|
-
presentationStyle:
|
|
7388
|
+
presentationStyle: import_react_native19.Platform.OS === "ios" && !import_react_native19.Platform.isPad ? "pageSheet" : "fullScreen",
|
|
7200
7389
|
statusBarTranslucent: true,
|
|
7201
7390
|
navigationBarTranslucent: true,
|
|
7202
|
-
onRequestClose: () =>
|
|
7203
|
-
children: app && /* @__PURE__ */ (0,
|
|
7204
|
-
/* @__PURE__ */ (0,
|
|
7205
|
-
image && /* @__PURE__ */ (0,
|
|
7391
|
+
onRequestClose: () => import_react_native19.Platform.OS === "android" && image ? setImage(null) : zean.close(),
|
|
7392
|
+
children: app && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(ChatContext, { value: context, children: [
|
|
7393
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ChatScreen, { state, insets, onClose: zean.close }),
|
|
7394
|
+
image && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ImageViewer, { image, onClose: () => setImage(null) })
|
|
7206
7395
|
] })
|
|
7207
7396
|
}
|
|
7208
7397
|
);
|
|
7209
7398
|
}
|
|
7210
7399
|
|
|
7211
7400
|
// src/components/ZeanChat.tsx
|
|
7212
|
-
var
|
|
7401
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
7213
7402
|
function ZeanChat({
|
|
7214
7403
|
appKey,
|
|
7215
7404
|
storage,
|
|
7216
|
-
|
|
7405
|
+
user,
|
|
7217
7406
|
attributes: attributes2,
|
|
7218
7407
|
locale,
|
|
7219
7408
|
colorScheme,
|
|
7220
7409
|
backendUrl = PRODUCTION_BACKEND_URL
|
|
7221
7410
|
}) {
|
|
7222
|
-
const [chat2, setChat] = (0,
|
|
7223
|
-
const storageRef = (0,
|
|
7224
|
-
const
|
|
7225
|
-
const
|
|
7226
|
-
const identified = (0, import_react13.useRef)(false);
|
|
7227
|
-
const signedIn = Boolean(getToken);
|
|
7411
|
+
const [chat2, setChat] = (0, import_react14.useState)(null);
|
|
7412
|
+
const storageRef = (0, import_react14.useRef)(storage);
|
|
7413
|
+
const userKey = user ? JSON.stringify(user) : null;
|
|
7414
|
+
const identified = (0, import_react14.useRef)(false);
|
|
7228
7415
|
const attributesKey = attributes2 ? JSON.stringify(attributes2) : null;
|
|
7229
|
-
(0,
|
|
7230
|
-
latestToken.current = getToken;
|
|
7231
|
-
});
|
|
7232
|
-
(0, import_react13.useEffect)(() => {
|
|
7416
|
+
(0, import_react14.useEffect)(() => {
|
|
7233
7417
|
const started = createChat({
|
|
7234
7418
|
appKey,
|
|
7235
7419
|
backendUrl,
|
|
7236
7420
|
storage: storageRef.current,
|
|
7237
7421
|
// A chosen language goes first: the chat takes the first one it speaks.
|
|
7238
7422
|
languages: locale ? [locale] : deviceLanguages(),
|
|
7423
|
+
deviceLanguage: deviceLanguages()[0],
|
|
7239
7424
|
os: deviceOs()
|
|
7240
7425
|
});
|
|
7241
7426
|
const detach = attachChat(started);
|
|
@@ -7245,20 +7430,20 @@ function ZeanChat({
|
|
|
7245
7430
|
started.destroy();
|
|
7246
7431
|
};
|
|
7247
7432
|
}, [appKey, backendUrl, locale]);
|
|
7248
|
-
(0,
|
|
7249
|
-
if (
|
|
7250
|
-
else if (
|
|
7251
|
-
identified.current =
|
|
7252
|
-
}, [
|
|
7253
|
-
(0,
|
|
7433
|
+
(0, import_react14.useEffect)(() => {
|
|
7434
|
+
if (userKey) zean.identify(JSON.parse(userKey));
|
|
7435
|
+
else if (identified.current) zean.signOut();
|
|
7436
|
+
identified.current = userKey !== null;
|
|
7437
|
+
}, [userKey]);
|
|
7438
|
+
(0, import_react14.useEffect)(() => {
|
|
7254
7439
|
if (attributesKey) zean.setAttributes(JSON.parse(attributesKey));
|
|
7255
7440
|
}, [attributesKey]);
|
|
7256
|
-
return chat2 ? /* @__PURE__ */ (0,
|
|
7441
|
+
return chat2 ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ChatModal, { chat: chat2, colorScheme }) : null;
|
|
7257
7442
|
}
|
|
7258
7443
|
|
|
7259
7444
|
// src/hooks/use-zean.ts
|
|
7260
|
-
var
|
|
7445
|
+
var import_react15 = require("react");
|
|
7261
7446
|
function useZean() {
|
|
7262
|
-
const { unread } = (0,
|
|
7447
|
+
const { unread } = (0, import_react15.useSyncExternalStore)(subscribeChatView, chatView);
|
|
7263
7448
|
return { ...zean, unreadCount: unread };
|
|
7264
7449
|
}
|