mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-16 17:44:39 +08:00
feat(babel6): Convert account.coffee to account.es6
This commit is contained in:
parent
5251819942
commit
409704fe8f
9 changed files with 197 additions and 170 deletions
|
@ -1,6 +1,6 @@
|
||||||
Contact = require "../../src/flux/models/contact"
|
Contact = require "../../src/flux/models/contact"
|
||||||
AccountStore = require "../../src/flux/stores/account-store"
|
AccountStore = require "../../src/flux/stores/account-store"
|
||||||
Account = require "../../src/flux/models/account"
|
Account = require("../../src/flux/models/account").default
|
||||||
|
|
||||||
contact_1 =
|
contact_1 =
|
||||||
name: "Evan Morikawa"
|
name: "Evan Morikawa"
|
||||||
|
|
|
@ -2,7 +2,7 @@ ModelQuery = require '../../src/flux/models/query'
|
||||||
{Matcher} = require '../../src/flux/attributes'
|
{Matcher} = require '../../src/flux/attributes'
|
||||||
Message = require '../../src/flux/models/message'
|
Message = require '../../src/flux/models/message'
|
||||||
Thread = require('../../src/flux/models/thread').default
|
Thread = require('../../src/flux/models/thread').default
|
||||||
Account = require '../../src/flux/models/account'
|
Account = require('../../src/flux/models/account').default
|
||||||
|
|
||||||
describe "ModelQuery", ->
|
describe "ModelQuery", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
|
@ -306,7 +306,7 @@ describe "NylasAPI", ->
|
||||||
"folder": require('../src/flux/models/folder')
|
"folder": require('../src/flux/models/folder')
|
||||||
"thread": require('../src/flux/models/thread').default
|
"thread": require('../src/flux/models/thread').default
|
||||||
"draft": require('../src/flux/models/message')
|
"draft": require('../src/flux/models/message')
|
||||||
"account": require('../src/flux/models/account')
|
"account": require('../src/flux/models/account').default
|
||||||
"message": require('../src/flux/models/message')
|
"message": require('../src/flux/models/message')
|
||||||
"contact": require('../src/flux/models/contact')
|
"contact": require('../src/flux/models/contact')
|
||||||
"calendar": require('../src/flux/models/calendar')
|
"calendar": require('../src/flux/models/calendar')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
keytar = require 'keytar'
|
keytar = require 'keytar'
|
||||||
AccountStore = require '../../src/flux/stores/account-store'
|
AccountStore = require '../../src/flux/stores/account-store'
|
||||||
Account = require '../../src/flux/models/account'
|
Account = require('../../src/flux/models/account').default
|
||||||
Actions = require '../../src/flux/actions'
|
Actions = require '../../src/flux/actions'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,161 +0,0 @@
|
||||||
ModelWithMetadata = require('./model-with-metadata').default
|
|
||||||
Attributes = require '../attributes'
|
|
||||||
_ = require 'underscore'
|
|
||||||
CategoryStore = null
|
|
||||||
Contact = null
|
|
||||||
|
|
||||||
###
|
|
||||||
Public: The Account model represents a Account served by the Nylas Platform API.
|
|
||||||
Every object on the Nylas platform exists within a Account, which typically represents
|
|
||||||
an email account.
|
|
||||||
|
|
||||||
For more information about Accounts on the Nylas Platform, read the
|
|
||||||
[Account API Documentation](https://nylas.com/docs/api#Account)
|
|
||||||
|
|
||||||
## Attributes
|
|
||||||
|
|
||||||
`name`: {AttributeString} The name of the Account.
|
|
||||||
|
|
||||||
`provider`: {AttributeString} The Account's mail provider (ie: `gmail`)
|
|
||||||
|
|
||||||
`emailAddress`: {AttributeString} The Account's email address
|
|
||||||
(ie: `ben@nylas.com`). Queryable.
|
|
||||||
|
|
||||||
`organizationUnit`: {AttributeString} Either "label" or "folder".
|
|
||||||
Depending on the provider, the account may be organized by folders or
|
|
||||||
labels.
|
|
||||||
|
|
||||||
This class also inherits attributes from {Model}
|
|
||||||
|
|
||||||
Section: Models
|
|
||||||
###
|
|
||||||
class Account extends ModelWithMetadata
|
|
||||||
|
|
||||||
@SYNC_STATE_RUNNING = "running"
|
|
||||||
@SYNC_STATE_STOPPED = "stopped"
|
|
||||||
@SYNC_STATE_AUTH_FAILED = "invalid"
|
|
||||||
@SYNC_STATE_ERROR = "sync_error"
|
|
||||||
|
|
||||||
@attributes: _.extend {}, ModelWithMetadata.attributes,
|
|
||||||
'name': Attributes.String
|
|
||||||
modelKey: 'name'
|
|
||||||
|
|
||||||
'provider': Attributes.String
|
|
||||||
modelKey: 'provider'
|
|
||||||
|
|
||||||
'emailAddress': Attributes.String
|
|
||||||
queryable: true
|
|
||||||
modelKey: 'emailAddress'
|
|
||||||
jsonKey: 'email_address'
|
|
||||||
|
|
||||||
'organizationUnit': Attributes.String
|
|
||||||
modelKey: 'organizationUnit'
|
|
||||||
jsonKey: 'organization_unit'
|
|
||||||
|
|
||||||
'label': Attributes.String
|
|
||||||
queryable: false
|
|
||||||
modelKey: 'label'
|
|
||||||
|
|
||||||
'aliases': Attributes.Object
|
|
||||||
queryable: false
|
|
||||||
modelKey: 'aliases'
|
|
||||||
|
|
||||||
'defaultAlias': Attributes.Object
|
|
||||||
queryable: false
|
|
||||||
modelKey: 'defaultAlias'
|
|
||||||
jsonKey: 'default_alias'
|
|
||||||
|
|
||||||
'syncState': Attributes.String
|
|
||||||
queryable: false
|
|
||||||
modelKey: 'syncState'
|
|
||||||
jsonKey: 'sync_state'
|
|
||||||
|
|
||||||
constructor: ->
|
|
||||||
super
|
|
||||||
@aliases ||= []
|
|
||||||
@label ||= @emailAddress
|
|
||||||
@syncState ||= "running"
|
|
||||||
|
|
||||||
fromJSON: (json) ->
|
|
||||||
json["label"] ||= json[@constructor.attributes['emailAddress'].jsonKey]
|
|
||||||
super
|
|
||||||
|
|
||||||
# Returns a {Contact} model that represents the current user.
|
|
||||||
me: ->
|
|
||||||
Contact ?= require './contact'
|
|
||||||
return new Contact
|
|
||||||
accountId: @id
|
|
||||||
name: @name
|
|
||||||
email: @emailAddress
|
|
||||||
|
|
||||||
meUsingAlias: (alias) ->
|
|
||||||
Contact ?= require './contact'
|
|
||||||
return @me() unless alias
|
|
||||||
return Contact.fromString(alias, accountId: @id)
|
|
||||||
|
|
||||||
defaultMe: ->
|
|
||||||
if @defaultAlias
|
|
||||||
return @meUsingAlias(@defaultAlias)
|
|
||||||
else
|
|
||||||
return @me()
|
|
||||||
|
|
||||||
usesLabels: ->
|
|
||||||
@organizationUnit is "label"
|
|
||||||
|
|
||||||
usesFolders: ->
|
|
||||||
@organizationUnit is "folder"
|
|
||||||
|
|
||||||
categoryLabel: ->
|
|
||||||
if @usesFolders()
|
|
||||||
'Folders'
|
|
||||||
else if @usesLabels()
|
|
||||||
'Labels'
|
|
||||||
else
|
|
||||||
'Unknown'
|
|
||||||
|
|
||||||
categoryCollection: ->
|
|
||||||
"#{@organizationUnit}s"
|
|
||||||
|
|
||||||
categoryIcon: ->
|
|
||||||
if @usesFolders()
|
|
||||||
'folder.png'
|
|
||||||
else if @usesLabels()
|
|
||||||
'tag.png'
|
|
||||||
else
|
|
||||||
'folder.png'
|
|
||||||
|
|
||||||
# Public: Returns the localized, properly capitalized provider name,
|
|
||||||
# like Gmail, Exchange, or Outlook 365
|
|
||||||
displayProvider: ->
|
|
||||||
if @provider is 'eas'
|
|
||||||
return 'Exchange'
|
|
||||||
else if @provider is 'gmail'
|
|
||||||
return 'Gmail'
|
|
||||||
else
|
|
||||||
return @provider
|
|
||||||
|
|
||||||
canArchiveThreads: ->
|
|
||||||
CategoryStore ?= require '../stores/category-store'
|
|
||||||
CategoryStore.getArchiveCategory(@)?
|
|
||||||
|
|
||||||
canTrashThreads: ->
|
|
||||||
CategoryStore ?= require '../stores/category-store'
|
|
||||||
CategoryStore.getTrashCategory(@)?
|
|
||||||
|
|
||||||
defaultFinishedCategory: ->
|
|
||||||
CategoryStore ?= require '../stores/category-store'
|
|
||||||
preferDelete = NylasEnv.config.get('core.reading.backspaceDelete')
|
|
||||||
archiveCategory = CategoryStore.getArchiveCategory(@)
|
|
||||||
trashCategory = CategoryStore.getTrashCategory(@)
|
|
||||||
|
|
||||||
if preferDelete or not archiveCategory
|
|
||||||
trashCategory
|
|
||||||
else
|
|
||||||
archiveCategory
|
|
||||||
|
|
||||||
hasSyncStateError: ->
|
|
||||||
# TODO: ignoring "stopped" until it's no longer overloaded on API
|
|
||||||
return @syncState != Account.SYNC_STATE_RUNNING &&
|
|
||||||
@syncState != Account.SYNC_STATE_STOPPED
|
|
||||||
|
|
||||||
module.exports = Account
|
|
188
src/flux/models/account.es6
Normal file
188
src/flux/models/account.es6
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
import Attributes from '../attributes'
|
||||||
|
import ModelWithMetadata from './model-with-metadata'
|
||||||
|
|
||||||
|
let CategoryStore = null
|
||||||
|
let Contact = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public: The Account model represents a Account served by the Nylas Platform API.
|
||||||
|
* Every object on the Nylas platform exists within a Account, which typically represents
|
||||||
|
* an email account.
|
||||||
|
*
|
||||||
|
* For more information about Accounts on the Nylas Platform, read the
|
||||||
|
* [Account API Documentation](https://nylas.com/docs/api#Account)
|
||||||
|
*
|
||||||
|
* ## Attributes
|
||||||
|
*
|
||||||
|
* `name`: {AttributeString} The name of the Account.
|
||||||
|
*
|
||||||
|
* `provider`: {AttributeString} The Account's mail provider (ie: `gmail`)
|
||||||
|
*
|
||||||
|
* `emailAddress`: {AttributeString} The Account's email address
|
||||||
|
* (ie: `ben@nylas.com`). Queryable.
|
||||||
|
*
|
||||||
|
* `organizationUnit`: {AttributeString} Either "label" or "folder".
|
||||||
|
* Depending on the provider, the account may be organized by folders or
|
||||||
|
* labels.
|
||||||
|
*
|
||||||
|
* This class also inherits attributes from {Model}
|
||||||
|
*
|
||||||
|
* Section: Models
|
||||||
|
*/
|
||||||
|
export default class Account extends ModelWithMetadata {
|
||||||
|
|
||||||
|
static SYNC_STATE_RUNNING = "running"
|
||||||
|
static SYNC_STATE_STOPPED = "stopped"
|
||||||
|
static SYNC_STATE_AUTH_FAILED = "invalid"
|
||||||
|
static SYNC_STATE_ERROR = "sync_error"
|
||||||
|
|
||||||
|
static attributes = Object.assign({}, ModelWithMetadata.attributes, {
|
||||||
|
name: Attributes.String({
|
||||||
|
modelKey: 'name',
|
||||||
|
}),
|
||||||
|
|
||||||
|
provider: Attributes.String({
|
||||||
|
modelKey: 'provider',
|
||||||
|
}),
|
||||||
|
|
||||||
|
emailAddress: Attributes.String({
|
||||||
|
queryable: true,
|
||||||
|
modelKey: 'emailAddress',
|
||||||
|
jsonKey: 'email_address',
|
||||||
|
}),
|
||||||
|
|
||||||
|
organizationUnit: Attributes.String({
|
||||||
|
modelKey: 'organizationUnit',
|
||||||
|
jsonKey: 'organization_unit',
|
||||||
|
}),
|
||||||
|
|
||||||
|
label: Attributes.String({
|
||||||
|
queryable: false,
|
||||||
|
modelKey: 'label',
|
||||||
|
}),
|
||||||
|
|
||||||
|
aliases: Attributes.Object({
|
||||||
|
queryable: false,
|
||||||
|
modelKey: 'aliases',
|
||||||
|
}),
|
||||||
|
|
||||||
|
defaultAlias: Attributes.Object({
|
||||||
|
queryable: false,
|
||||||
|
modelKey: 'defaultAlias',
|
||||||
|
jsonKey: 'default_alias',
|
||||||
|
}),
|
||||||
|
|
||||||
|
syncState: Attributes.String({
|
||||||
|
queryable: false,
|
||||||
|
modelKey: 'syncState',
|
||||||
|
jsonKey: 'sync_state',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.aliases = this.aliases || [];
|
||||||
|
this.label = this.label || this.emailAddress;
|
||||||
|
this.syncState = this.syncState || "running";
|
||||||
|
}
|
||||||
|
|
||||||
|
fromJSON(inJSON) {
|
||||||
|
const json = inJSON;
|
||||||
|
json.label = json.label || json[Account.attributes.emailAddress.jsonKey]
|
||||||
|
return super.fromJSON(json)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a {Contact} model that represents the current user.
|
||||||
|
me() {
|
||||||
|
Contact = Contact || require('./contact')
|
||||||
|
return new Contact({
|
||||||
|
accountId: this.id,
|
||||||
|
name: this.name,
|
||||||
|
email: this.emailAddress,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
meUsingAlias(alias) {
|
||||||
|
Contact = Contact || require('./contact')
|
||||||
|
if (!alias) {
|
||||||
|
return this.me()
|
||||||
|
}
|
||||||
|
return Contact.fromString(alias, {accountId: this.id})
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultMe() {
|
||||||
|
if (this.defaultAlias) {
|
||||||
|
return this.meUsingAlias(this.defaultAlias)
|
||||||
|
}
|
||||||
|
return this.me()
|
||||||
|
}
|
||||||
|
|
||||||
|
usesLabels() {
|
||||||
|
return this.organizationUnit === "label"
|
||||||
|
}
|
||||||
|
|
||||||
|
usesFolders() {
|
||||||
|
return this.organizationUnit === "folder"
|
||||||
|
}
|
||||||
|
|
||||||
|
categoryLabel() {
|
||||||
|
if (this.usesFolders()) {
|
||||||
|
return 'Folders'
|
||||||
|
} else if (this.usesLabels()) {
|
||||||
|
return 'Labels'
|
||||||
|
}
|
||||||
|
return 'Unknown'
|
||||||
|
}
|
||||||
|
|
||||||
|
categoryCollection() {
|
||||||
|
return "#{this.organizationUnit}s"
|
||||||
|
}
|
||||||
|
|
||||||
|
categoryIcon() {
|
||||||
|
if (this.usesFolders()) {
|
||||||
|
return 'folder.png'
|
||||||
|
} else if (this.usesLabels()) {
|
||||||
|
return 'tag.png'
|
||||||
|
}
|
||||||
|
return 'folder.png'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public: Returns the localized, properly capitalized provider name,
|
||||||
|
// like Gmail, Exchange, or Outlook 365
|
||||||
|
displayProvider() {
|
||||||
|
if (this.provider === 'eas') {
|
||||||
|
return 'Exchange'
|
||||||
|
} else if (this.provider === 'gmail') {
|
||||||
|
return 'Gmail'
|
||||||
|
}
|
||||||
|
return this.provider
|
||||||
|
}
|
||||||
|
|
||||||
|
canArchiveThreads() {
|
||||||
|
CategoryStore = CategoryStore || require('../stores/category-store')
|
||||||
|
return CategoryStore.getArchiveCategory(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
canTrashThreads() {
|
||||||
|
CategoryStore = CategoryStore || require('../stores/category-store')
|
||||||
|
return CategoryStore.getTrashCategory(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultFinishedCategory() {
|
||||||
|
CategoryStore = CategoryStore || require('../stores/category-store')
|
||||||
|
const preferDelete = NylasEnv.config.get('core.reading.backspaceDelete')
|
||||||
|
const archiveCategory = CategoryStore.getArchiveCategory(this)
|
||||||
|
const trashCategory = CategoryStore.getTrashCategory(this)
|
||||||
|
|
||||||
|
if (preferDelete || !archiveCategory) {
|
||||||
|
return trashCategory
|
||||||
|
}
|
||||||
|
return archiveCategory
|
||||||
|
}
|
||||||
|
|
||||||
|
hasSyncStateError() {
|
||||||
|
// TODO: ignoring "stopped" until it's no longer overloaded on API
|
||||||
|
return this.syncState !== Account.SYNC_STATE_RUNNING &&
|
||||||
|
this.syncState !== Account.SYNC_STATE_STOPPED
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ _ = require 'underscore'
|
||||||
request = require 'request'
|
request = require 'request'
|
||||||
NylasLongConnection = require('./nylas-long-connection').default
|
NylasLongConnection = require('./nylas-long-connection').default
|
||||||
Utils = require './models/utils'
|
Utils = require './models/utils'
|
||||||
Account = require './models/account'
|
Account = require('./models/account').default
|
||||||
Message = require './models/message'
|
Message = require './models/message'
|
||||||
Actions = require './actions'
|
Actions = require './actions'
|
||||||
{APIError} = require './errors'
|
{APIError} = require './errors'
|
||||||
|
@ -351,7 +351,7 @@ class NylasAPI
|
||||||
"folder": require('./models/folder')
|
"folder": require('./models/folder')
|
||||||
"thread": require('./models/thread').default
|
"thread": require('./models/thread').default
|
||||||
"draft": require('./models/message')
|
"draft": require('./models/message')
|
||||||
"account": require('./models/account')
|
"account": require('./models/account').default
|
||||||
"message": require('./models/message')
|
"message": require('./models/message')
|
||||||
"contact": require('./models/contact')
|
"contact": require('./models/contact')
|
||||||
"calendar": require('./models/calendar')
|
"calendar": require('./models/calendar')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
NylasStore = require 'nylas-store'
|
NylasStore = require 'nylas-store'
|
||||||
Actions = require '../actions'
|
Actions = require '../actions'
|
||||||
Account = require '../models/account'
|
Account = require('../models/account').default
|
||||||
Utils = require '../models/utils'
|
Utils = require '../models/utils'
|
||||||
DatabaseStore = require './database-store'
|
DatabaseStore = require './database-store'
|
||||||
keytar = require 'keytar'
|
keytar = require 'keytar'
|
||||||
|
@ -237,7 +237,7 @@ class AccountStore extends NylasStore
|
||||||
fs = require 'fs-plus'
|
fs = require 'fs-plus'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
Message = require '../models/message'
|
Message = require '../models/message'
|
||||||
Account = require '../models/account'
|
Account = require('../models/account').default
|
||||||
Thread = require('../models/thread').default
|
Thread = require('../models/thread').default
|
||||||
Label = require '../models/label'
|
Label = require '../models/label'
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ Rx = require 'rx-lite'
|
||||||
NylasStore = require 'nylas-store'
|
NylasStore = require 'nylas-store'
|
||||||
AccountStore = require './account-store'
|
AccountStore = require './account-store'
|
||||||
NylasSyncStatusStore = require './nylas-sync-status-store'
|
NylasSyncStatusStore = require './nylas-sync-status-store'
|
||||||
Account = require '../models/account'
|
Account = require('../models/account').default
|
||||||
{StandardCategoryNames} = require '../models/category'
|
{StandardCategoryNames} = require '../models/category'
|
||||||
{Categories} = require 'nylas-observables'
|
{Categories} = require 'nylas-observables'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue