Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moderation based on flags #83

Merged
4 commits merged into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 77 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ Calls `cb()` when the underlying indexes are caught up.

Calls `cb()` when the cabal and its resources have been closed. This also leaves the swarm, if joined.

### cabal.getMessage(key, cb)

Read a message from `key`, a string of `feedKey@seq` or an object of
`{ key, seq }` as `cb(err, node)` from the underlying hypercore.

### Channels

#### cabal.channels.get(function (error, channels) {})
Expand Down Expand Up @@ -115,19 +120,83 @@ This means that if a group of people all specify the same *moderation key*,
they will collectively see the same set of administrators, moderators, and
banned users.

#### var rs = cabal.moderation.listBans(channel)
#### cabal.moderation.listByFlag({ channel, flag })

Return a readable object stream of records for `channel` that for each user with
`flag` set.

Each `row` object in the output stream has:

* `row.id` - string user key
* `row.flags` - array of string flags
* `row.key` - string of `key@seq` referring to log records

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.list(cb)

Return a readable object stream of records for all moderation actions across all
channels.

Each `row` object in the output stream has:

* `row.id` - string key which is the target of this moderation operation
* `row.flags` - array of string flags set for this user
* `row.channel` - string channel name this operation applies to
* `row.key` - key of log record (not defined for self-admin and admins added by modkey)

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.listBlocks(channel, cb)

Return a readable object stream of records for the blocks in `channel`.

The objects in the output have the same form as `listByFlag()`.

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.listHides(channel, cb)

Return a readable object stream of records for the hides in `channel`.

The objects in the output have the same form as `listByFlag()`.

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.listMutes(channel, cb)

Return a readable object stream of records for the mutes in `channel`.

The objects in the output have the same form as `listByFlag()`.

Optionally collect results into `cb(err, rows)`.

Return a readable objectMode stream of bans for `channel`.
#### cabal.moderation.getFlags({ id, channel }, cb)

Each ban is an object with either a `key` or `ip` property.
Get a list of flags set for the user identified by `id` in `channel` as
`cb(err, flags)`.

To list cabal-wide bans use the special channel `@`.
#### cabal.moderation.setFlags({ id, channel, flags }, cb)

#### cabal.moderation.isBanned({ ip, key, channel }, cb)
Set an array of `flags` for `id` in `channel`.

Determine whether a user identified by `ip` and/or `key` is banned on `channel`
or cabal-wide as `cb(err, banned)` for a boolean `banned`. If `channel` is
omitted, only check cabal-wide.
#### cabal.moderation.addFlags({ id, channel, flags }, cb)

Add an array of `flags` to the existing set of flags for `id` in `channel`.

#### cabal.moderation.removeFlags({ id, channel, flags }, cb)

Remove an array of `flags` from the existing set of flags for `id` in `channel`.

#### cabal.moderation.events.on('update', function (update) {})

This event happens when a user's flags change with `update`, the log record
responsible for the state change.

#### cabal.moderation.events.on('skip', function (skip) {})

This event happens when a moderation update was skipped with `skip`, the log
record responsible for the state change.

### Publishing

Expand Down Expand Up @@ -164,31 +233,6 @@ documented types include
}
```

#### mod/{add,remove}

```js
{
type: '"mod/add" or "mod/remove"',
content: {
key: 'hex string key of the user to add/remove as mod',
channel: 'channel name as a string or "@" for cabal-wide'
role: '"admin", "mod", or a custom role string'
}
}
```

#### ban/{add,remove}

```js
{
type: '"ban/add" or "ban/remove"',
content: {
key: 'hex string key of the user to ban/unban',
channel: 'channel name as a string or "@" for cabal-wide'
}
}
```

## License

AGPLv3
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ Cabal.prototype.getLocalKey = function (cb) {
})
}

Cabal.prototype.getMessage = function (feedAtSeq, cb) {
if (typeof feedAtSeq === 'string') {
var p = feedAtSeq.split('@')
feedAtSeq = { key: p[0], seq: Number(p[1]) }
}
this.kcore._logs.feed(feedAtSeq.key).get(feedAtSeq.seq, cb)
}

Cabal.prototype.swarm = function (opts, cb) {
if (typeof opts === 'function') {
cb = opts
Expand Down Expand Up @@ -244,7 +252,7 @@ function generateKeyHex () {
}

function isHypercoreKey (key) {
if (typeof key === 'string') return key.length === 64 && /^[0-9a-f]+$/.test(key)
if (typeof key === 'string') return /^[0-9a-f]{64}$/.test(key)
else if (Buffer.isBuffer(key)) return key.length === 32
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"homepage": "https://github.com/cabal-club/cabal-core#readme",
"dependencies": {
"charwise": "^3.0.1",
"collect-stream": "^1.2.1",
"concat-stream": "^2.0.0",
"dat-encoding": "^5.0.1",
"debug": "^4.1.1",
Expand All @@ -41,7 +42,7 @@
"kappa-core": "^6.0.0",
"kappa-view-level": "^2.0.1",
"level-mem": "^5.0.1",
"materialized-group-auth": "^1.1.1",
"materialized-group-auth": "^2.1.0",
"monotonic-timestamp": "0.0.9",
"once": "^1.4.0",
"pump": "^3.0.0",
Expand All @@ -56,7 +57,6 @@
"xtend": "^4.0.1"
},
"devDependencies": {
"collect-stream": "^1.2.1",
"documentation": "^6.3.2",
"pump": "^3.0.0",
"random-access-memory": "^3.0.0",
Expand Down
Loading