-
Notifications
You must be signed in to change notification settings - Fork 102
fix: allow same-name staged attachments #1950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Bilb
merged 3 commits into
session-foundation:dev
from
Ap4sh:fix-staged-attachments-same-name
Jul 23, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
215 changes: 215 additions & 0 deletions
215
ts/test/session/unit/staged_attachments/StagedAttachments_test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| import { expect } from 'chai'; | ||
| import Sinon from 'sinon'; | ||
|
|
||
| import { | ||
| addStagedAttachmentsInConversation, | ||
| getEmptyStagedAttachmentsState, | ||
| reducer, | ||
| removeStagedAttachmentInConversation, | ||
| } from '../../../../state/ducks/stagedAttachments'; | ||
| import type { StagedAttachmentType } from '../../../../components/conversation/composition/CompositionBox'; | ||
|
|
||
| const conversationKey = 'conversation-key'; | ||
|
|
||
| function makeAttachment({ | ||
| stagedAttachmentId, | ||
| fileName, | ||
| url = '', | ||
| videoUrl, | ||
| isVoiceMessage = false, | ||
| }: { | ||
| stagedAttachmentId: string; | ||
| fileName: string; | ||
| url?: string; | ||
| videoUrl?: string; | ||
| isVoiceMessage?: boolean; | ||
| }): StagedAttachmentType { | ||
| return { | ||
| stagedAttachmentId, | ||
| file: {} as File, | ||
| contentType: 'image/jpeg', | ||
| fileName, | ||
| url, | ||
| videoUrl, | ||
| fileSize: null, | ||
| isVoiceMessage, | ||
| screenshot: null, | ||
| thumbnail: null, | ||
| }; | ||
| } | ||
|
|
||
| describe('state/ducks/stagedAttachments', () => { | ||
| beforeEach(() => { | ||
| (global as any).window = { | ||
| log: { | ||
| warn: Sinon.stub(), | ||
| }, | ||
| }; | ||
|
Comment on lines
+43
to
+47
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be |
||
|
|
||
| if (!URL.revokeObjectURL) { | ||
| URL.revokeObjectURL = () => undefined; | ||
| } | ||
|
|
||
| Sinon.stub(URL, 'revokeObjectURL'); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| Sinon.restore(); | ||
| delete (global as any).window; | ||
| }); | ||
|
|
||
| it('keeps staged attachments with the same filename when their staged ids differ', () => { | ||
| const first = makeAttachment({ | ||
| stagedAttachmentId: 'first', | ||
| fileName: 'image.jpg', | ||
| url: 'blob:first', | ||
| }); | ||
| const second = makeAttachment({ | ||
| stagedAttachmentId: 'second', | ||
| fileName: 'image.jpg', | ||
| url: 'blob:second', | ||
| }); | ||
|
|
||
| const state = reducer( | ||
| getEmptyStagedAttachmentsState(), | ||
| addStagedAttachmentsInConversation({ | ||
| conversationKey, | ||
| newAttachments: [first, second], | ||
| }) | ||
| ); | ||
|
|
||
| expect(state.stagedAttachments[conversationKey].map(attachment => attachment.url)).to.deep.eq([ | ||
| 'blob:first', | ||
| 'blob:second', | ||
| ]); | ||
| }); | ||
|
|
||
| it('removes only the staged attachment matching the staged id', () => { | ||
| const first = makeAttachment({ | ||
| stagedAttachmentId: 'first', | ||
| fileName: 'image.jpg', | ||
| url: 'blob:first', | ||
| }); | ||
| const second = makeAttachment({ | ||
| stagedAttachmentId: 'second', | ||
| fileName: 'image.jpg', | ||
| url: 'blob:second', | ||
| videoUrl: 'blob:second-video', | ||
| }); | ||
|
|
||
| const stateWithAttachments = reducer( | ||
| getEmptyStagedAttachmentsState(), | ||
| addStagedAttachmentsInConversation({ | ||
| conversationKey, | ||
| newAttachments: [first, second], | ||
| }) | ||
| ); | ||
|
|
||
| const state = reducer( | ||
| stateWithAttachments, | ||
| removeStagedAttachmentInConversation({ | ||
| conversationKey, | ||
| stagedAttachmentId: 'second', | ||
| }) | ||
| ); | ||
|
|
||
| const revokedUrls = (URL.revokeObjectURL as Sinon.SinonStub) | ||
| .getCalls() | ||
| .map(call => call.args[0]); | ||
|
|
||
| expect( | ||
| state.stagedAttachments[conversationKey].map(attachment => attachment.stagedAttachmentId) | ||
| ).to.deep.eq(['first']); | ||
| expect(revokedUrls).to.deep.eq(['blob:second', 'blob:second-video']); | ||
| }); | ||
|
|
||
| it('does not add a voice message with another staged attachment', () => { | ||
| const currentAttachment = makeAttachment({ | ||
| stagedAttachmentId: 'current', | ||
| fileName: 'image.jpg', | ||
| }); | ||
| const voiceAttachment = makeAttachment({ | ||
| stagedAttachmentId: 'voice', | ||
| fileName: 'session-audio-message', | ||
| isVoiceMessage: true, | ||
| }); | ||
|
|
||
| const stateWithAttachment = reducer( | ||
| getEmptyStagedAttachmentsState(), | ||
| addStagedAttachmentsInConversation({ | ||
| conversationKey, | ||
| newAttachments: [currentAttachment], | ||
| }) | ||
| ); | ||
|
|
||
| const state = reducer( | ||
| stateWithAttachment, | ||
| addStagedAttachmentsInConversation({ | ||
| conversationKey, | ||
| newAttachments: [voiceAttachment], | ||
| }) | ||
| ); | ||
|
|
||
| expect( | ||
| state.stagedAttachments[conversationKey].map(attachment => attachment.stagedAttachmentId) | ||
| ).to.deep.eq(['current']); | ||
| expect((global as any).window.log.warn.calledOnce).to.eq(true); | ||
| }); | ||
|
|
||
| it('does not add multiple voice messages at once', () => { | ||
| const firstVoiceAttachment = makeAttachment({ | ||
| stagedAttachmentId: 'first-voice', | ||
| fileName: 'session-audio-message', | ||
| isVoiceMessage: true, | ||
| }); | ||
| const secondVoiceAttachment = makeAttachment({ | ||
| stagedAttachmentId: 'second-voice', | ||
| fileName: 'session-audio-message', | ||
| isVoiceMessage: true, | ||
| }); | ||
|
|
||
| const state = reducer( | ||
| getEmptyStagedAttachmentsState(), | ||
| addStagedAttachmentsInConversation({ | ||
| conversationKey, | ||
| newAttachments: [firstVoiceAttachment, secondVoiceAttachment], | ||
| }) | ||
| ); | ||
|
|
||
| expect(state.stagedAttachments[conversationKey]).to.eq(undefined); | ||
| expect((global as any).window.log.warn.calledOnce).to.eq(true); | ||
| }); | ||
|
|
||
| it('does not add another attachment when a voice message is already staged', () => { | ||
| const voiceAttachment = makeAttachment({ | ||
| stagedAttachmentId: 'voice', | ||
| fileName: 'session-audio-message', | ||
| isVoiceMessage: true, | ||
| }); | ||
| const nextAttachment = makeAttachment({ | ||
| stagedAttachmentId: 'next', | ||
| fileName: 'image.jpg', | ||
| }); | ||
|
|
||
| const stateWithVoiceMessage = reducer( | ||
| getEmptyStagedAttachmentsState(), | ||
| addStagedAttachmentsInConversation({ | ||
| conversationKey, | ||
| newAttachments: [voiceAttachment], | ||
| }) | ||
| ); | ||
|
|
||
| const state = reducer( | ||
| stateWithVoiceMessage, | ||
| addStagedAttachmentsInConversation({ | ||
| conversationKey, | ||
| newAttachments: [nextAttachment], | ||
| }) | ||
| ); | ||
|
|
||
| expect( | ||
| state.stagedAttachments[conversationKey].map(attachment => attachment.stagedAttachmentId) | ||
| ).to.deep.eq(['voice']); | ||
| expect((global as any).window.log.warn.calledOnce).to.eq(true); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.