Mailspring/packages/client-app/internal_packages/thread-search/lib/search-mailbox-perspective.es6
Ben Gotow 8348bb210c Revert "[client-app] Measure and report times for removing from inbox"
This reverts commit 90e49d31aa.

# Conflicts:
#	packages/client-app/src/flux/actions.es6
#	packages/client-app/src/flux/stores/thread-list-actions-store.es6
2017-06-23 16:10:15 -07:00

64 lines
1.9 KiB
JavaScript

import _ from 'underscore'
import {AccountStore, CategoryStore, TaskFactory, MailboxPerspective} from 'nylas-exports'
import SearchQuerySubscription from './search-query-subscription'
class SearchMailboxPerspective extends MailboxPerspective {
constructor(sourcePerspective, searchQuery) {
super(sourcePerspective.accountIds)
if (!_.isString(searchQuery)) {
throw new Error("SearchMailboxPerspective: Expected a `string` search query")
}
this.searchQuery = searchQuery;
if (sourcePerspective instanceof SearchMailboxPerspective) {
this.sourcePerspective = sourcePerspective.sourcePerspective;
} else {
this.sourcePerspective = sourcePerspective;
}
this.name = `Searching ${this.sourcePerspective.name}`
}
_folderScope() {
// When the inbox is focused we don't specify a folder scope. If the user
// wants to search just the inbox then they have to specify it explicitly.
if (this.sourcePerspective.isInbox()) {
return '';
}
const folderQuery = this.sourcePerspective.categories().map((c) => c.displayName).join('" OR in:"');
return `AND (in:"${folderQuery}")`;
}
emptyMessage() {
return "No search results available"
}
isEqual(other) {
return super.isEqual(other) && other.searchQuery === this.searchQuery
}
threads() {
return new SearchQuerySubscription(`(${this.searchQuery}) ${this._folderScope()}`, this.accountIds)
}
canReceiveThreadsFromAccountIds() {
return false
}
tasksForRemovingItems(threads) {
return TaskFactory.tasksForApplyingCategories({
source: "Dragged Out of List",
threads: threads,
categoriesToAdd: (accountId) => {
const account = AccountStore.accountForId(accountId)
return [account.defaultFinishedCategory()]
},
categoriesToRemove: (accountId) => {
return [CategoryStore.getInboxCategory(accountId)]
},
})
}
}
export default SearchMailboxPerspective;