diff --git a/PROTOCOL.md b/PROTOCOL.md index 18f8172..8304b8d 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -46,12 +46,32 @@ publication, containing: { "whitelist": true, "blacklist": false, - "approval_required": true, + "approval_required": false, + "whitelist_only": true, "fullname": "The Full Name Can Be Long With Spaces", "description": "A very Long Full Description with Spaces" } The blacklist and whitelist should contain just IDs separated by spaces. +The admin is _always_ considered as if he is in the whitelist. + +if content approval is required: + +- content is allowed if it's approved even if the author isn't whitelisted or he is blacklisted +- content is allowed even if not approved if the author is in the whitelist +- content from the whitelisted users is allowed, doesn't need approval + +If only whitelisted users are allowed to post: + +- only show content from whitelisted users +- approval required option and blacklist are not considered + +If the whitelist is disabled, whitelist only is disabled and approval required is disabled: + +- eveything from everyone except blacklisted users is allowed +- if the blacklist is disabled, everything is allowed + +__TODO__ implement the ability to manually hide content and to name moderators that can approve and hide content #### Post diff --git a/lib/boards-api.js b/lib/boards-api.js index 7b6b537..ae1cb45 100644 --- a/lib/boards-api.js +++ b/lib/boards-api.js @@ -192,48 +192,99 @@ BoardsAPI.prototype.getProfile = function(userID,done){ return this.ee } -BoardsAPI.prototype.getBoardSettings = function(userID,board,done){ +BoardsAPI.prototype.getBoardSettings = function(userID,board){ this.resolveIPNS(userID,(r,e) => { if(e){ this.ee.emit('error',e) - done(e) } else { var url = r+this.baseurl+'boards/'+board+'/settings.json' - this.ipfs.cat(url,(err,res) => { + this.ipfs.cat(url,(err,settings) => { if(err){ this.ee.emit('error',err) - done(err) } else { - // It's already json... - done(err,res) + // SETTINGS file is here, need to parse it a little bit + this.ee.emit('settings for '+board+'@'+userID,settings,r) + if(settings.whitelist == true){ + // Get the whitelist + var url = r+this.baseurl+'boards/'+board+'/whitelist' + this.ipfs.cat(url,(err,whitelist) => { + if(err){ + this.ee.emit('error',err) + // Emit an empty whitelist. + this.emit('whitelist for '+board+'@'+userID,[]) + } else { + // Send whitelist + var w = whitelist.split(' ') + this.emit('whitelist for '+board+'@'+userID,w) + } + }) + } + if(!settings.whitelist_only && !settings.approval_required && settings.blacklist == true){ + // Get the blacklist + var u = r+this.baseurl+'boards/'+board+'/blacklist' + this.ipfs.cat(u,(err,blacklist) => { + if(err){ + this.ee.emit('error',err) + } else { + // Send blacklist + var w = blacklist.split(' ') + this.emit('blacklist for '+board+'@'+userID,w) + } + }) + } } }) } return true // remove myself from listeners }) + return this.ee } BoardsAPI.prototype.getPostsInBoard = function(adminID,board){ - /* - this.getBoardSettings(administratorID,board,(err,res) => { - // NEEDS: board settings structure definition - // For now we only list admin's posts + var downloadPost = hash => { + this.ipfs.cat(hash,(err2,r) => { + if(err2){ + this.ee.emit('error',err2) + console.log('Could not download post',hash,'of',board+'@'+adminID) + } else { + // It already returns a JSON? + this.ee.emit('post in '+board+'@'+adminID,r,hash) + } + }) + } + this.getBoardSettings(adminID,board) + this.ee.on('settings for'+board+'@'+adminID,function(settings,addr){ + // Download posts based on settings + if(settings.approval_required == true){ + // Get approved posts list + var a = addr+this.baseurl+'boards/'+board+'/approved/posts/' + this.ipfs.ls(a,(err,res) => { + if(err){ + this.ee.emit('error',err) + } else { + // Send approved posts list + var ret = res.Objects[0].Links.map(item => { + return { date: item.Name, hash: item.Hash } + }) + this.emit('approved posts for '+board+'@'+adminID,ret) + // Automatically download approved posts + ret.forEach(item => downloadPost(item.hash)) + } + }) + if(settings.whitelist == true){ + // TODO: Download all posts from whitelisted users + } + } else if(settings.whitelist_only == true){ + // TODO: download all posts from whitelisted users + } else if(settings.blacklist == true){ + // TODO: get the blacklist, then start downloading posts from everyone not in the blacklist + } }) - */ + // Get the admin's posts this.getUserPostListInBoard(adminID,board,(err,res) => { if(err){ console.log(err) - } else res.forEach(item => { - this.ipfs.cat(item.hash,(err2,r) => { - if(err2){ - this.ee.emit('error',err2) - console.log('Could not download post',item,'of',board+'@'+adminID) - } else { - // It already returns a JSON? - this.ee.emit('post',r,item.hash) - } - }) - }) + } else res.forEach(item => downloadPost(item.hash)) }) return this.ee } @@ -303,4 +354,8 @@ BoardsAPI.prototype.init = function(done){ }) } +BoardsAPI.prototype.getEventEmitter = function(){ + return this.ee +} + module.exports = BoardsAPI diff --git a/webapp/app.jsx b/webapp/app.jsx index 6e8c1fb..7b6ff05 100644 --- a/webapp/app.jsx +++ b/webapp/app.jsx @@ -91,7 +91,8 @@ var PostList = React.createClass({ }, componentDidMount: function(){ console.log('Initial POSTS',this.state.posts.length) - boards.getPostsInBoard(this.props.admin,this.props.board).on('post',(post,hash) => { + boards.getPostsInBoard(this.props.admin,this.props.board) + .on('post in '+this.props.board+'@'+this.props.admin,(post,hash) => { if(!this.isMounted()) return true this.setState({ posts: this.state.posts.concat(post) }) }) @@ -136,14 +137,11 @@ var Board = React.createClass({ return { name: '# '+this.props.params.boardname } }, componentDidMount: function(){ - boards.getBoardSettings(this.props.params.userid,this.props.params.boardname, (err,res) => { + var ee = boards.getBoardSettings(this.props.params.userid,this.props.params.boardname) + ee.on('settings for '+this.props.params.boardname+'@'+this.props.params.userid, (res) => { if(!this.isMounted()) return true - if(err) { - console.log('Huh? Invalid board settings?',err) - } else { - console.log('Found name:',res.fullname) - this.setState({ name: '# '+res.fullname.trim() }) - } + console.log('Found name:',res.fullname) + this.setState({ name: '# '+res.fullname.trim() }) }) }, render: function(){