mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-25 14:54:19 +01:00
updated protocol information, wrote guidelines to implement aggregation
This commit is contained in:
parent
3905c23a68
commit
bd229e9413
22
PROTOCOL.md
22
PROTOCOL.md
@ -46,12 +46,32 @@ publication, containing:
|
|||||||
{
|
{
|
||||||
"whitelist": true,
|
"whitelist": true,
|
||||||
"blacklist": false,
|
"blacklist": false,
|
||||||
"approval_required": true,
|
"approval_required": false,
|
||||||
|
"whitelist_only": true,
|
||||||
"fullname": "The Full Name Can Be Long With Spaces",
|
"fullname": "The Full Name Can Be Long With Spaces",
|
||||||
"description": "A very Long Full Description with Spaces"
|
"description": "A very Long Full Description with Spaces"
|
||||||
}
|
}
|
||||||
|
|
||||||
The blacklist and whitelist should contain just IDs separated by 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
|
#### Post
|
||||||
|
|
||||||
|
@ -192,48 +192,99 @@ BoardsAPI.prototype.getProfile = function(userID,done){
|
|||||||
return this.ee
|
return this.ee
|
||||||
}
|
}
|
||||||
|
|
||||||
BoardsAPI.prototype.getBoardSettings = function(userID,board,done){
|
BoardsAPI.prototype.getBoardSettings = function(userID,board){
|
||||||
this.resolveIPNS(userID,(r,e) => {
|
this.resolveIPNS(userID,(r,e) => {
|
||||||
if(e){
|
if(e){
|
||||||
this.ee.emit('error',e)
|
this.ee.emit('error',e)
|
||||||
done(e)
|
|
||||||
} else {
|
} else {
|
||||||
var url = r+this.baseurl+'boards/'+board+'/settings.json'
|
var url = r+this.baseurl+'boards/'+board+'/settings.json'
|
||||||
this.ipfs.cat(url,(err,res) => {
|
this.ipfs.cat(url,(err,settings) => {
|
||||||
if(err){
|
if(err){
|
||||||
this.ee.emit('error',err)
|
this.ee.emit('error',err)
|
||||||
done(err)
|
|
||||||
} else {
|
} else {
|
||||||
// It's already json...
|
// SETTINGS file is here, need to parse it a little bit
|
||||||
done(err,res)
|
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 true // remove myself from listeners
|
||||||
})
|
})
|
||||||
|
return this.ee
|
||||||
}
|
}
|
||||||
|
|
||||||
BoardsAPI.prototype.getPostsInBoard = function(adminID,board){
|
BoardsAPI.prototype.getPostsInBoard = function(adminID,board){
|
||||||
/*
|
var downloadPost = hash => {
|
||||||
this.getBoardSettings(administratorID,board,(err,res) => {
|
this.ipfs.cat(hash,(err2,r) => {
|
||||||
// NEEDS: board settings structure definition
|
if(err2){
|
||||||
// For now we only list admin's posts
|
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) => {
|
this.getUserPostListInBoard(adminID,board,(err,res) => {
|
||||||
if(err){
|
if(err){
|
||||||
console.log(err)
|
console.log(err)
|
||||||
} else res.forEach(item => {
|
} else res.forEach(item => downloadPost(item.hash))
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
return this.ee
|
return this.ee
|
||||||
}
|
}
|
||||||
@ -303,4 +354,8 @@ BoardsAPI.prototype.init = function(done){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoardsAPI.prototype.getEventEmitter = function(){
|
||||||
|
return this.ee
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = BoardsAPI
|
module.exports = BoardsAPI
|
||||||
|
@ -91,7 +91,8 @@ var PostList = React.createClass({
|
|||||||
},
|
},
|
||||||
componentDidMount: function(){
|
componentDidMount: function(){
|
||||||
console.log('Initial POSTS',this.state.posts.length)
|
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
|
if(!this.isMounted()) return true
|
||||||
this.setState({ posts: this.state.posts.concat(post) })
|
this.setState({ posts: this.state.posts.concat(post) })
|
||||||
})
|
})
|
||||||
@ -136,14 +137,11 @@ var Board = React.createClass({
|
|||||||
return { name: '# '+this.props.params.boardname }
|
return { name: '# '+this.props.params.boardname }
|
||||||
},
|
},
|
||||||
componentDidMount: function(){
|
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(!this.isMounted()) return true
|
||||||
if(err) {
|
|
||||||
console.log('Huh? Invalid board settings?',err)
|
|
||||||
} else {
|
|
||||||
console.log('Found name:',res.fullname)
|
console.log('Found name:',res.fullname)
|
||||||
this.setState({ name: '# '+res.fullname.trim() })
|
this.setState({ name: '# '+res.fullname.trim() })
|
||||||
}
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
render: function(){
|
render: function(){
|
||||||
|
Loading…
Reference in New Issue
Block a user