diff --git a/src/main/account.js b/src/main/account.js index e7fae4e5..b3f393b3 100644 --- a/src/main/account.js +++ b/src/main/account.js @@ -17,7 +17,7 @@ export default class Account { listAccounts () { return new Promise((resolve, reject) => { - this.db.find({accessToken: { $ne: '' }}, (err, docs) => { + this.db.find({accessToken: { $ne: '' }}).sort({ order: 1 }).exec((err, docs) => { if (err) return reject(err) if (empty(docs)) return reject(new EmptyRecordError('empty')) resolve(docs) @@ -25,6 +25,15 @@ export default class Account { }) } + countAuthorizedAccounts () { + return new Promise((resolve, reject) => { + this.db.count({accessToken: { $ne: '' }}, (err, count) => { + if (err) return reject(err) + resolve(count) + }) + }) + } + getAccount (id) { return new Promise((resolve, reject) => { this.db.findOne( diff --git a/src/main/auth.js b/src/main/auth.js index 46d2ce5e..c04bbfe1 100644 --- a/src/main/auth.js +++ b/src/main/auth.js @@ -26,7 +26,7 @@ export default class Authentication { this.clientId = res.client_id this.clientSecret = res.client_secret - // TODO: Save order number + const count = await this.db.countAuthorizedAccounts() const json = { baseURL: this.baseURL, domain: this.domain, @@ -34,7 +34,8 @@ export default class Authentication { clientSecret: this.clientSecret, accessToken: '', username: '', - accountId: '' + accountId: '', + order: count + 1 } await this.db.insertAccount(json) const url = await Mastodon.getAuthorizationUrl(this.clientId, this.clientSecret, this.baseURL)