diff --git a/packages/client-app/spec/stores/draft-factory-spec.es6 b/packages/client-app/spec/stores/draft-factory-spec.es6
index ee9f57f97..56d9b1cdf 100644
--- a/packages/client-app/spec/stores/draft-factory-spec.es6
+++ b/packages/client-app/spec/stores/draft-factory-spec.es6
@@ -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");
});
});
});
diff --git a/packages/client-app/src/flux/stores/draft-factory.coffee b/packages/client-app/src/flux/stores/draft-factory.coffee
index 442ab3576..0efba8271 100644
--- a/packages/client-app/src/flux/stores/draft-factory.coffee
+++ b/packages/client-app/src/flux/stores/draft-factory.coffee
@@ -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
#{body}
"""
- )
+ ).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']