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

unfiltered board view implemented

This commit is contained in:
Enrico Fasoli 2015-11-26 18:21:28 +01:00
parent 4ae055be45
commit 5794ac3d4c
4 changed files with 39 additions and 21 deletions

View File

@ -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
}

View File

@ -90,6 +90,7 @@ ReactDOM.render(
</Route>
</Route>
<Route path="/post/:posthash" component={PostPage} />
<Route path="/board/:boardname" component={Board} />
<Route path="/users" component={Users} />
<Route path="/settings" component={Settings} />
<Route path="*" component={NotFound} />

View File

@ -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 (<div className="board">
<h2>{this.state.name}</h2>
<Markdown source={this.state.description} skipHtml={true} />
<h5><UserID id={this.props.params.userid} /></h5>
{this.props.params.userid?<h5><UserID id={this.props.params.userid} /></h5>:<p></p>}
<hr />
<PostList board={this.props.params.boardname} admin={this.props.params.userid}/>
</div>)
} else return <GetIPFS />

View File

@ -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