2015-02-21 04:19:34 +08:00
|
|
|
_ = require 'underscore-plus'
|
2015-04-01 08:19:17 +08:00
|
|
|
{Actions, DatabaseStore, Thread, Tag} = require 'inbox-exports'
|
2015-02-21 04:19:34 +08:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
activate: ->
|
|
|
|
@unlisteners = []
|
|
|
|
@unlisteners.push Actions.didPassivelyReceiveNewModels.listen(@_onNewMailReceived, @)
|
2015-03-11 07:08:07 +08:00
|
|
|
@activationTime = Date.now()
|
2015-02-21 04:19:34 +08:00
|
|
|
|
|
|
|
deactivate: ->
|
|
|
|
fn() for fn in @unlisteners
|
|
|
|
|
|
|
|
serialize: ->
|
|
|
|
|
2015-03-28 07:37:13 +08:00
|
|
|
_onNewMailReceived: (incoming) ->
|
|
|
|
new Promise (resolve, reject) =>
|
|
|
|
incomingMessages = incoming['message'] ? []
|
|
|
|
incomingThreads = incoming['thread'] ? []
|
|
|
|
|
|
|
|
# Filter for new messages
|
|
|
|
newUnread = _.filter incomingMessages, (msg) =>
|
|
|
|
msg.unread is true and msg.date?.valueOf() >= @activationTime
|
|
|
|
|
|
|
|
return resolve() if newUnread.length is 0
|
|
|
|
|
|
|
|
# For each message, find it's corresponding thread. First, look to see
|
|
|
|
# if it's already in the `incoming` payload (sent via delta sync
|
|
|
|
# at the same time as the message.) If it's not, try loading it from
|
|
|
|
# the local cache.
|
|
|
|
#
|
|
|
|
# Note we may receive multiple unread msgs for the same thread.
|
|
|
|
# Using a map and ?= to avoid repeating work.
|
|
|
|
threads = {}
|
|
|
|
for msg in newUnread
|
|
|
|
threads[msg.threadId] ?= _.findWhere(incomingThreads, {id: msg.threadId})
|
|
|
|
threads[msg.threadId] ?= DatabaseStore.find(Thread, msg.threadId)
|
|
|
|
|
|
|
|
Promise.props(threads).then (threads) ->
|
|
|
|
|
|
|
|
# Filter new unread messages to just the ones in the inbox
|
|
|
|
newUnreadInInbox = _.filter newUnread, (msg) ->
|
|
|
|
threads[msg.threadId]?.hasTagId('inbox')
|
|
|
|
|
|
|
|
if newUnreadInInbox.length is 1
|
|
|
|
msg = newUnreadInInbox.pop()
|
refactor(*): Thread list fixes, flexible workspace store, multiple root sheets
Summary:
Remember to remove all the event listeners added to email frame
New files tab, queryable filename, not attribute
Rename ThreadSelectionBar to RootSelectionBar to go with RootCenterComponent, make it appear for draft selection and file selection as well
Initial file list and file list store, File Location
Remove unnecessary shouldComponentUpdate
Always track whether new requests have happened since ours to prevent out of order triggers
Always scroll to the current [focused/keyboard-cursor] in lists
So goodbye to the trash tag
Only scroll to current item if focus or keyboard has moved
Show message snippet in notification if no subject line
Make the RootSelectionBar pull items from Component Registry
New Archive button (prettier than the other one)
Refactor event additions to iframe so iframe can be used for file display also
Thread List is no longer the uber root package - drafts and files moved to separate packages
WorkspaceStore now allows packages to register sheets, "view" concept replaced with "root sheet" concept, "mode" may not be observed by all sheets, and is now called "preferred mode"
Don't animate transitions between two root sheets
Mode switch is only visible on root sheets that support multiple modes
Account sidebar now shows "Views" that have registered themselves: drafts and files for now
Model Selection Bar is now a component, just like ModelList. Meant to be in the toolbar above a Model List
Misc supporting changes
New files package which registers it's views and components
Rename files package to `file-list`
Move checkmark column down into model list
Don't throw exception if shift-down arrow and nothing selected
Takes a long time on login to fetch first page of threads, make pages smaller
Displaynames, spec fixes
Test Plan: Run tests
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1412
2015-04-11 05:33:05 +08:00
|
|
|
body = msg.subject
|
|
|
|
if not body or body.length is 0
|
|
|
|
body = msg.snippet
|
2015-03-28 07:37:13 +08:00
|
|
|
notif = new Notification(msg.from[0].displayName(), {
|
refactor(*): Thread list fixes, flexible workspace store, multiple root sheets
Summary:
Remember to remove all the event listeners added to email frame
New files tab, queryable filename, not attribute
Rename ThreadSelectionBar to RootSelectionBar to go with RootCenterComponent, make it appear for draft selection and file selection as well
Initial file list and file list store, File Location
Remove unnecessary shouldComponentUpdate
Always track whether new requests have happened since ours to prevent out of order triggers
Always scroll to the current [focused/keyboard-cursor] in lists
So goodbye to the trash tag
Only scroll to current item if focus or keyboard has moved
Show message snippet in notification if no subject line
Make the RootSelectionBar pull items from Component Registry
New Archive button (prettier than the other one)
Refactor event additions to iframe so iframe can be used for file display also
Thread List is no longer the uber root package - drafts and files moved to separate packages
WorkspaceStore now allows packages to register sheets, "view" concept replaced with "root sheet" concept, "mode" may not be observed by all sheets, and is now called "preferred mode"
Don't animate transitions between two root sheets
Mode switch is only visible on root sheets that support multiple modes
Account sidebar now shows "Views" that have registered themselves: drafts and files for now
Model Selection Bar is now a component, just like ModelList. Meant to be in the toolbar above a Model List
Misc supporting changes
New files package which registers it's views and components
Rename files package to `file-list`
Move checkmark column down into model list
Don't throw exception if shift-down arrow and nothing selected
Takes a long time on login to fetch first page of threads, make pages smaller
Displaynames, spec fixes
Test Plan: Run tests
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1412
2015-04-11 05:33:05 +08:00
|
|
|
body: body
|
2015-03-28 07:37:13 +08:00
|
|
|
tag: 'unread-update'
|
|
|
|
})
|
|
|
|
notif.onclick = ->
|
|
|
|
atom.displayWindow()
|
2015-04-01 08:19:17 +08:00
|
|
|
Actions.focusTag(new Tag(name: "inbox", id: "inbox"))
|
2015-04-09 10:25:00 +08:00
|
|
|
Actions.focusInCollection(collection: 'thread', item: threads[msg.threadId])
|
2015-03-28 07:37:13 +08:00
|
|
|
|
|
|
|
if newUnreadInInbox.length > 1
|
|
|
|
new Notification("#{newUnreadInInbox.length} Unread Messages", {
|
|
|
|
tag: 'unread-update'
|
|
|
|
})
|
|
|
|
|
|
|
|
if newUnreadInInbox.length > 0
|
|
|
|
atom.playSound('new_mail.ogg')
|
|
|
|
|
|
|
|
resolve()
|