mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-10 12:24:20 +01:00
fixed #31
This commit is contained in:
parent
65375896be
commit
acd05deb15
@ -8,15 +8,21 @@ Needs to be browserified to work in the browser
|
||||
|
||||
// EventEmitter used to communicate with clients
|
||||
var EventEmitter = require('wolfy87-eventemitter')
|
||||
var asyncjs = require('async')
|
||||
|
||||
function asObj(str,done){
|
||||
var obj
|
||||
try {
|
||||
obj = JSON.parse(str)
|
||||
} catch (e) {
|
||||
return done(e,null)
|
||||
if(typeof str === 'string'){
|
||||
var obj
|
||||
try {
|
||||
obj = JSON.parse(str)
|
||||
} catch (e) {
|
||||
console.log('error parsing:',str,'Error:',e)
|
||||
return done(e,null)
|
||||
}
|
||||
done(null,obj)
|
||||
} else {
|
||||
done(null,str)
|
||||
}
|
||||
done(null,obj)
|
||||
}
|
||||
|
||||
function replyAsObj(res,isJson,done){
|
||||
@ -136,17 +142,22 @@ BoardsAPI.prototype.searchUsers = function(){
|
||||
this.ipfs.swarm.peers((err,r) => {
|
||||
if(err) return console.log(err)
|
||||
replyAsObj(r,true,(e,reply) => {
|
||||
if(e){
|
||||
this.ee.emit('error',e)
|
||||
return console.log('There was an error while getting swarm peers:',e)
|
||||
}
|
||||
console.log('Checking',reply.Strings.length,'peers')
|
||||
reply.Strings.forEach(item => {
|
||||
//reply.Strings.forEach(item => {
|
||||
var f = (item, done) => {
|
||||
var ss = item.split('/')
|
||||
var n = ss[ss.length-1]
|
||||
this.ee.once(n,(res,err) => done(err))
|
||||
this.resolveIPNS(n)
|
||||
})
|
||||
}
|
||||
asyncjs.eachSeries(reply.Strings,f.bind(this))
|
||||
})
|
||||
})
|
||||
// Look for who has the correct version file, they probably have a profile
|
||||
// Disabled at the moment
|
||||
/*
|
||||
this.ipfs.dht.findprovs(this.version_hash, (err,res) => {
|
||||
if(err){
|
||||
console.log('DHT FINDPROVS err',err)
|
||||
@ -156,7 +167,6 @@ BoardsAPI.prototype.searchUsers = function(){
|
||||
console.log('DHT FINDPROVS string',res)
|
||||
}
|
||||
})
|
||||
*/
|
||||
return this.ee
|
||||
}
|
||||
|
||||
@ -362,4 +372,8 @@ BoardsAPI.prototype.getEventEmitter = function(){
|
||||
return this.ee
|
||||
}
|
||||
|
||||
BoardsAPI.prototype.getUsers = function(){
|
||||
return Object.keys(this.users)
|
||||
}
|
||||
|
||||
module.exports = BoardsAPI
|
||||
|
@ -258,7 +258,7 @@ var Board = React.createClass({
|
||||
|
||||
var Users = React.createClass({
|
||||
getInitialState: function(){
|
||||
return { users: [ boards.id ] }
|
||||
return { users: boards.getUsers() }
|
||||
},
|
||||
componentDidMount: function(){
|
||||
boards.searchUsers().on('user',(id) => {
|
||||
@ -269,7 +269,7 @@ var Users = React.createClass({
|
||||
render: function(){
|
||||
return <div>
|
||||
<h1><Icon name="users" /> Users</h1>
|
||||
<p>Found <b>{this.state.users.length}</b> users, looking for more...</p>
|
||||
<p>Found <b>{this.state.users.length}</b> users</p>
|
||||
<ul>
|
||||
{this.state.users.map(user => {
|
||||
return <UserID key={user} id={user} />
|
||||
|
Loading…
Reference in New Issue
Block a user