Minimal support for importing chat histories in Chub format

Fix crasher in script.js:displayChats if user has directly put a Chub chat file into their user data

Let eslint tidy a few things
This commit is contained in:
ceruleandeep
2024-09-19 14:18:15 +10:00
parent 83c3f6d1bf
commit a2d9526cdf
2 changed files with 64 additions and 23 deletions

View File

@ -6923,15 +6923,13 @@ export async function displayPastChats() {
}
// Check whether `text` {string} includes all of the `fragments` {string[]}.
function matchFragments(fragments, text) {
if (!text) {
return false;
}
return fragments.every(item => text.includes(item));
if (!text || !text.toLowerCase) return false;
return fragments.every(item => text.toLowerCase().includes(item));
}
const fragments = makeQueryFragments(searchQuery);
// At least one chat message must match *all* the fragments.
// Currently, this doesn't match if the fragment matches are distributed across several chat messages.
return chatContent && Object.values(chatContent).some(message => matchFragments(fragments, message?.mes?.toLowerCase()));
return chatContent && Object.values(chatContent).some(message => matchFragments(fragments, message?.mes));
});
console.debug(filteredData);