@liftitapp/wa-conversations 0.8.2 → 0.9.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/dist/element/index.js +38 -14
- package/dist/react/index.d.ts +27 -0
- package/dist/react/index.js +217 -27
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -206,6 +206,19 @@ interface LeadThreadResponse {
|
|
|
206
206
|
taken_by?: string | null;
|
|
207
207
|
taken_until?: string | null;
|
|
208
208
|
taken_by_me?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* **DEV-6309 / DEV-6399** — desde cuándo está tomada y con qué rol, para la barra ámbar
|
|
211
|
+
* «La tiene Paula Castaño (operadora) · 12 m».
|
|
212
|
+
*
|
|
213
|
+
* `taken_at` es un **instante ISO-8601** (mismo motivo que `taken_until`: el transcurrido lo
|
|
214
|
+
* cuenta el front contra su reloj). `taken_by_role` es texto libre para pintar entre paréntesis:
|
|
215
|
+
* se tipa abierto (`string`) porque es un rótulo, no un enum que el visor interprete.
|
|
216
|
+
*
|
|
217
|
+
* Opcionales y nullables: el servidor todavía no los emite (los agrega DEV-6399). Ausentes, la
|
|
218
|
+
* barra cae a «· se libera en N» y sin paréntesis — exactamente lo de antes.
|
|
219
|
+
*/
|
|
220
|
+
taken_at?: string | null;
|
|
221
|
+
taken_by_role?: string | null;
|
|
209
222
|
/** E2 — el bot dueño de la conversación. La unicidad es `(phone_number_id, phone)`, nunca el teléfono solo. */
|
|
210
223
|
phone_number_id: string;
|
|
211
224
|
/** E2 — qué servicio la originó (`self_onboarding_whatsapp`, y los que vengan). */
|
|
@@ -325,6 +338,13 @@ interface ConversationSummary {
|
|
|
325
338
|
taken_by?: string | null;
|
|
326
339
|
taken_until?: string | null;
|
|
327
340
|
taken_by_me?: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* **DEV-6309 / DEV-6399** — el mismo par que en `LeadThreadResponse` (`taken_at` ISO-8601,
|
|
343
|
+
* `taken_by_role` rótulo libre), opcionales y nullables. La fila de la lista todavía no los
|
|
344
|
+
* pinta: entran al tipo para que el contrato de los dos sobres no se desvíe.
|
|
345
|
+
*/
|
|
346
|
+
taken_at?: string | null;
|
|
347
|
+
taken_by_role?: string | null;
|
|
328
348
|
}
|
|
329
349
|
/**
|
|
330
350
|
* El sobre de la lista.
|
|
@@ -974,6 +994,13 @@ interface UseThreadResult {
|
|
|
974
994
|
takenBy: string | null;
|
|
975
995
|
takenUntil: string | null;
|
|
976
996
|
takenByMe: boolean;
|
|
997
|
+
/**
|
|
998
|
+
* DEV-6309 — el instante de la toma (`taken_at`, ISO verbatim) y el rol de quien la tiene
|
|
999
|
+
* (`taken_by_role`). Opcionales en el cable: hasta que DEV-6399 los emita llegan `null` y la
|
|
1000
|
+
* barra cae a «se libera en N». Un error de red también los deja en `null`.
|
|
1001
|
+
*/
|
|
1002
|
+
takenAt: string | null;
|
|
1003
|
+
takenByRole: string | null;
|
|
977
1004
|
/**
|
|
978
1005
|
* Hay página anterior que pedir (DEC-M): lo dice el `older_cursor` del servidor (DEV-4983),
|
|
979
1006
|
* `null` = hilo agotado. Se apaga PERMANENTE al agotar el hilo.
|
package/dist/react/index.js
CHANGED
|
@@ -1002,7 +1002,9 @@ async function loadThread(fetcher, request, options) {
|
|
|
1002
1002
|
can_reply: payload.can_reply === true,
|
|
1003
1003
|
taken_by: asNullableString(payload.taken_by),
|
|
1004
1004
|
taken_until: asNullableString(payload.taken_until),
|
|
1005
|
-
taken_by_me: payload.taken_by_me === true
|
|
1005
|
+
taken_by_me: payload.taken_by_me === true,
|
|
1006
|
+
taken_at: asNullableString(payload.taken_at),
|
|
1007
|
+
taken_by_role: asNullableString(payload.taken_by_role)
|
|
1006
1008
|
};
|
|
1007
1009
|
}
|
|
1008
1010
|
/**
|
|
@@ -1823,7 +1825,7 @@ function ReleaseToBot({ composer }) {
|
|
|
1823
1825
|
]
|
|
1824
1826
|
});
|
|
1825
1827
|
}
|
|
1826
|
-
function Composer({ canReply, composer, onRetryWindow, prefill }) {
|
|
1828
|
+
function Composer({ canReply, composer, onRetryWindow, prefill, locked = false, takeoverNotice = null, focusRequest = null }) {
|
|
1827
1829
|
/**
|
|
1828
1830
|
* Lo que el operador tipeó, junto con **de qué precarga vino** (DEC-G).
|
|
1829
1831
|
*
|
|
@@ -1865,6 +1867,12 @@ function Composer({ canReply, composer, onRetryWindow, prefill }) {
|
|
|
1865
1867
|
if (prefill === null || prefill === void 0) return;
|
|
1866
1868
|
inputRef.current?.focus();
|
|
1867
1869
|
}, [prefill]);
|
|
1870
|
+
useEffect(() => {
|
|
1871
|
+
if (focusRequest === null) return;
|
|
1872
|
+
inputRef.current?.focus();
|
|
1873
|
+
}, [focusRequest]);
|
|
1874
|
+
/** El id del aviso del pie, para que el lector de pantalla lo lea al enfocar el textarea. */
|
|
1875
|
+
const noticeId = useId();
|
|
1868
1876
|
if (!canReply) return null;
|
|
1869
1877
|
if (composer.windowState === "closed") return /* @__PURE__ */ jsxs("div", {
|
|
1870
1878
|
className: "wa-composer wa-composer--closed",
|
|
@@ -1905,6 +1913,7 @@ function Composer({ canReply, composer, onRetryWindow, prefill }) {
|
|
|
1905
1913
|
]
|
|
1906
1914
|
});
|
|
1907
1915
|
const send = () => {
|
|
1916
|
+
if (locked) return;
|
|
1908
1917
|
const text = draft.trim();
|
|
1909
1918
|
if (text === "") return;
|
|
1910
1919
|
composer.send(text);
|
|
@@ -1947,6 +1956,8 @@ function Composer({ canReply, composer, onRetryWindow, prefill }) {
|
|
|
1947
1956
|
value: draft,
|
|
1948
1957
|
placeholder: "Escribí tu respuesta…",
|
|
1949
1958
|
"aria-label": "Mensaje para la persona",
|
|
1959
|
+
disabled: locked,
|
|
1960
|
+
"aria-describedby": takeoverNotice !== null ? noticeId : void 0,
|
|
1950
1961
|
onChange: (event) => setDraft(event.target.value),
|
|
1951
1962
|
onKeyDown: (event) => {
|
|
1952
1963
|
if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing) return;
|
|
@@ -1956,7 +1967,12 @@ function Composer({ canReply, composer, onRetryWindow, prefill }) {
|
|
|
1956
1967
|
}), /* @__PURE__ */ jsxs("div", {
|
|
1957
1968
|
className: "wa-composer__hint-row",
|
|
1958
1969
|
children: [
|
|
1959
|
-
/* @__PURE__ */ jsx("span", {
|
|
1970
|
+
takeoverNotice !== null ? /* @__PURE__ */ jsx("span", {
|
|
1971
|
+
className: "wa-composer__hint",
|
|
1972
|
+
"data-takeover": "true",
|
|
1973
|
+
id: noticeId,
|
|
1974
|
+
children: takeoverNotice
|
|
1975
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
1960
1976
|
className: "wa-composer__hint",
|
|
1961
1977
|
children: "Al enviar, el bot se pausa y la conversación queda tomada por ti"
|
|
1962
1978
|
}),
|
|
@@ -1971,7 +1987,7 @@ function Composer({ canReply, composer, onRetryWindow, prefill }) {
|
|
|
1971
1987
|
/* @__PURE__ */ jsx("button", {
|
|
1972
1988
|
type: "submit",
|
|
1973
1989
|
className: "wa-composer__send",
|
|
1974
|
-
disabled: draft.trim() === "",
|
|
1990
|
+
disabled: locked || draft.trim() === "",
|
|
1975
1991
|
children: "Enviar"
|
|
1976
1992
|
})
|
|
1977
1993
|
]
|
|
@@ -2865,17 +2881,18 @@ const THREAD_CSS = `
|
|
|
2865
2881
|
font-weight: 400;
|
|
2866
2882
|
}
|
|
2867
2883
|
|
|
2868
|
-
/* DEV-5061 — la barra de takeover
|
|
2869
|
-
|
|
2870
|
-
|
|
2884
|
+
/* DEV-5061 — la barra de takeover. Ámbar cuando la tiene otro (es un aviso: no escribas encima)
|
|
2885
|
+
y añil cuando es tuya (es tu control, con su acción). Los dos tonos son los de la paleta que
|
|
2886
|
+
fijó DEV-5053. Desde DEV-6309 va ENCIMA del composer, de ancho completo: el borde pasa arriba. */
|
|
2871
2887
|
.wa-thread__takeover {
|
|
2872
2888
|
display: flex;
|
|
2889
|
+
flex: 0 0 auto;
|
|
2873
2890
|
align-items: center;
|
|
2874
2891
|
justify-content: space-between;
|
|
2875
2892
|
gap: 12px;
|
|
2876
2893
|
flex-wrap: wrap;
|
|
2877
2894
|
padding: 8px 12px;
|
|
2878
|
-
border-
|
|
2895
|
+
border-top: 1px solid #e4e7ee;
|
|
2879
2896
|
background: #fff7e8;
|
|
2880
2897
|
color: #b7791f;
|
|
2881
2898
|
font-size: 13px;
|
|
@@ -2885,12 +2902,24 @@ const THREAD_CSS = `
|
|
|
2885
2902
|
color: #4f5aed;
|
|
2886
2903
|
}
|
|
2887
2904
|
.wa-thread__takeover-text {
|
|
2905
|
+
display: inline-flex;
|
|
2906
|
+
align-items: center;
|
|
2907
|
+
gap: 6px;
|
|
2888
2908
|
min-width: 0;
|
|
2889
2909
|
}
|
|
2910
|
+
/* DEV-6309: el icono de persona de la toma ajena. flex: none para que un nombre largo no lo
|
|
2911
|
+
aplaste; el texto es el que envuelve. */
|
|
2912
|
+
.wa-thread__takeover-icon {
|
|
2913
|
+
flex: none;
|
|
2914
|
+
}
|
|
2890
2915
|
/* Pill, el mismo molde que el Reintentar de DEV-5053 P7. \`currentColor\` es lo que hace que el
|
|
2891
2916
|
botón siga al tono de la barra sin duplicar la regla por variante. */
|
|
2892
2917
|
.wa-thread__takeover-button {
|
|
2918
|
+
display: inline-flex;
|
|
2893
2919
|
flex: none;
|
|
2920
|
+
align-items: center;
|
|
2921
|
+
gap: 6px;
|
|
2922
|
+
white-space: nowrap;
|
|
2894
2923
|
padding: 4px 12px;
|
|
2895
2924
|
border: 1px solid currentColor;
|
|
2896
2925
|
border-radius: 999px;
|
|
@@ -3172,6 +3201,13 @@ const THREAD_CSS = `
|
|
|
3172
3201
|
outline: 2px solid rgba(79, 90, 237, 0.25);
|
|
3173
3202
|
outline-offset: 0;
|
|
3174
3203
|
}
|
|
3204
|
+
/* DEV-6309: bloqueado por la toma de otra persona. Atenuado y sin cursor de texto: que se vea que
|
|
3205
|
+
no es un campo roto sino uno que espera «Escribir igual». */
|
|
3206
|
+
.wa-composer__input:disabled {
|
|
3207
|
+
color: #9AA1AE;
|
|
3208
|
+
cursor: not-allowed;
|
|
3209
|
+
opacity: 0.7;
|
|
3210
|
+
}
|
|
3175
3211
|
/* DEV-5053 P2: hint del takeover a la izquierda; contador y Enviar a la derecha. */
|
|
3176
3212
|
.wa-composer__hint-row {
|
|
3177
3213
|
display: flex;
|
|
@@ -3188,6 +3224,10 @@ const THREAD_CSS = `
|
|
|
3188
3224
|
font-size: 10.5px;
|
|
3189
3225
|
color: #9AA1AE;
|
|
3190
3226
|
}
|
|
3227
|
+
/* DEV-6309: el aviso de «Escribir igual» — ámbar como la barra de la que es consecuencia. */
|
|
3228
|
+
.wa-composer__hint[data-takeover='true'] {
|
|
3229
|
+
color: #b7791f;
|
|
3230
|
+
}
|
|
3191
3231
|
.wa-composer__counter {
|
|
3192
3232
|
flex: 0 0 auto;
|
|
3193
3233
|
font-size: 10.5px;
|
|
@@ -4026,6 +4066,8 @@ function useThread({ fetcher, phone, refreshIntervalMs = DEFAULT_REFRESH_INTERVA
|
|
|
4026
4066
|
takenBy: thread.taken_by ?? null,
|
|
4027
4067
|
takenUntil: thread.taken_until ?? null,
|
|
4028
4068
|
takenByMe: thread.taken_by_me === true,
|
|
4069
|
+
takenAt: thread.taken_at ?? null,
|
|
4070
|
+
takenByRole: thread.taken_by_role ?? null,
|
|
4029
4071
|
status: messages.length > 0 ? "ready" : "empty",
|
|
4030
4072
|
error: null,
|
|
4031
4073
|
olderCursor: thread.older_cursor,
|
|
@@ -4043,6 +4085,8 @@ function useThread({ fetcher, phone, refreshIntervalMs = DEFAULT_REFRESH_INTERVA
|
|
|
4043
4085
|
takenBy: null,
|
|
4044
4086
|
takenUntil: null,
|
|
4045
4087
|
takenByMe: false,
|
|
4088
|
+
takenAt: null,
|
|
4089
|
+
takenByRole: null,
|
|
4046
4090
|
status: "error",
|
|
4047
4091
|
error: toError(cause),
|
|
4048
4092
|
olderCursor: null,
|
|
@@ -4161,6 +4205,8 @@ function useThread({ fetcher, phone, refreshIntervalMs = DEFAULT_REFRESH_INTERVA
|
|
|
4161
4205
|
takenBy: thread.taken_by ?? null,
|
|
4162
4206
|
takenUntil: thread.taken_until ?? null,
|
|
4163
4207
|
takenByMe: thread.taken_by_me === true,
|
|
4208
|
+
takenAt: thread.taken_at ?? null,
|
|
4209
|
+
takenByRole: thread.taken_by_role ?? null,
|
|
4164
4210
|
status: messages.length > 0 ? "ready" : "empty",
|
|
4165
4211
|
error: null
|
|
4166
4212
|
};
|
|
@@ -4194,6 +4240,8 @@ function useThread({ fetcher, phone, refreshIntervalMs = DEFAULT_REFRESH_INTERVA
|
|
|
4194
4240
|
takenBy: current?.takenBy ?? null,
|
|
4195
4241
|
takenUntil: current?.takenUntil ?? null,
|
|
4196
4242
|
takenByMe: current?.takenByMe ?? false,
|
|
4243
|
+
takenAt: current?.takenAt ?? null,
|
|
4244
|
+
takenByRole: current?.takenByRole ?? null,
|
|
4197
4245
|
hasOlder: current?.hasOlder ?? false,
|
|
4198
4246
|
loadOlder,
|
|
4199
4247
|
retry,
|
|
@@ -4236,7 +4284,36 @@ function takeoverCountdown(iso, now = Date.now()) {
|
|
|
4236
4284
|
if (Number.isNaN(until)) return null;
|
|
4237
4285
|
const left = until - now;
|
|
4238
4286
|
if (left <= 0) return null;
|
|
4239
|
-
|
|
4287
|
+
return formatMinutes(Math.max(1, Math.ceil(left / MINUTE)));
|
|
4288
|
+
}
|
|
4289
|
+
/**
|
|
4290
|
+
* Cuánto hace que se tomó la conversación (DEV-6309): «12 m», «1 h 5 m», o `null` si `taken_at`
|
|
4291
|
+
* no está o no parsea.
|
|
4292
|
+
*
|
|
4293
|
+
* Mismo formato corto que `takeoverCountdown` a propósito: la barra muestra uno u otro según lo
|
|
4294
|
+
* que mande el servidor, y dos formatos para la misma magnitud se leerían como dos datos
|
|
4295
|
+
* distintos. Se redondea hacia ABAJO (son minutos cumplidos) con piso de `1 m`: «0 m» se lee como
|
|
4296
|
+
* dato faltante, y un reloj del operador atrasado —que daría negativo— significa «recién».
|
|
4297
|
+
*/
|
|
4298
|
+
function takeoverElapsed(iso, now = Date.now()) {
|
|
4299
|
+
if (typeof iso !== "string") return null;
|
|
4300
|
+
const since = Date.parse(iso);
|
|
4301
|
+
if (Number.isNaN(since)) return null;
|
|
4302
|
+
return formatMinutes(Math.max(1, Math.floor((now - since) / MINUTE)));
|
|
4303
|
+
}
|
|
4304
|
+
/**
|
|
4305
|
+
* ¿La toma ya venció contra el reloj de quien mira? (DEV-6309)
|
|
4306
|
+
*
|
|
4307
|
+
* `true` SÓLO si `taken_until` es un instante válido y ya pasó. Ausente o basura NO es «vencida»:
|
|
4308
|
+
* es «no sé hasta cuándo», y ahí manda el `taken_by` del servidor — tratar un dato deforme como
|
|
4309
|
+
* vencimiento desbloquearía el composer sobre una conversación que alguien sí está atendiendo.
|
|
4310
|
+
*/
|
|
4311
|
+
function takeoverExpired(iso, now = Date.now()) {
|
|
4312
|
+
if (typeof iso !== "string") return false;
|
|
4313
|
+
const until = Date.parse(iso);
|
|
4314
|
+
return !Number.isNaN(until) && until <= now;
|
|
4315
|
+
}
|
|
4316
|
+
function formatMinutes(totalMinutes) {
|
|
4240
4317
|
const hours = Math.floor(totalMinutes / 60);
|
|
4241
4318
|
const minutes = totalMinutes % 60;
|
|
4242
4319
|
if (hours === 0) return `${minutes} m`;
|
|
@@ -4326,7 +4403,7 @@ function currentServiceState(messages) {
|
|
|
4326
4403
|
return null;
|
|
4327
4404
|
}
|
|
4328
4405
|
/**
|
|
4329
|
-
* La barra de takeover del hilo (DEV-5061).
|
|
4406
|
+
* La barra de takeover del hilo (DEV-5061, rediseñada para la toma ajena en DEV-6309).
|
|
4330
4407
|
*
|
|
4331
4408
|
* El problema que resuelve: el store ya guardaba quién tomó la conversación y el bot ya se callaba,
|
|
4332
4409
|
* pero nada de eso llegaba acá. Una conversación atendida por un compañero se veía **idéntica** a
|
|
@@ -4335,28 +4412,86 @@ function currentServiceState(messages) {
|
|
|
4335
4412
|
*
|
|
4336
4413
|
* Dos ramas, deliberadamente distintas:
|
|
4337
4414
|
*
|
|
4338
|
-
* - **La tomaste vos** — se ofrece «Reactivar bot», porque es tuya y podés soltarla.
|
|
4339
|
-
* -
|
|
4340
|
-
*
|
|
4341
|
-
*
|
|
4415
|
+
* - **La tomaste vos** — se ofrece «Reactivar bot», porque es tuya y podés soltarla. Igual que en
|
|
4416
|
+
* DEV-5061: DEV-6309 sólo la cambió de lugar.
|
|
4417
|
+
* - **La tiene otra persona** (DEV-6309) — barra ámbar «La tiene ‹nombre› (‹rol›) · ‹tiempo›» y el
|
|
4418
|
+
* composer BLOQUEADO. Escribir encima de un compañero pasa a ser una decisión explícita
|
|
4419
|
+
* («Escribir igual»), no un accidente: antes el composer dejaba escribir y el envío le robaba la
|
|
4420
|
+
* toma a su nombre sin que nadie lo hubiera decidido. El botón NO es «Reactivar bot»: soltar la
|
|
4421
|
+
* toma de otro sigue sin ofrecerse.
|
|
4342
4422
|
*
|
|
4343
4423
|
* `takenByMe` viene del SERVIDOR y no se deriva comparando `takenBy` con nadie: dos operadores
|
|
4344
4424
|
* pueden llamarse igual, y confundirlos es exactamente darle a uno el botón del otro.
|
|
4345
4425
|
*
|
|
4346
|
-
* El nombre
|
|
4426
|
+
* El nombre y el rol entran sólo como hijos de texto, que React escapa (T-03-02).
|
|
4347
4427
|
*/
|
|
4348
|
-
function TakeoverBar({ takenBy, takenUntil, takenByMe, composer }) {
|
|
4428
|
+
function TakeoverBar({ takenBy, takenUntil, takenByMe, takenAt, takenByRole, foreignLive, offerWriteAnyway, onWriteAnyway, composer }) {
|
|
4349
4429
|
if (composer.releaseState === "released") return null;
|
|
4350
4430
|
const left = takeoverCountdown(takenUntil);
|
|
4431
|
+
if (!takenByMe) {
|
|
4432
|
+
if (!foreignLive) return null;
|
|
4433
|
+
const role = typeof takenByRole === "string" ? takenByRole.trim() : "";
|
|
4434
|
+
const elapsed = takeoverElapsed(takenAt);
|
|
4435
|
+
const when = elapsed !== null ? elapsed : left !== null ? `se libera en ${left}` : null;
|
|
4436
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4437
|
+
className: "wa-thread__takeover",
|
|
4438
|
+
role: "status",
|
|
4439
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
4440
|
+
className: "wa-thread__takeover-text",
|
|
4441
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
4442
|
+
className: "wa-thread__takeover-icon",
|
|
4443
|
+
width: 14,
|
|
4444
|
+
height: 14,
|
|
4445
|
+
viewBox: "0 0 16 16",
|
|
4446
|
+
fill: "none",
|
|
4447
|
+
stroke: "currentColor",
|
|
4448
|
+
strokeWidth: 1.5,
|
|
4449
|
+
strokeLinecap: "round",
|
|
4450
|
+
strokeLinejoin: "round",
|
|
4451
|
+
"aria-hidden": "true",
|
|
4452
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
4453
|
+
cx: "8",
|
|
4454
|
+
cy: "5.5",
|
|
4455
|
+
r: "2.75"
|
|
4456
|
+
}), /* @__PURE__ */ jsx("path", { d: "M2.75 14c.6-2.6 2.7-4.25 5.25-4.25s4.65 1.65 5.25 4.25" })]
|
|
4457
|
+
}), /* @__PURE__ */ jsxs("span", { children: [
|
|
4458
|
+
"La tiene",
|
|
4459
|
+
" ",
|
|
4460
|
+
/* @__PURE__ */ jsxs("strong", { children: [takenBy ?? "otro operador", role !== "" && ` (${role})`] }),
|
|
4461
|
+
when !== null && ` · ${when}`
|
|
4462
|
+
] })]
|
|
4463
|
+
}), offerWriteAnyway && /* @__PURE__ */ jsxs("button", {
|
|
4464
|
+
type: "button",
|
|
4465
|
+
className: "wa-thread__takeover-button",
|
|
4466
|
+
onClick: onWriteAnyway,
|
|
4467
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
4468
|
+
width: 12,
|
|
4469
|
+
height: 12,
|
|
4470
|
+
viewBox: "0 0 16 16",
|
|
4471
|
+
fill: "none",
|
|
4472
|
+
stroke: "currentColor",
|
|
4473
|
+
strokeWidth: 1.5,
|
|
4474
|
+
strokeLinecap: "round",
|
|
4475
|
+
strokeLinejoin: "round",
|
|
4476
|
+
"aria-hidden": "true",
|
|
4477
|
+
children: /* @__PURE__ */ jsx("path", { d: "M11 2.5l2.5 2.5L5.5 13H3v-2.5z" })
|
|
4478
|
+
}), "Escribir igual"]
|
|
4479
|
+
})]
|
|
4480
|
+
});
|
|
4481
|
+
}
|
|
4351
4482
|
if (takenBy === null && left === null) return null;
|
|
4352
4483
|
return /* @__PURE__ */ jsxs("div", {
|
|
4353
4484
|
className: "wa-thread__takeover",
|
|
4354
|
-
"data-mine":
|
|
4485
|
+
"data-mine": "true",
|
|
4355
4486
|
role: "status",
|
|
4356
4487
|
children: [/* @__PURE__ */ jsxs("span", {
|
|
4357
4488
|
className: "wa-thread__takeover-text",
|
|
4358
|
-
children: [
|
|
4359
|
-
|
|
4489
|
+
children: [
|
|
4490
|
+
/* @__PURE__ */ jsx("strong", { children: "Bot en pausa" }),
|
|
4491
|
+
" — la tomaste tú",
|
|
4492
|
+
left !== null && ` · se libera en ${left}`
|
|
4493
|
+
]
|
|
4494
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
4360
4495
|
type: "button",
|
|
4361
4496
|
className: "wa-thread__takeover-button",
|
|
4362
4497
|
onClick: composer.release,
|
|
@@ -4365,8 +4500,17 @@ function TakeoverBar({ takenBy, takenUntil, takenByMe, composer }) {
|
|
|
4365
4500
|
})]
|
|
4366
4501
|
});
|
|
4367
4502
|
}
|
|
4503
|
+
/**
|
|
4504
|
+
* El primer nombre para el aviso del pie («Paula está atendiendo…», DEV-6309), como el diseño.
|
|
4505
|
+
* Partir por espacios puede quedarse corto con un nombre compuesto («María José» ⇒ «María»), y se
|
|
4506
|
+
* acepta: el nombre COMPLETO está en la barra, una línea más arriba. Sin nombre, un genérico.
|
|
4507
|
+
*/
|
|
4508
|
+
function firstName(takenBy) {
|
|
4509
|
+
const first = typeof takenBy === "string" ? takenBy.trim().split(/\s+/)[0] : "";
|
|
4510
|
+
return first !== void 0 && first !== "" ? first : "Otra persona";
|
|
4511
|
+
}
|
|
4368
4512
|
function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, className }) {
|
|
4369
|
-
const { messages: serverMessages, status, error, windowState, canReply, takenBy, takenUntil, takenByMe, hasOlder, loadOlder, retry, refresh } = useThread({
|
|
4513
|
+
const { messages: serverMessages, status, error, windowState, canReply, takenBy, takenUntil, takenByMe, takenAt, takenByRole, hasOlder, loadOlder, retry, refresh } = useThread({
|
|
4370
4514
|
fetcher,
|
|
4371
4515
|
phone,
|
|
4372
4516
|
refreshIntervalMs
|
|
@@ -4442,6 +4586,44 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, cl
|
|
|
4442
4586
|
* sola. La comparación es por identidad de objeto — son literalmente las mismas filas.
|
|
4443
4587
|
*/
|
|
4444
4588
|
const visible = messages.filter((message) => !isSuggestion(message) || message === suggestion.suggestion);
|
|
4589
|
+
/**
|
|
4590
|
+
* «Escribir igual» (DEV-6309): el operador eligió escribir encima de la toma de otra persona.
|
|
4591
|
+
*
|
|
4592
|
+
* Es estado LOCAL de este hilo y guarda **de qué consulta vino** (DEC-G, el patrón de
|
|
4593
|
+
* `useThread`/`useComposer`): cambiar de conversación lo invalida en el render mismo, sin un
|
|
4594
|
+
* efecto que lo resetee, y remontar lo pierde. Dura mientras esta conversación siga abierta:
|
|
4595
|
+
* volver a preguntarlo en cada latido sería un botón que se enciende solo cada 10 s.
|
|
4596
|
+
*
|
|
4597
|
+
* `focus` es una caja nueva por clic: el disparador del foco del composer (ver `focusRequest`).
|
|
4598
|
+
*/
|
|
4599
|
+
const [writeAnyway, setWriteAnyway] = useState(null);
|
|
4600
|
+
const unlocked = writeAnyway !== null && writeAnyway.fetcher === fetcher && writeAnyway.phone === phone;
|
|
4601
|
+
const handleWriteAnyway = useCallback(() => setWriteAnyway({
|
|
4602
|
+
fetcher,
|
|
4603
|
+
phone,
|
|
4604
|
+
focus: {}
|
|
4605
|
+
}), [fetcher, phone]);
|
|
4606
|
+
/**
|
|
4607
|
+
* ¿Hay una toma AJENA vigente? (DEV-6309) De esto dependen a la vez la barra ámbar, el bloqueo
|
|
4608
|
+
* del composer y el aviso del pie — por eso se decide una sola vez, acá.
|
|
4609
|
+
*
|
|
4610
|
+
* - `takenByMe` manda: si el servidor dice que es mía (p. ej. tras enviar), no hay nada ajeno.
|
|
4611
|
+
* - Recién liberada por este operador (`released`), el guard de siempre la tapa.
|
|
4612
|
+
* - Vencida contra el reloj de quien mira ⇒ ya no es de nadie: se va la barra y se desbloquea.
|
|
4613
|
+
* Ausente o basura NO es vencida (`takeoverExpired`).
|
|
4614
|
+
* - Con sólo el nombre o sólo el tiempo alcanza: media verdad sobre una toma sigue siendo mejor
|
|
4615
|
+
* que hacerla pasar por libre (DEV-5061).
|
|
4616
|
+
*
|
|
4617
|
+
* No hay timer para el vencimiento, igual que para la cuenta regresiva: se recalcula en cada
|
|
4618
|
+
* render, y el latido del hilo re-renderiza cada 10 s en producción.
|
|
4619
|
+
*/
|
|
4620
|
+
const foreignLive = !takenByMe && composer.releaseState !== "released" && !takeoverExpired(takenUntil) && (takenBy !== null || takeoverCountdown(takenUntil) !== null);
|
|
4621
|
+
/**
|
|
4622
|
+
* Hay dónde escribir: con `can_reply` y la ventana no cerrada. Con `closed` el panel frío
|
|
4623
|
+
* REEMPLAZA al composer (COMP-04), así que «Escribir igual» no tendría nada que desbloquear y no
|
|
4624
|
+
* se ofrece; el bloqueo por ventana sigue mandando.
|
|
4625
|
+
*/
|
|
4626
|
+
const hasComposer = canReply && composer.windowState !== "closed";
|
|
4445
4627
|
const messagesRef = useRef(null);
|
|
4446
4628
|
/** De qué consulta ya se hizo el scroll inicial: una vez por hilo, no en cada página. */
|
|
4447
4629
|
const scrolledForRef = useRef(null);
|
|
@@ -4540,12 +4722,6 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, cl
|
|
|
4540
4722
|
})
|
|
4541
4723
|
})]
|
|
4542
4724
|
}),
|
|
4543
|
-
/* @__PURE__ */ jsx(TakeoverBar, {
|
|
4544
|
-
takenBy,
|
|
4545
|
-
takenUntil,
|
|
4546
|
-
takenByMe,
|
|
4547
|
-
composer
|
|
4548
|
-
}),
|
|
4549
4725
|
/* @__PURE__ */ jsxs("div", {
|
|
4550
4726
|
className: "wa-thread__messages",
|
|
4551
4727
|
ref: messagesRef,
|
|
@@ -4581,11 +4757,25 @@ function ConversationThread({ fetcher, phone, displayName, refreshIntervalMs, cl
|
|
|
4581
4757
|
})] }, message.id ?? `sin-wamid-${position}`))]
|
|
4582
4758
|
}, group.key ?? `sin-dia-${groupIndex}`))]
|
|
4583
4759
|
}),
|
|
4760
|
+
/* @__PURE__ */ jsx(TakeoverBar, {
|
|
4761
|
+
takenBy,
|
|
4762
|
+
takenUntil,
|
|
4763
|
+
takenByMe,
|
|
4764
|
+
takenAt,
|
|
4765
|
+
takenByRole,
|
|
4766
|
+
foreignLive,
|
|
4767
|
+
offerWriteAnyway: hasComposer && !unlocked,
|
|
4768
|
+
onWriteAnyway: handleWriteAnyway,
|
|
4769
|
+
composer
|
|
4770
|
+
}),
|
|
4584
4771
|
/* @__PURE__ */ jsx(Composer, {
|
|
4585
4772
|
canReply,
|
|
4586
4773
|
composer,
|
|
4587
4774
|
onRetryWindow: retry,
|
|
4588
|
-
prefill
|
|
4775
|
+
prefill,
|
|
4776
|
+
locked: foreignLive && !unlocked,
|
|
4777
|
+
takeoverNotice: foreignLive && unlocked ? `${firstName(takenBy)} está atendiendo · el lifter verá a dos personas` : null,
|
|
4778
|
+
focusRequest: unlocked && writeAnyway !== null ? writeAnyway.focus : null
|
|
4589
4779
|
})
|
|
4590
4780
|
]
|
|
4591
4781
|
});
|
package/package.json
CHANGED