Some users experience their chats being nuked on load. This is most likely a concurrency issue when an emptied chat is being saved before it could be loaded from a server. The solution is plain and dumb: generate an integrity token, save it to the metadata, and check the token with the already saved file. If tokens mismatch, we cancel the save but give an option to overwrite.
I'm not too happy with putting a config toggle to backups section, but there isn't just a generic "Chat settings" section there, since it's all UI.
Out of scope: groups.
Copilot summary
This pull request includes several changes to improve the chat backup functionality and enhance the integrity check process. The most important changes include adding an integrity check for chat backups, updating the saveChat function to support additional options, and ensuring that the integrity metadata is included during chat loading and saving.
Improvements to chat backup functionality:
default/config.yaml: Added a new configuration option checkIntegrity to enable integrity checks before saving chat files.
src/endpoints/chats.js: Introduced a function checkChatIntegrity to verify the integrity of chat files before saving and updated the chat saving endpoint to use this function. [1][2]
Enhancements to chat saving process:
public/script.js: Updated the saveChat function to accept an options object, including a force parameter to override the integrity check if necessary. Added JSDoc comments for better documentation. [1][2]
public/script.js: Ensured that integrity metadata is included when loading chats by generating a UUID if it is missing.
Some users experience their chats being nuked on load. This is most likely a concurrency issue when an emptied chat is being saved before it could be loaded from a server. The solution is plain and dumb: generate an integrity token, save it to the metadata, and check the token with the already saved file. If tokens mismatch, we cancel the save but give an option to overwrite.
I'm not too happy with putting a config toggle to backups section, but there isn't just a generic "Chat settings" section there, since it's all UI.
Out of scope: groups.
Copilot summary
This pull request includes several changes to improve the chat backup functionality and enhance the integrity check process. The most important changes include adding an integrity check for chat backups, updating the
saveChat
function to support additional options, and ensuring that the integrity metadata is included during chat loading and saving.Improvements to chat backup functionality:
default/config.yaml
: Added a new configuration optioncheckIntegrity
to enable integrity checks before saving chat files.src/endpoints/chats.js
: Introduced a functioncheckChatIntegrity
to verify the integrity of chat files before saving and updated the chat saving endpoint to use this function. [1] [2]Enhancements to chat saving process:
public/script.js
: Updated thesaveChat
function to accept an options object, including aforce
parameter to override the integrity check if necessary. Added JSDoc comments for better documentation. [1] [2]public/script.js
: Ensured that integrity metadata is included when loading chats by generating a UUID if it is missing.Refactoring for consistency:
public/scripts/bookmarks.js
: Modified calls tosaveChat
to use the new options object format. [1] [2]Checklist: