mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-14 00:24:33 +08:00
fix(attachments): fixes + specs for download on-receive
option
This commit is contained in:
parent
840b48c2df
commit
f1cd1056cc
3 changed files with 26 additions and 6 deletions
|
@ -3,6 +3,7 @@ path = require 'path'
|
||||||
{shell} = require 'electron'
|
{shell} = require 'electron'
|
||||||
NylasAPI = require '../../src/flux/nylas-api'
|
NylasAPI = require '../../src/flux/nylas-api'
|
||||||
File = require '../../src/flux/models/file'
|
File = require '../../src/flux/models/file'
|
||||||
|
Message = require '../../src/flux/models/message'
|
||||||
FileDownloadStore = require '../../src/flux/stores/file-download-store'
|
FileDownloadStore = require '../../src/flux/stores/file-download-store'
|
||||||
AccountStore = require '../../src/flux/stores/account-store'
|
AccountStore = require '../../src/flux/stores/account-store'
|
||||||
|
|
||||||
|
@ -112,6 +113,23 @@ describe "FileDownloadStore", ->
|
||||||
FileDownloadStore._checkForDownloadedFile(f).then (downloaded) ->
|
FileDownloadStore._checkForDownloadedFile(f).then (downloaded) ->
|
||||||
expect(downloaded).toBe(false)
|
expect(downloaded).toBe(false)
|
||||||
|
|
||||||
|
describe "_newMailReceived", ->
|
||||||
|
it "should fetch attachments if the setting is on-receive", ->
|
||||||
|
spyOn(FileDownloadStore, '_fetch')
|
||||||
|
spyOn(NylasEnv.config, 'get').andCallFake (key) ->
|
||||||
|
return 'on-receive' if key is 'core.attachments.downloadPolicy'
|
||||||
|
return null
|
||||||
|
FileDownloadStore._newMailReceived(message: [new Message(files: [new File()])])
|
||||||
|
expect(FileDownloadStore._fetch).toHaveBeenCalled()
|
||||||
|
|
||||||
|
it "should not fetch attachments otherwise", ->
|
||||||
|
spyOn(FileDownloadStore, '_fetch')
|
||||||
|
spyOn(NylasEnv.config, 'get').andCallFake (key) ->
|
||||||
|
return 'on-read' if key is 'core.attachments.downloadPolicy'
|
||||||
|
return null
|
||||||
|
FileDownloadStore._newMailReceived(message: [new Message(files: [new File()])])
|
||||||
|
expect(FileDownloadStore._fetch).not.toHaveBeenCalled()
|
||||||
|
|
||||||
describe "_runDownload", ->
|
describe "_runDownload", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
spyOn(FileDownloadStore.Download.prototype, 'run').andCallFake -> Promise.resolve(@)
|
spyOn(FileDownloadStore.Download.prototype, 'run').andCallFake -> Promise.resolve(@)
|
||||||
|
|
|
@ -140,9 +140,9 @@ FileDownloadStore = Reflux.createStore
|
||||||
|
|
||||||
########### PRIVATE ####################################################
|
########### PRIVATE ####################################################
|
||||||
|
|
||||||
_newMailReceived: (incoming) =>
|
_newMailReceived: (incoming) ->
|
||||||
return unless NylasEnv.config.get('core.attachments.downloadPolicy') is 'on-receive'
|
if NylasEnv.config.get('core.attachments.downloadPolicy') is 'on-receive'
|
||||||
for message in incoming
|
for message in incoming['message']
|
||||||
for file in message.files
|
for file in message.files
|
||||||
@_fetch(file)
|
@_fetch(file)
|
||||||
|
|
||||||
|
|
|
@ -259,7 +259,9 @@ class MessageStore extends NylasStore
|
||||||
startedAFetch
|
startedAFetch
|
||||||
|
|
||||||
_fetchExpandedAttachments: (items) ->
|
_fetchExpandedAttachments: (items) ->
|
||||||
return unless NylasEnv.config.get('core.attachments.downloadPolicy') is 'on-read'
|
policy = NylasEnv.config.get('core.attachments.downloadPolicy')
|
||||||
|
return if policy is 'manually'
|
||||||
|
|
||||||
for item in items
|
for item in items
|
||||||
continue unless @_itemsExpanded[item.id]
|
continue unless @_itemsExpanded[item.id]
|
||||||
for file in item.files
|
for file in item.files
|
||||||
|
|
Loading…
Add table
Reference in a new issue