diff --git a/public/script.js b/public/script.js index 9e6600ff4..b9a1c0b69 100644 --- a/public/script.js +++ b/public/script.js @@ -3210,13 +3210,13 @@ async function displayPastChats() { if (mes.length > strlen) { mes = "..." + mes.substring(mes.length - strlen); } - + const chat_items = data[key]["chat_items"]; const file_size = data[key]["file_size"]; const fileName = data[key]['file_name']; const template = $('#past_chat_template .select_chat_block_wrapper').clone(); template.find('.select_chat_block').attr('file_name', fileName); template.find('.avatar img').attr('src', avatarImg); - template.find('.select_chat_block_filename').text(fileName + " (" + file_size + ")"); + template.find('.select_chat_block_filename').text(fileName + " (" + file_size + ") (" + chat_items + " messages)"); template.find('.select_chat_block_mes').text(mes); template.find('.PastChat_cross').attr('file_name', fileName); diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 0480d115f..3ea7b9881 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -1123,8 +1123,14 @@ export async function getGroupPastChats(groupId) { for (const chatId of group.chats) { const messages = await loadGroupChat(chatId); let this_chat_file_size = (JSON.stringify(messages).length / 1024).toFixed(2) + "kb"; + let chat_items = messages.length; const lastMessage = messages.length ? messages[messages.length - 1].mes : '[The chat is empty]'; - chats.push({ 'file_name': chatId, 'mes': lastMessage, 'file_size': this_chat_file_size }); + chats.push({ + 'file_name': chatId, + 'mes': lastMessage, + 'file_size': this_chat_file_size, + 'chat_items': chat_items, + }); } } catch (err) { console.error(err); diff --git a/server.js b/server.js index 74893b5b0..f1d8dec63 100644 --- a/server.js +++ b/server.js @@ -1401,7 +1401,7 @@ app.post("/getallchatsofcharacter", jsonParser, function (request, response) { const stats = fs.statSync(fullPathAndFile); const fileSizeInKB = (stats.size / 1024).toFixed(2) + "kb"; - console.log(fileSizeInKB); + //console.log(fileSizeInKB); const rl = readline.createInterface({ input: fileStream, @@ -1409,25 +1409,29 @@ app.post("/getallchatsofcharacter", jsonParser, function (request, response) { }); let lastLine; + let itemCounter = 0; rl.on('line', (line) => { + itemCounter++; lastLine = line; }); rl.on('close', () => { ii--; if (lastLine) { + let jsonData = json5.parse(lastLine); if (jsonData.name !== undefined || jsonData.character_name !== undefined) { chatData[i] = {}; chatData[i]['file_name'] = file; chatData[i]['file_size'] = fileSizeInKB; + chatData[i]['chat_items'] = itemCounter - 1; chatData[i]['mes'] = jsonData['mes'] || '[The chat is empty]'; } } if (ii === 0) { - console.log('ii count went to zero, responding with chatData'); + //console.log('ii count went to zero, responding with chatData'); response.send(chatData); } - console.log('successfully closing getallchatsofcharacter'); + //console.log('successfully closing getallchatsofcharacter'); rl.close(); }); };