2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-02-21 04:19:34 +08:00
|
|
|
Contact = require '../../../src/flux/models/contact'
|
|
|
|
Message = require '../../../src/flux/models/message'
|
2015-03-28 07:37:13 +08:00
|
|
|
Thread = require '../../../src/flux/models/thread'
|
2015-07-16 23:54:20 +08:00
|
|
|
Label = require '../../../src/flux/models/label'
|
|
|
|
CategoryStore = require '../../../src/flux/stores/category-store'
|
2015-03-28 07:37:13 +08:00
|
|
|
DatabaseStore = require '../../../src/flux/stores/database-store'
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
AccountStore = require '../../../src/flux/stores/account-store'
|
2015-02-21 04:19:34 +08:00
|
|
|
Main = require '../lib/main'
|
|
|
|
|
|
|
|
describe "UnreadNotifications", ->
|
|
|
|
beforeEach ->
|
2015-03-11 07:08:07 +08:00
|
|
|
Main.activate()
|
2015-03-28 07:37:13 +08:00
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
inbox = new Label(id: "l1", name: "inbox", displayName: "Inbox")
|
|
|
|
archive = new Label(id: "l2", name: "archive", displayName: "Archive")
|
|
|
|
|
|
|
|
spyOn(CategoryStore, "getStandardCategory").andReturn inbox
|
|
|
|
|
2015-03-28 07:37:13 +08:00
|
|
|
@threadA = new Thread
|
2015-07-16 23:54:20 +08:00
|
|
|
labels: [inbox]
|
2015-03-28 07:37:13 +08:00
|
|
|
@threadB = new Thread
|
2015-07-16 23:54:20 +08:00
|
|
|
labels: [archive]
|
2015-03-28 07:37:13 +08:00
|
|
|
|
2015-02-21 04:19:34 +08:00
|
|
|
@msg1 = new Message
|
|
|
|
unread: true
|
2015-03-11 07:08:07 +08:00
|
|
|
date: new Date()
|
2015-02-21 04:19:34 +08:00
|
|
|
from: [new Contact(name: 'Ben', email: 'ben@example.com')]
|
|
|
|
subject: "Hello World"
|
2015-03-28 07:37:13 +08:00
|
|
|
threadId: "A"
|
2015-05-11 03:21:18 +08:00
|
|
|
@msgNoSender = new Message
|
|
|
|
unread: true
|
|
|
|
date: new Date()
|
|
|
|
from: []
|
|
|
|
subject: "Hello World"
|
|
|
|
threadId: "A"
|
2015-02-21 04:19:34 +08:00
|
|
|
@msg2 = new Message
|
|
|
|
unread: true
|
2015-03-11 07:08:07 +08:00
|
|
|
date: new Date()
|
2015-02-21 04:19:34 +08:00
|
|
|
from: [new Contact(name: 'Mark', email: 'mark@example.com')]
|
|
|
|
subject: "Hello World 2"
|
2015-03-28 07:37:13 +08:00
|
|
|
threadId: "A"
|
2015-07-16 04:18:10 +08:00
|
|
|
@msg3 = new Message
|
|
|
|
unread: true
|
|
|
|
date: new Date()
|
|
|
|
from: [new Contact(name: 'Ben', email: 'ben@example.com')]
|
|
|
|
subject: "Hello World"
|
|
|
|
threadId: "A"
|
|
|
|
@msg4 = new Message
|
|
|
|
unread: true
|
|
|
|
date: new Date()
|
|
|
|
from: [new Contact(name: 'Ben', email: 'ben@example.com')]
|
|
|
|
subject: "Hello World"
|
|
|
|
threadId: "A"
|
|
|
|
@msg5 = new Message
|
|
|
|
unread: true
|
|
|
|
date: new Date()
|
|
|
|
from: [new Contact(name: 'Ben', email: 'ben@example.com')]
|
|
|
|
subject: "Hello World"
|
|
|
|
threadId: "A"
|
2015-03-28 07:37:13 +08:00
|
|
|
@msgUnreadButArchived = new Message
|
|
|
|
unread: true
|
|
|
|
date: new Date()
|
|
|
|
from: [new Contact(name: 'Mark', email: 'mark@example.com')]
|
|
|
|
subject: "Hello World 2"
|
|
|
|
threadId: "B"
|
2015-02-21 04:19:34 +08:00
|
|
|
@msgRead = new Message
|
|
|
|
unread: false
|
2015-03-11 07:08:07 +08:00
|
|
|
date: new Date()
|
2015-02-21 04:19:34 +08:00
|
|
|
from: [new Contact(name: 'Mark', email: 'mark@example.com')]
|
|
|
|
subject: "Hello World Read Already"
|
2015-03-28 07:37:13 +08:00
|
|
|
threadId: "A"
|
2015-03-11 07:08:07 +08:00
|
|
|
@msgOld = new Message
|
|
|
|
unread: true
|
|
|
|
date: new Date(2000,1,1)
|
|
|
|
from: [new Contact(name: 'Mark', email: 'mark@example.com')]
|
|
|
|
subject: "Hello World Old"
|
2015-03-28 07:37:13 +08:00
|
|
|
threadId: "A"
|
feat(*): draft icon, misc fixes, and WorkspaceStore / custom toolbar in secondary windows
Summary:
Features:
- ThreadListParticipants ignores drafts when computing participants, renders "Draft" label, pending design
- Put the WorkspaceStore in every window—means they all get toolbars and custom gumdrop icons on Mac OS X
Bug Fixes:
- Never display notifications for email the user just sent
- Fix obscure issue with DatabaseView trying to update metadata on items it froze. This resolves issue with names remaining bold after marking as read, drafts not appearing in message list immediately.
- When you pop out a draft, save it first and *wait* for the commit() promise to succeed.
- If you scroll very fast, you node.contentWindow can be null in eventedIframe
Other:
Make it OK to re-register the same component
Make it possible to unregister a hot window
Break the Sheet Toolbar out into it's own file to make things manageable
Replace `package.windowPropsReceived` with a store-style model where anyone can listen for changes to `windowProps`
When I put the WorkspaceStore in every window, I ran into a problem because the package was no longer rendering an instance of the Composer, it was declaring a root sheet with a composer in it. This meant that it was actually a React component that needed to listen to window props, not the package itself.
`atom` is already an event emitter, so I added a `onWindowPropsReceived` hook so that components can listen to window props as if they were listening to a store. I think this might be more flexible than only broadcasting the props change event to packages.
Test Plan: Run tests
Reviewers: evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1592
2015-06-04 07:02:19 +08:00
|
|
|
@msgFromMe = new Message
|
|
|
|
unread: true
|
|
|
|
date: new Date()
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
from: [AccountStore.current().me()]
|
feat(*): draft icon, misc fixes, and WorkspaceStore / custom toolbar in secondary windows
Summary:
Features:
- ThreadListParticipants ignores drafts when computing participants, renders "Draft" label, pending design
- Put the WorkspaceStore in every window—means they all get toolbars and custom gumdrop icons on Mac OS X
Bug Fixes:
- Never display notifications for email the user just sent
- Fix obscure issue with DatabaseView trying to update metadata on items it froze. This resolves issue with names remaining bold after marking as read, drafts not appearing in message list immediately.
- When you pop out a draft, save it first and *wait* for the commit() promise to succeed.
- If you scroll very fast, you node.contentWindow can be null in eventedIframe
Other:
Make it OK to re-register the same component
Make it possible to unregister a hot window
Break the Sheet Toolbar out into it's own file to make things manageable
Replace `package.windowPropsReceived` with a store-style model where anyone can listen for changes to `windowProps`
When I put the WorkspaceStore in every window, I ran into a problem because the package was no longer rendering an instance of the Composer, it was declaring a root sheet with a composer in it. This meant that it was actually a React component that needed to listen to window props, not the package itself.
`atom` is already an event emitter, so I added a `onWindowPropsReceived` hook so that components can listen to window props as if they were listening to a store. I think this might be more flexible than only broadcasting the props change event to packages.
Test Plan: Run tests
Reviewers: evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1592
2015-06-04 07:02:19 +08:00
|
|
|
subject: "A Sent Mail!"
|
|
|
|
threadId: "A"
|
2015-03-28 07:37:13 +08:00
|
|
|
|
|
|
|
spyOn(DatabaseStore, 'find').andCallFake (klass, id) =>
|
|
|
|
return Promise.resolve(@threadA) if id is 'A'
|
|
|
|
return Promise.resolve(@threadB) if id is 'B'
|
|
|
|
return Promise.resolve(null)
|
|
|
|
|
|
|
|
spyOn(window, 'Notification').andCallFake ->
|
|
|
|
spyOn(Promise, 'props').andCallFake (dict) ->
|
|
|
|
dictOut = {}
|
|
|
|
for key, val of dict
|
|
|
|
if val.value?
|
|
|
|
dictOut[key] = val.value()
|
|
|
|
else
|
|
|
|
dictOut[key] = val
|
|
|
|
Promise.resolve(dictOut)
|
2015-03-11 07:08:07 +08:00
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
Main.deactivate()
|
2015-02-21 04:19:34 +08:00
|
|
|
|
|
|
|
it "should create a Notification if there is one unread message", ->
|
2015-03-28 07:37:13 +08:00
|
|
|
waitsForPromise =>
|
|
|
|
Main._onNewMailReceived({message: [@msgRead, @msg1]})
|
|
|
|
.then ->
|
2015-07-16 04:18:10 +08:00
|
|
|
advanceClock(2000)
|
2015-03-28 07:37:13 +08:00
|
|
|
expect(window.Notification).toHaveBeenCalled()
|
|
|
|
expect(window.Notification.mostRecentCall.args).toEqual([ 'Ben', { body : 'Hello World', tag : 'unread-update' } ])
|
2015-02-21 04:19:34 +08:00
|
|
|
|
2015-07-16 04:18:10 +08:00
|
|
|
it "should create multiple Notifications if there is more than one but less than five unread messages", ->
|
|
|
|
waitsForPromise =>
|
|
|
|
Main._onNewMailReceived({message: [@msg1, @msg2, @msg3]})
|
|
|
|
.then ->
|
|
|
|
#Need to call advance clock twice because we call setTimeout twice
|
|
|
|
advanceClock(2000)
|
|
|
|
advanceClock(2000)
|
|
|
|
expect(window.Notification.callCount).toEqual(3)
|
|
|
|
|
|
|
|
it "should create a Notification if there are five or more unread messages", ->
|
2015-03-28 07:37:13 +08:00
|
|
|
waitsForPromise =>
|
2015-07-16 04:18:10 +08:00
|
|
|
Main._onNewMailReceived({
|
|
|
|
message: [@msg1, @msg2, @msg3, @msg4, @msg5]})
|
2015-03-28 07:37:13 +08:00
|
|
|
.then ->
|
2015-07-16 04:18:10 +08:00
|
|
|
advanceClock(2000)
|
2015-03-28 07:37:13 +08:00
|
|
|
expect(window.Notification).toHaveBeenCalled()
|
2015-07-16 04:18:10 +08:00
|
|
|
expect(window.Notification.mostRecentCall.args).toEqual([ '5 Unread Messages', { tag : 'unread-update' } ])
|
2015-02-21 04:19:34 +08:00
|
|
|
|
2015-05-11 03:21:18 +08:00
|
|
|
it "should create a Notification correctly, even if new mail has no sender", ->
|
|
|
|
waitsForPromise =>
|
|
|
|
Main._onNewMailReceived({message: [@msgNoSender]})
|
|
|
|
.then ->
|
|
|
|
expect(window.Notification).toHaveBeenCalled()
|
|
|
|
expect(window.Notification.mostRecentCall.args).toEqual([ 'Unknown', { body : 'Hello World', tag : 'unread-update' } ])
|
|
|
|
|
2015-02-21 04:19:34 +08:00
|
|
|
it "should not create a Notification if there are no new messages", ->
|
2015-03-28 07:37:13 +08:00
|
|
|
waitsForPromise ->
|
|
|
|
Main._onNewMailReceived({message: []})
|
|
|
|
.then ->
|
|
|
|
expect(window.Notification).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
Main._onNewMailReceived({})
|
|
|
|
.then ->
|
|
|
|
expect(window.Notification).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "should not notify about unread messages that are outside the inbox", ->
|
|
|
|
waitsForPromise =>
|
|
|
|
Main._onNewMailReceived({message: [@msgUnreadButArchived, @msg1]})
|
|
|
|
.then ->
|
|
|
|
expect(window.Notification).toHaveBeenCalled()
|
|
|
|
expect(window.Notification.mostRecentCall.args).toEqual([ 'Ben', { body : 'Hello World', tag : 'unread-update' } ])
|
2015-02-21 04:19:34 +08:00
|
|
|
|
|
|
|
it "should not create a Notification if the new messages are not unread", ->
|
2015-03-28 07:37:13 +08:00
|
|
|
waitsForPromise =>
|
|
|
|
Main._onNewMailReceived({message: [@msgRead]})
|
|
|
|
.then ->
|
|
|
|
expect(window.Notification).not.toHaveBeenCalled()
|
2015-02-21 04:19:34 +08:00
|
|
|
|
2015-03-11 07:08:07 +08:00
|
|
|
it "should not create a Notification if the new messages are actually old ones", ->
|
2015-03-28 07:37:13 +08:00
|
|
|
waitsForPromise =>
|
|
|
|
Main._onNewMailReceived({message: [@msgOld]})
|
|
|
|
.then ->
|
|
|
|
expect(window.Notification).not.toHaveBeenCalled()
|
2015-03-11 07:08:07 +08:00
|
|
|
|
feat(*): draft icon, misc fixes, and WorkspaceStore / custom toolbar in secondary windows
Summary:
Features:
- ThreadListParticipants ignores drafts when computing participants, renders "Draft" label, pending design
- Put the WorkspaceStore in every window—means they all get toolbars and custom gumdrop icons on Mac OS X
Bug Fixes:
- Never display notifications for email the user just sent
- Fix obscure issue with DatabaseView trying to update metadata on items it froze. This resolves issue with names remaining bold after marking as read, drafts not appearing in message list immediately.
- When you pop out a draft, save it first and *wait* for the commit() promise to succeed.
- If you scroll very fast, you node.contentWindow can be null in eventedIframe
Other:
Make it OK to re-register the same component
Make it possible to unregister a hot window
Break the Sheet Toolbar out into it's own file to make things manageable
Replace `package.windowPropsReceived` with a store-style model where anyone can listen for changes to `windowProps`
When I put the WorkspaceStore in every window, I ran into a problem because the package was no longer rendering an instance of the Composer, it was declaring a root sheet with a composer in it. This meant that it was actually a React component that needed to listen to window props, not the package itself.
`atom` is already an event emitter, so I added a `onWindowPropsReceived` hook so that components can listen to window props as if they were listening to a store. I think this might be more flexible than only broadcasting the props change event to packages.
Test Plan: Run tests
Reviewers: evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1592
2015-06-04 07:02:19 +08:00
|
|
|
it "should not create a Notification if the new message is one I sent", ->
|
|
|
|
waitsForPromise =>
|
|
|
|
Main._onNewMailReceived({message: [@msgFromMe]})
|
|
|
|
.then ->
|
|
|
|
expect(window.Notification).not.toHaveBeenCalled()
|
|
|
|
|