mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-23 23:54:13 +08:00
Update SearchSubscription to support basic multiaccount search... seems to work?
This commit is contained in:
parent
81bd78fb09
commit
864f808823
1 changed files with 15 additions and 9 deletions
|
@ -8,7 +8,7 @@ MutableQuerySubscription = require './flux/models/mutable-query-subscription'
|
|||
|
||||
class SearchSubscription extends MutableQuerySubscription
|
||||
|
||||
constructor: (@_terms, @_accountId) ->
|
||||
constructor: (@_terms, @_accountIds) ->
|
||||
super(null, {asResultSet: true})
|
||||
|
||||
@_version = 0
|
||||
|
@ -30,15 +30,21 @@ class SearchSubscription extends MutableQuerySubscription
|
|||
retrievePage: (idx) =>
|
||||
version = @_version += 1
|
||||
|
||||
requests = @_accountIds.map (aid) =>
|
||||
NylasAPI.makeRequest
|
||||
method: 'GET'
|
||||
path: "/threads/search?q=#{encodeURIComponent(@_terms)}"
|
||||
accountId: @_accountId
|
||||
accountId: aid
|
||||
json: true
|
||||
returnsModel: true
|
||||
.then (threads) =>
|
||||
|
||||
Promise.all(requests).then (resultArrays) =>
|
||||
return unless @_version is version
|
||||
query = DatabaseStore.findAll(Thread).where(id: _.pluck(threads, 'id'))
|
||||
resultIds = []
|
||||
for resultArray in resultArrays
|
||||
resultIds = resultIds.concat _.pluck(resultArray, 'id')
|
||||
|
||||
query = DatabaseStore.findAll(Thread).where(id: resultIds).order(Thread.attributes.lastMessageReceivedTimestamp.descending())
|
||||
@replaceQuery(query)
|
||||
|
||||
module.exports = SearchSubscription
|
||||
|
|
Loading…
Reference in a new issue