fix(category): Consolidate logic around "archive" vs" all"

This commit is contained in:
Ben Gotow 2015-10-21 11:36:23 -07:00
parent b963688455
commit 392ba542b1
5 changed files with 51 additions and 43 deletions

View file

@ -110,7 +110,6 @@ class ThreadList extends React.Component
attachment = <div className="thread-icon thread-icon-attachment"></div>
currentCategoryId = FocusedMailViewStore.mailView()?.categoryId()
allCategoryId = CategoryStore.getStandardCategory('all')?.id
ignoredIds = [currentCategoryId]
ignoredIds.push(cat.id) for cat in CategoryStore.getHiddenCategories()
@ -265,7 +264,7 @@ class ThreadList extends React.Component
return unless ThreadListStore.view()
focused = FocusedContentStore.focused('thread')
if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
threads = [focused]
else if ThreadListStore.view().selection.count() > 0

View file

@ -53,24 +53,29 @@ class Account extends Model
name: @name
email: @emailAddress
# Public: The current organization_unit used by the account.
usesLabels: -> @organizationUnit is "label"
usesFolders: -> @organizationUnit is "folder"
usesLabels: ->
@organizationUnit is "label"
usesFolders: ->
@organizationUnit is "folder"
categoryClass: ->
if @usesLabels()
return require './label'
else
else if @usesFolders()
return require './folder'
else
return null
# Public: Returns the localized, properly capitalized provider name,
# like Gmail, Exchange, or Outlook 365
displayProvider: ->
if @provider is 'eas'
return 'Exchange'
if @provider is 'gmail'
else if @provider is 'gmail'
return 'Gmail'
return @provider
else
return @provider
usesImportantFlag: ->
@provider is 'gmail'

View file

@ -58,17 +58,15 @@ class CategoryStore extends NylasStore
return "Folders"
else if account.usesLabels()
return "Labels"
return "Unknown"
else
return "Unknown"
# Public: Returns {Folder} or {Label}, depending on the current provider.
#
categoryClass: ->
account = AccountStore.current()
return null unless account
if account.usesFolders()
return Folder
else if account.usesLabels()
return Label
return null
return account.categoryClass()
# 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
@ -85,6 +83,24 @@ class CategoryStore extends NylasStore
throw new Error("'#{name}' is not a standard category")
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.
#
getStandardCategories: ->

View file

@ -46,19 +46,19 @@ class TaskFactory
labelsToAdd: labelsToAdd
taskForArchiving: ({threads, fromView}) ->
category = @_archiveCategory()
category = CategoryStore.getArchiveCategory()
@taskForApplyingCategory({threads, fromView, category, exclusive: true})
taskForUnarchiving: ({threads, fromView}) ->
category = @_archiveCategory()
category = CategoryStore.getArchiveCategory()
@taskForRemovingCategory({threads, fromView, category, exclusive: true})
taskForMovingToTrash: ({threads, fromView}) ->
category = CategoryStore.getStandardCategory("trash")
category = CategoryStore.getTrashCategory()
@taskForApplyingCategory({threads, fromView, category, exclusive: true})
taskForMovingFromTrash: ({threads, fromView}) ->
category = CategoryStore.getStandardCategory("trash")
category = CategoryStore.getTrashCategory()
@taskForRemovingCategory({threads, fromView, category, exclusive: true})
taskForInvertingUnread: ({threads}) ->
@ -69,11 +69,4 @@ class TaskFactory
starred = _.every threads, (t) -> _.isMatch(t, {starred: false})
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

View file

@ -48,16 +48,19 @@ class MailViewFilter
canApplyToThreads: ->
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) ->
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
constructor: (@searchQuery) ->
@
@ -96,12 +99,6 @@ class StarredMailViewFilter extends MailViewFilter
canApplyToThreads: ->
true
canArchiveThreads: ->
true
canTrashThreads: ->
true
applyToThreads: (threadsOrIds) ->
ChangeStarredTask = require './flux/tasks/change-starred-task'
task = new ChangeStarredTask({threads:threadsOrIds, starred: true})
@ -139,13 +136,11 @@ class CategoryMailViewFilter extends MailViewFilter
canArchiveThreads: ->
return false if @category.name in ["archive", "all", "sent"]
return false if @category.displayName is atom.config.get("core.archiveFolder")
return false unless CategoryStore.getStandardCategory("archive")
return true
super
canTrashThreads: ->
return false if @category.name in ["trash"]
return true
super
applyToThreads: (threadsOrIds) ->
if AccountStore.current().usesLabels()