1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00

implemented comments to dinamyc structures, closes #53

This commit is contained in:
Enrico Fasoli 2015-12-12 12:51:09 +01:00
parent 674f54477f
commit 013266b3f7

View File

@ -384,37 +384,50 @@ BoardsAPI.prototype.getUserPostListInBoard = function(user,board,done){
return this.ee
}
BoardsAPI.prototype.downloadComment = function(hash,adminID,board,done){
BoardsAPI.prototype.downloadComment = function(hash,adminID,board,target){
this.ipfs.cat(hash,(err2,r) => {
if(err2){
this.ee.emit('error',err2)
console.log('Could not download comment',hash,'of',board+'@'+adminID)
if(done && done.apply) done(err2)
} else {
// TODO: add JSON parsing error handling
var cmnt = JSON.parse(r.toString())
cmnt.hash = hash
this.ee.emit(hash,cmnt,adminID,board)
this.ee.emit('comment for '+cmnt.parent,cmnt)
if(done && done.apply) done(null,cmnt)
this.ee.emit('comment for '+(target || cmnt.parent),cmnt)
}
})
return this.ee
}
BoardsAPI.prototype.getCommentsFor = function(parent,board,adminID){
BoardsAPI.prototype.getCommentsFor = function(parent,board,adminID,target){
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))
// figure out if there's a previous version of the item
this.ipfs.cat(parent, (err,res) => {
if(err){
this.ee.emit('error',err)
} else {
replyAsObj(res,true,(err2,obj) => {
if(err2){
this.ee.emit('error',err2)
} else if(typeof obj.previous == 'string'){
this.getCommentsFor(obj.previous,board,adminID,parent)
}
})
}
})
// get the admin's comments
this.getUserCommentList(parent,adminID,(err,res) => {
if(!err){
res.forEach(item => this.downloadComment(item.hash,adminID,board))
res.forEach(item => this.downloadComment(item.hash,adminID,board,target))
}
})
// Handle approved comments
this.ee.on('approved comments for '+board+'@'+adminID,ret => {
ret.forEach(item => this.downloadComment(item.hash,adminID,board,target))
})
this.getAllowedContentProducers(adminID,board,{ comments: true })
}