This commit is contained in:
Ben Gotow 2017-06-24 19:58:19 -07:00
parent f038c97144
commit ab0908b263
3 changed files with 9 additions and 115 deletions

View file

@ -144,15 +144,15 @@ export default class NylasAPIRequest {
const identity = IdentityStore.identity();
if (!identity || !identity.token) {
const clickedIndex = remote.dialog.showMessageBox({
type: 'error',
message: 'Your NylasID is invalid. Please log out then log back in.',
detail: `Actions like sending and receiving mail require this token. Please log back into your Nylas ID to restore it—your email accounts will not be removed in this process.`,
buttons: ['Log out'],
})
if (clickedIndex === 0) {
Actions.logoutNylasIdentity()
}
// const clickedIndex = remote.dialog.showMessageBox({
// type: 'error',
// message: 'Your NylasID is invalid. Please log out then log back in.',
// detail: `Actions like sending and receiving mail require this token. Please log back into your Nylas ID to restore it—your email accounts will not be removed in this process.`,
// buttons: ['Log out'],
// })
// if (clickedIndex === 0) {
// Actions.logoutNylasIdentity()
// }
throw new Error("No Identity")
}

View file

@ -384,101 +384,6 @@ class AccountStore extends NylasStore {
tokensForAccountId(id) {
return this._tokens[id]
}
// Private: Load fake data from a directory for taking nice screenshots
_importFakeData = (dir) => {
const fs = require('fs-plus')
const path = require('path')
const Message = require('../models/message').default
const Thread = require('../models/thread').default
this._caches = {}
let folders = []
const threads = []
let messages = []
let account = this.accountForEmail('nora@nylas.com')
if (!account) {
account = new Account()
account.emailAddress = "nora@nylas.com"
account.organizationUnit = 'label'
account.label = "Nora's Email"
account.aliases = []
account.name = "Nora"
account.provider = "gmail"
const json = account.toJSON()
json.token = 'nope'
this.addAccountFromJSON(json)
}
const filenames = fs.readdirSync(path.join(dir, 'threads'))
for (const filename of filenames) {
const threadJSON = fs.readFileSync(path.join(dir, 'threads', filename))
const threadMessages = JSON.parse(threadJSON).map((j) => (new Message()).fromJSON(j))
let threadFolders = []
let threadParticipants = []
let threadAttachment = false
let threadUnread = false
for (const m of threadMessages) {
m.accountId = account.id
m.folder.accountId = account.id
for (const l of m.files) {
l.accountId = account.id
}
threadParticipants = threadParticipants.concat(m.participants())
threadFolders = threadFolders.push(m.folder)
threadAttachment = threadAttachment || m.files.length > 0
threadUnread = threadUnread || m.unread
}
threadParticipants = _.uniq(threadParticipants, (p) => p.email)
threadFolders = _.uniq(threadFolders, (l) => l.id)
folders = _.uniq(folders.concat(threadFolders), (l) => l.id)
const lastMsg = _.last(threadMessages)
const thread = new Thread({
accountId: account.id,
id: lastMsg.threadId,
subject: lastMsg.subject,
lastMessageReceivedTimestamp: lastMsg.date,
hasAttachment: threadAttachment,
folders: threadFolders,
participants: threadParticipants,
unread: threadUnread,
snippet: lastMsg.snippet,
starred: lastMsg.starred,
})
messages = messages.concat(threadMessages)
threads.push(thread)
}
const downloadsDir = path.join(dir, 'downloads')
if (fs.existsSync(downloadsDir)) {
for (const filename of fs.readdirSync(downloadsDir)) {
const destPath = path.join(NylasEnv.getConfigDirPath(), 'downloads', filename)
if (fs.existsSync(destPath)) {
fs.removeSync(destPath)
}
fs.copySync(path.join(downloadsDir, filename), destPath)
}
}
DatabaseStore.inTransaction((t) =>
Promise.all([
t.persistModel(account),
t.persistModels(folders),
t.persistModels(messages),
t.persistModels(threads),
])
).then(() => {
Actions.focusDefaultMailboxPerspectiveForAccounts([account.id])
})
.then(() => {
return new Promise((resolve) => setTimeout(resolve, 1000))
})
}
}
export default new AccountStore()

View file

@ -18,21 +18,10 @@ class ThreadCountsStore extends NylasStore
_onCountsChanged: =>
DatabaseStore._query("SELECT * FROM `ThreadCounts`").then (results) =>
nextCounts = {}
foundNegative = false
for {categoryId, unread, total} in results
nextCounts[categoryId] = {unread, total}
if unread < 0 or total < 0
foundNegative = true
if foundNegative
NylasEnv.reportError(new Error('Assertion Failure: Negative Count'))
@reset()
return
if _.isEqual(nextCounts, @_counts)
return
@_counts = nextCounts
@trigger()