@adatechnology/meta-whatsapp-module 0.2.0-rc.5 → 0.2.0-rc.6
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/index.cjs +31 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -341,17 +341,46 @@ var SessionRepository = class {
|
|
|
341
341
|
currentState: sessions.currentState,
|
|
342
342
|
lastActivity: sessions.lastActivity,
|
|
343
343
|
lastInboundAt: sessions.lastInboundAt,
|
|
344
|
-
humanRequestedAt: sessions.humanRequestedAt
|
|
344
|
+
humanRequestedAt: sessions.humanRequestedAt,
|
|
345
|
+
// Prévia e contagem saem de subquery correlacionada em vez de N+1 na volta: uma inbox
|
|
346
|
+
// lista dezenas de conversas por página, e uma query por linha é o gargalo clássico
|
|
347
|
+
// dessa tela. Ambos os campos são dados do próprio módulo — deixá-los para o host
|
|
348
|
+
// obrigaria todo consumidor a reescrever o mesmo join contra tabelas que não são dele.
|
|
349
|
+
lastContent: import_drizzle_orm2.sql`(
|
|
350
|
+
select m.content from ${messages} m
|
|
351
|
+
where m.company_id = ${sessions.companyId} and m.session_id = ${sessions.id}
|
|
352
|
+
order by m.created_at desc limit 1
|
|
353
|
+
)`,
|
|
354
|
+
lastDirection: import_drizzle_orm2.sql`(
|
|
355
|
+
select m.direction from ${messages} m
|
|
356
|
+
where m.company_id = ${sessions.companyId} and m.session_id = ${sessions.id}
|
|
357
|
+
order by m.created_at desc limit 1
|
|
358
|
+
)`,
|
|
359
|
+
// Entradas do cliente depois da última leitura do atendente. Sessão nunca lida conta
|
|
360
|
+
// tudo — é o comportamento esperado de uma conversa que ninguém abriu ainda.
|
|
361
|
+
unread: import_drizzle_orm2.sql`(
|
|
362
|
+
select count(*)::int from ${messages} m
|
|
363
|
+
where m.company_id = ${sessions.companyId}
|
|
364
|
+
and m.session_id = ${sessions.id}
|
|
365
|
+
and m.direction = 'inbound'
|
|
366
|
+
and (${sessions.lastAgentReadAt} is null or m.created_at > ${sessions.lastAgentReadAt})
|
|
367
|
+
)`
|
|
345
368
|
}).from(sessions).where((0, import_drizzle_orm2.and)(...conditions)).orderBy((0, import_drizzle_orm2.desc)(sessions.lastActivity)).limit(limit).offset(offset);
|
|
346
369
|
return rows.map((row) => ({
|
|
347
370
|
id: row.id,
|
|
348
371
|
whatsappNumber: row.whatsappNumber,
|
|
372
|
+
...row.lastContent !== null ? {
|
|
373
|
+
lastContent: row.lastContent
|
|
374
|
+
} : {},
|
|
375
|
+
...row.lastDirection !== null ? {
|
|
376
|
+
lastDirection: row.lastDirection
|
|
377
|
+
} : {},
|
|
349
378
|
lastAt: row.lastActivity.toISOString(),
|
|
350
379
|
lastInboundAt: row.lastInboundAt?.toISOString() ?? null,
|
|
351
380
|
mode: row.mode,
|
|
352
381
|
assignedUserId: row.assignedUserId,
|
|
353
382
|
waitingHuman: row.humanRequestedAt !== null,
|
|
354
|
-
unread:
|
|
383
|
+
unread: Number(row.unread),
|
|
355
384
|
currentState: row.currentState
|
|
356
385
|
}));
|
|
357
386
|
}
|