mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-24 08:04:11 +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
|
class SearchSubscription extends MutableQuerySubscription
|
||||||
|
|
||||||
constructor: (@_terms, @_accountId) ->
|
constructor: (@_terms, @_accountIds) ->
|
||||||
super(null, {asResultSet: true})
|
super(null, {asResultSet: true})
|
||||||
|
|
||||||
@_version = 0
|
@_version = 0
|
||||||
|
@ -30,15 +30,21 @@ class SearchSubscription extends MutableQuerySubscription
|
||||||
retrievePage: (idx) =>
|
retrievePage: (idx) =>
|
||||||
version = @_version += 1
|
version = @_version += 1
|
||||||
|
|
||||||
|
requests = @_accountIds.map (aid) =>
|
||||||
NylasAPI.makeRequest
|
NylasAPI.makeRequest
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
path: "/threads/search?q=#{encodeURIComponent(@_terms)}"
|
path: "/threads/search?q=#{encodeURIComponent(@_terms)}"
|
||||||
accountId: @_accountId
|
accountId: aid
|
||||||
json: true
|
json: true
|
||||||
returnsModel: true
|
returnsModel: true
|
||||||
.then (threads) =>
|
|
||||||
|
Promise.all(requests).then (resultArrays) =>
|
||||||
return unless @_version is version
|
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)
|
@replaceQuery(query)
|
||||||
|
|
||||||
module.exports = SearchSubscription
|
module.exports = SearchSubscription
|
||||||
|
|
Loading…
Reference in a new issue