@runnerpro/backend 1.3.12 → 1.4.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.
|
@@ -240,6 +240,7 @@ const readMessage = (req, res, { query, isClient }) => __awaiter(void 0, void 0,
|
|
|
240
240
|
const markReadMessage = ({ isClient, query, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
241
241
|
const conditionSender = isClient ? ' AND [ID SENDER] != ?' : ' AND [ID SENDER] = ?';
|
|
242
242
|
yield query('UPDATE [CHAT MESSAGE] SET [READ] = TRUE WHERE [ID CLIENTE] = ? AND [READ] = FALSE ' + conditionSender, [idCliente, idCliente]);
|
|
243
|
+
yield saveResponseTime({ query, isClient, idCliente });
|
|
243
244
|
});
|
|
244
245
|
const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
246
|
if (mimetype.includes('webp'))
|
|
@@ -280,3 +281,29 @@ const readFeelings = (req, res, { query, isClient }) => __awaiter(void 0, void 0
|
|
|
280
281
|
}
|
|
281
282
|
res.send({ status: 'ok' });
|
|
282
283
|
});
|
|
284
|
+
const saveResponseTime = ({ query, isClient, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
285
|
+
if (isClient)
|
|
286
|
+
return;
|
|
287
|
+
let lastNotReadMessage;
|
|
288
|
+
let firstNotReadMessage;
|
|
289
|
+
// eslint-disable-next-line no-constant-condition
|
|
290
|
+
while (true) {
|
|
291
|
+
const [lastMessage] = yield query(`
|
|
292
|
+
SELECT * FROM [CHAT MESSAGE]
|
|
293
|
+
WHERE [ID CLIENTE] = ? AND [ID] < ?
|
|
294
|
+
ORDER BY [DATE] DESC
|
|
295
|
+
LIMIT 1
|
|
296
|
+
`, [idCliente, (lastNotReadMessage === null || lastNotReadMessage === void 0 ? void 0 : lastNotReadMessage.id) || 2147483646]);
|
|
297
|
+
// Si no hay más mensajes || el mensaje no es del cliente || ya tiene tiempo de respuesta => salimos del bucle
|
|
298
|
+
if (!lastMessage || (lastMessage.idSender && lastMessage.idCliente !== lastMessage.idSender) || lastMessage.tiempoRespuesta)
|
|
299
|
+
break;
|
|
300
|
+
lastNotReadMessage = lastMessage; // Se va actualizando el último mensaje no leído hasta que se encuentra el primero
|
|
301
|
+
if (!firstNotReadMessage)
|
|
302
|
+
firstNotReadMessage = lastMessage; // Se guarda el primer mensaje no leído para añadir en este el tiempo de respuesta
|
|
303
|
+
}
|
|
304
|
+
if (!lastNotReadMessage)
|
|
305
|
+
return;
|
|
306
|
+
// @ts-ignore
|
|
307
|
+
const responseTime = Math.floor((new Date() - new Date(lastNotReadMessage.date)) / 1000);
|
|
308
|
+
yield query('UPDATE [CHAT MESSAGE] SET [TIEMPO RESPUESTA] = ? WHERE [ID] = ?', [responseTime, firstNotReadMessage.id]);
|
|
309
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAmBpD,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAmBpD,CAAC;AAkSF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|