@liftitapp/wa-conversations 0.2.0
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 +206 -0
- package/dist/element/index.d.ts +1 -0
- package/dist/element/index.js +598 -0
- package/dist/react/index.d.ts +419 -0
- package/dist/react/index.js +2016 -0
- package/package.json +133 -0
|
@@ -0,0 +1,2016 @@
|
|
|
1
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region src/core/list/relative-time.ts
|
|
4
|
+
/**
|
|
5
|
+
* La hora de la fila del inbox, en español y **siempre relativa**.
|
|
6
|
+
*
|
|
7
|
+
* Por qué relativa y nunca una fecha corta formateada: una fecha arrastra locale y zona horaria del
|
|
8
|
+
* host, y este paquete monta en `lms-web-app`, en `backoffice-v2-lite` y en FlexOS. `Intl` daría
|
|
9
|
+
* "15/8/26" en uno y "8/15/26" en otro para la MISMA fila, y ninguna de las dos le dice al operador
|
|
10
|
+
* lo único que necesita saber de un vistazo: si esa conversación se enfrió. El absoluto no se
|
|
11
|
+
* pierde — viaja en el `dateTime` y en el `title` del `<time>`, que es donde el navegador y los
|
|
12
|
+
* lectores de pantalla lo esperan.
|
|
13
|
+
*
|
|
14
|
+
* `now` es un parámetro y no una lectura de `Date.now()` adentro para que el test pase su propio
|
|
15
|
+
* reloj: congelar el reloj global con timers falsos contagia a todo el archivo de tests y después
|
|
16
|
+
* nadie sabe por qué un test vecino se cuelga.
|
|
17
|
+
*
|
|
18
|
+
* **No se exporta desde el barrel del core.** Es detalle interno de la fila; lo que sale del barrel
|
|
19
|
+
* es API pública del entry `./react` y renombrarlo rompería el import de `lms-web-app` (PKG-04).
|
|
20
|
+
*/
|
|
21
|
+
const MINUTE = 6e4;
|
|
22
|
+
const HOUR = 60 * MINUTE;
|
|
23
|
+
const DAY = 24 * HOUR;
|
|
24
|
+
const WEEK = 7 * DAY;
|
|
25
|
+
/** Aproximaciones a propósito: es una distancia legible, no un cálculo de calendario. */
|
|
26
|
+
const MONTH = 30 * DAY;
|
|
27
|
+
const YEAR = 365 * DAY;
|
|
28
|
+
/**
|
|
29
|
+
* Distancia legible entre `iso` y `now`.
|
|
30
|
+
*
|
|
31
|
+
* Los dos casos degenerados no revientan, porque el dato lo origina el backend y el reloj lo pone
|
|
32
|
+
* la máquina del operador:
|
|
33
|
+
*
|
|
34
|
+
* - **Timestamp futuro** (desfase de reloj entre el server y el browser): devuelve `ahora`. Un
|
|
35
|
+
* "hace -3 min" en pantalla es peor que un redondeo.
|
|
36
|
+
* - **`iso` que no parsea**: devuelve cadena vacía, y la fila simplemente no pinta hora. Lanzar acá
|
|
37
|
+
* tumbaría la lista entera por una fila mala.
|
|
38
|
+
*/
|
|
39
|
+
function relativeTime(iso, now = Date.now()) {
|
|
40
|
+
const at = Date.parse(iso);
|
|
41
|
+
if (Number.isNaN(at)) return "";
|
|
42
|
+
const elapsed = now - at;
|
|
43
|
+
if (elapsed < MINUTE) return "ahora";
|
|
44
|
+
if (elapsed < HOUR) return `hace ${Math.floor(elapsed / MINUTE)} min`;
|
|
45
|
+
if (elapsed < DAY) return `hace ${Math.floor(elapsed / HOUR)} h`;
|
|
46
|
+
if (elapsed < WEEK) return `hace ${Math.floor(elapsed / DAY)} d`;
|
|
47
|
+
if (elapsed < MONTH) return `hace ${Math.floor(elapsed / WEEK)} sem`;
|
|
48
|
+
if (elapsed < YEAR) return `hace ${Math.floor(elapsed / MONTH)} mes`;
|
|
49
|
+
return `hace ${Math.floor(elapsed / YEAR)} a`;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/core/list/ConversationRow.tsx
|
|
53
|
+
function ConversationRow({ item, selected, onSelect }) {
|
|
54
|
+
return /* @__PURE__ */ jsx("li", {
|
|
55
|
+
className: "wa-list__item",
|
|
56
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
57
|
+
type: "button",
|
|
58
|
+
className: "wa-list__row",
|
|
59
|
+
"aria-current": selected ? "true" : void 0,
|
|
60
|
+
onClick: () => onSelect(item),
|
|
61
|
+
children: [
|
|
62
|
+
/* @__PURE__ */ jsxs("span", {
|
|
63
|
+
className: "wa-list__head",
|
|
64
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
65
|
+
className: "wa-list__title",
|
|
66
|
+
children: item.name ?? item.phone
|
|
67
|
+
}), /* @__PURE__ */ jsx("time", {
|
|
68
|
+
className: "wa-list__time",
|
|
69
|
+
dateTime: item.last_message_at,
|
|
70
|
+
title: item.last_message_at,
|
|
71
|
+
children: relativeTime(item.last_message_at)
|
|
72
|
+
})]
|
|
73
|
+
}),
|
|
74
|
+
item.last_message !== null && /* @__PURE__ */ jsx("span", {
|
|
75
|
+
className: "wa-list__preview",
|
|
76
|
+
children: item.last_message
|
|
77
|
+
}),
|
|
78
|
+
item.service_state !== null && /* @__PURE__ */ jsx("span", {
|
|
79
|
+
className: "wa-list__state",
|
|
80
|
+
title: item.service_state,
|
|
81
|
+
children: item.service_state
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/core/list/list-styles.ts
|
|
89
|
+
/**
|
|
90
|
+
* El CSS del panel, como string, para que viaje DENTRO del componente.
|
|
91
|
+
*
|
|
92
|
+
* Por qué un string y no un `.css` importado: el entry `./element` no puede emitir un archivo suelto
|
|
93
|
+
* que el host tenga que acordarse de importar (Pitfall 5, ya asserteado por `verify-externals`), y
|
|
94
|
+
* el entry `./react` no puede obligar a `lms-web-app` a agregar un import de CSS a su bundle para
|
|
95
|
+
* que el panel no se vea roto.
|
|
96
|
+
*
|
|
97
|
+
* Reglas duras de este archivo:
|
|
98
|
+
*
|
|
99
|
+
* - 🔴 **Todos los selectores van prefijados con `.wa-list`.** En el entry `./react` NO hay shadow
|
|
100
|
+
* DOM: un selector de elemento suelto (`ul`, `button`, `input`) le pisaría los estilos al host, y
|
|
101
|
+
* `backoffice-v2-lite` no perdona eso. Tampoco hay `:host` acá — eso es del entry del elemento.
|
|
102
|
+
* - **Sin tokens del LMS, sin variables, sin `@import`, sin fuentes remotas** (C-04/LIST-05). El
|
|
103
|
+
* paquete monta en tres hosts con temas distintos: cualquier paleta acá sería inventar un tema.
|
|
104
|
+
* Tipografía heredable y grises, en la línea de `src/element/styles.css`.
|
|
105
|
+
* - **El layout angosto/ancho se selecciona por `[data-layout]`, no por `@media`.** El panel va
|
|
106
|
+
* embebido y el viewport miente sobre el ancho que realmente tiene (ver `useContainerLayout`).
|
|
107
|
+
*
|
|
108
|
+
* Dos instancias montadas emiten este mismo CSS dos veces. Es idempotente —las reglas son las
|
|
109
|
+
* mismas— y se acepta a conciencia: la alternativa (un registro global de "ya lo inyecté") es
|
|
110
|
+
* estado compartido entre instancias, que es peor.
|
|
111
|
+
*/
|
|
112
|
+
const LIST_CSS = `
|
|
113
|
+
.wa-list {
|
|
114
|
+
box-sizing: border-box;
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-direction: column;
|
|
117
|
+
min-height: 0;
|
|
118
|
+
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
|
119
|
+
font-size: 14px;
|
|
120
|
+
line-height: 1.5;
|
|
121
|
+
color: #1f2933;
|
|
122
|
+
background: #ffffff;
|
|
123
|
+
}
|
|
124
|
+
.wa-list *,
|
|
125
|
+
.wa-list *::before,
|
|
126
|
+
.wa-list *::after {
|
|
127
|
+
box-sizing: inherit;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* 🔴 Ancho: SIEMPRE el del contenedor, jamás derivado de [data-layout]. El data-layout sale de
|
|
131
|
+
medir el propio ancho con ResizeObserver: si el ancho dependiera del layout medido, el ciclo
|
|
132
|
+
wide→320px→"mido angosto"→narrow→100%→"mido ancho"→wide oscila para siempre y el panel entero
|
|
133
|
+
parpadea (visto en el banco visual). Quién es columna y de qué ancho lo decide el CONTENEDOR:
|
|
134
|
+
el shell de WaConversations fija los 320px de la columna en SU CSS, y un host que monte la
|
|
135
|
+
lista sola la dimensiona con su propio layout. Acá [data-layout] solo adapta el contenido. */
|
|
136
|
+
.wa-list {
|
|
137
|
+
width: 100%;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.wa-list__filters {
|
|
141
|
+
display: flex;
|
|
142
|
+
flex-wrap: wrap;
|
|
143
|
+
gap: 8px;
|
|
144
|
+
padding: 10px 12px;
|
|
145
|
+
border-bottom: 1px solid #e4e7eb;
|
|
146
|
+
}
|
|
147
|
+
.wa-list__field {
|
|
148
|
+
display: flex;
|
|
149
|
+
flex: 1 1 120px;
|
|
150
|
+
min-width: 0;
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
gap: 2px;
|
|
153
|
+
}
|
|
154
|
+
.wa-list__field label {
|
|
155
|
+
font-size: 11px;
|
|
156
|
+
letter-spacing: 0.04em;
|
|
157
|
+
text-transform: uppercase;
|
|
158
|
+
color: #616e7c;
|
|
159
|
+
}
|
|
160
|
+
.wa-list__field input {
|
|
161
|
+
min-width: 0;
|
|
162
|
+
padding: 5px 8px;
|
|
163
|
+
border: 1px solid #cbd2d9;
|
|
164
|
+
border-radius: 4px;
|
|
165
|
+
font: inherit;
|
|
166
|
+
color: inherit;
|
|
167
|
+
background: #ffffff;
|
|
168
|
+
}
|
|
169
|
+
.wa-list__actions {
|
|
170
|
+
display: flex;
|
|
171
|
+
align-items: flex-end;
|
|
172
|
+
gap: 8px;
|
|
173
|
+
}
|
|
174
|
+
.wa-list__actions button,
|
|
175
|
+
.wa-list__more {
|
|
176
|
+
padding: 6px 10px;
|
|
177
|
+
border: 1px solid #cbd2d9;
|
|
178
|
+
border-radius: 4px;
|
|
179
|
+
font: inherit;
|
|
180
|
+
color: inherit;
|
|
181
|
+
background: #ffffff;
|
|
182
|
+
cursor: pointer;
|
|
183
|
+
}
|
|
184
|
+
.wa-list__actions button:hover,
|
|
185
|
+
.wa-list__more:hover {
|
|
186
|
+
background: #f5f7fa;
|
|
187
|
+
}
|
|
188
|
+
.wa-list__more {
|
|
189
|
+
margin: 8px 12px;
|
|
190
|
+
}
|
|
191
|
+
.wa-list__more:disabled {
|
|
192
|
+
color: #9aa5b1;
|
|
193
|
+
cursor: default;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.wa-list__items {
|
|
197
|
+
flex: 1 1 auto;
|
|
198
|
+
min-height: 0;
|
|
199
|
+
margin: 0;
|
|
200
|
+
padding: 0;
|
|
201
|
+
overflow-y: auto;
|
|
202
|
+
list-style: none;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.wa-list__row {
|
|
206
|
+
display: flex;
|
|
207
|
+
flex-direction: column;
|
|
208
|
+
gap: 2px;
|
|
209
|
+
width: 100%;
|
|
210
|
+
padding: 10px 12px;
|
|
211
|
+
border: 0;
|
|
212
|
+
border-bottom: 1px solid #f0f2f4;
|
|
213
|
+
font: inherit;
|
|
214
|
+
color: inherit;
|
|
215
|
+
text-align: left;
|
|
216
|
+
background: transparent;
|
|
217
|
+
cursor: pointer;
|
|
218
|
+
}
|
|
219
|
+
.wa-list__row:hover {
|
|
220
|
+
background: #f5f7fa;
|
|
221
|
+
}
|
|
222
|
+
/* El seleccionado se marca por el MISMO atributo que lo anuncia a un lector de pantalla: si un día
|
|
223
|
+
alguien saca el aria-current, el resaltado se va con él y el bug se ve. */
|
|
224
|
+
.wa-list__row[aria-current='true'] {
|
|
225
|
+
background: #e9eef4;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.wa-list__head {
|
|
229
|
+
display: flex;
|
|
230
|
+
align-items: baseline;
|
|
231
|
+
justify-content: space-between;
|
|
232
|
+
gap: 8px;
|
|
233
|
+
}
|
|
234
|
+
.wa-list__title {
|
|
235
|
+
overflow: hidden;
|
|
236
|
+
font-weight: 600;
|
|
237
|
+
text-overflow: ellipsis;
|
|
238
|
+
white-space: nowrap;
|
|
239
|
+
}
|
|
240
|
+
.wa-list__time {
|
|
241
|
+
flex: 0 0 auto;
|
|
242
|
+
font-size: 12px;
|
|
243
|
+
color: #7b8794;
|
|
244
|
+
}
|
|
245
|
+
.wa-list__preview {
|
|
246
|
+
overflow: hidden;
|
|
247
|
+
color: #52606d;
|
|
248
|
+
text-overflow: ellipsis;
|
|
249
|
+
white-space: nowrap;
|
|
250
|
+
}
|
|
251
|
+
/* El estado del emisor es una cadena OPACA que escribe otro servicio: se pinta como texto y nada
|
|
252
|
+
más. Nunca se interpola su valor en un selector ni en una clase (C-01 / T-03-02). */
|
|
253
|
+
.wa-list__state {
|
|
254
|
+
align-self: flex-start;
|
|
255
|
+
font-size: 11px;
|
|
256
|
+
color: #616e7c;
|
|
257
|
+
word-break: break-word;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* Angosto: la fila se apila. \`display: contents\` saca al agrupador del flujo para que la hora
|
|
261
|
+
pueda quedar DEBAJO del preview en vez de a la derecha del título. */
|
|
262
|
+
.wa-list[data-layout='narrow'] .wa-list__head {
|
|
263
|
+
display: contents;
|
|
264
|
+
}
|
|
265
|
+
.wa-list[data-layout='narrow'] .wa-list__time {
|
|
266
|
+
order: 1;
|
|
267
|
+
}
|
|
268
|
+
.wa-list[data-layout='narrow'] .wa-list__state {
|
|
269
|
+
order: 2;
|
|
270
|
+
}
|
|
271
|
+
.wa-list[data-layout='narrow'] .wa-list__preview,
|
|
272
|
+
.wa-list[data-layout='narrow'] .wa-list__title {
|
|
273
|
+
white-space: normal;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.wa-list__note {
|
|
277
|
+
margin: 0;
|
|
278
|
+
padding: 12px;
|
|
279
|
+
color: #616e7c;
|
|
280
|
+
}
|
|
281
|
+
.wa-list__error {
|
|
282
|
+
padding: 10px 12px;
|
|
283
|
+
border-bottom: 1px solid #e4e7eb;
|
|
284
|
+
background: #fdf6f6;
|
|
285
|
+
}
|
|
286
|
+
.wa-list__error p {
|
|
287
|
+
margin: 0 0 8px;
|
|
288
|
+
}
|
|
289
|
+
.wa-list__error button {
|
|
290
|
+
padding: 5px 10px;
|
|
291
|
+
border: 1px solid #cbd2d9;
|
|
292
|
+
border-radius: 4px;
|
|
293
|
+
font: inherit;
|
|
294
|
+
color: inherit;
|
|
295
|
+
background: #ffffff;
|
|
296
|
+
cursor: pointer;
|
|
297
|
+
}
|
|
298
|
+
`;
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/core/list/useContainerLayout.ts
|
|
301
|
+
/**
|
|
302
|
+
* Decide angosto/ancho midiendo **el contenedor**, no el viewport.
|
|
303
|
+
*
|
|
304
|
+
* Un `@media (max-width: …)` mentiría acá y no es un detalle: este panel va embebido. En
|
|
305
|
+
* `lms-web-app` vive en una columna de ~380 px de una pantalla de 1920, así que el viewport dice
|
|
306
|
+
* "ancho" mientras la columna real es angosta, y la fila se rompe. Lo que importa es el ancho del
|
|
307
|
+
* elemento, y eso sólo lo sabe `ResizeObserver`.
|
|
308
|
+
*
|
|
309
|
+
* **Este hook es el seam de la Fase 4** (DEV-4987). El switch de dos vistas —en angosto, el hilo
|
|
310
|
+
* EN LUGAR DE la lista— necesita exactamente esta misma decisión, y que existan dos mecanismos
|
|
311
|
+
* para la misma pregunta es cómo se desincronizan: uno diría angosto y el otro ancho en el mismo
|
|
312
|
+
* pixel. Por eso sale del barrel del core aunque hoy lo use un solo componente.
|
|
313
|
+
*
|
|
314
|
+
* Feature-detect obligatorio: el paquete no puede asumir el navegador del host y jsdom no trae
|
|
315
|
+
* `ResizeObserver`. Donde no existe, el panel asume `'wide'` y no observa nada — degrada a la
|
|
316
|
+
* columna de siempre en vez de reventar.
|
|
317
|
+
*/
|
|
318
|
+
/**
|
|
319
|
+
* Hasta acá (inclusive) el panel se considera angosto.
|
|
320
|
+
*
|
|
321
|
+
* 520 px es el punto donde la fila deja de poder llevar título y hora en la misma línea sin cortar
|
|
322
|
+
* el nombre; no es un breakpoint de dispositivo, porque acá no se mide un dispositivo. Se exporta
|
|
323
|
+
* para que la Fase 4 use el MISMO número y no invente otro.
|
|
324
|
+
*/
|
|
325
|
+
const NARROW_MAX_WIDTH = 520;
|
|
326
|
+
/**
|
|
327
|
+
* Observa el ancho de `ref` y devuelve el layout.
|
|
328
|
+
*
|
|
329
|
+
* El estado se escribe desde el callback del observer —nunca sincrónicamente en el efecto— y el
|
|
330
|
+
* observer se desconecta en el cleanup: sin eso, un panel desmontado sigue midiendo un elemento
|
|
331
|
+
* que ya no está en el documento.
|
|
332
|
+
*/
|
|
333
|
+
function useContainerLayout(ref, narrowMaxWidth = 520) {
|
|
334
|
+
const [layout, setLayout] = useState("wide");
|
|
335
|
+
useEffect(() => {
|
|
336
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
337
|
+
const element = ref.current;
|
|
338
|
+
if (element === null) return;
|
|
339
|
+
const observer = new ResizeObserver((entries) => {
|
|
340
|
+
for (const entry of entries) setLayout(entry.contentRect.width <= narrowMaxWidth ? "narrow" : "wide");
|
|
341
|
+
});
|
|
342
|
+
observer.observe(element);
|
|
343
|
+
return () => observer.disconnect();
|
|
344
|
+
}, [ref, narrowMaxWidth]);
|
|
345
|
+
return layout;
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/core/contract/thread.ts
|
|
349
|
+
/**
|
|
350
|
+
* Cierra hacia `unverified`, **nunca** hacia `closed`.
|
|
351
|
+
*
|
|
352
|
+
* No es una preferencia: `closed` bloquea el composer y afirma "la ventana de 24h venció". Un valor
|
|
353
|
+
* que no reconocemos significa literalmente "no pudimos determinarlo", y `unverified` es la única
|
|
354
|
+
* lectura que no afirma nada — le dice al operador "reintentá" en vez de mentirle en cualquiera de
|
|
355
|
+
* las dos direcciones. Aplanar los tres estados en dos es la lección cara del inbox de FlexOS:
|
|
356
|
+
* mandaba una plantilla MARKETING **cobrada** por un parpadeo de Postgres.
|
|
357
|
+
*
|
|
358
|
+
* Ojo con la asimetría respecto del backend: en Pydantic el default del campo sí es `closed`
|
|
359
|
+
* (fail-closed del lado que cobra). En el cable, lo desconocido es `unverified`.
|
|
360
|
+
*/
|
|
361
|
+
function normalizeWindowState(state) {
|
|
362
|
+
return state === "open" || state === "closed" ? state : "unverified";
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Colapsa por **wamid** una lista ya concatenada (hilo previo + refetch), que es el primitivo que
|
|
366
|
+
* sirve tanto al refetch de la Fase 4 como a la reconciliación optimista de la Fase 7.
|
|
367
|
+
*
|
|
368
|
+
* Reglas, y el porqué de cada una:
|
|
369
|
+
*
|
|
370
|
+
* - **Los mensajes sin wamid nunca se colapsan entre sí.** Son burbujas optimistas que Meta todavía
|
|
371
|
+
* no confirmó: no hay clave con qué compararlas, y unirlas por "parecen iguales" perdería un
|
|
372
|
+
* mensaje que la persona sí mandó.
|
|
373
|
+
* - **Se conserva la posición de la primera aparición y el contenido de la última.** El estado
|
|
374
|
+
* avanza `pending -> sent -> delivered -> read`, así que el refetch trae la versión fresca; y
|
|
375
|
+
* mover la burbuja de lugar reordenaría el hilo delante del operador mientras lo lee.
|
|
376
|
+
* - **No ordena por fecha.** El orden cronológico es THREAD-01, de la Fase 4: mezclar las dos
|
|
377
|
+
* responsabilidades acá haría que un refetch reordene el hilo sin que nadie lo haya pedido.
|
|
378
|
+
* - **El índice es un `Map`, no un objeto literal** (T-02-04). El wamid lo origina Meta y viaja por
|
|
379
|
+
* el cable: un `id` con valor `__proto__` o `constructor` sobre un objeto literal envenenaría el
|
|
380
|
+
* prototipo o colapsaría burbujas ajenas contra un método heredado. Un `Map` no tiene prototipo
|
|
381
|
+
* que consultar.
|
|
382
|
+
*/
|
|
383
|
+
function dedupeByWamid(messages) {
|
|
384
|
+
const deduped = [];
|
|
385
|
+
const positionByWamid = /* @__PURE__ */ new Map();
|
|
386
|
+
for (const message of messages) {
|
|
387
|
+
const wamid = typeof message.id === "string" && message.id !== "" ? message.id : null;
|
|
388
|
+
if (wamid === null) {
|
|
389
|
+
deduped.push(message);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
const position = positionByWamid.get(wamid);
|
|
393
|
+
if (position === void 0) {
|
|
394
|
+
positionByWamid.set(wamid, deduped.length);
|
|
395
|
+
deduped.push(message);
|
|
396
|
+
} else deduped[position] = message;
|
|
397
|
+
}
|
|
398
|
+
return deduped;
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/core/data/fetcher.ts
|
|
402
|
+
/**
|
|
403
|
+
* La capa de datos del paquete: un único punto de entrada, y el host pone la función.
|
|
404
|
+
*
|
|
405
|
+
* 🔴 **El paquete nunca arma URLs ni conoce la autenticación** (`CLAUDE.md`, DATA-05). Acá no hay
|
|
406
|
+
* host de API, no hay base path, no hay token, no hay `fetch`. Y no es purismo: el backend de
|
|
407
|
+
* FlexOS scopea el hilo **por organización en la ruta** y el nuestro por `phone_number_id`. Si este
|
|
408
|
+
* módulo concatenara una ruta —aunque fuera relativa— el mismo core dejaría de servir a los dos, y
|
|
409
|
+
* la migración del inbox de Felipe dejaría de ser plug-in.
|
|
410
|
+
*
|
|
411
|
+
* Por eso el `fetcher` recibe un **descriptor semántico** (`{ resource: 'thread', phone }`) y no un
|
|
412
|
+
* path: un path relativo YA es armar una URL. El host mapea ese descriptor a su propia ruta, con su
|
|
413
|
+
* propia auth, cerrando por closure sobre lo suyo:
|
|
414
|
+
*
|
|
415
|
+
* ```ts
|
|
416
|
+
* const fetcher: WaFetcher = async (request, options) => {
|
|
417
|
+
* const url = request.resource === 'thread'
|
|
418
|
+
* ? `${API}/wa/threads/${encodeURIComponent(request.phone)}?phone_number_id=${PNID}`
|
|
419
|
+
* : `${API}/wa/conversations?phone_number_id=${PNID}`;
|
|
420
|
+
* const res = await fetch(url, { headers: { authorization: `Bearer ${token}` }, ...options });
|
|
421
|
+
* return res.json();
|
|
422
|
+
* };
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* Ese ejemplo es del HOST. Nada de eso puede mudarse a este archivo (T-02-02): el paquete no guarda
|
|
426
|
+
* ni reenvía un token porque nunca lo recibe.
|
|
427
|
+
*
|
|
428
|
+
* ⚠️ Si alguien "simplifica" el fetcher a una función que recibe un path, este archivo pierde su
|
|
429
|
+
* razón de existir y el requisito se rompe sin que ningún test de UI se ponga rojo.
|
|
430
|
+
*/
|
|
431
|
+
/** El payload del backend es entrada NO confiable: se mira como diccionario, no como tipo. */
|
|
432
|
+
function asRecord(value) {
|
|
433
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
434
|
+
}
|
|
435
|
+
function asString(value) {
|
|
436
|
+
return typeof value === "string" ? value : "";
|
|
437
|
+
}
|
|
438
|
+
function asNullableString(value) {
|
|
439
|
+
return typeof value === "string" ? value : null;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Pide el hilo por el fetcher del host y devuelve el sobre tipado.
|
|
443
|
+
*
|
|
444
|
+
* La coerción es defensiva pero **no valida campo por campo**: los enums son abiertos justamente
|
|
445
|
+
* para no necesitarlo (DATA-01), y un validador de esquema sería una dependencia y un contrato
|
|
446
|
+
* paralelo al que ya existe. Lo que sí se garantiza es que un payload deforme degrade la vista en
|
|
447
|
+
* vez de tumbar el hilo (T-02-03): `messages` que no es lista sale lista vacía, y `window_state`
|
|
448
|
+
* desconocido sale `unverified`.
|
|
449
|
+
*
|
|
450
|
+
* El `window_state` del resultado siempre es uno de los tres valores de `LeadWindowState`.
|
|
451
|
+
*/
|
|
452
|
+
async function loadThread(fetcher, request, options) {
|
|
453
|
+
const payload = asRecord(await fetcher({
|
|
454
|
+
resource: "thread",
|
|
455
|
+
...request
|
|
456
|
+
}, options));
|
|
457
|
+
const messages = Array.isArray(payload.messages) ? payload.messages : [];
|
|
458
|
+
return {
|
|
459
|
+
phone_e164: asString(payload.phone_e164),
|
|
460
|
+
messages: dedupeByWamid(messages),
|
|
461
|
+
older_cursor: asNullableString(payload.older_cursor),
|
|
462
|
+
window_open: payload.window_open === true,
|
|
463
|
+
window_state: normalizeWindowState(asNullableString(payload.window_state)),
|
|
464
|
+
window_expires_at: asNullableString(payload.window_expires_at),
|
|
465
|
+
phone_number_id: asString(payload.phone_number_id),
|
|
466
|
+
service: asString(payload.service)
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Resuelve el descriptor firmado de un adjunto por el fetcher del host.
|
|
471
|
+
*
|
|
472
|
+
* Misma coerción defensiva que los otros loaders: un payload deforme degrada (`url: ''`) en vez de
|
|
473
|
+
* lanzar. Los rechazos del fetcher (el 404 del host incluido) se dejan propagar TAL CUAL: quién
|
|
474
|
+
* decide "Adjunto no disponible" es la burbuja, no esta capa — acá no hay reintentos ni traducción.
|
|
475
|
+
*
|
|
476
|
+
* ⚠️ El `media_format` de esta respuesta es INFORMATIVO. El gate del render inline usa
|
|
477
|
+
* EXCLUSIVAMENTE el `media_format` del `ThreadMessage` (MEDIA-01, invariante 3 del contrato):
|
|
478
|
+
* gatear con este campo abriría una segunda fuente de verdad para una decisión de seguridad.
|
|
479
|
+
*/
|
|
480
|
+
async function loadMedia(fetcher, request, options) {
|
|
481
|
+
const payload = asRecord(await fetcher({
|
|
482
|
+
resource: "media",
|
|
483
|
+
...request
|
|
484
|
+
}, options));
|
|
485
|
+
return {
|
|
486
|
+
url: asString(payload.url),
|
|
487
|
+
media_format: asNullableString(payload.media_format)
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
async function loadConversations(fetcher, request = {}, options) {
|
|
491
|
+
const payload = asRecord(await fetcher({
|
|
492
|
+
resource: "conversations",
|
|
493
|
+
...request
|
|
494
|
+
}, options));
|
|
495
|
+
return {
|
|
496
|
+
items: Array.isArray(payload.items) ? payload.items : [],
|
|
497
|
+
next_cursor: asNullableString(payload.next_cursor)
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
/** Identidad estable para "sin filtros": un `{}` nuevo por render reiniciaría la lista sin parar. */
|
|
501
|
+
const NO_FILTERS$1 = {};
|
|
502
|
+
/** Lo que rechaza una promesa es `unknown`: se normaliza acá y no en cada consumidor. */
|
|
503
|
+
function toError$1(cause) {
|
|
504
|
+
return cause instanceof Error ? cause : new Error(String(cause));
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Anexa la página nueva **deduplicando por `phone`**.
|
|
508
|
+
*
|
|
509
|
+
* Dentro de una lista el scope ya lo fijó el `fetcher` del host, así que `phone` identifica la fila
|
|
510
|
+
* (mismo espíritu que `dedupeByWamid` en el hilo). Un backend que pagina por timestamp devuelve
|
|
511
|
+
* filas solapadas apenas entra un mensaje nuevo mientras el operador scrollea: sin esto, la misma
|
|
512
|
+
* conversación aparecería dos veces y el `key` de React chocaría.
|
|
513
|
+
*/
|
|
514
|
+
function appendWithoutDuplicates(previous, incoming) {
|
|
515
|
+
const seen = new Set(previous.map((item) => item.phone));
|
|
516
|
+
return [...previous, ...incoming.filter((item) => !seen.has(item.phone))];
|
|
517
|
+
}
|
|
518
|
+
function useConversations({ fetcher, filters = NO_FILTERS$1 }) {
|
|
519
|
+
const [loaded, setLoaded] = useState(null);
|
|
520
|
+
/** Cambia sólo cuando `retry()` rearranca de cero: es lo que vuelve a disparar el efecto. */
|
|
521
|
+
const [attempt, setAttempt] = useState(0);
|
|
522
|
+
/**
|
|
523
|
+
* La petición en vuelo, si hay.
|
|
524
|
+
*
|
|
525
|
+
* Es un ref y no estado a propósito: el bloqueo de "una página a la vez" tiene que ser exacto
|
|
526
|
+
* **en el mismo tick**. Un `IntersectionObserver` que dispara dos veces seguidas ve el mismo
|
|
527
|
+
* render —y por lo tanto el mismo `status`— en las dos llamadas, así que mirar el estado no
|
|
528
|
+
* alcanza: para cuando React re-renderiza, ya salieron dos peticiones por la misma página.
|
|
529
|
+
*/
|
|
530
|
+
const inFlight = useRef(null);
|
|
531
|
+
const start = useCallback(() => {
|
|
532
|
+
inFlight.current?.abort();
|
|
533
|
+
const controller = new AbortController();
|
|
534
|
+
inFlight.current = controller;
|
|
535
|
+
return controller;
|
|
536
|
+
}, []);
|
|
537
|
+
const finish = useCallback((controller) => {
|
|
538
|
+
if (inFlight.current === controller) inFlight.current = null;
|
|
539
|
+
}, []);
|
|
540
|
+
useEffect(() => {
|
|
541
|
+
const controller = start();
|
|
542
|
+
loadConversations(fetcher, filters, { signal: controller.signal }).then((page) => {
|
|
543
|
+
if (controller.signal.aborted) return;
|
|
544
|
+
finish(controller);
|
|
545
|
+
setLoaded({
|
|
546
|
+
fetcher,
|
|
547
|
+
filters,
|
|
548
|
+
items: page.items,
|
|
549
|
+
cursor: page.next_cursor,
|
|
550
|
+
status: page.items.length > 0 ? "ready" : "empty",
|
|
551
|
+
error: null,
|
|
552
|
+
autoPages: 0
|
|
553
|
+
});
|
|
554
|
+
}, (cause) => {
|
|
555
|
+
if (controller.signal.aborted) return;
|
|
556
|
+
finish(controller);
|
|
557
|
+
setLoaded({
|
|
558
|
+
fetcher,
|
|
559
|
+
filters,
|
|
560
|
+
items: [],
|
|
561
|
+
cursor: null,
|
|
562
|
+
status: "error",
|
|
563
|
+
error: toError$1(cause),
|
|
564
|
+
autoPages: 0
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
return () => controller.abort();
|
|
568
|
+
}, [
|
|
569
|
+
fetcher,
|
|
570
|
+
filters,
|
|
571
|
+
attempt,
|
|
572
|
+
start,
|
|
573
|
+
finish
|
|
574
|
+
]);
|
|
575
|
+
/**
|
|
576
|
+
* Lo cargado sólo vale si vino de ESTA consulta. Si no, la vista vuelve a "cargando" por
|
|
577
|
+
* derivación — que es como se distingue "cambié de filtro" (reinicia) de "falló" (no reinicia).
|
|
578
|
+
*/
|
|
579
|
+
const current = loaded !== null && loaded.fetcher === fetcher && loaded.filters === filters ? loaded : null;
|
|
580
|
+
const loadMore = useCallback((auto = false) => {
|
|
581
|
+
if (current === null) return;
|
|
582
|
+
if (current.cursor === null) return;
|
|
583
|
+
if (inFlight.current !== null) return;
|
|
584
|
+
if (auto && current.autoPages >= 20) return;
|
|
585
|
+
const cursor = current.cursor;
|
|
586
|
+
const base = {
|
|
587
|
+
...current,
|
|
588
|
+
status: "loading-more",
|
|
589
|
+
error: null,
|
|
590
|
+
autoPages: current.autoPages + (auto ? 1 : 0)
|
|
591
|
+
};
|
|
592
|
+
setLoaded(base);
|
|
593
|
+
const controller = start();
|
|
594
|
+
loadConversations(fetcher, {
|
|
595
|
+
...filters,
|
|
596
|
+
cursor
|
|
597
|
+
}, { signal: controller.signal }).then((page) => {
|
|
598
|
+
if (controller.signal.aborted) return;
|
|
599
|
+
finish(controller);
|
|
600
|
+
setLoaded({
|
|
601
|
+
...base,
|
|
602
|
+
items: appendWithoutDuplicates(base.items, page.items),
|
|
603
|
+
cursor: page.next_cursor,
|
|
604
|
+
status: "ready",
|
|
605
|
+
error: null
|
|
606
|
+
});
|
|
607
|
+
}, (cause) => {
|
|
608
|
+
if (controller.signal.aborted) return;
|
|
609
|
+
finish(controller);
|
|
610
|
+
setLoaded({
|
|
611
|
+
...base,
|
|
612
|
+
status: "error",
|
|
613
|
+
error: toError$1(cause)
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
}, [
|
|
617
|
+
fetcher,
|
|
618
|
+
filters,
|
|
619
|
+
current,
|
|
620
|
+
start,
|
|
621
|
+
finish
|
|
622
|
+
]);
|
|
623
|
+
const retry = useCallback(() => {
|
|
624
|
+
if (current !== null && current.items.length > 0) {
|
|
625
|
+
loadMore();
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
setLoaded(null);
|
|
629
|
+
setAttempt((n) => n + 1);
|
|
630
|
+
}, [current, loadMore]);
|
|
631
|
+
return {
|
|
632
|
+
items: current?.items ?? [],
|
|
633
|
+
status: current?.status ?? "loading",
|
|
634
|
+
error: current?.error ?? null,
|
|
635
|
+
hasMore: current !== null && current.cursor !== null,
|
|
636
|
+
loadMore,
|
|
637
|
+
retry,
|
|
638
|
+
autoLoadExhausted: current !== null && current.autoPages >= 20
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region src/core/list/ConversationList.tsx
|
|
643
|
+
/**
|
|
644
|
+
* El panel de la lista de conversaciones — la mitad izquierda del visor (DEV-4986).
|
|
645
|
+
*
|
|
646
|
+
* Su razón de ser no es "una agenda de teléfonos": cada fila lleva el `service_state` del emisor,
|
|
647
|
+
* que es lo que convierte la lista en un tablero de "estos cinco llevan dos días trabados". Por eso
|
|
648
|
+
* la fila lo pinta opaco y sin traducir (ver `ConversationRow`).
|
|
649
|
+
*
|
|
650
|
+
* 🔴 **Ninguna prop de este componente puede ser `orgId`, `phoneNumberId`, `apiUrl`, `baseUrl` ni
|
|
651
|
+
* `token`, ni nada con lo que se pueda construir una ruta** (C-03/DATA-05/T-03-03). El scope —qué
|
|
652
|
+
* inbox es éste— ya viene cerrado por closure adentro del `fetcher` que inyecta el host: el backend
|
|
653
|
+
* de FlexOS scopea por organización en la ruta y el nuestro por `phone_number_id`, y ese es
|
|
654
|
+
* exactamente el detalle que el paquete no puede conocer si quiere servir a los dos.
|
|
655
|
+
*
|
|
656
|
+
* La selección es **controlada**: el panel no recuerda a quién elegiste. `selectedPhone` lo manda
|
|
657
|
+
* el host (o, en la Fase 4, el shell del visor) y `onSelect` avisa. Que el estado de selección viva
|
|
658
|
+
* afuera es lo que permite que la Fase 4 arme el switch de dos vistas sin pelearse con un estado
|
|
659
|
+
* interno que el panel guardó por su cuenta.
|
|
660
|
+
*
|
|
661
|
+
* Decisiones visuales de esta fase, tomadas sin UI-SPEC y a conciencia (se revisan en el PR):
|
|
662
|
+
*
|
|
663
|
+
* - **Los filtros se aplican por submit, no en vivo.** Un debounce necesita una decisión de
|
|
664
|
+
* latencia que nadie tomó y timers falsos en los tests; un `<form>` con "Filtrar" y "Limpiar" no
|
|
665
|
+
* necesita ninguna de las dos.
|
|
666
|
+
* - **El centinela del scroll infinito es un `<button>` de verdad.** Se auto-dispara cuando entra
|
|
667
|
+
* en viewport, pero existe y es accesible por teclado igual: así degrada solo donde no hay
|
|
668
|
+
* `IntersectionObserver` y los tests ejercitan el cursor sin falsear geometría de scroll.
|
|
669
|
+
* - **Textos en español, hardcodeados.** El paquete no tiene i18n y el host no le pasa tokens; si
|
|
670
|
+
* algún día hace falta, es su propia decisión (DEV-4990).
|
|
671
|
+
*/
|
|
672
|
+
/** Identidad estable para "sin filtros": un `{}` nuevo por render reiniciaría la lista sin parar. */
|
|
673
|
+
const NO_FILTERS = {};
|
|
674
|
+
function ConversationList({ fetcher, selectedPhone, onSelect, className }) {
|
|
675
|
+
const fieldId = useId();
|
|
676
|
+
/**
|
|
677
|
+
* El layout lo decide el ancho de ESTE contenedor, no el del viewport: el panel va embebido y en
|
|
678
|
+
* `lms-web-app` vive en una columna de ~380 px de una pantalla de 1920 (LIST-04).
|
|
679
|
+
*/
|
|
680
|
+
const rootRef = useRef(null);
|
|
681
|
+
const layout = useContainerLayout(rootRef);
|
|
682
|
+
/** Lo que hay escrito en el formulario. No es la consulta: la consulta se aplica al enviar. */
|
|
683
|
+
const [phone, setPhone] = useState("");
|
|
684
|
+
const [from, setFrom] = useState("");
|
|
685
|
+
const [to, setTo] = useState("");
|
|
686
|
+
/** La consulta vigente. Su IDENTIDAD es lo que el hook mira para reiniciar la lista. */
|
|
687
|
+
const [filters, setFilters] = useState(NO_FILTERS);
|
|
688
|
+
const { items, status, error, hasMore, loadMore, retry, autoLoadExhausted } = useConversations({
|
|
689
|
+
fetcher,
|
|
690
|
+
filters
|
|
691
|
+
});
|
|
692
|
+
const hasFilters = Object.keys(filters).length > 0;
|
|
693
|
+
const handleSelect = useCallback((item) => {
|
|
694
|
+
onSelect?.(item);
|
|
695
|
+
}, [onSelect]);
|
|
696
|
+
const applyFilters = (event) => {
|
|
697
|
+
event.preventDefault();
|
|
698
|
+
const next = {};
|
|
699
|
+
if (phone.trim() !== "") next.phone = phone;
|
|
700
|
+
if (from !== "") next.from = from;
|
|
701
|
+
if (to !== "") next.to = to;
|
|
702
|
+
setFilters(next);
|
|
703
|
+
};
|
|
704
|
+
const clearFilters = () => {
|
|
705
|
+
setPhone("");
|
|
706
|
+
setFrom("");
|
|
707
|
+
setTo("");
|
|
708
|
+
setFilters(NO_FILTERS);
|
|
709
|
+
};
|
|
710
|
+
/**
|
|
711
|
+
* El auto-disparo del scroll infinito.
|
|
712
|
+
*
|
|
713
|
+
* Con feature-detect porque jsdom no trae `IntersectionObserver` y porque el paquete no puede
|
|
714
|
+
* asumir el navegador del host. Donde no existe, el botón sigue estando y la lista avanza por
|
|
715
|
+
* clic — que es también como lo ejercitan los tests: determinista, sin falsear scroll.
|
|
716
|
+
*/
|
|
717
|
+
const sentinel = useRef(null);
|
|
718
|
+
useEffect(() => {
|
|
719
|
+
if (typeof IntersectionObserver === "undefined") return;
|
|
720
|
+
const element = sentinel.current;
|
|
721
|
+
if (element === null || !hasMore || autoLoadExhausted) return;
|
|
722
|
+
const observer = new IntersectionObserver((entries) => {
|
|
723
|
+
if (entries.some((entry) => entry.isIntersecting)) loadMore(true);
|
|
724
|
+
});
|
|
725
|
+
observer.observe(element);
|
|
726
|
+
return () => observer.disconnect();
|
|
727
|
+
}, [
|
|
728
|
+
hasMore,
|
|
729
|
+
autoLoadExhausted,
|
|
730
|
+
loadMore
|
|
731
|
+
]);
|
|
732
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
733
|
+
ref: rootRef,
|
|
734
|
+
className: className ? `wa-list ${className}` : "wa-list",
|
|
735
|
+
"data-layout": layout,
|
|
736
|
+
children: [
|
|
737
|
+
/* @__PURE__ */ jsx("style", { children: LIST_CSS }),
|
|
738
|
+
/* @__PURE__ */ jsxs("form", {
|
|
739
|
+
className: "wa-list__filters",
|
|
740
|
+
onSubmit: applyFilters,
|
|
741
|
+
children: [
|
|
742
|
+
/* @__PURE__ */ jsxs("div", {
|
|
743
|
+
className: "wa-list__field",
|
|
744
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
745
|
+
htmlFor: `${fieldId}-phone`,
|
|
746
|
+
children: "Teléfono"
|
|
747
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
748
|
+
id: `${fieldId}-phone`,
|
|
749
|
+
type: "search",
|
|
750
|
+
value: phone,
|
|
751
|
+
onChange: (event) => setPhone(event.target.value)
|
|
752
|
+
})]
|
|
753
|
+
}),
|
|
754
|
+
/* @__PURE__ */ jsxs("div", {
|
|
755
|
+
className: "wa-list__field",
|
|
756
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
757
|
+
htmlFor: `${fieldId}-from`,
|
|
758
|
+
children: "Desde"
|
|
759
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
760
|
+
id: `${fieldId}-from`,
|
|
761
|
+
type: "date",
|
|
762
|
+
value: from,
|
|
763
|
+
onChange: (event) => setFrom(event.target.value)
|
|
764
|
+
})]
|
|
765
|
+
}),
|
|
766
|
+
/* @__PURE__ */ jsxs("div", {
|
|
767
|
+
className: "wa-list__field",
|
|
768
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
769
|
+
htmlFor: `${fieldId}-to`,
|
|
770
|
+
children: "Hasta"
|
|
771
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
772
|
+
id: `${fieldId}-to`,
|
|
773
|
+
type: "date",
|
|
774
|
+
value: to,
|
|
775
|
+
onChange: (event) => setTo(event.target.value)
|
|
776
|
+
})]
|
|
777
|
+
}),
|
|
778
|
+
/* @__PURE__ */ jsxs("div", {
|
|
779
|
+
className: "wa-list__actions",
|
|
780
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
781
|
+
type: "submit",
|
|
782
|
+
children: "Filtrar"
|
|
783
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
784
|
+
type: "button",
|
|
785
|
+
onClick: clearFilters,
|
|
786
|
+
children: "Limpiar"
|
|
787
|
+
})]
|
|
788
|
+
})
|
|
789
|
+
]
|
|
790
|
+
}),
|
|
791
|
+
status === "loading" && /* @__PURE__ */ jsx("p", {
|
|
792
|
+
className: "wa-list__note",
|
|
793
|
+
children: "Cargando conversaciones…"
|
|
794
|
+
}),
|
|
795
|
+
error !== null && /* @__PURE__ */ jsxs("div", {
|
|
796
|
+
className: "wa-list__error",
|
|
797
|
+
role: "alert",
|
|
798
|
+
children: [/* @__PURE__ */ jsxs("p", { children: ["No se pudieron cargar las conversaciones: ", error.message] }), /* @__PURE__ */ jsx("button", {
|
|
799
|
+
type: "button",
|
|
800
|
+
onClick: retry,
|
|
801
|
+
children: "Reintentar"
|
|
802
|
+
})]
|
|
803
|
+
}),
|
|
804
|
+
status === "empty" && /* @__PURE__ */ jsx("p", {
|
|
805
|
+
className: "wa-list__note",
|
|
806
|
+
children: hasFilters ? "No hay conversaciones con ese filtro." : "No hay conversaciones todavía."
|
|
807
|
+
}),
|
|
808
|
+
/* @__PURE__ */ jsx("ul", {
|
|
809
|
+
className: "wa-list__items",
|
|
810
|
+
children: items.map((item) => /* @__PURE__ */ jsx(ConversationRow, {
|
|
811
|
+
item,
|
|
812
|
+
selected: item.phone === selectedPhone,
|
|
813
|
+
onSelect: handleSelect
|
|
814
|
+
}, item.phone))
|
|
815
|
+
}),
|
|
816
|
+
hasMore && /* @__PURE__ */ jsx("button", {
|
|
817
|
+
ref: sentinel,
|
|
818
|
+
type: "button",
|
|
819
|
+
className: "wa-list__more",
|
|
820
|
+
onClick: () => loadMore(),
|
|
821
|
+
disabled: status === "loading-more",
|
|
822
|
+
children: status === "loading-more" ? "Cargando…" : "Cargar más"
|
|
823
|
+
})
|
|
824
|
+
]
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
//#endregion
|
|
828
|
+
//#region src/core/thread/day-label.ts
|
|
829
|
+
/**
|
|
830
|
+
* El día del separador del hilo (DEC-O, coherente con DEC-K de la lista): día LOCAL del operador,
|
|
831
|
+
* meses en español hardcodeados, **sin `Intl`**.
|
|
832
|
+
*
|
|
833
|
+
* Sin `Intl` no es capricho: `Intl` depende del locale del host y este componente monta en tres
|
|
834
|
+
* hosts distintos — el mismo hilo diría "August 15" en uno y "15 de agosto" en otro. Los textos del
|
|
835
|
+
* paquete son en español, hardcodeados (si algún día hace falta i18n, es decisión del host,
|
|
836
|
+
* DEV-4990). El ISO completo vive en `dateTime`/`title` de cada burbuja, no acá.
|
|
837
|
+
*
|
|
838
|
+
* Interno del hilo: NO sale al barrel del core.
|
|
839
|
+
*/
|
|
840
|
+
/** Meses en español, índice 0-11 como `Date.getMonth()`. */
|
|
841
|
+
const MONTHS = [
|
|
842
|
+
"enero",
|
|
843
|
+
"febrero",
|
|
844
|
+
"marzo",
|
|
845
|
+
"abril",
|
|
846
|
+
"mayo",
|
|
847
|
+
"junio",
|
|
848
|
+
"julio",
|
|
849
|
+
"agosto",
|
|
850
|
+
"septiembre",
|
|
851
|
+
"octubre",
|
|
852
|
+
"noviembre",
|
|
853
|
+
"diciembre"
|
|
854
|
+
];
|
|
855
|
+
function parseAt(at) {
|
|
856
|
+
const date = new Date(at);
|
|
857
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* La clave de agrupación por día LOCAL. `null` significa "no abre grupo nuevo": la burbuja sin
|
|
861
|
+
* fecha (una optimista, o una fila corrupta) se pega al grupo vigente en vez de reventar el render.
|
|
862
|
+
*/
|
|
863
|
+
function dayKey(at) {
|
|
864
|
+
if (typeof at !== "string") return null;
|
|
865
|
+
const date = parseAt(at);
|
|
866
|
+
if (date === null) return null;
|
|
867
|
+
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
868
|
+
}
|
|
869
|
+
/** La etiqueta visible del separador: "15 de agosto de 2026". Vacía si el instante no parsea. */
|
|
870
|
+
function dayLabel(at) {
|
|
871
|
+
const date = parseAt(at);
|
|
872
|
+
if (date === null) return "";
|
|
873
|
+
return `${date.getDate()} de ${MONTHS[date.getMonth()]} de ${date.getFullYear()}`;
|
|
874
|
+
}
|
|
875
|
+
//#endregion
|
|
876
|
+
//#region src/core/contract/thread-ctas.ts
|
|
877
|
+
/**
|
|
878
|
+
* Los `kind` que NUNCA son navegables, traigan destino o no (DEC-B).
|
|
879
|
+
*
|
|
880
|
+
* Un `quick_reply` es el tap que dio el lifter y un `location` es el mapa que compartió: los dos son
|
|
881
|
+
* el espejo inerte de algo que ya pasó, no un control que el operador pueda accionar. El apéndice B
|
|
882
|
+
* excluye sólo `location` y confía en que un `quick_reply` nunca traiga `url`; acá se exige además
|
|
883
|
+
* el `kind`, porque `CLAUDE.md` los declara inertes SIEMPRE. Sobre el fixture las dos formulaciones
|
|
884
|
+
* dan el mismo veredicto fila por fila (todo `quick_reply` llega con `url: null`), así que esto no
|
|
885
|
+
* contradice ningún dato real: sólo cierra la combinación anómala.
|
|
886
|
+
*
|
|
887
|
+
* La lista es cerrada y explícita, no un "todo lo que no reconozco": con enums abiertos (DATA-01),
|
|
888
|
+
* negar lo desconocido convertiría un `kind` nuevo del backend en un botón muerto.
|
|
889
|
+
*/
|
|
890
|
+
const INERT_KINDS = /* @__PURE__ */ new Set(["quick_reply", "location"]);
|
|
891
|
+
/**
|
|
892
|
+
* Los únicos esquemas que se consideran navegables (DEC-C, T-02-01).
|
|
893
|
+
*
|
|
894
|
+
* Desviación del port literal, motivada por seguridad: el visor es una herramienta de operadores, y
|
|
895
|
+
* un `javascript:` o un `data:text/html` convertido en ancla clickeable es elevación de privilegio
|
|
896
|
+
* —el destino lo origina el lifter y viaja por Meta—. Un destino con otro esquema no se oculta: se
|
|
897
|
+
* pinta inerte, porque existió en el teléfono de la persona (THREAD-03).
|
|
898
|
+
*/
|
|
899
|
+
const WEB_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
900
|
+
/**
|
|
901
|
+
* Los botones a pintar, normalizados — la ÚNICA fuente del render.
|
|
902
|
+
*
|
|
903
|
+
* Prefiere la lista `ctas`; si el mensaje no la trae, cae al singular `cta` deprecado (D2: el
|
|
904
|
+
* backend nunca lo emite, el fallback es para filas viejas). Una `ctas` vacía significa "sin
|
|
905
|
+
* botones" y no resucita el singular.
|
|
906
|
+
*
|
|
907
|
+
* Descarta los botones sin texto utilizable porque **un botón sin etiqueta no es un botón**: pintar
|
|
908
|
+
* un bloque vacío inventaría una acción que la persona nunca vio en su teléfono, y el operador la
|
|
909
|
+
* leería como si hubiera pasado.
|
|
910
|
+
*
|
|
911
|
+
* Pide sólo los dos campos que mira (`Pick`) en vez del mensaje entero: deja claro que no depende de
|
|
912
|
+
* nada más de la burbuja, y lo hace testeable con objetos mínimos.
|
|
913
|
+
*/
|
|
914
|
+
function threadCtas(msg) {
|
|
915
|
+
return (Array.isArray(msg.ctas) ? msg.ctas : msg.cta ? [msg.cta] : []).filter((cta) => cta != null && typeof cta.text === "string" && cta.text.trim() !== "");
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* ¿Es un enlace navegable o un espejo inerte de la acción del lifter?
|
|
919
|
+
*
|
|
920
|
+
* Verdadero sólo si el `kind` no es de los siempre inertes (DEC-B) y el destino existe, parsea como
|
|
921
|
+
* URL absoluta y usa un esquema web (DEC-C). Un destino malformado es "no navegable", no una
|
|
922
|
+
* excepción: por eso el parseo va en try/catch y no con una regex de esquemas, que sería una lista
|
|
923
|
+
* negra siempre incompleta.
|
|
924
|
+
*/
|
|
925
|
+
function isCtaLink(cta) {
|
|
926
|
+
if (typeof cta.kind === "string" && INERT_KINDS.has(cta.kind)) return false;
|
|
927
|
+
const url = typeof cta.url === "string" ? cta.url.trim() : "";
|
|
928
|
+
if (url === "") return false;
|
|
929
|
+
try {
|
|
930
|
+
return WEB_SCHEMES.has(new URL(url).protocol);
|
|
931
|
+
} catch {
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
//#endregion
|
|
936
|
+
//#region src/core/thread/MediaAttachment.tsx
|
|
937
|
+
/**
|
|
938
|
+
* El adjunto de una burbuja (DEV-4988). Interno del hilo — NO sale al barrel (mismo criterio que
|
|
939
|
+
* `MessageBubble`). Es el ÚNICO lugar del paquete que monta `<img>` a partir de media.
|
|
940
|
+
*
|
|
941
|
+
* Registro de amenazas de este componente (plan DEV-4988):
|
|
942
|
+
*
|
|
943
|
+
* 🔴 **T-05-01**: el gate del render inline lo decide EXCLUSIVAMENTE `message.media_format`, que el
|
|
944
|
+
* backend deriva de los **bytes reales**. Ni `message_type` ni la extensión de `file_name`
|
|
945
|
+
* (spoofables, los origina Meta/el lifter) entran a `normalizeMediaFormat`. Tampoco el
|
|
946
|
+
* `media_format` de la respuesta del EP: es informativo, no gate.
|
|
947
|
+
* 🔴 **T-05-02**: default seguro — ausente o desconocido cae a `'other'` ⇒ descarga, JAMÁS inline:
|
|
948
|
+
* un mime hostil (`text/html`, `image/svg+xml`) no puede ejecutarse desde nuestro origen.
|
|
949
|
+
* 🔴 **T-05-03**: todo `<a>` sale con `target="_blank"` + `rel="noopener noreferrer"`, y la
|
|
950
|
+
* navegación final es el anchor plano — sin fetch de bytes, sin blob, sin `createObjectURL`.
|
|
951
|
+
* 🔴 **T-05-04**: la url firmada (~10 min de vida) se usa TAL CUAL en `src`/`href`; nunca se
|
|
952
|
+
* loguea ni se interpola en selectores/className.
|
|
953
|
+
* 🔴 **T-05-05**: el 404 es TERMINAL (`unavailable`, cero re-llamadas); la firma vencida reintenta
|
|
954
|
+
* exactamente UNA vez.
|
|
955
|
+
*/
|
|
956
|
+
/**
|
|
957
|
+
* La ÚNICA entrada del router. Lee `message.media_format` y nada más (T-05-01): 'image' y 'pdf'
|
|
958
|
+
* pasan; TODO lo demás — null, undefined, 'audio', 'video', un string desconocido — cae a 'other'
|
|
959
|
+
* (T-05-02). 'pdf' se conserva como rama propia aunque hoy comparta UI con 'other': la fase de
|
|
960
|
+
* paridad sólo cambia esa rama (preview sandboxeado).
|
|
961
|
+
*/
|
|
962
|
+
function normalizeMediaFormat(value) {
|
|
963
|
+
if (value === "image") return "image";
|
|
964
|
+
if (value === "pdf") return "pdf";
|
|
965
|
+
return "other";
|
|
966
|
+
}
|
|
967
|
+
/** La etiqueta visible del adjunto. SÓLO texto (React la escapa): nunca entra al router. */
|
|
968
|
+
function attachmentLabel(message, fallback) {
|
|
969
|
+
return typeof message.file_name === "string" && message.file_name !== "" ? message.file_name : fallback;
|
|
970
|
+
}
|
|
971
|
+
/** El estado terminal: sin botón de retry, sin re-llamadas; la burbuja y el hilo siguen intactos. */
|
|
972
|
+
function MediaUnavailable() {
|
|
973
|
+
return /* @__PURE__ */ jsx("span", {
|
|
974
|
+
className: "wa-thread__media-unavailable",
|
|
975
|
+
children: "Adjunto no disponible"
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Rama image: carga perezosa (no bloquea el render del hilo), miniatura clicable y lightbox
|
|
980
|
+
* propio, sin dependencias nuevas. Primer intento: la `media_url` del mensaje si viene; si es
|
|
981
|
+
* null, el descriptor vía fetcher. `onError` de la `<img>` (firma vencida con la pestaña abierta)
|
|
982
|
+
* re-pide el descriptor UNA vez (T-05-05).
|
|
983
|
+
*/
|
|
984
|
+
function ImageAttachment({ message, fetcher, mediaId }) {
|
|
985
|
+
const [state, setState] = useState(() => typeof message.media_url === "string" && message.media_url !== "" ? {
|
|
986
|
+
kind: "ready",
|
|
987
|
+
url: message.media_url
|
|
988
|
+
} : { kind: "loading" });
|
|
989
|
+
const [open, setOpen] = useState(false);
|
|
990
|
+
/** La resolución inicial se dispara una sola vez, aunque el fetcher cambie de identidad. */
|
|
991
|
+
const requestedRef = useRef(false);
|
|
992
|
+
/** El retry por onError es único en la vida del componente (T-05-05). */
|
|
993
|
+
const retriedRef = useRef(false);
|
|
994
|
+
const mountedRef = useRef(true);
|
|
995
|
+
useEffect(() => {
|
|
996
|
+
return () => {
|
|
997
|
+
mountedRef.current = false;
|
|
998
|
+
};
|
|
999
|
+
}, []);
|
|
1000
|
+
useEffect(() => {
|
|
1001
|
+
if (requestedRef.current) return;
|
|
1002
|
+
requestedRef.current = true;
|
|
1003
|
+
if (typeof message.media_url === "string" && message.media_url !== "") return;
|
|
1004
|
+
let cancelled = false;
|
|
1005
|
+
loadMedia(fetcher, { mediaId }).then((descriptor) => {
|
|
1006
|
+
if (cancelled || !mountedRef.current) return;
|
|
1007
|
+
setState(descriptor.url !== "" ? {
|
|
1008
|
+
kind: "ready",
|
|
1009
|
+
url: descriptor.url
|
|
1010
|
+
} : { kind: "unavailable" });
|
|
1011
|
+
}).catch(() => {
|
|
1012
|
+
if (!cancelled && mountedRef.current) setState({ kind: "unavailable" });
|
|
1013
|
+
});
|
|
1014
|
+
return () => {
|
|
1015
|
+
cancelled = true;
|
|
1016
|
+
};
|
|
1017
|
+
}, [
|
|
1018
|
+
fetcher,
|
|
1019
|
+
mediaId,
|
|
1020
|
+
message.media_url
|
|
1021
|
+
]);
|
|
1022
|
+
useEffect(() => {
|
|
1023
|
+
if (!open) return;
|
|
1024
|
+
const handleKeyDown = (event) => {
|
|
1025
|
+
if (event.key === "Escape") setOpen(false);
|
|
1026
|
+
};
|
|
1027
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
1028
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
1029
|
+
}, [open]);
|
|
1030
|
+
const handleImageError = () => {
|
|
1031
|
+
if (retriedRef.current) {
|
|
1032
|
+
setState({ kind: "unavailable" });
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
retriedRef.current = true;
|
|
1036
|
+
setState({ kind: "loading" });
|
|
1037
|
+
loadMedia(fetcher, { mediaId }).then((descriptor) => {
|
|
1038
|
+
if (!mountedRef.current) return;
|
|
1039
|
+
setState(descriptor.url !== "" ? {
|
|
1040
|
+
kind: "ready",
|
|
1041
|
+
url: descriptor.url
|
|
1042
|
+
} : { kind: "unavailable" });
|
|
1043
|
+
}).catch(() => {
|
|
1044
|
+
if (mountedRef.current) setState({ kind: "unavailable" });
|
|
1045
|
+
});
|
|
1046
|
+
};
|
|
1047
|
+
if (state.kind === "loading") return /* @__PURE__ */ jsx("span", {
|
|
1048
|
+
className: "wa-thread__media-loading",
|
|
1049
|
+
children: "Cargando adjunto…"
|
|
1050
|
+
});
|
|
1051
|
+
if (state.kind === "unavailable") return /* @__PURE__ */ jsx(MediaUnavailable, {});
|
|
1052
|
+
const alt = attachmentLabel(message, "Imagen adjunta");
|
|
1053
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
|
|
1054
|
+
type: "button",
|
|
1055
|
+
className: "wa-thread__media-button",
|
|
1056
|
+
onClick: () => setOpen(true),
|
|
1057
|
+
"aria-label": "Ampliar imagen adjunta",
|
|
1058
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
1059
|
+
className: "wa-thread__media-img",
|
|
1060
|
+
src: state.url,
|
|
1061
|
+
alt,
|
|
1062
|
+
onError: handleImageError
|
|
1063
|
+
})
|
|
1064
|
+
}), open && /* @__PURE__ */ jsx("div", {
|
|
1065
|
+
className: "wa-thread__lightbox",
|
|
1066
|
+
role: "dialog",
|
|
1067
|
+
"aria-label": "Imagen ampliada",
|
|
1068
|
+
onClick: () => setOpen(false),
|
|
1069
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
1070
|
+
className: "wa-thread__lightbox-img",
|
|
1071
|
+
src: state.url,
|
|
1072
|
+
alt
|
|
1073
|
+
})
|
|
1074
|
+
})] });
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Rama descarga ('pdf' y 'other'): un solo `<a>` plano. La url se resuelve AL MOMENTO del clic —
|
|
1078
|
+
* así nunca está vencida; un anchor no puede detectar una firma expirada, y por eso acá no aplica
|
|
1079
|
+
* el primer intento con `media_url`. El onClick intercepta, resuelve, setea el href y re-dispara
|
|
1080
|
+
* el clic programático (el guard deja pasar esa segunda pasada hacia la navegación real).
|
|
1081
|
+
*/
|
|
1082
|
+
function DownloadAttachment({ message, fetcher, mediaId }) {
|
|
1083
|
+
const [unavailable, setUnavailable] = useState(false);
|
|
1084
|
+
const anchorRef = useRef(null);
|
|
1085
|
+
/** true sólo durante el clic programático post-resolución: esa pasada navega, no re-resuelve. */
|
|
1086
|
+
const passThroughRef = useRef(false);
|
|
1087
|
+
const mountedRef = useRef(true);
|
|
1088
|
+
useEffect(() => {
|
|
1089
|
+
return () => {
|
|
1090
|
+
mountedRef.current = false;
|
|
1091
|
+
};
|
|
1092
|
+
}, []);
|
|
1093
|
+
const handleClick = (event) => {
|
|
1094
|
+
if (passThroughRef.current) {
|
|
1095
|
+
passThroughRef.current = false;
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
event.preventDefault();
|
|
1099
|
+
loadMedia(fetcher, { mediaId }).then((descriptor) => {
|
|
1100
|
+
if (!mountedRef.current) return;
|
|
1101
|
+
const anchor = anchorRef.current;
|
|
1102
|
+
if (anchor === null) return;
|
|
1103
|
+
if (descriptor.url === "") {
|
|
1104
|
+
setUnavailable(true);
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
anchor.href = descriptor.url;
|
|
1108
|
+
passThroughRef.current = true;
|
|
1109
|
+
anchor.click();
|
|
1110
|
+
}).catch(() => {
|
|
1111
|
+
if (mountedRef.current) setUnavailable(true);
|
|
1112
|
+
});
|
|
1113
|
+
};
|
|
1114
|
+
if (unavailable) return /* @__PURE__ */ jsx(MediaUnavailable, {});
|
|
1115
|
+
return /* @__PURE__ */ jsx("a", {
|
|
1116
|
+
ref: anchorRef,
|
|
1117
|
+
className: "wa-thread__media-download",
|
|
1118
|
+
href: "#",
|
|
1119
|
+
download: true,
|
|
1120
|
+
target: "_blank",
|
|
1121
|
+
rel: "noopener noreferrer",
|
|
1122
|
+
onClick: handleClick,
|
|
1123
|
+
children: attachmentLabel(message, "Descargar adjunto")
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
function MediaAttachment({ message, fetcher }) {
|
|
1127
|
+
const mediaId = message.media_id;
|
|
1128
|
+
if (mediaId === null) return null;
|
|
1129
|
+
const attachment = (() => {
|
|
1130
|
+
switch (normalizeMediaFormat(message.media_format)) {
|
|
1131
|
+
case "image": return /* @__PURE__ */ jsx(ImageAttachment, {
|
|
1132
|
+
message,
|
|
1133
|
+
fetcher,
|
|
1134
|
+
mediaId
|
|
1135
|
+
});
|
|
1136
|
+
case "pdf": return /* @__PURE__ */ jsx(DownloadAttachment, {
|
|
1137
|
+
message,
|
|
1138
|
+
fetcher,
|
|
1139
|
+
mediaId
|
|
1140
|
+
});
|
|
1141
|
+
default: return /* @__PURE__ */ jsx(DownloadAttachment, {
|
|
1142
|
+
message,
|
|
1143
|
+
fetcher,
|
|
1144
|
+
mediaId
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
})();
|
|
1148
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1149
|
+
className: "wa-thread__media",
|
|
1150
|
+
children: attachment
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
//#endregion
|
|
1154
|
+
//#region src/core/thread/MessageBubble.tsx
|
|
1155
|
+
/**
|
|
1156
|
+
* El tick de una saliente. El vocabulario conocido y nada más: lo desconocido devuelve `null` y la
|
|
1157
|
+
* burbuja simplemente no lleva tick (enum abierto — un status nuevo del cable no rompe el render).
|
|
1158
|
+
* `read` usa el MISMO ✓✓ que `delivered` y se distingue por color vía `data-status`: es semántica
|
|
1159
|
+
* de estado, no tema del host.
|
|
1160
|
+
*/
|
|
1161
|
+
function tickFor(status) {
|
|
1162
|
+
switch (status) {
|
|
1163
|
+
case "pending": return {
|
|
1164
|
+
mark: "◷",
|
|
1165
|
+
label: "Pendiente"
|
|
1166
|
+
};
|
|
1167
|
+
case "sent": return {
|
|
1168
|
+
mark: "✓",
|
|
1169
|
+
label: "Enviado"
|
|
1170
|
+
};
|
|
1171
|
+
case "delivered": return {
|
|
1172
|
+
mark: "✓✓",
|
|
1173
|
+
label: "Entregado"
|
|
1174
|
+
};
|
|
1175
|
+
case "read": return {
|
|
1176
|
+
mark: "✓✓",
|
|
1177
|
+
label: "Leído"
|
|
1178
|
+
};
|
|
1179
|
+
default: return null;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
/** La hora HH:MM local de la burbuja (DEC-O). `null` si el instante no existe o no parsea. */
|
|
1183
|
+
function formatHour(at) {
|
|
1184
|
+
if (typeof at !== "string") return null;
|
|
1185
|
+
const date = new Date(at);
|
|
1186
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
1187
|
+
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
1188
|
+
}
|
|
1189
|
+
function MessageBubble({ message, showServiceState, fetcher }) {
|
|
1190
|
+
const direction = message.direction === "out" ? "out" : "in";
|
|
1191
|
+
const hour = formatHour(message.at);
|
|
1192
|
+
const ctas = threadCtas(message);
|
|
1193
|
+
const tick = direction === "out" ? tickFor(message.status) : null;
|
|
1194
|
+
const failed = direction === "out" && message.status === "failed";
|
|
1195
|
+
const author = typeof message.sent_by_name === "string" && message.sent_by_name.trim() !== "" ? message.sent_by_name : null;
|
|
1196
|
+
const serviceState = showServiceState && typeof message.service_state === "string" && message.service_state !== "" ? message.service_state : null;
|
|
1197
|
+
const locationFallback = message.body === null && message.message_type === "location" ? message.location_name ?? "Ubicación compartida" : null;
|
|
1198
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1199
|
+
className: "wa-thread__bubble",
|
|
1200
|
+
"data-direction": direction,
|
|
1201
|
+
"data-failed": failed || void 0,
|
|
1202
|
+
children: [
|
|
1203
|
+
author !== null && /* @__PURE__ */ jsx("span", {
|
|
1204
|
+
className: "wa-thread__author",
|
|
1205
|
+
children: author
|
|
1206
|
+
}),
|
|
1207
|
+
serviceState !== null && /* @__PURE__ */ jsx("span", {
|
|
1208
|
+
className: "wa-thread__state",
|
|
1209
|
+
title: serviceState,
|
|
1210
|
+
children: serviceState
|
|
1211
|
+
}),
|
|
1212
|
+
message.body !== null && /* @__PURE__ */ jsx("p", {
|
|
1213
|
+
className: "wa-thread__body",
|
|
1214
|
+
children: message.body
|
|
1215
|
+
}),
|
|
1216
|
+
locationFallback !== null && /* @__PURE__ */ jsx("p", {
|
|
1217
|
+
className: "wa-thread__body",
|
|
1218
|
+
children: locationFallback
|
|
1219
|
+
}),
|
|
1220
|
+
message.media_id !== null && /* @__PURE__ */ jsx(MediaAttachment, {
|
|
1221
|
+
message,
|
|
1222
|
+
fetcher
|
|
1223
|
+
}),
|
|
1224
|
+
ctas.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
1225
|
+
className: "wa-thread__ctas",
|
|
1226
|
+
children: ctas.map((cta, index) => isCtaLink(cta) ? /* @__PURE__ */ jsx("a", {
|
|
1227
|
+
className: "wa-thread__cta wa-thread__cta--link",
|
|
1228
|
+
href: cta.url ?? void 0,
|
|
1229
|
+
target: "_blank",
|
|
1230
|
+
rel: "noopener noreferrer",
|
|
1231
|
+
children: cta.text
|
|
1232
|
+
}, `${index}-${cta.text}`) : /* @__PURE__ */ jsx("span", {
|
|
1233
|
+
className: "wa-thread__cta wa-thread__cta--inert",
|
|
1234
|
+
children: cta.text
|
|
1235
|
+
}, `${index}-${cta.text}`))
|
|
1236
|
+
}),
|
|
1237
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1238
|
+
className: "wa-thread__meta",
|
|
1239
|
+
children: [hour !== null && message.at !== null && /* @__PURE__ */ jsx("time", {
|
|
1240
|
+
className: "wa-thread__hour",
|
|
1241
|
+
dateTime: message.at,
|
|
1242
|
+
title: message.at,
|
|
1243
|
+
children: hour
|
|
1244
|
+
}), failed ? /* @__PURE__ */ jsx("span", {
|
|
1245
|
+
className: "wa-thread__failed",
|
|
1246
|
+
children: "No entregado"
|
|
1247
|
+
}) : tick !== null && /* @__PURE__ */ jsx("span", {
|
|
1248
|
+
className: "wa-thread__tick",
|
|
1249
|
+
"data-status": message.status,
|
|
1250
|
+
title: tick.label,
|
|
1251
|
+
"aria-label": tick.label,
|
|
1252
|
+
children: tick.mark
|
|
1253
|
+
})]
|
|
1254
|
+
})
|
|
1255
|
+
]
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
//#endregion
|
|
1259
|
+
//#region src/core/thread/thread-styles.ts
|
|
1260
|
+
/**
|
|
1261
|
+
* El CSS del hilo, como string, para que viaje DENTRO del componente — mismas razones que
|
|
1262
|
+
* `list-styles.ts`: el entry `./element` no puede emitir un `.css` suelto y el entry `./react` no
|
|
1263
|
+
* puede obligar al host a importar uno.
|
|
1264
|
+
*
|
|
1265
|
+
* Reglas duras de este archivo (las mismas de la lista):
|
|
1266
|
+
*
|
|
1267
|
+
* - 🔴 **Todos los selectores van prefijados con `.wa-thread`.** En el entry `./react` NO hay
|
|
1268
|
+
* shadow DOM: un selector de elemento suelto le pisaría los estilos al host.
|
|
1269
|
+
* - **Sin tokens del LMS, sin variables, sin `@import`, sin fuentes remotas** (C-04). Grises y
|
|
1270
|
+
* tipografía heredable: el paquete monta en tres hosts con temas distintos.
|
|
1271
|
+
* - **El scroll del hilo VIVE en `.wa-thread__messages`** (`overflow-y: auto` + `min-height: 0`):
|
|
1272
|
+
* es el contenedor que la paginación hacia atrás ancla en la Task 3 — moverlo de lugar rompe la
|
|
1273
|
+
* compensación de `scrollTop`.
|
|
1274
|
+
*/
|
|
1275
|
+
const THREAD_CSS = `
|
|
1276
|
+
.wa-thread {
|
|
1277
|
+
box-sizing: border-box;
|
|
1278
|
+
display: flex;
|
|
1279
|
+
min-height: 0;
|
|
1280
|
+
flex: 1 1 auto;
|
|
1281
|
+
flex-direction: column;
|
|
1282
|
+
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
|
1283
|
+
font-size: 14px;
|
|
1284
|
+
line-height: 1.5;
|
|
1285
|
+
color: #1f2933;
|
|
1286
|
+
background: #f7f8fa;
|
|
1287
|
+
}
|
|
1288
|
+
.wa-thread *,
|
|
1289
|
+
.wa-thread *::before,
|
|
1290
|
+
.wa-thread *::after {
|
|
1291
|
+
box-sizing: inherit;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/* El scroll vive ACÁ: la paginación hacia atrás compensa scrollTop sobre este elemento. */
|
|
1295
|
+
.wa-thread__messages {
|
|
1296
|
+
display: flex;
|
|
1297
|
+
flex: 1 1 auto;
|
|
1298
|
+
min-height: 0;
|
|
1299
|
+
flex-direction: column;
|
|
1300
|
+
gap: 4px;
|
|
1301
|
+
padding: 12px;
|
|
1302
|
+
overflow-y: auto;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
/* El centinela superior de la paginación hacia atrás: un botón de verdad, accesible por teclado. */
|
|
1306
|
+
.wa-thread__older {
|
|
1307
|
+
align-self: center;
|
|
1308
|
+
margin: 0 0 8px;
|
|
1309
|
+
padding: 6px 10px;
|
|
1310
|
+
border: 1px solid #cbd2d9;
|
|
1311
|
+
border-radius: 4px;
|
|
1312
|
+
font: inherit;
|
|
1313
|
+
font-size: 12px;
|
|
1314
|
+
color: inherit;
|
|
1315
|
+
background: #ffffff;
|
|
1316
|
+
cursor: pointer;
|
|
1317
|
+
}
|
|
1318
|
+
.wa-thread__older:hover {
|
|
1319
|
+
background: #f5f7fa;
|
|
1320
|
+
}
|
|
1321
|
+
.wa-thread__older:disabled {
|
|
1322
|
+
color: #9aa5b1;
|
|
1323
|
+
cursor: default;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
/* Un grupo por día: columna flex propia, para que el align-self de las burbujas mire acá. */
|
|
1327
|
+
.wa-thread__group {
|
|
1328
|
+
display: flex;
|
|
1329
|
+
flex-direction: column;
|
|
1330
|
+
gap: 4px;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
/* Separador de día: centrado y discreto. */
|
|
1334
|
+
.wa-thread__day {
|
|
1335
|
+
align-self: center;
|
|
1336
|
+
margin: 8px 0 4px;
|
|
1337
|
+
padding: 2px 10px;
|
|
1338
|
+
border-radius: 10px;
|
|
1339
|
+
font-size: 12px;
|
|
1340
|
+
color: #616e7c;
|
|
1341
|
+
background: #eceff2;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
.wa-thread__bubble {
|
|
1345
|
+
display: flex;
|
|
1346
|
+
max-width: 75%;
|
|
1347
|
+
flex-direction: column;
|
|
1348
|
+
gap: 2px;
|
|
1349
|
+
padding: 6px 10px;
|
|
1350
|
+
border-radius: 8px;
|
|
1351
|
+
overflow-wrap: anywhere;
|
|
1352
|
+
}
|
|
1353
|
+
/* Entrante: a la izquierda, fondo claro. Lo desconocido cae acá (enums abiertos). */
|
|
1354
|
+
.wa-thread__bubble[data-direction='in'] {
|
|
1355
|
+
align-self: flex-start;
|
|
1356
|
+
background: #ffffff;
|
|
1357
|
+
border: 1px solid #e4e7eb;
|
|
1358
|
+
}
|
|
1359
|
+
/* Saliente: a la derecha, un gris un tono más marcado. */
|
|
1360
|
+
.wa-thread__bubble[data-direction='out'] {
|
|
1361
|
+
align-self: flex-end;
|
|
1362
|
+
background: #e3e8ee;
|
|
1363
|
+
border: 1px solid #d4dae1;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
.wa-thread__body {
|
|
1367
|
+
margin: 0;
|
|
1368
|
+
white-space: pre-wrap;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/* Hora + tick (o el error de entrega), en la esquina de la burbuja. */
|
|
1372
|
+
.wa-thread__meta {
|
|
1373
|
+
display: flex;
|
|
1374
|
+
align-self: flex-end;
|
|
1375
|
+
align-items: baseline;
|
|
1376
|
+
gap: 4px;
|
|
1377
|
+
font-size: 11px;
|
|
1378
|
+
color: #7b8794;
|
|
1379
|
+
}
|
|
1380
|
+
.wa-thread__hour {
|
|
1381
|
+
font-size: 11px;
|
|
1382
|
+
color: #7b8794;
|
|
1383
|
+
}
|
|
1384
|
+
.wa-thread__tick {
|
|
1385
|
+
letter-spacing: -0.12em;
|
|
1386
|
+
}
|
|
1387
|
+
/* \`read\` se distingue por color: un azul genérico — semántica de estado, no tema del host. */
|
|
1388
|
+
.wa-thread__tick[data-status='read'] {
|
|
1389
|
+
color: #2f6fde;
|
|
1390
|
+
}
|
|
1391
|
+
/* THREAD-02: el failed es un error EXPLÍCITO, nunca una ausencia. */
|
|
1392
|
+
.wa-thread__failed {
|
|
1393
|
+
font-weight: 600;
|
|
1394
|
+
color: #b3261e;
|
|
1395
|
+
}
|
|
1396
|
+
.wa-thread__bubble[data-failed='true'] {
|
|
1397
|
+
border-color: #e5b9b6;
|
|
1398
|
+
background: #fdf6f6;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
/* El operador que escribió la saliente, sobre la burbuja. */
|
|
1402
|
+
.wa-thread__author {
|
|
1403
|
+
font-size: 11px;
|
|
1404
|
+
font-weight: 600;
|
|
1405
|
+
color: #52606d;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
/* El estado del emisor es una cadena OPACA de otro servicio: se pinta como texto y nada más.
|
|
1409
|
+
Nunca se interpola su valor en un selector ni en una clase (THREAD-04). */
|
|
1410
|
+
.wa-thread__state {
|
|
1411
|
+
align-self: flex-start;
|
|
1412
|
+
font-size: 11px;
|
|
1413
|
+
color: #616e7c;
|
|
1414
|
+
word-break: break-word;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
/* El slot de media (DEV-4988): miniatura, link de descarga o el estado unavailable.
|
|
1418
|
+
media_rotation NO se aplica en v0 — queda para la fase de paridad. */
|
|
1419
|
+
.wa-thread__media {
|
|
1420
|
+
display: flex;
|
|
1421
|
+
flex-direction: column;
|
|
1422
|
+
align-items: flex-start;
|
|
1423
|
+
}
|
|
1424
|
+
/* Wrapper de la miniatura: un botón de verdad (abre el lightbox), sin cosmética de botón. */
|
|
1425
|
+
.wa-thread__media-button {
|
|
1426
|
+
padding: 0;
|
|
1427
|
+
border: none;
|
|
1428
|
+
background: none;
|
|
1429
|
+
cursor: pointer;
|
|
1430
|
+
line-height: 0;
|
|
1431
|
+
}
|
|
1432
|
+
/* Miniatura acotada a la burbuja. Los mínimos no son cosmética: una imagen degenerada
|
|
1433
|
+
(1×1, truncada) sin caja mínima colapsa la burbuja a nada y el adjunto queda invisible
|
|
1434
|
+
e inclicable — visto en UAT con el fixture. El fondo pinta la caja aunque el pixel
|
|
1435
|
+
sea transparente. */
|
|
1436
|
+
.wa-thread__media-img {
|
|
1437
|
+
display: block;
|
|
1438
|
+
max-width: 240px;
|
|
1439
|
+
max-height: 240px;
|
|
1440
|
+
min-width: 48px;
|
|
1441
|
+
min-height: 48px;
|
|
1442
|
+
object-fit: contain;
|
|
1443
|
+
border-radius: 6px;
|
|
1444
|
+
background: #eef1f4;
|
|
1445
|
+
}
|
|
1446
|
+
.wa-thread__media-download {
|
|
1447
|
+
padding: 6px 8px;
|
|
1448
|
+
border: 1px solid #cbd2d9;
|
|
1449
|
+
border-radius: 6px;
|
|
1450
|
+
font-size: 12px;
|
|
1451
|
+
color: #2f6fde;
|
|
1452
|
+
background: #f5f7fa;
|
|
1453
|
+
text-decoration: none;
|
|
1454
|
+
word-break: break-word;
|
|
1455
|
+
}
|
|
1456
|
+
.wa-thread__media-download:hover {
|
|
1457
|
+
text-decoration: underline;
|
|
1458
|
+
}
|
|
1459
|
+
.wa-thread__media-loading,
|
|
1460
|
+
.wa-thread__media-unavailable {
|
|
1461
|
+
font-size: 12px;
|
|
1462
|
+
color: #616e7c;
|
|
1463
|
+
}
|
|
1464
|
+
/* El lightbox de la imagen: overlay propio, clic o Escape cierran. */
|
|
1465
|
+
.wa-thread__lightbox {
|
|
1466
|
+
position: fixed;
|
|
1467
|
+
inset: 0;
|
|
1468
|
+
z-index: 1000;
|
|
1469
|
+
display: flex;
|
|
1470
|
+
align-items: center;
|
|
1471
|
+
justify-content: center;
|
|
1472
|
+
background: rgba(31, 41, 51, 0.78);
|
|
1473
|
+
cursor: zoom-out;
|
|
1474
|
+
}
|
|
1475
|
+
.wa-thread__lightbox-img {
|
|
1476
|
+
max-width: 90vw;
|
|
1477
|
+
max-height: 90vh;
|
|
1478
|
+
border-radius: 4px;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
/* CTAs: los links y los inertes se pintan IGUAL de visibles — la diferencia es la navegabilidad,
|
|
1482
|
+
no la existencia (THREAD-03). */
|
|
1483
|
+
.wa-thread__ctas {
|
|
1484
|
+
display: flex;
|
|
1485
|
+
flex-wrap: wrap;
|
|
1486
|
+
gap: 6px;
|
|
1487
|
+
}
|
|
1488
|
+
.wa-thread__cta {
|
|
1489
|
+
padding: 3px 10px;
|
|
1490
|
+
border: 1px solid #cbd2d9;
|
|
1491
|
+
border-radius: 12px;
|
|
1492
|
+
font-size: 12px;
|
|
1493
|
+
background: #ffffff;
|
|
1494
|
+
}
|
|
1495
|
+
.wa-thread__cta--link {
|
|
1496
|
+
color: #2f6fde;
|
|
1497
|
+
text-decoration: none;
|
|
1498
|
+
}
|
|
1499
|
+
.wa-thread__cta--link:hover {
|
|
1500
|
+
text-decoration: underline;
|
|
1501
|
+
}
|
|
1502
|
+
.wa-thread__cta--inert {
|
|
1503
|
+
color: #616e7c;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
.wa-thread__note {
|
|
1507
|
+
margin: 0;
|
|
1508
|
+
padding: 12px;
|
|
1509
|
+
color: #616e7c;
|
|
1510
|
+
}
|
|
1511
|
+
.wa-thread__error {
|
|
1512
|
+
padding: 10px 12px;
|
|
1513
|
+
border-bottom: 1px solid #e4e7eb;
|
|
1514
|
+
background: #fdf6f6;
|
|
1515
|
+
}
|
|
1516
|
+
.wa-thread__error p {
|
|
1517
|
+
margin: 0 0 8px;
|
|
1518
|
+
}
|
|
1519
|
+
.wa-thread__error button {
|
|
1520
|
+
padding: 5px 10px;
|
|
1521
|
+
border: 1px solid #cbd2d9;
|
|
1522
|
+
border-radius: 4px;
|
|
1523
|
+
font: inherit;
|
|
1524
|
+
color: inherit;
|
|
1525
|
+
background: #ffffff;
|
|
1526
|
+
cursor: pointer;
|
|
1527
|
+
}
|
|
1528
|
+
`;
|
|
1529
|
+
//#endregion
|
|
1530
|
+
//#region src/core/thread/useThread.ts
|
|
1531
|
+
/**
|
|
1532
|
+
* El estado del hilo de conversación: pide el hilo por el `fetcher` del host y sostiene los estados
|
|
1533
|
+
* que un operador va a ver en un turno real. Espeja la anatomía de `useConversations` (Fase 3) a
|
|
1534
|
+
* propósito: mismas decisiones, mismos porqués.
|
|
1535
|
+
*
|
|
1536
|
+
* 🔴 El hook **no arma URLs ni conoce la autenticación** (`CLAUDE.md`, DATA-05): recibe el
|
|
1537
|
+
* `WaFetcher` que el host inyectó, con su ruta y su credencial ya cerradas por closure. Acá no
|
|
1538
|
+
* entra ni un `orgId`, ni un `phoneNumberId`, ni un `apiUrl`, ni un token — sólo `fetcher` y
|
|
1539
|
+
* `phone`.
|
|
1540
|
+
*
|
|
1541
|
+
* Las reglas que no son estilo:
|
|
1542
|
+
*
|
|
1543
|
+
* 1. **Un error NUNCA vacía `messages`** (espíritu LIST-03). El hilo que el operador ya tenía en
|
|
1544
|
+
* pantalla es trabajo; borrarlo por un 500 transitorio le hace perder dónde estaba leyendo.
|
|
1545
|
+
* 2. **Cambiar de `phone` SÍ reinicia**: es una consulta nueva, no un error. El reset se DERIVA en
|
|
1546
|
+
* render (DEC-G) — el estado guarda de qué `fetcher`+`phone` vino — porque un `setState`
|
|
1547
|
+
* síncrono en un efecto encadena renders y `react-hooks` lo marca como error.
|
|
1548
|
+
* 3. **El orden cronológico es de esta vista** (THREAD-01/DEC-N): `dedupeByWamid` lo delega
|
|
1549
|
+
* explícitamente. Sort ESTABLE ascendente por `at`, con los `at: null` al final conservando su
|
|
1550
|
+
* orden relativo — son las optimistas recientes; una fila corrupta degrada de posición, no
|
|
1551
|
+
* revienta.
|
|
1552
|
+
*/
|
|
1553
|
+
/** Lo que rechaza una promesa es `unknown`: se normaliza acá y no en cada consumidor. */
|
|
1554
|
+
function toError(cause) {
|
|
1555
|
+
return cause instanceof Error ? cause : new Error(String(cause));
|
|
1556
|
+
}
|
|
1557
|
+
/** La clave de orden de un mensaje: su instante, o infinito si no lo tiene o no parsea. */
|
|
1558
|
+
function chronoKey(at) {
|
|
1559
|
+
if (typeof at !== "string") return Number.POSITIVE_INFINITY;
|
|
1560
|
+
const timestamp = Date.parse(at);
|
|
1561
|
+
return Number.isNaN(timestamp) ? Number.POSITIVE_INFINITY : timestamp;
|
|
1562
|
+
}
|
|
1563
|
+
/**
|
|
1564
|
+
* Sort ESTABLE ascendente por `at` (DEC-N). Los mensajes con `at: null` o no parseable van al
|
|
1565
|
+
* final conservando su orden relativo: son las optimistas recientes (o una fila corrupta, que
|
|
1566
|
+
* degrada de posición en vez de reventar). Pura y sin mutación: devuelve una lista nueva.
|
|
1567
|
+
*
|
|
1568
|
+
* Exportada para test directo; no sale al barrel del core.
|
|
1569
|
+
*/
|
|
1570
|
+
function sortChronologically(messages) {
|
|
1571
|
+
return messages.map((message, index) => ({
|
|
1572
|
+
message,
|
|
1573
|
+
index,
|
|
1574
|
+
key: chronoKey(message.at)
|
|
1575
|
+
})).sort((a, b) => {
|
|
1576
|
+
if (a.key === b.key) return a.index - b.index;
|
|
1577
|
+
return a.key < b.key ? -1 : 1;
|
|
1578
|
+
}).map((entry) => entry.message);
|
|
1579
|
+
}
|
|
1580
|
+
function useThread({ fetcher, phone }) {
|
|
1581
|
+
const [loaded, setLoaded] = useState(null);
|
|
1582
|
+
/** Cambia sólo cuando `retry()` rearranca de cero: es lo que vuelve a disparar el efecto. */
|
|
1583
|
+
const [attempt, setAttempt] = useState(0);
|
|
1584
|
+
/**
|
|
1585
|
+
* La petición en vuelo, si hay (DEC-H).
|
|
1586
|
+
*
|
|
1587
|
+
* Es un ref y no estado a propósito: el bloqueo de "una página a la vez" tiene que ser exacto
|
|
1588
|
+
* **en el mismo tick** — dos disparos del observer ven el mismo render y el mismo `status`.
|
|
1589
|
+
*/
|
|
1590
|
+
const inFlight = useRef(null);
|
|
1591
|
+
const start = useCallback(() => {
|
|
1592
|
+
inFlight.current?.abort();
|
|
1593
|
+
const controller = new AbortController();
|
|
1594
|
+
inFlight.current = controller;
|
|
1595
|
+
return controller;
|
|
1596
|
+
}, []);
|
|
1597
|
+
const finish = useCallback((controller) => {
|
|
1598
|
+
if (inFlight.current === controller) inFlight.current = null;
|
|
1599
|
+
}, []);
|
|
1600
|
+
useEffect(() => {
|
|
1601
|
+
const controller = start();
|
|
1602
|
+
loadThread(fetcher, { phone }, { signal: controller.signal }).then((thread) => {
|
|
1603
|
+
if (controller.signal.aborted) return;
|
|
1604
|
+
finish(controller);
|
|
1605
|
+
const messages = sortChronologically(thread.messages);
|
|
1606
|
+
setLoaded({
|
|
1607
|
+
fetcher,
|
|
1608
|
+
phone,
|
|
1609
|
+
messages,
|
|
1610
|
+
windowState: normalizeWindowState(thread.window_state),
|
|
1611
|
+
status: messages.length > 0 ? "ready" : "empty",
|
|
1612
|
+
error: null,
|
|
1613
|
+
olderCursor: thread.older_cursor,
|
|
1614
|
+
hasOlder: thread.older_cursor !== null
|
|
1615
|
+
});
|
|
1616
|
+
}, (cause) => {
|
|
1617
|
+
if (controller.signal.aborted) return;
|
|
1618
|
+
finish(controller);
|
|
1619
|
+
setLoaded({
|
|
1620
|
+
fetcher,
|
|
1621
|
+
phone,
|
|
1622
|
+
messages: [],
|
|
1623
|
+
windowState: "unverified",
|
|
1624
|
+
status: "error",
|
|
1625
|
+
error: toError(cause),
|
|
1626
|
+
olderCursor: null,
|
|
1627
|
+
hasOlder: false
|
|
1628
|
+
});
|
|
1629
|
+
});
|
|
1630
|
+
return () => controller.abort();
|
|
1631
|
+
}, [
|
|
1632
|
+
fetcher,
|
|
1633
|
+
phone,
|
|
1634
|
+
attempt,
|
|
1635
|
+
start,
|
|
1636
|
+
finish
|
|
1637
|
+
]);
|
|
1638
|
+
/**
|
|
1639
|
+
* Lo cargado sólo vale si vino de ESTA consulta. Si no, la vista vuelve a "cargando" por
|
|
1640
|
+
* derivación — que es como se distingue "cambié de hilo" (reinicia) de "falló" (no reinicia).
|
|
1641
|
+
*/
|
|
1642
|
+
const current = loaded !== null && loaded.fetcher === fetcher && loaded.phone === phone ? loaded : null;
|
|
1643
|
+
const loadOlder = useCallback(() => {
|
|
1644
|
+
if (current === null) return;
|
|
1645
|
+
if (!current.hasOlder) return;
|
|
1646
|
+
if (inFlight.current !== null) return;
|
|
1647
|
+
const cursor = current.olderCursor;
|
|
1648
|
+
if (cursor === null) return;
|
|
1649
|
+
const base = {
|
|
1650
|
+
...current,
|
|
1651
|
+
status: "loading-older",
|
|
1652
|
+
error: null
|
|
1653
|
+
};
|
|
1654
|
+
setLoaded(base);
|
|
1655
|
+
const controller = start();
|
|
1656
|
+
loadThread(fetcher, {
|
|
1657
|
+
phone,
|
|
1658
|
+
cursor
|
|
1659
|
+
}, { signal: controller.signal }).then((thread) => {
|
|
1660
|
+
if (controller.signal.aborted) return;
|
|
1661
|
+
finish(controller);
|
|
1662
|
+
const knownWamids = new Set(base.messages.map((message) => message.id).filter((id) => typeof id === "string" && id !== ""));
|
|
1663
|
+
if (!thread.messages.some((message) => typeof message.id === "string" && message.id !== "" && !knownWamids.has(message.id))) {
|
|
1664
|
+
setLoaded({
|
|
1665
|
+
...base,
|
|
1666
|
+
status: "ready",
|
|
1667
|
+
error: null,
|
|
1668
|
+
hasOlder: false
|
|
1669
|
+
});
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
const merged = sortChronologically(dedupeByWamid([...thread.messages, ...base.messages]));
|
|
1673
|
+
setLoaded({
|
|
1674
|
+
...base,
|
|
1675
|
+
messages: merged,
|
|
1676
|
+
status: "ready",
|
|
1677
|
+
error: null,
|
|
1678
|
+
olderCursor: thread.older_cursor,
|
|
1679
|
+
hasOlder: thread.older_cursor !== null
|
|
1680
|
+
});
|
|
1681
|
+
}, (cause) => {
|
|
1682
|
+
if (controller.signal.aborted) return;
|
|
1683
|
+
finish(controller);
|
|
1684
|
+
setLoaded({
|
|
1685
|
+
...base,
|
|
1686
|
+
status: "error",
|
|
1687
|
+
error: toError(cause)
|
|
1688
|
+
});
|
|
1689
|
+
});
|
|
1690
|
+
}, [
|
|
1691
|
+
fetcher,
|
|
1692
|
+
phone,
|
|
1693
|
+
current,
|
|
1694
|
+
start,
|
|
1695
|
+
finish
|
|
1696
|
+
]);
|
|
1697
|
+
const retry = useCallback(() => {
|
|
1698
|
+
if (current !== null && current.messages.length > 0) {
|
|
1699
|
+
loadOlder();
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
setLoaded(null);
|
|
1703
|
+
setAttempt((n) => n + 1);
|
|
1704
|
+
}, [current, loadOlder]);
|
|
1705
|
+
return {
|
|
1706
|
+
messages: current?.messages ?? [],
|
|
1707
|
+
status: current?.status ?? "loading",
|
|
1708
|
+
error: current?.error ?? null,
|
|
1709
|
+
windowState: current?.windowState ?? "unverified",
|
|
1710
|
+
hasOlder: current?.hasOlder ?? false,
|
|
1711
|
+
loadOlder,
|
|
1712
|
+
retry
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
//#endregion
|
|
1716
|
+
//#region src/core/thread/ConversationThread.tsx
|
|
1717
|
+
/**
|
|
1718
|
+
* El panel del hilo de conversación — la mitad derecha del visor (DEV-4987).
|
|
1719
|
+
*
|
|
1720
|
+
* Lo que este panel muestra es **la conversación como la vio el lifter**: burbujas `in` a la
|
|
1721
|
+
* izquierda y `out` a la derecha, en orden cronológico, con separadores de día. No es un log de
|
|
1722
|
+
* eventos: es la herramienta con la que un operador entiende de un golpe quién dijo qué y dónde se
|
|
1723
|
+
* atascó la persona.
|
|
1724
|
+
*
|
|
1725
|
+
* 🔴 **Ninguna prop de este componente puede ser `orgId`, `phoneNumberId`, `apiUrl`, `baseUrl` ni
|
|
1726
|
+
* `token`, ni nada con lo que se pueda construir una ruta** (DATA-05). El scope —qué hilo es
|
|
1727
|
+
* éste— ya viene cerrado por closure adentro del `fetcher` que inyecta el host.
|
|
1728
|
+
*
|
|
1729
|
+
* 🔴 Todo el contenido de la burbuja (`body`, y en la Task 2 `file_name`, `location_name`,
|
|
1730
|
+
* `service_state`, los CTAs) lo origina el lifter o el bot y viaja por Meta: entrada NO confiable
|
|
1731
|
+
* que entra como hijo de texto, que React escapa (T-04-02). Prohibido `dangerouslySetInnerHTML`
|
|
1732
|
+
* en todo `src/core/thread/`.
|
|
1733
|
+
*/
|
|
1734
|
+
/**
|
|
1735
|
+
* Agrupa los mensajes (ya ordenados por DEC-N) por día local. Un `at` null o no parseable no abre
|
|
1736
|
+
* grupo nuevo: la burbuja se pega al grupo vigente (DEC-O).
|
|
1737
|
+
*/
|
|
1738
|
+
function groupByDay(messages) {
|
|
1739
|
+
const groups = [];
|
|
1740
|
+
messages.forEach((message, position) => {
|
|
1741
|
+
const key = dayKey(message.at);
|
|
1742
|
+
const currentGroup = groups.length > 0 ? groups[groups.length - 1] : null;
|
|
1743
|
+
if (key === null && currentGroup !== null) {
|
|
1744
|
+
currentGroup.items.push({
|
|
1745
|
+
message,
|
|
1746
|
+
position
|
|
1747
|
+
});
|
|
1748
|
+
return;
|
|
1749
|
+
}
|
|
1750
|
+
if (currentGroup !== null && currentGroup.key === key) {
|
|
1751
|
+
currentGroup.items.push({
|
|
1752
|
+
message,
|
|
1753
|
+
position
|
|
1754
|
+
});
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
groups.push({
|
|
1758
|
+
key,
|
|
1759
|
+
label: key !== null && message.at !== null ? dayLabel(message.at) : null,
|
|
1760
|
+
items: [{
|
|
1761
|
+
message,
|
|
1762
|
+
position
|
|
1763
|
+
}]
|
|
1764
|
+
});
|
|
1765
|
+
});
|
|
1766
|
+
return groups;
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* En qué posiciones se pinta la etiqueta `service_state` (DEC-P): sólo cuando el valor difiere del
|
|
1770
|
+
* último NO-NULO ya pintado en el hilo — es el marcador de "acá cambió de paso", que es la lectura
|
|
1771
|
+
* de diagnóstico; pintarlo en todas las burbujas sería ruido. `null`/vacío no pinta y NO cuenta
|
|
1772
|
+
* como cambio. La comparación vive acá (el recorrido es del padre), no en la burbuja.
|
|
1773
|
+
*/
|
|
1774
|
+
function serviceStateTransitions(messages) {
|
|
1775
|
+
let lastPainted = null;
|
|
1776
|
+
return messages.map((message) => {
|
|
1777
|
+
const state = typeof message.service_state === "string" && message.service_state !== "" ? message.service_state : null;
|
|
1778
|
+
if (state === null || state === lastPainted) return false;
|
|
1779
|
+
lastPainted = state;
|
|
1780
|
+
return true;
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
function ConversationThread({ fetcher, phone, className }) {
|
|
1784
|
+
const { messages, status, error, hasOlder, loadOlder, retry } = useThread({
|
|
1785
|
+
fetcher,
|
|
1786
|
+
phone
|
|
1787
|
+
});
|
|
1788
|
+
const messagesRef = useRef(null);
|
|
1789
|
+
/** De qué consulta ya se hizo el scroll inicial: una vez por hilo, no en cada página. */
|
|
1790
|
+
const scrolledForRef = useRef(null);
|
|
1791
|
+
/** La captura del "antes" para el anclaje del prepend: se toma al disparar loadOlder. */
|
|
1792
|
+
const anchorRef = useRef(null);
|
|
1793
|
+
useLayoutEffect(() => {
|
|
1794
|
+
const element = messagesRef.current;
|
|
1795
|
+
if (element === null || messages.length === 0) return;
|
|
1796
|
+
if (scrolledForRef.current === phone) return;
|
|
1797
|
+
scrolledForRef.current = phone;
|
|
1798
|
+
element.scrollTop = element.scrollHeight;
|
|
1799
|
+
}, [phone, messages]);
|
|
1800
|
+
/** Dispara la página anterior capturando ANTES las medidas del contenedor (THREAD-05). */
|
|
1801
|
+
const handleLoadOlder = useCallback(() => {
|
|
1802
|
+
const element = messagesRef.current;
|
|
1803
|
+
anchorRef.current = element === null ? null : {
|
|
1804
|
+
scrollTop: element.scrollTop,
|
|
1805
|
+
scrollHeight: element.scrollHeight
|
|
1806
|
+
};
|
|
1807
|
+
loadOlder();
|
|
1808
|
+
}, [loadOlder]);
|
|
1809
|
+
useLayoutEffect(() => {
|
|
1810
|
+
if (status === "loading-older") return;
|
|
1811
|
+
const anchor = anchorRef.current;
|
|
1812
|
+
const element = messagesRef.current;
|
|
1813
|
+
anchorRef.current = null;
|
|
1814
|
+
if (anchor === null || element === null) return;
|
|
1815
|
+
element.scrollTop = anchor.scrollTop + (element.scrollHeight - anchor.scrollHeight);
|
|
1816
|
+
}, [status, messages]);
|
|
1817
|
+
/**
|
|
1818
|
+
* El auto-disparo del centinela superior: con feature-detect porque jsdom no trae
|
|
1819
|
+
* `IntersectionObserver` y el paquete no puede asumir el navegador del host. Donde no existe,
|
|
1820
|
+
* el botón sigue estando y el hilo avanza por clic — que es como lo ejercitan los tests.
|
|
1821
|
+
*/
|
|
1822
|
+
const sentinel = useRef(null);
|
|
1823
|
+
useEffect(() => {
|
|
1824
|
+
if (typeof IntersectionObserver === "undefined") return;
|
|
1825
|
+
const element = sentinel.current;
|
|
1826
|
+
if (element === null || !hasOlder) return;
|
|
1827
|
+
const observer = new IntersectionObserver((entries) => {
|
|
1828
|
+
if (entries.some((entry) => entry.isIntersecting)) handleLoadOlder();
|
|
1829
|
+
});
|
|
1830
|
+
observer.observe(element);
|
|
1831
|
+
return () => observer.disconnect();
|
|
1832
|
+
}, [hasOlder, handleLoadOlder]);
|
|
1833
|
+
const groups = groupByDay(messages);
|
|
1834
|
+
const showServiceState = serviceStateTransitions(messages);
|
|
1835
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1836
|
+
className: className ? `wa-thread ${className}` : "wa-thread",
|
|
1837
|
+
children: [
|
|
1838
|
+
/* @__PURE__ */ jsx("style", { children: THREAD_CSS }),
|
|
1839
|
+
status === "loading" && /* @__PURE__ */ jsx("p", {
|
|
1840
|
+
className: "wa-thread__note",
|
|
1841
|
+
children: "Cargando conversación…"
|
|
1842
|
+
}),
|
|
1843
|
+
error !== null && /* @__PURE__ */ jsxs("div", {
|
|
1844
|
+
className: "wa-thread__error",
|
|
1845
|
+
role: "alert",
|
|
1846
|
+
children: [/* @__PURE__ */ jsxs("p", { children: ["No se pudo cargar la conversación: ", error.message] }), /* @__PURE__ */ jsx("button", {
|
|
1847
|
+
type: "button",
|
|
1848
|
+
onClick: retry,
|
|
1849
|
+
children: "Reintentar"
|
|
1850
|
+
})]
|
|
1851
|
+
}),
|
|
1852
|
+
status === "empty" && /* @__PURE__ */ jsx("p", {
|
|
1853
|
+
className: "wa-thread__note",
|
|
1854
|
+
children: "Sin mensajes en esta conversación."
|
|
1855
|
+
}),
|
|
1856
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1857
|
+
className: "wa-thread__messages",
|
|
1858
|
+
ref: messagesRef,
|
|
1859
|
+
children: [hasOlder && /* @__PURE__ */ jsx("button", {
|
|
1860
|
+
ref: sentinel,
|
|
1861
|
+
type: "button",
|
|
1862
|
+
className: "wa-thread__older",
|
|
1863
|
+
onClick: handleLoadOlder,
|
|
1864
|
+
disabled: status === "loading-older",
|
|
1865
|
+
children: status === "loading-older" ? "Cargando…" : "Cargar mensajes anteriores"
|
|
1866
|
+
}), groups.map((group, groupIndex) => /* @__PURE__ */ jsxs("div", {
|
|
1867
|
+
className: "wa-thread__group",
|
|
1868
|
+
children: [group.label !== null && /* @__PURE__ */ jsx("div", {
|
|
1869
|
+
className: "wa-thread__day",
|
|
1870
|
+
children: group.label
|
|
1871
|
+
}), group.items.map(({ message, position }) => /* @__PURE__ */ jsx(MessageBubble, {
|
|
1872
|
+
message,
|
|
1873
|
+
showServiceState: showServiceState[position],
|
|
1874
|
+
fetcher
|
|
1875
|
+
}, message.id ?? `sin-wamid-${position}`))]
|
|
1876
|
+
}, group.key ?? `sin-dia-${groupIndex}`))]
|
|
1877
|
+
})
|
|
1878
|
+
]
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
//#endregion
|
|
1882
|
+
//#region src/core/WaConversations.tsx
|
|
1883
|
+
/**
|
|
1884
|
+
* WaConversations — el shell de dos vistas del visor: la lista (Fase 3) y el hilo (Fase 4),
|
|
1885
|
+
* cerrando el residual LIST-04 declarado por la Fase 3.
|
|
1886
|
+
*
|
|
1887
|
+
* El `fetcher` es opcional A PROPÓSITO: sin él, el componente conserva el placeholder de la Fase 1
|
|
1888
|
+
* — es lo que mantiene compilando y montando al entry `./element`, que hoy renderiza sin props (la
|
|
1889
|
+
* superficie por atributos del Web Component es DEV-4989). El docstring original de la Fase 1
|
|
1890
|
+
* prohibía agregar props de contrato acá porque el contrato del fetcher aún no existía; existe
|
|
1891
|
+
* desde la Fase 2, y este shell es su consumidor previsto.
|
|
1892
|
+
*
|
|
1893
|
+
* 🔴 **Ninguna prop puede ser `orgId`, `phoneNumberId`, `apiUrl`, `baseUrl` ni `token`, ni nada
|
|
1894
|
+
* con lo que se pueda construir una ruta** (DATA-05). El scope viaja CERRADO dentro del `fetcher`.
|
|
1895
|
+
*
|
|
1896
|
+
* El switch angosto/ancho lo decide `useContainerLayout` sobre el contenedor de ESTE shell, con el
|
|
1897
|
+
* MISMO `NARROW_MAX_WIDTH` de la lista — jamás un `@media`: dos mecanismos para la misma pregunta
|
|
1898
|
+
* se desincronizan (uno diría angosto y el otro ancho en el mismo pixel). En `wide`, lista e hilo
|
|
1899
|
+
* van lado a lado; en `narrow`, el hilo se muestra EN LUGAR DE la lista, con "Volver" para salir.
|
|
1900
|
+
*/
|
|
1901
|
+
/**
|
|
1902
|
+
* El CSS del shell, mínimo: sólo el layout de las dos columnas. Los paneles traen el suyo. Como
|
|
1903
|
+
* en la lista y el hilo: string embebido, selectores prefijados `.wa-conversations`, sin tokens
|
|
1904
|
+
* del host, y el `<style>` sin `href` ni `precedence` (WC-02).
|
|
1905
|
+
*/
|
|
1906
|
+
const SHELL_CSS = `
|
|
1907
|
+
.wa-conversations {
|
|
1908
|
+
box-sizing: border-box;
|
|
1909
|
+
display: flex;
|
|
1910
|
+
/* El eslabón que activa los scrollers internos: sin height acotado, el shell crece con el
|
|
1911
|
+
contenido, .wa-thread__messages y .wa-list__items nunca desbordan, y quien scrollea es LA
|
|
1912
|
+
PÁGINA del host (visto en el banco E2E con un hilo de 31 mensajes). Con height: 100% el
|
|
1913
|
+
shell toma la altura que el host le dé a su contenedor; si el host no define altura, 100%
|
|
1914
|
+
de un padre auto degrada a auto — el comportamiento de antes, sin romper a nadie. */
|
|
1915
|
+
height: 100%;
|
|
1916
|
+
min-height: 0;
|
|
1917
|
+
align-items: stretch;
|
|
1918
|
+
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
|
1919
|
+
}
|
|
1920
|
+
/* El ancho de la columna de la lista lo fija EL SHELL, no la lista: el data-layout de la lista
|
|
1921
|
+
se mide de su propio ancho, así que un ancho derivado de él oscila (ver list-styles.ts). El
|
|
1922
|
+
observer del shell mide el contenedor raíz, cuyo ancho no depende del layout — estable. */
|
|
1923
|
+
.wa-conversations[data-layout='wide'] > .wa-list {
|
|
1924
|
+
width: 320px;
|
|
1925
|
+
flex: 0 0 320px;
|
|
1926
|
+
border-right: 1px solid #e4e7eb;
|
|
1927
|
+
}
|
|
1928
|
+
.wa-conversations[data-layout='narrow'] > .wa-list {
|
|
1929
|
+
flex: 1 1 auto;
|
|
1930
|
+
}
|
|
1931
|
+
.wa-conversations__thread {
|
|
1932
|
+
display: flex;
|
|
1933
|
+
min-width: 0;
|
|
1934
|
+
min-height: 0;
|
|
1935
|
+
flex: 1 1 auto;
|
|
1936
|
+
flex-direction: column;
|
|
1937
|
+
}
|
|
1938
|
+
.wa-conversations__back {
|
|
1939
|
+
align-self: flex-start;
|
|
1940
|
+
margin: 8px 12px 0;
|
|
1941
|
+
padding: 5px 10px;
|
|
1942
|
+
border: 1px solid #cbd2d9;
|
|
1943
|
+
border-radius: 4px;
|
|
1944
|
+
font: inherit;
|
|
1945
|
+
color: inherit;
|
|
1946
|
+
background: #ffffff;
|
|
1947
|
+
cursor: pointer;
|
|
1948
|
+
}
|
|
1949
|
+
.wa-conversations__back:hover {
|
|
1950
|
+
background: #f5f7fa;
|
|
1951
|
+
}
|
|
1952
|
+
.wa-conversations__empty {
|
|
1953
|
+
margin: 0;
|
|
1954
|
+
padding: 24px;
|
|
1955
|
+
flex: 1 1 auto;
|
|
1956
|
+
color: #616e7c;
|
|
1957
|
+
}
|
|
1958
|
+
`;
|
|
1959
|
+
function WaConversations({ fetcher, initialPhone, className }) {
|
|
1960
|
+
/**
|
|
1961
|
+
* El layout lo decide el ancho de ESTE contenedor, no el del viewport: el visor va embebido
|
|
1962
|
+
* (en lms-web-app vive dentro del layout del LMS, no a pantalla completa).
|
|
1963
|
+
*/
|
|
1964
|
+
const rootRef = useRef(null);
|
|
1965
|
+
const layout = useContainerLayout(rootRef);
|
|
1966
|
+
/**
|
|
1967
|
+
* La conversación elegida. Vive acá — el panel de la lista es controlado a propósito.
|
|
1968
|
+
* `initialPhone` sólo SIEMBRA el estado: un cambio posterior de la prop no lo pisa (ver el
|
|
1969
|
+
* docstring de la prop — la reactividad post-mount es del key-swap del element).
|
|
1970
|
+
*/
|
|
1971
|
+
const [selectedPhone, setSelectedPhone] = useState(initialPhone ?? null);
|
|
1972
|
+
const rootClass = className ? `wa-conversations ${className}` : "wa-conversations";
|
|
1973
|
+
if (fetcher === void 0) return /* @__PURE__ */ jsx("div", {
|
|
1974
|
+
className: rootClass,
|
|
1975
|
+
children: /* @__PURE__ */ jsx("p", { children: "Visor de conversaciones de WhatsApp — falta el fetcher del host." })
|
|
1976
|
+
});
|
|
1977
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1978
|
+
ref: rootRef,
|
|
1979
|
+
className: rootClass,
|
|
1980
|
+
"data-layout": layout,
|
|
1981
|
+
children: [
|
|
1982
|
+
/* @__PURE__ */ jsx("style", { children: SHELL_CSS }),
|
|
1983
|
+
(layout === "wide" || selectedPhone === null) && /* @__PURE__ */ jsx(ConversationList, {
|
|
1984
|
+
fetcher,
|
|
1985
|
+
selectedPhone,
|
|
1986
|
+
onSelect: (item) => setSelectedPhone(item.phone)
|
|
1987
|
+
}),
|
|
1988
|
+
selectedPhone !== null ? /* @__PURE__ */ jsxs("div", {
|
|
1989
|
+
className: "wa-conversations__thread",
|
|
1990
|
+
children: [layout === "narrow" && /* @__PURE__ */ jsx("button", {
|
|
1991
|
+
type: "button",
|
|
1992
|
+
className: "wa-conversations__back",
|
|
1993
|
+
onClick: () => setSelectedPhone(null),
|
|
1994
|
+
children: "Volver"
|
|
1995
|
+
}), /* @__PURE__ */ jsx(ConversationThread, {
|
|
1996
|
+
fetcher,
|
|
1997
|
+
phone: selectedPhone
|
|
1998
|
+
})]
|
|
1999
|
+
}) : layout === "wide" && /* @__PURE__ */ jsx("p", {
|
|
2000
|
+
className: "wa-conversations__empty",
|
|
2001
|
+
children: "Selecciona una conversación"
|
|
2002
|
+
})
|
|
2003
|
+
]
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
//#endregion
|
|
2007
|
+
//#region src/core/index.ts
|
|
2008
|
+
/**
|
|
2009
|
+
* Nombre del custom element que registra el entry `./element`.
|
|
2010
|
+
*
|
|
2011
|
+
* Vive en el core y no en el entry porque el entry `./element` y los tests de la Fase 2 lo
|
|
2012
|
+
* comparten: un tag hardcodeado en dos lugares es un tag que se desincroniza.
|
|
2013
|
+
*/
|
|
2014
|
+
const WA_CONVERSATIONS_TAG = "wa-conversations";
|
|
2015
|
+
//#endregion
|
|
2016
|
+
export { ConversationList, ConversationThread, NARROW_MAX_WIDTH, WA_CONVERSATIONS_TAG, WaConversations, dedupeByWamid, isCtaLink, loadConversations, loadThread, normalizeWindowState, threadCtas, useContainerLayout, useConversations, useThread };
|