Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,11 @@ export default {
required: true,
},

isDraft: {
type: Boolean,
default: false,
},

requestMdn: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -1329,7 +1334,12 @@ export default {

onEditorReady(editor) {
this.bodyVal = editor.getData()
this.insertSignature()

// Only append signature on opening drafts if alias changed.
// Otherwise leads to unwanted or even duplicate signatures.
if (!this.isDraft || this.changeSignature) {
this.insertSignature()
}
if (this.smartReply) {
this.bus.emit('append-to-body-at-cursor', this.smartReply)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/NewMessageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
:smime-sign="composerData.smimeSign"
:smime-encrypt="composerData.smimeEncrypt"
:is-first-open="modalFirstOpen"
:is-draft="composerData.draftId !== undefined"
:request-mdn="composerData.requestMdn"
:accounts="accounts"
@update:from-account="patchComposerData({ accountId: $event })"
Expand Down
82 changes: 82 additions & 0 deletions src/tests/unit/components/Composer.vue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,86 @@ describe('Composer', () => {
search: 'alice',
})).toEqual(true)
})

it('inserts the signature when composing a new message', () => {
const view = shallowMount(Composer, {
propsData: {
isFirstOpen: true,
isDraft: false,
accounts: [
{
id: 123,
editorMode: 'plaintext',
isUnified: false,
aliases: [],
},
],
},
mocks: {
$route,
},
store,
localVue,
})
const insertSignature = vi.spyOn(view.vm, 'insertSignature').mockImplementation(() => {})

view.vm.onEditorReady({ getData: () => '' })

expect(insertSignature).toHaveBeenCalled()
})

it('does not insert the signature when opening a draft', () => {
const view = shallowMount(Composer, {
propsData: {
isFirstOpen: true,
isDraft: true,
accounts: [
{
id: 123,
editorMode: 'plaintext',
isUnified: false,
aliases: [],
},
],
},
mocks: {
$route,
},
store,
localVue,
})
const insertSignature = vi.spyOn(view.vm, 'insertSignature').mockImplementation(() => {})

view.vm.onEditorReady({ getData: () => '' })

expect(insertSignature).not.toHaveBeenCalled()
})

it('inserts the signature on alias change even when opening a draft', () => {
const view = shallowMount(Composer, {
propsData: {
isFirstOpen: true,
isDraft: true,
accounts: [
{
id: 123,
editorMode: 'plaintext',
isUnified: false,
aliases: [],
},
],
},
mocks: {
$route,
},
store,
localVue,
})
const insertSignature = vi.spyOn(view.vm, 'insertSignature').mockImplementation(() => {})
view.vm.changeSignature = true

view.vm.onEditorReady({ getData: () => '' })

expect(insertSignature).toHaveBeenCalled()
})
})
Loading