Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
prevent duplicated apps entries in devices
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Ray committed Sep 2, 2019
1 parent ba29ae6 commit eb6d64e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/lib/masq.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,19 @@ class Masq {
this._startReplicate(this.profileDB)

const apps = await this.getApps()
apps.forEach(async (app) => {
for (let app of apps) {
const dbName = `app-${profileId}-${app.id}`

// app is not replicated yet
if (!(await dbExists(dbName))) return
if (!(await dbExists(dbName))) {
continue
}

const db = openOrCreateDB(dbName)
this.appsDBs[dbName] = db
await dbReady(db)
this._startReplicate(db)
})
}

const profile = await this.getAndDecrypt('/profile')
this.setState(STATES.LOGGED)
Expand Down Expand Up @@ -668,16 +670,21 @@ class Masq {
}
}

_watchAndAuthorizeApps () {
watch(this.profileDB, this.nonce, '/devices', async () => {
await this.syncApps()
})
/**
* Private methods
*/

_watchAndAuthorizeApps () {
watch(this.profileDB, this.nonce, '/devices', () => this.syncApps())
this.syncApps()
}

_createDBAndSyncApp (dbName, hex = null) {
return new Promise((resolve) => {
if (this.appsDBs[dbName]) {
return resolve(this.appsDBs[dbName])
}

const db = openOrCreateDB(dbName, hex)
this.appsDBs[dbName] = db
db.on('ready', async () => {
Expand Down

0 comments on commit eb6d64e

Please sign in to comment.