mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-09 01:35:52 +08:00
[client-app] Ensure files get transferred in forwarded messages
Summary: We need to download the files and then treat them as uploads. Rather than using an actual Upload object, which would require another data transfer, we create an object with all the necessary Upload-like properties and point it to the downloaded file. Addresses part of T7960 Test Plan: Manual, some specs Reviewers: evan, spang, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D4249
This commit is contained in:
parent
3e3b0b84f1
commit
470e6563ec
2 changed files with 43 additions and 6 deletions
|
@ -9,6 +9,7 @@ import {
|
|||
DraftStore,
|
||||
AccountStore,
|
||||
DatabaseStore,
|
||||
FileDownloadStore,
|
||||
DatabaseTransaction,
|
||||
SanitizeTransformer,
|
||||
InlineStyleTransformer,
|
||||
|
@ -24,14 +25,30 @@ let fakeMessageWithFiles = null;
|
|||
let msgWithReplyToDuplicates = null;
|
||||
let msgWithReplyToFromMe = null;
|
||||
let account = null;
|
||||
const downloadData = {}
|
||||
|
||||
describe('DraftFactory', function draftFactory() {
|
||||
beforeEach(() => {
|
||||
// Out of the scope of these specs
|
||||
spyOn(InlineStyleTransformer, 'run').andCallFake((input) => Promise.resolve(input));
|
||||
spyOn(SanitizeTransformer, 'run').andCallFake((input) => Promise.resolve(input));
|
||||
spyOn(FileDownloadStore, 'downloadDataForFile').andCallFake((fid) => {
|
||||
return downloadData[fid]
|
||||
});
|
||||
|
||||
account = AccountStore.accounts()[0];
|
||||
const files = [
|
||||
new File({filename: "test.jpg", accountId: account.id}),
|
||||
new File({filename: "test.pdj", accountId: account.id}),
|
||||
];
|
||||
files.forEach((file) => {
|
||||
downloadData[file.id] = {
|
||||
fileId: file.id,
|
||||
filename: file.filename,
|
||||
targetPath: file.filename,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
fakeThread = new Thread({
|
||||
id: 'fake-thread-id',
|
||||
|
@ -59,7 +76,7 @@ describe('DraftFactory', function draftFactory() {
|
|||
cc: [new Contact({email: 'mg@nylas.com'}), account.me()],
|
||||
bcc: [new Contact({email: 'recruiting@nylas.com'})],
|
||||
from: [new Contact({email: 'customer@example.com', name: 'Customer'})],
|
||||
files: [new File({filename: "test.jpg"}), new File({filename: "test.pdj"})],
|
||||
files: files,
|
||||
threadId: 'fake-thread-id',
|
||||
body: 'Fake Message 1',
|
||||
subject: 'Fake Subject',
|
||||
|
@ -368,11 +385,12 @@ describe('DraftFactory', function draftFactory() {
|
|||
expect(SanitizeTransformer.run).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should include the attached files", () => {
|
||||
it("should include the attached files as uploads", () => {
|
||||
waitsForPromise(() => {
|
||||
return DraftFactory.createDraftForForward({thread: fakeThread, message: fakeMessageWithFiles}).then((draft) => {
|
||||
expect(draft.files.length).toBe(2);
|
||||
expect(draft.files[0].filename).toBe("test.jpg");
|
||||
expect(draft.uploads.length).toBe(2);
|
||||
expect(draft.uploads[0].filename).toBe("test.jpg");
|
||||
expect(draft.uploads[1].filename).toBe("test.pdj");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
_ = require 'underscore'
|
||||
path = require 'path'
|
||||
|
||||
{FileDownloadStore} = require 'nylas-exports'
|
||||
|
||||
Actions = require('../actions').default
|
||||
DatabaseStore = require('./database-store').default
|
||||
|
@ -119,6 +122,9 @@ class DraftFactory
|
|||
)
|
||||
|
||||
createDraftForForward: ({thread, message}) =>
|
||||
# Start downloading the attachments, if they haven't been already
|
||||
message.files.forEach((f) => Actions.fetchFile(f))
|
||||
|
||||
contactsAsHtml = (cs) ->
|
||||
DOMUtils.escapeHTMLCharacters(_.invoke(cs, "toString").join(", "))
|
||||
fields = []
|
||||
|
@ -131,7 +137,6 @@ class DraftFactory
|
|||
DraftHelpers.prepareBodyForQuoting(message.body).then (body) =>
|
||||
@createDraft(
|
||||
subject: subjectWithPrefix(message.subject, 'Fwd:')
|
||||
files: [].concat(message.files),
|
||||
from: [@_fromContactForReply(message)],
|
||||
threadId: thread.id,
|
||||
accountId: message.accountId,
|
||||
|
@ -145,7 +150,21 @@ class DraftFactory
|
|||
<br><br>
|
||||
#{body}
|
||||
</div>"""
|
||||
)
|
||||
).then (draft) =>
|
||||
draft.uploads = message.files.map((f) =>
|
||||
{fileId, filename, filesize, targetPath} = FileDownloadStore.downloadDataForFile(f.id)
|
||||
# Return an object that can act as an Upload instance.
|
||||
return (
|
||||
messageClientId: draft.clientId,
|
||||
id: fileId,
|
||||
filename: filename,
|
||||
size: filesize,
|
||||
targetPath: targetPath,
|
||||
targetDir: path.dirname(targetPath)
|
||||
)
|
||||
)
|
||||
return draft
|
||||
|
||||
|
||||
candidateDraftForUpdating: (message, behavior) =>
|
||||
if behavior not in ['prefer-existing-if-pristine', 'prefer-existing']
|
||||
|
|
Loading…
Reference in a new issue