Fix handling of recent group chats if empty Fixes #4022
| @@ -372,12 +372,26 @@ export async function getChatInfo(pathToFile, additionalData = {}, isGroup = fal | ||
| 372 | 372 | const stats = await fs.promises.stat(pathToFile); |
| 373 | 373 | const fileSizeInKB = `${(stats.size / 1024).toFixed(2)}kb`; |
| 374 | 374 | |
| 375 | 375 | ifconst (stats.sizechatData === 0) { |
| 376 | + file_name: path.parse(pathToFile).base, | |
| 377 | + file_size: fileSizeInKB, | |
| 378 | + chat_items: 0, | |
| 379 | + mes: '[The chat is empty]', | |
| 380 | + last_mes: stats.mtimeMs, | |
| 381 | + ...additionalData, | |
| 382 | + }; | |
| 383 | + | |
| 384 | + if (stats.size === 0 && !isGroup) { | |
| 376 | 385 | console.warn(`Found an empty chat file: ${pathToFile}`); |
| 377 | 386 | res({}); |
| 378 | 387 | return; |
| 379 | 388 | } |
| 380 | 389 | |
| 390 | + if (stats.size === 0 && isGroup) { | |
| 391 | + res(chatData); | |
| 392 | + return; | |
| 393 | + } | |
| 394 | + | |
| 381 | 395 | const rl = readline.createInterface({ |
| 382 | 396 | input: fileStream, |
| 383 | 397 | crlfDelay: Infinity, |
| @@ -395,14 +409,9 @@ export async function getChatInfo(pathToFile, additionalData = {}, isGroup = fal | ||
| 395 | 409 | if (lastLine) { |
| 396 | 410 | const jsonData = tryParse(lastLine); |
| 397 | 411 | if (jsonData && (jsonData.name || jsonData.character_name)) { |
| 398 | - const chatData = {}; | |
| 412 | + chatData.chat_items = isGroup ? itemCounter : (itemCounter - 1); | |
| 399 | - | |
| 413 | + chatData.mes = jsonData['mes'] || '[The chat is empty]'; | |
| 400 | 414 | chatData.last_mes = jsonData['file_namesend_date'] =|| path.parse(pathToFile)stats.basemtimeMs; |
| 401 | - chatData['file_size'] = fileSizeInKB; | |
| 402 | - chatData['chat_items'] = isGroup ? itemCounter : (itemCounter - 1); | |
| 403 | - chatData['mes'] = jsonData['mes'] || '[The chat is empty]'; | |
| 404 | - chatData['last_mes'] = jsonData['send_date'] || stats.mtimeMs; | |
| 405 | - Object.assign(chatData, additionalData); | |
| 406 | 415 | |
| 407 | 416 | res(chatData); |
| 408 | 417 | } else { |