2016-04-11 06:58:23 +08:00
|
|
|
import _ from 'underscore'
|
|
|
|
import {AccountStore, TaskFactory, MailboxPerspective} from 'nylas-exports'
|
|
|
|
import SearchQuerySubscription from './search-query-subscription'
|
|
|
|
|
|
|
|
|
|
|
|
class SearchMailboxPerspective extends MailboxPerspective {
|
|
|
|
|
|
|
|
constructor(accountIds, searchQuery) {
|
|
|
|
super(accountIds)
|
|
|
|
this.searchQuery = searchQuery
|
|
|
|
this.name = 'Search'
|
|
|
|
|
|
|
|
if (!_.isString(this.searchQuery)) {
|
|
|
|
throw new Error("SearchMailboxPerspective: Expected a `string` search query")
|
|
|
|
}
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
emptyMessage() {
|
|
|
|
return "No search results available"
|
|
|
|
}
|
|
|
|
|
|
|
|
isEqual(other) {
|
|
|
|
return super.isEqual(other) && other.searchQuery === this.searchQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
threads() {
|
|
|
|
return new SearchQuerySubscription(this.searchQuery, this.accountIds)
|
|
|
|
}
|
|
|
|
|
|
|
|
canReceiveThreadsFromAccountIds() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
tasksForRemovingItems(threads) {
|
2016-04-14 04:40:42 +08:00
|
|
|
return TaskFactory.tasksForApplyingCategories({
|
2016-04-11 06:58:23 +08:00
|
|
|
threads: threads,
|
|
|
|
categoriesToAdd: (accountId) => {
|
|
|
|
const account = AccountStore.accountForId(accountId)
|
|
|
|
return [account.defaultFinishedCategory()]
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SearchMailboxPerspective;
|