diff --git a/lib/boards-api.js b/lib/boards-api.js
index 93558df..c058aa8 100644
--- a/lib/boards-api.js
+++ b/lib/boards-api.js
@@ -60,8 +60,8 @@ function BoardsAPI(ipfs){
this.ipfs = ipfs
this.version = 'ipfs:boards:version:dev'
this.baseurl = '/ipfs-boards-profile/'
- this.users = {} // userID : profileHash
- this.resolving_ipns = {} // to check if a resolve is already in progress
+ this.users = [] // list of IPNS names
+ this.resolvingIPNS = {}
this.ee = new EventEmitter()
if(localStorage !== undefined){
// Use localStorage to store the IPNS cache
@@ -69,10 +69,10 @@ function BoardsAPI(ipfs){
try {
this.users = JSON.parse(stored)
if(this.users === null || this.users === undefined){
- this.users = {}
+ this.users = []
}
} catch(e){
- this.users = {}
+ this.users = []
}
}
}
@@ -87,16 +87,10 @@ BoardsAPI.prototype.backupCache = function(){
// Rewrote this to use event emitters. Should also add periodic rechecking
BoardsAPI.prototype.resolveIPNS = function(n,handler){
if(handler && handler.apply) this.ee.on(n,handler)
- var cached = this.users[n]
- if(cached){
- this.ee.emit(n,cached)
- //console.log(n,'was cached',cached)
- } else {
- console.log(n,'not cached')
- }
- if(this.resolving_ipns[n] != true){
- this.resolving_ipns[n] = true
+ if(!this.resolvingIPNS[n]){
+ this.resolvingIPNS[n] = true
this.ipfs.name.resolve(n,(err,r) => {
+ delete this.resolvingIPNS[n]
if(err){
// Communicate error
this.ee.emit('error',err)
@@ -105,20 +99,25 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){
if(url === undefined){
console.log('Could not resolve',n)
this.ee.emit('error',r.Message)
- } else if(this.users[n] != url) this.isUserProfile(url,(isit,err) => {
- if(isit){
- console.log(n,'is a user')
- if(this.users[n] === undefined) this.ee.emit('user',n,url)
- this.users[n] = url
- this.ee.emit(n,url)
- this.backupCache()
- } else {
- console.log(n,'not a valid profile:',err)
- this.ee.emit(n,undefined,'not a valid profile: '+err)
- }
- this.resolving_ipns[n] = false
- return true // Remove from listeners
- })
+ } else if(this.users.indexOf(n) < 0){ // new find
+ this.isUserProfile(url,(isit,err) => {
+ if(isit){
+ console.log(n,'is a user')
+ this.ee.emit(n,url)
+ if(this.users.indexOf(n) < 0){
+ this.ee.emit('user',n,url)
+ this.users.push(n)
+ this.backupCache()
+ }
+ } else {
+ console.log(n,'not a valid profile:',err)
+ this.ee.emit(n,undefined,'not a valid profile: '+err)
+ }
+ return true // Remove from listeners
+ })
+ } else { // Already known
+ this.ee.emit(n,url)
+ }
}
})
}
@@ -497,7 +496,7 @@ BoardsAPI.prototype.getEventEmitter = function(){
}
BoardsAPI.prototype.getUsers = function(){
- return Object.keys(this.users)
+ return this.users
}
BoardsAPI.prototype.getMyID = function(){
diff --git a/webapp/pages/board.jsx b/webapp/pages/board.jsx
index 1afee67..5b7f3f6 100644
--- a/webapp/pages/board.jsx
+++ b/webapp/pages/board.jsx
@@ -59,7 +59,7 @@ module.exports = function(boardsAPI){