mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-25 14:54:19 +01:00
implemented comments to dinamyc structures, closes #53
This commit is contained in:
parent
674f54477f
commit
013266b3f7
@ -384,37 +384,50 @@ BoardsAPI.prototype.getUserPostListInBoard = function(user,board,done){
|
|||||||
return this.ee
|
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) => {
|
this.ipfs.cat(hash,(err2,r) => {
|
||||||
if(err2){
|
if(err2){
|
||||||
this.ee.emit('error',err2)
|
this.ee.emit('error',err2)
|
||||||
console.log('Could not download comment',hash,'of',board+'@'+adminID)
|
console.log('Could not download comment',hash,'of',board+'@'+adminID)
|
||||||
if(done && done.apply) done(err2)
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: add JSON parsing error handling
|
// TODO: add JSON parsing error handling
|
||||||
var cmnt = JSON.parse(r.toString())
|
var cmnt = JSON.parse(r.toString())
|
||||||
cmnt.hash = hash
|
cmnt.hash = hash
|
||||||
this.ee.emit(hash,cmnt,adminID,board)
|
this.ee.emit(hash,cmnt,adminID,board)
|
||||||
this.ee.emit('comment for '+cmnt.parent,cmnt)
|
this.ee.emit('comment for '+(target || cmnt.parent),cmnt)
|
||||||
if(done && done.apply) done(null,cmnt)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return this.ee
|
return this.ee
|
||||||
}
|
}
|
||||||
|
|
||||||
BoardsAPI.prototype.getCommentsFor = function(parent,board,adminID){
|
BoardsAPI.prototype.getCommentsFor = function(parent,board,adminID,target){
|
||||||
if(!parent || !board || !adminID){
|
if(!parent || !board || !adminID){
|
||||||
return console.log('malformed arguments:',parent,board,adminID)
|
return console.log('malformed arguments:',parent,board,adminID)
|
||||||
}
|
}
|
||||||
this.ee.on('approved comments for '+board+'@'+adminID,ret => {
|
// figure out if there's a previous version of the item
|
||||||
ret.forEach(item => this.downloadComment(item.hash,adminID,board))
|
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
|
// get the admin's comments
|
||||||
this.getUserCommentList(parent,adminID,(err,res) => {
|
this.getUserCommentList(parent,adminID,(err,res) => {
|
||||||
if(!err){
|
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 })
|
this.getAllowedContentProducers(adminID,board,{ comments: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user