2015-07-16 23:54:20 +08:00
|
|
|
React = require 'react'
|
|
|
|
classNames = require 'classnames'
|
2015-07-24 02:10:51 +08:00
|
|
|
{Actions,
|
|
|
|
Utils,
|
|
|
|
WorkspaceStore,
|
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,
|
2015-09-05 03:23:15 +08:00
|
|
|
FocusedMailViewStore,
|
2015-07-24 02:10:51 +08:00
|
|
|
ChangeLabelsTask,
|
|
|
|
ChangeFolderTask,
|
|
|
|
CategoryStore} = require 'nylas-exports'
|
|
|
|
{RetinaImg, DropZone} = require 'nylas-component-kit'
|
2015-07-16 23:54:20 +08:00
|
|
|
|
2015-09-05 03:23:15 +08:00
|
|
|
class AccountSidebarMailViewItem extends React.Component
|
|
|
|
@displayName: 'AccountSidebarMailViewItem'
|
|
|
|
|
|
|
|
@propTypes:
|
|
|
|
select: React.PropTypes.bool
|
2015-10-23 01:53:57 +08:00
|
|
|
item: React.PropTypes.object.isRequired
|
2015-09-05 03:23:15 +08:00
|
|
|
mailView: React.PropTypes.object.isRequired
|
2015-07-16 23:54:20 +08:00
|
|
|
|
|
|
|
constructor: (@props) ->
|
feat(counts): Unread counts for all folders and labels across all accounts
Summary:
This diff replaces the UnreadCountStore with a better approach that is able to track unread counts for all folders/labels without continuous (and cripplingly slow) SELECT COUNT(*) queries.
When models are written to the database, we currently don't send out notifications with the "previous" state of those objects in the database. This makes it hard to determine how to update counters. (In the future, we may need to do this for live queries). Unfortunately, getting the "previous" state is going to be very hard, because multiple windows write to the database and the "previous" state we have might be outdated. We'd almost have to run a "SELECT" right before every "REPLACE INTO".
I created an API that allows you to register observers around persistModel and unpersistModel. With this API, you can run queries before and after the database changes are made and pluck just the "before" state you're interested in.
The `ThreadCountsStore` uses this API to determine the impact of persisting a set of threads on the unread counts of different labels. Before the threads are saved, it says "how much do these thread IDs contribute to unread counts currently?". After the write is complete it looks at the models and computes the difference between the old count impact and the new count impact, and updates the counters.
I decided not to attach the unread count to the Label objects themselves because 1) they update frequently and 2) most things observing the DatabaseStore for categories do not care about counts, so they would be updating unnecessarily.
The AccountSidebar now listens to the ThreadCountsStore as well as the CategoryStore, and there's a new preference in the General tab for turning off the counts.
Test Plan: Tests are a work in progress, want to get feedback first!
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2232
2015-11-24 09:12:22 +08:00
|
|
|
@state = {}
|
2015-07-16 23:54:20 +08:00
|
|
|
|
2015-07-24 02:10:51 +08:00
|
|
|
shouldComponentUpdate: (nextProps, nextState) =>
|
|
|
|
!Utils.isEqualReact(@props, nextProps) or !Utils.isEqualReact(@state, nextState)
|
2015-07-16 23:54:20 +08:00
|
|
|
|
|
|
|
render: =>
|
2015-11-24 11:41:53 +08:00
|
|
|
isDeleted = @props.mailView?.category?.isDeleted is true
|
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
containerClass = classNames
|
|
|
|
'item': true
|
|
|
|
'selected': @props.select
|
2015-07-24 02:10:51 +08:00
|
|
|
'dropping': @state.isDropping
|
2015-11-24 11:41:53 +08:00
|
|
|
'deleted': isDeleted
|
2015-07-16 23:54:20 +08:00
|
|
|
|
2015-07-24 02:10:51 +08:00
|
|
|
<DropZone className={containerClass}
|
|
|
|
onClick={@_onClick}
|
2015-09-05 03:23:15 +08:00
|
|
|
id={@props.mailView.id}
|
2015-07-24 02:10:51 +08:00
|
|
|
shouldAcceptDrop={@_shouldAcceptDrop}
|
|
|
|
onDragStateChange={ ({isDropping}) => @setState({isDropping}) }
|
|
|
|
onDrop={@_onDrop}>
|
feat(counts): Unread counts for all folders and labels across all accounts
Summary:
This diff replaces the UnreadCountStore with a better approach that is able to track unread counts for all folders/labels without continuous (and cripplingly slow) SELECT COUNT(*) queries.
When models are written to the database, we currently don't send out notifications with the "previous" state of those objects in the database. This makes it hard to determine how to update counters. (In the future, we may need to do this for live queries). Unfortunately, getting the "previous" state is going to be very hard, because multiple windows write to the database and the "previous" state we have might be outdated. We'd almost have to run a "SELECT" right before every "REPLACE INTO".
I created an API that allows you to register observers around persistModel and unpersistModel. With this API, you can run queries before and after the database changes are made and pluck just the "before" state you're interested in.
The `ThreadCountsStore` uses this API to determine the impact of persisting a set of threads on the unread counts of different labels. Before the threads are saved, it says "how much do these thread IDs contribute to unread counts currently?". After the write is complete it looks at the models and computes the difference between the old count impact and the new count impact, and updates the counters.
I decided not to attach the unread count to the Label objects themselves because 1) they update frequently and 2) most things observing the DatabaseStore for categories do not care about counts, so they would be updating unnecessarily.
The AccountSidebar now listens to the ThreadCountsStore as well as the CategoryStore, and there's a new preference in the General tab for turning off the counts.
Test Plan: Tests are a work in progress, want to get feedback first!
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2232
2015-11-24 09:12:22 +08:00
|
|
|
{@_renderUnreadCount()}
|
2015-09-01 01:47:25 +08:00
|
|
|
<div className="icon">{@_renderIcon()}</div>
|
2015-10-23 01:53:57 +08:00
|
|
|
<div className="name">{@props.item.name}</div>
|
2015-07-24 02:10:51 +08:00
|
|
|
</DropZone>
|
|
|
|
|
feat(counts): Unread counts for all folders and labels across all accounts
Summary:
This diff replaces the UnreadCountStore with a better approach that is able to track unread counts for all folders/labels without continuous (and cripplingly slow) SELECT COUNT(*) queries.
When models are written to the database, we currently don't send out notifications with the "previous" state of those objects in the database. This makes it hard to determine how to update counters. (In the future, we may need to do this for live queries). Unfortunately, getting the "previous" state is going to be very hard, because multiple windows write to the database and the "previous" state we have might be outdated. We'd almost have to run a "SELECT" right before every "REPLACE INTO".
I created an API that allows you to register observers around persistModel and unpersistModel. With this API, you can run queries before and after the database changes are made and pluck just the "before" state you're interested in.
The `ThreadCountsStore` uses this API to determine the impact of persisting a set of threads on the unread counts of different labels. Before the threads are saved, it says "how much do these thread IDs contribute to unread counts currently?". After the write is complete it looks at the models and computes the difference between the old count impact and the new count impact, and updates the counters.
I decided not to attach the unread count to the Label objects themselves because 1) they update frequently and 2) most things observing the DatabaseStore for categories do not care about counts, so they would be updating unnecessarily.
The AccountSidebar now listens to the ThreadCountsStore as well as the CategoryStore, and there's a new preference in the General tab for turning off the counts.
Test Plan: Tests are a work in progress, want to get feedback first!
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2232
2015-11-24 09:12:22 +08:00
|
|
|
_renderUnreadCount: =>
|
2015-11-24 11:41:53 +08:00
|
|
|
return false unless @props.item.unreadCount
|
feat(counts): Unread counts for all folders and labels across all accounts
Summary:
This diff replaces the UnreadCountStore with a better approach that is able to track unread counts for all folders/labels without continuous (and cripplingly slow) SELECT COUNT(*) queries.
When models are written to the database, we currently don't send out notifications with the "previous" state of those objects in the database. This makes it hard to determine how to update counters. (In the future, we may need to do this for live queries). Unfortunately, getting the "previous" state is going to be very hard, because multiple windows write to the database and the "previous" state we have might be outdated. We'd almost have to run a "SELECT" right before every "REPLACE INTO".
I created an API that allows you to register observers around persistModel and unpersistModel. With this API, you can run queries before and after the database changes are made and pluck just the "before" state you're interested in.
The `ThreadCountsStore` uses this API to determine the impact of persisting a set of threads on the unread counts of different labels. Before the threads are saved, it says "how much do these thread IDs contribute to unread counts currently?". After the write is complete it looks at the models and computes the difference between the old count impact and the new count impact, and updates the counters.
I decided not to attach the unread count to the Label objects themselves because 1) they update frequently and 2) most things observing the DatabaseStore for categories do not care about counts, so they would be updating unnecessarily.
The AccountSidebar now listens to the ThreadCountsStore as well as the CategoryStore, and there's a new preference in the General tab for turning off the counts.
Test Plan: Tests are a work in progress, want to get feedback first!
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2232
2015-11-24 09:12:22 +08:00
|
|
|
className = 'item-count-box '
|
|
|
|
className += @props.mailView.category?.name
|
2015-11-24 11:41:53 +08:00
|
|
|
<div className={className}>{@props.item.unreadCount}</div>
|
feat(counts): Unread counts for all folders and labels across all accounts
Summary:
This diff replaces the UnreadCountStore with a better approach that is able to track unread counts for all folders/labels without continuous (and cripplingly slow) SELECT COUNT(*) queries.
When models are written to the database, we currently don't send out notifications with the "previous" state of those objects in the database. This makes it hard to determine how to update counters. (In the future, we may need to do this for live queries). Unfortunately, getting the "previous" state is going to be very hard, because multiple windows write to the database and the "previous" state we have might be outdated. We'd almost have to run a "SELECT" right before every "REPLACE INTO".
I created an API that allows you to register observers around persistModel and unpersistModel. With this API, you can run queries before and after the database changes are made and pluck just the "before" state you're interested in.
The `ThreadCountsStore` uses this API to determine the impact of persisting a set of threads on the unread counts of different labels. Before the threads are saved, it says "how much do these thread IDs contribute to unread counts currently?". After the write is complete it looks at the models and computes the difference between the old count impact and the new count impact, and updates the counters.
I decided not to attach the unread count to the Label objects themselves because 1) they update frequently and 2) most things observing the DatabaseStore for categories do not care about counts, so they would be updating unnecessarily.
The AccountSidebar now listens to the ThreadCountsStore as well as the CategoryStore, and there's a new preference in the General tab for turning off the counts.
Test Plan: Tests are a work in progress, want to get feedback first!
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2232
2015-11-24 09:12:22 +08:00
|
|
|
|
2015-07-24 03:33:21 +08:00
|
|
|
_renderIcon: ->
|
2015-09-05 03:23:15 +08:00
|
|
|
<RetinaImg name={@props.mailView.iconName} fallback={'folder.png'} mode={RetinaImg.Mode.ContentIsMask} />
|
2015-07-24 03:33:21 +08:00
|
|
|
|
2015-07-24 02:10:51 +08:00
|
|
|
_shouldAcceptDrop: (e) =>
|
2015-09-05 03:23:15 +08:00
|
|
|
return false if @props.mailView.isEqual(FocusedMailViewStore.mailView())
|
|
|
|
return false unless @props.mailView.canApplyToThreads()
|
2015-07-24 02:10:51 +08:00
|
|
|
'nylas-thread-ids' in e.dataTransfer.types
|
|
|
|
|
|
|
|
_onDrop: (e) =>
|
|
|
|
jsonString = e.dataTransfer.getData('nylas-thread-ids')
|
|
|
|
try
|
|
|
|
ids = JSON.parse(jsonString)
|
|
|
|
catch err
|
2015-09-05 03:23:15 +08:00
|
|
|
console.error("AccountSidebarMailViewItem onDrop: JSON parse #{err}")
|
2015-07-24 02:10:51 +08:00
|
|
|
return unless ids
|
|
|
|
|
2015-09-05 03:23:15 +08:00
|
|
|
@props.mailView.applyToThreads(ids)
|
2015-07-16 23:54:20 +08:00
|
|
|
|
|
|
|
_onClick: (event) =>
|
|
|
|
event.preventDefault()
|
|
|
|
Actions.selectRootSheet(WorkspaceStore.Sheet.Threads)
|
2015-09-05 03:23:15 +08:00
|
|
|
Actions.focusMailView(@props.mailView)
|
2015-07-16 23:54:20 +08:00
|
|
|
|
2015-09-05 03:23:15 +08:00
|
|
|
module.exports = AccountSidebarMailViewItem
|