mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-10 10:11:25 +08:00
1339ef19d3
Summary: This diff fixes T3389 and makes it possible to define mail views which are not based on a category and focus them in the app. I think that we need to create a new index on the starred attribute to make sure the query runs fast. More tests WIP Test Plan: Run tests, more coming soon! Reviewers: dillon, evan Reviewed By: evan Maniphest Tasks: T3389 Differential Revision: https://phab.nylas.com/D1979
89 lines
2.6 KiB
CoffeeScript
89 lines
2.6 KiB
CoffeeScript
NylasStore = require 'nylas-store'
|
|
_ = require 'underscore'
|
|
{CategoryStore,
|
|
DatabaseStore,
|
|
CategoryStore,
|
|
AccountStore,
|
|
WorkspaceStore,
|
|
DraftCountStore,
|
|
Actions,
|
|
Label,
|
|
Folder,
|
|
Message,
|
|
MailViewFilter,
|
|
FocusedMailViewStore,
|
|
NylasAPI,
|
|
Thread} = require 'nylas-exports'
|
|
|
|
class AccountSidebarStore extends NylasStore
|
|
constructor: ->
|
|
@_sections = []
|
|
@_registerListeners()
|
|
@_refreshSections()
|
|
|
|
########### PUBLIC #####################################################
|
|
|
|
sections: ->
|
|
@_sections
|
|
|
|
selected: ->
|
|
if WorkspaceStore.rootSheet() is WorkspaceStore.Sheet.Threads
|
|
FocusedMailViewStore.mailView()
|
|
else
|
|
WorkspaceStore.rootSheet()
|
|
|
|
########### PRIVATE ####################################################
|
|
|
|
_registerListeners: ->
|
|
@listenTo CategoryStore, @_refreshSections
|
|
@listenTo WorkspaceStore, @_refreshSections
|
|
@listenTo DraftCountStore, @_refreshSections
|
|
@listenTo FocusedMailViewStore, => @trigger()
|
|
|
|
_refreshSections: =>
|
|
account = AccountStore.current()
|
|
return unless account
|
|
|
|
viewFilterForCategory = (cat) ->
|
|
return MailViewFilter.forCategory(cat)
|
|
|
|
userCategories = CategoryStore.getUserCategories()
|
|
userCategoryViews = _.map(userCategories, viewFilterForCategory)
|
|
|
|
# Our drafts are displayed via the `DraftListSidebarItem` which
|
|
# is loading into the `Drafts` Sheet.
|
|
standardCategories = CategoryStore.getStandardCategories()
|
|
standardCategories = _.reject standardCategories, (category) =>
|
|
category.name is "drafts"
|
|
|
|
standardViews = _.map(standardCategories, viewFilterForCategory)
|
|
standardViews.push(WorkspaceStore.Sheet["Drafts"])
|
|
|
|
starredView = MailViewFilter.forStarred()
|
|
standardViews.splice(1, 0, starredView)
|
|
|
|
# Find root views, add the Views section
|
|
# featureSheets = _.filter WorkspaceStore.Sheet, (sheet) ->
|
|
# sheet.name in ['Today']
|
|
# extraSheets = _.filter WorkspaceStore.Sheet, (sheet) ->
|
|
# sheet.root and sheet.name and not (sheet in featureSheets)
|
|
|
|
@_sections = []
|
|
# if featureSheets.length > 0
|
|
# @_sections.push { label: '', items: featureSheets, type: 'sheet' }
|
|
@_sections.push
|
|
label: 'Mailboxes'
|
|
items: standardViews
|
|
type: 'mailboxes'
|
|
# @_sections.push { label: 'Views', items: extraSheets, type: 'sheet' }
|
|
@_sections.push
|
|
label: CategoryStore.categoryLabel()
|
|
items: userCategoryViews
|
|
type: 'category'
|
|
|
|
@trigger()
|
|
|
|
_isStandardCategory: (category) =>
|
|
category.name and category.name in CategoryStore.standardCategories
|
|
|
|
module.exports = new AccountSidebarStore()
|