mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-10 14:44:52 +08:00
fix(category): Consolidate logic around "archive" vs" all"
This commit is contained in:
parent
b963688455
commit
392ba542b1
5 changed files with 51 additions and 43 deletions
|
@ -110,7 +110,6 @@ class ThreadList extends React.Component
|
||||||
attachment = <div className="thread-icon thread-icon-attachment"></div>
|
attachment = <div className="thread-icon thread-icon-attachment"></div>
|
||||||
|
|
||||||
currentCategoryId = FocusedMailViewStore.mailView()?.categoryId()
|
currentCategoryId = FocusedMailViewStore.mailView()?.categoryId()
|
||||||
allCategoryId = CategoryStore.getStandardCategory('all')?.id
|
|
||||||
|
|
||||||
ignoredIds = [currentCategoryId]
|
ignoredIds = [currentCategoryId]
|
||||||
ignoredIds.push(cat.id) for cat in CategoryStore.getHiddenCategories()
|
ignoredIds.push(cat.id) for cat in CategoryStore.getHiddenCategories()
|
||||||
|
@ -265,7 +264,7 @@ class ThreadList extends React.Component
|
||||||
return unless ThreadListStore.view()
|
return unless ThreadListStore.view()
|
||||||
|
|
||||||
focused = FocusedContentStore.focused('thread')
|
focused = FocusedContentStore.focused('thread')
|
||||||
|
|
||||||
if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
|
if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
|
||||||
threads = [focused]
|
threads = [focused]
|
||||||
else if ThreadListStore.view().selection.count() > 0
|
else if ThreadListStore.view().selection.count() > 0
|
||||||
|
|
|
@ -53,24 +53,29 @@ class Account extends Model
|
||||||
name: @name
|
name: @name
|
||||||
email: @emailAddress
|
email: @emailAddress
|
||||||
|
|
||||||
# Public: The current organization_unit used by the account.
|
usesLabels: ->
|
||||||
usesLabels: -> @organizationUnit is "label"
|
@organizationUnit is "label"
|
||||||
usesFolders: -> @organizationUnit is "folder"
|
|
||||||
|
usesFolders: ->
|
||||||
|
@organizationUnit is "folder"
|
||||||
|
|
||||||
categoryClass: ->
|
categoryClass: ->
|
||||||
if @usesLabels()
|
if @usesLabels()
|
||||||
return require './label'
|
return require './label'
|
||||||
else
|
else if @usesFolders()
|
||||||
return require './folder'
|
return require './folder'
|
||||||
|
else
|
||||||
|
return null
|
||||||
|
|
||||||
# Public: Returns the localized, properly capitalized provider name,
|
# Public: Returns the localized, properly capitalized provider name,
|
||||||
# like Gmail, Exchange, or Outlook 365
|
# like Gmail, Exchange, or Outlook 365
|
||||||
displayProvider: ->
|
displayProvider: ->
|
||||||
if @provider is 'eas'
|
if @provider is 'eas'
|
||||||
return 'Exchange'
|
return 'Exchange'
|
||||||
if @provider is 'gmail'
|
else if @provider is 'gmail'
|
||||||
return 'Gmail'
|
return 'Gmail'
|
||||||
return @provider
|
else
|
||||||
|
return @provider
|
||||||
|
|
||||||
usesImportantFlag: ->
|
usesImportantFlag: ->
|
||||||
@provider is 'gmail'
|
@provider is 'gmail'
|
||||||
|
|
|
@ -58,17 +58,15 @@ class CategoryStore extends NylasStore
|
||||||
return "Folders"
|
return "Folders"
|
||||||
else if account.usesLabels()
|
else if account.usesLabels()
|
||||||
return "Labels"
|
return "Labels"
|
||||||
return "Unknown"
|
else
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
# Public: Returns {Folder} or {Label}, depending on the current provider.
|
||||||
|
#
|
||||||
categoryClass: ->
|
categoryClass: ->
|
||||||
account = AccountStore.current()
|
account = AccountStore.current()
|
||||||
return null unless account
|
return null unless account
|
||||||
|
return account.categoryClass()
|
||||||
if account.usesFolders()
|
|
||||||
return Folder
|
|
||||||
else if account.usesLabels()
|
|
||||||
return Label
|
|
||||||
return null
|
|
||||||
|
|
||||||
# Public: Returns an array of all the categories in the current account, both
|
# Public: Returns an array of all the categories in the current account, both
|
||||||
# standard and user generated. The items returned by this function will be
|
# standard and user generated. The items returned by this function will be
|
||||||
|
@ -85,6 +83,24 @@ class CategoryStore extends NylasStore
|
||||||
throw new Error("'#{name}' is not a standard category")
|
throw new Error("'#{name}' is not a standard category")
|
||||||
return _.findWhere @_categoryCache, {name}
|
return _.findWhere @_categoryCache, {name}
|
||||||
|
|
||||||
|
# Public: Returns the Folder or Label object that should be used for "Archive"
|
||||||
|
# actions. On Gmail, this is the "all" label. On providers using folders, it
|
||||||
|
# returns any available "Archive" folder, or null if no such folder exists.
|
||||||
|
#
|
||||||
|
getArchiveCategory: ->
|
||||||
|
account = AccountStore.current()
|
||||||
|
return null unless account
|
||||||
|
if account.usesFolders()
|
||||||
|
return @getStandardCategory("archive")
|
||||||
|
else
|
||||||
|
return @getStandardCategory("all")
|
||||||
|
|
||||||
|
# Public: Returns the Folder or Label object taht should be used for
|
||||||
|
# "Move to Trash", or null if no trash folder exists.
|
||||||
|
#
|
||||||
|
getTrashCategory: ->
|
||||||
|
@getStandardCategory("trash")
|
||||||
|
|
||||||
# Public: Returns all of the standard categories for the current account.
|
# Public: Returns all of the standard categories for the current account.
|
||||||
#
|
#
|
||||||
getStandardCategories: ->
|
getStandardCategories: ->
|
||||||
|
|
|
@ -46,19 +46,19 @@ class TaskFactory
|
||||||
labelsToAdd: labelsToAdd
|
labelsToAdd: labelsToAdd
|
||||||
|
|
||||||
taskForArchiving: ({threads, fromView}) ->
|
taskForArchiving: ({threads, fromView}) ->
|
||||||
category = @_archiveCategory()
|
category = CategoryStore.getArchiveCategory()
|
||||||
@taskForApplyingCategory({threads, fromView, category, exclusive: true})
|
@taskForApplyingCategory({threads, fromView, category, exclusive: true})
|
||||||
|
|
||||||
taskForUnarchiving: ({threads, fromView}) ->
|
taskForUnarchiving: ({threads, fromView}) ->
|
||||||
category = @_archiveCategory()
|
category = CategoryStore.getArchiveCategory()
|
||||||
@taskForRemovingCategory({threads, fromView, category, exclusive: true})
|
@taskForRemovingCategory({threads, fromView, category, exclusive: true})
|
||||||
|
|
||||||
taskForMovingToTrash: ({threads, fromView}) ->
|
taskForMovingToTrash: ({threads, fromView}) ->
|
||||||
category = CategoryStore.getStandardCategory("trash")
|
category = CategoryStore.getTrashCategory()
|
||||||
@taskForApplyingCategory({threads, fromView, category, exclusive: true})
|
@taskForApplyingCategory({threads, fromView, category, exclusive: true})
|
||||||
|
|
||||||
taskForMovingFromTrash: ({threads, fromView}) ->
|
taskForMovingFromTrash: ({threads, fromView}) ->
|
||||||
category = CategoryStore.getStandardCategory("trash")
|
category = CategoryStore.getTrashCategory()
|
||||||
@taskForRemovingCategory({threads, fromView, category, exclusive: true})
|
@taskForRemovingCategory({threads, fromView, category, exclusive: true})
|
||||||
|
|
||||||
taskForInvertingUnread: ({threads}) ->
|
taskForInvertingUnread: ({threads}) ->
|
||||||
|
@ -69,11 +69,4 @@ class TaskFactory
|
||||||
starred = _.every threads, (t) -> _.isMatch(t, {starred: false})
|
starred = _.every threads, (t) -> _.isMatch(t, {starred: false})
|
||||||
return new ChangeStarredTask({threads, starred})
|
return new ChangeStarredTask({threads, starred})
|
||||||
|
|
||||||
_archiveCategory: (account) ->
|
|
||||||
account = AccountStore.current()
|
|
||||||
if account.usesFolders()
|
|
||||||
return CategoryStore.getStandardCategory("archive")
|
|
||||||
else
|
|
||||||
return CategoryStore.getStandardCategory("all")
|
|
||||||
|
|
||||||
module.exports = new TaskFactory
|
module.exports = new TaskFactory
|
||||||
|
|
|
@ -48,16 +48,19 @@ class MailViewFilter
|
||||||
canApplyToThreads: ->
|
canApplyToThreads: ->
|
||||||
throw new Error("canApplyToThreads: Not implemented in base class.")
|
throw new Error("canApplyToThreads: Not implemented in base class.")
|
||||||
|
|
||||||
# Whether or not the current MailViewFilter can "archive" or "trash"
|
|
||||||
canArchiveThreads: ->
|
|
||||||
throw new Error("canArchiveThreads: Not implemented in base class.")
|
|
||||||
|
|
||||||
canTrashThreads: ->
|
|
||||||
throw new Error("canTrashThreads: Not implemented in base class.")
|
|
||||||
|
|
||||||
applyToThreads: (threadsOrIds) ->
|
applyToThreads: (threadsOrIds) ->
|
||||||
throw new Error("applyToThreads: Not implemented in base class.")
|
throw new Error("applyToThreads: Not implemented in base class.")
|
||||||
|
|
||||||
|
# Whether or not the current MailViewFilter can "archive" or "trash"
|
||||||
|
# Subclasses should call `super` if they override these methods
|
||||||
|
canArchiveThreads: ->
|
||||||
|
return false unless CategoryStore.getArchiveCategory()
|
||||||
|
return true
|
||||||
|
|
||||||
|
canTrashThreads: ->
|
||||||
|
return false unless CategoryStore.getTrashCategory()
|
||||||
|
return true
|
||||||
|
|
||||||
class SearchMailViewFilter extends MailViewFilter
|
class SearchMailViewFilter extends MailViewFilter
|
||||||
constructor: (@searchQuery) ->
|
constructor: (@searchQuery) ->
|
||||||
@
|
@
|
||||||
|
@ -96,12 +99,6 @@ class StarredMailViewFilter extends MailViewFilter
|
||||||
canApplyToThreads: ->
|
canApplyToThreads: ->
|
||||||
true
|
true
|
||||||
|
|
||||||
canArchiveThreads: ->
|
|
||||||
true
|
|
||||||
|
|
||||||
canTrashThreads: ->
|
|
||||||
true
|
|
||||||
|
|
||||||
applyToThreads: (threadsOrIds) ->
|
applyToThreads: (threadsOrIds) ->
|
||||||
ChangeStarredTask = require './flux/tasks/change-starred-task'
|
ChangeStarredTask = require './flux/tasks/change-starred-task'
|
||||||
task = new ChangeStarredTask({threads:threadsOrIds, starred: true})
|
task = new ChangeStarredTask({threads:threadsOrIds, starred: true})
|
||||||
|
@ -139,13 +136,11 @@ class CategoryMailViewFilter extends MailViewFilter
|
||||||
|
|
||||||
canArchiveThreads: ->
|
canArchiveThreads: ->
|
||||||
return false if @category.name in ["archive", "all", "sent"]
|
return false if @category.name in ["archive", "all", "sent"]
|
||||||
return false if @category.displayName is atom.config.get("core.archiveFolder")
|
super
|
||||||
return false unless CategoryStore.getStandardCategory("archive")
|
|
||||||
return true
|
|
||||||
|
|
||||||
canTrashThreads: ->
|
canTrashThreads: ->
|
||||||
return false if @category.name in ["trash"]
|
return false if @category.name in ["trash"]
|
||||||
return true
|
super
|
||||||
|
|
||||||
applyToThreads: (threadsOrIds) ->
|
applyToThreads: (threadsOrIds) ->
|
||||||
if AccountStore.current().usesLabels()
|
if AccountStore.current().usesLabels()
|
||||||
|
|
Loading…
Add table
Reference in a new issue