feat(desktop): SHA-256 dedup of image attachments + inline dup notice#3123
Open
HUQIANTAO wants to merge 1 commit into
Open
feat(desktop): SHA-256 dedup of image attachments + inline dup notice#3123HUQIANTAO wants to merge 1 commit into
HUQIANTAO wants to merge 1 commit into
Conversation
The composer's image paste/drop handlers were naive: drop the same file twice (or paste the same clipboard twice) and you'd get two chips, two @path references in the message, and the kernel would process the same image twice. The user expectation is one chip. Add lib/attachDedup.ts: a small SHA-256 helper (via Web Crypto Subtle) and a DedupIndex that lives for the composer's lifetime. The index is hash-keyed when crypto.subtle is available, path-keyed as a fallback when it isn't (a weaker dedup — same content from two different paths won't match — but the common 'dropped the same file twice' case is covered). The dedup check runs BEFORE the data-URL round-trip in attachImageFiles; a duplicate paste of a 5MB photo skips the encoding step entirely. The kernel's SavePastedImage and AttachmentDataURL are only called for the first occurrence. A small inline 'X already attached' note fades in next to the attachment chips when a paste/drops was a duplicate, so the user understands why their second paste didn't add a second chip. The note clears after 2.2s. The index resets automatically when the composer unmounts, which happens on newSession() in App — so a new session starts with a fresh palette, matching the user's mental model.
75f3eb2 to
b56033e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The composer's image paste/drop handlers were naive: drop the same file twice and you'd get two chips, two @path references, and the kernel would process the same image twice.
Add
lib/attachDedup.ts: a small SHA-256 helper (via Web Crypto Subtle) and aDedupIndexthat lives for the composer's lifetime. The index is hash-keyed when crypto.subtle is available, path-keyed as a fallback when it isn't.The dedup check runs BEFORE the data-URL round-trip; a duplicate paste of a 5MB photo skips the encoding step entirely. A small inline 'X already attached' note fades in next to the chips when a paste was a duplicate.