From 5794ac3d4cf5d630ebfcc11b44543bbe7187f7f4 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Thu, 26 Nov 2015 18:21:28 +0100 Subject: [PATCH] unfiltered board view implemented --- lib/boards-api.js | 37 +++++++++++++++++++++++----------- webapp/app.jsx | 1 + webapp/components/board.jsx | 20 ++++++++++-------- webapp/components/postlist.jsx | 2 +- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/lib/boards-api.js b/lib/boards-api.js index 48b88ec..574b624 100644 --- a/lib/boards-api.js +++ b/lib/boards-api.js @@ -281,7 +281,10 @@ BoardsAPI.prototype.downloadPost = function(hash,adminID,board,op,done){ var post = JSON.parse(r.toString()) post.hash = hash if(op) post.op = op // Inject op - if(board) this.ee.emit('post in '+board+'@'+adminID,post,hash) + if(board){ + if(adminID) this.ee.emit('post in '+board+'@'+adminID,post,hash) + else this.ee.emit('post in '+board,post,hash) + } this.ee.emit(hash,post,adminID,board) if(done && done.apply) done(null,post) } @@ -327,17 +330,27 @@ BoardsAPI.prototype.getAllowedContentProducers = function(adminID,board,options) } BoardsAPI.prototype.getPostsInBoard = function(adminID,board){ - this.ee.on('approved posts for '+board+'@'+adminID,ret => { - // Automatically download approved posts - ret.forEach(item => this.downloadPost(item.hash,adminID,board)) - }) - // Get the admin's posts - this.getUserPostListInBoard(adminID,board,(err,res) => { - if(err){ - console.log(err) - } else res.forEach(item => this.downloadPost(item.hash,adminID,board,adminID)) - }) - this.getAllowedContentProducers(adminID,board,{ posts: true }) + if(adminID){ + this.ee.on('approved posts for '+board+'@'+adminID,ret => { + // Automatically download approved posts + ret.forEach(item => this.downloadPost(item.hash,adminID,board)) + }) + // Get the admin's posts + this.getUserPostListInBoard(adminID,board,(err,res) => { + if(err){ + console.log(err) + } else res.forEach(item => this.downloadPost(item.hash,adminID,board,adminID)) + }) + this.getAllowedContentProducers(adminID,board,{ posts: true }) + } else { + // TODO: Download all posts in board from everyone + // Download my posts + this.getUserPostListInBoard(this.id,board,(err,res) => { + if(err){ + console.log(err) + } else res.forEach(item => this.downloadPost(item.hash,undefined,board,this.id)) + }) + } return this.ee } diff --git a/webapp/app.jsx b/webapp/app.jsx index 624a190..96aa233 100644 --- a/webapp/app.jsx +++ b/webapp/app.jsx @@ -90,6 +90,7 @@ ReactDOM.render( + diff --git a/webapp/components/board.jsx b/webapp/components/board.jsx index f7a769e..6a4fa70 100644 --- a/webapp/components/board.jsx +++ b/webapp/components/board.jsx @@ -28,21 +28,24 @@ module.exports = function(boardsAPI){ this.init(boards) } }) - ee.on('settings for '+this.props.params.boardname+'@'+this.props.params.userid, (res) => { - if(!this.isMounted()) return true - console.log('Found name:',res.fullname) - this.setState({ name: res.fullname.trim(), description: res.description }) - }) + if(this.props.params.userid){ + ee.on('settings for '+this.props.params.boardname+'@'+this.props.params.userid, (res) => { + if(!this.isMounted()) return true + if(res) this.setState({ name: res.fullname, description: res.description }) + }) + } else { + this.setState({ description: 'All the messages posted in __#'+this.props.params.boardname+'__' }) + } if(boards.isInit || this.state.api){ this.setState({api: true}) this.init(boards) - boards.getBoardSettings(this.props.params.userid,this.props.params.boardname) } }) }, init: function(boards){ if(!this.state.init){ - boards.getBoardSettings(this.props.params.userid,this.props.params.boardname) + if(this.props.params.userid) + boards.getBoardSettings(this.props.params.userid,this.props.params.boardname) this.setState({ init: true }) } }, @@ -51,7 +54,8 @@ module.exports = function(boardsAPI){ return (

{this.state.name}

-
+ {this.props.params.userid?
:

} +
) } else return diff --git a/webapp/components/postlist.jsx b/webapp/components/postlist.jsx index a900b72..bc5b0fc 100644 --- a/webapp/components/postlist.jsx +++ b/webapp/components/postlist.jsx @@ -14,7 +14,7 @@ module.exports = function(boardsAPI){ init: function(boards){ this.setState({ api: true }) boards.getPostsInBoard(this.props.admin,this.props.board) - .on('post in '+this.props.board+'@'+this.props.admin,(post,hash) => { + .on('post in '+this.props.board+(this.props.admin?'@'+this.props.admin:''),(post,hash) => { if(!this.isMounted()) return true var now = (new Date()).getTime() var posts = this.state.posts