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