mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 16:26:08 +08:00
8f2211f6a0
Summary: This diff uses the new ?expanded=true threads request to fetch threads and the messages inside them at the same time. The messages from this endpoint don't contain bodies. Message bodies have been moved to a new "secondary attribute" type, which can be optionally requested when making queries. This allows us to 1) quickly fetch messages without worrying about MBs of JSON, 2) update messages without updating their bodies, and 3) avoid calls to /messages?thread_id=123. The new message store fetches just the items it wants to display in expanded mode, and we'll show snippets for the rest. Fix up forwarded message Approach: Thread.messageMetadata join approach WIP join approach complete "" || null = null. OMG. Make spinner a bit smarter, use code delays and not css delays Search suggestion store should only show first 10 matches Msg collapsing, refactored msg store that will fetch individual messages that are marked as expanded, set loaded = true when it's all done Test Plan: Tests coming soon. The query refactoring here broke a lot of tests... Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1345
99 lines
2.5 KiB
CoffeeScript
99 lines
2.5 KiB
CoffeeScript
Reflux = require 'reflux'
|
|
{DatabaseStore, Actions, Contact} = require 'inbox-exports'
|
|
_ = require 'underscore-plus'
|
|
|
|
# Stores should closely match the needs of a particular part of the front end.
|
|
# For example, we might create a "MessageStore" that observes this store
|
|
# for changes in selectedThread, "DatabaseStore" for changes to the underlying database,
|
|
# and vends up the array used for that view.
|
|
|
|
SearchSuggestionStore = Reflux.createStore
|
|
init: ->
|
|
@_all = []
|
|
@_suggestions = []
|
|
@_searchConstants = {"from": 4, "subject": 2}
|
|
@_query = ""
|
|
@_committedQuery = ""
|
|
|
|
@listenTo Actions.searchConstantsChanged, @onSearchConstantsChanged
|
|
@listenTo Actions.searchQueryChanged, @onSearchQueryChanged
|
|
@listenTo Actions.searchQueryCommitted, @onSearchQueryCommitted
|
|
@listenTo Actions.searchBlurred, @onSearchBlurred
|
|
@listenTo DatabaseStore, @onDataChanged
|
|
@onDataChanged()
|
|
|
|
onDataChanged: (change) ->
|
|
return if change && change.objectClass != Contact.name
|
|
DatabaseStore.findAll(Contact).then (contacts) =>
|
|
@_all = contacts
|
|
@repopulate()
|
|
|
|
onSearchQueryChanged: (query) ->
|
|
@_query = query
|
|
@repopulate()
|
|
|
|
onSearchConstantsChanged: (constants) ->
|
|
@_searchConstants = constants
|
|
@trigger()
|
|
Actions.searchQueryCommitted(@_query)
|
|
|
|
onSearchQueryCommitted: (query) ->
|
|
@_query = query
|
|
@_committedQuery = query
|
|
@_suggestions = []
|
|
@trigger()
|
|
|
|
onSearchBlurred: ->
|
|
@_suggestions = []
|
|
@trigger()
|
|
|
|
repopulate: ->
|
|
@_suggestions = []
|
|
term = @_query?[0]
|
|
return @trigger(@) unless term
|
|
|
|
key = Object.keys(term)[0]
|
|
val = term[key]?.toLowerCase()
|
|
return @trigger(@) unless val
|
|
|
|
contactResults = []
|
|
for contact in @_all
|
|
if contact.name?.toLowerCase().indexOf(val) == 0 or contact.email?.toLowerCase().indexOf(val) == 0
|
|
contactResults.push(contact)
|
|
if contactResults.length is 10
|
|
break
|
|
|
|
@_suggestions.push
|
|
label: "Message Contains: #{val}"
|
|
value: [{"all": val}]
|
|
|
|
if contactResults.length
|
|
@_suggestions.push
|
|
divider: 'People'
|
|
|
|
_.each contactResults, (contact) =>
|
|
if contact.name
|
|
label = "#{contact.name} <#{contact.email}>"
|
|
else
|
|
label = contact.email
|
|
|
|
@_suggestions.push
|
|
label: label
|
|
value: [{"participants": contact.email}]
|
|
|
|
@trigger(@)
|
|
|
|
# Exposed Data
|
|
|
|
query: -> @_query
|
|
|
|
committedQuery: -> @_committedQuery
|
|
|
|
suggestions: ->
|
|
@_suggestions
|
|
|
|
searchConstants: ->
|
|
@_searchConstants
|
|
|
|
module.exports = SearchSuggestionStore
|