diff --git a/lib/boards-api.js b/lib/boards-api.js index 5c7637f..48b88ec 100644 --- a/lib/boards-api.js +++ b/lib/boards-api.js @@ -215,6 +215,12 @@ BoardsAPI.prototype.getProfile = function(userID,done){ } BoardsAPI.prototype.getBoardSettings = function(userID,board){ + if(!userID){ + return console.log('Invalid USERID',userID) + } + if(!board){ + return console.log('Invalid BOARD',board) + } this.resolveIPNS(userID,(r,e) => { if(e){ this.ee.emit('error',e) @@ -377,19 +383,25 @@ BoardsAPI.prototype.downloadComment = function(hash,adminID,board,done){ } BoardsAPI.prototype.getCommentsFor = function(parent,board,adminID){ + if(!parent || !board || !adminID){ + return console.log('malformed arguments:',parent,board,adminID) + } this.ee.on('approved comments for '+board+'@'+adminID,ret => { ret.forEach(item => this.downloadComment(item.hash,adminID,board)) }) // get the admin's comments this.getUserCommentList(parent,adminID,(err,res) => { - if(err){ - console.log(err) - } else res.forEach(item => this.downloadComment(item.hash,adminID,board)) + if(!err){ + res.forEach(item => this.downloadComment(item.hash,adminID,board)) + } }) this.getAllowedContentProducers(adminID,board,{ comments: true }) } BoardsAPI.prototype.getUserCommentList = function(parent,user,done){ + if(!parent || !user){ + return console.log('Malformed arguments:',parent,user) + } this.resolveIPNS(user,(url,err) => { if(err){ this.ee.emit('error',err) @@ -399,11 +411,13 @@ BoardsAPI.prototype.getUserCommentList = function(parent,user,done){ this.ee.emit('error',e) done(e) } else if(r && !r.split){ - console.log('Found',r.Objects[0].Links.length,'comments for',parent,'at',user) - var l = r.Objects[0].Links.map(i => { - return { date: i.Name, hash: i.Hash } - }) - done(null,l) + if(r.Objects && r.Objects[0]){ // If this is not true, then there are no comments + console.log('Found',r.Objects[0].Links.length,'comments for',parent,'at',user) + var l = r.Objects[0].Links.map(i => { + return { date: i.Name, hash: i.Hash } + }) + done(null,l) + } } }) return true // remove myself from listeners diff --git a/webapp/components/comment.jsx b/webapp/components/comment.jsx index 5134dcd..b999ed9 100644 --- a/webapp/components/comment.jsx +++ b/webapp/components/comment.jsx @@ -16,12 +16,14 @@ module.exports = function(boardsAPI){ }, render: function(){ if(this.props.comment){ + var Comments = this.props.comment.comments || require('comments.jsx')(boardsAPI) return