git ssb

0+

Dominic / ssb-lists



Tree: 59b967c4a700f27659404bc42d1d756dec0867bf

Files: 59b967c4a700f27659404bc42d1d756dec0867bf / create.js

982 bytesRaw
1var ref = require('ssb-ref')
2
3function isId (id) {
4 return ref.isFeed(id) || ref.isMsg(id)
5}
6
7//creating a list doesn't need any special properties
8exports.create = function (opts) {
9 return Object.assign({}, opts, {
10 type: 'list/create'
11 })
12}
13
14exports.contact = function (opts) {
15 if(!isId(opts.contact))
16 throw new Error('must have contact property, a feed or msg id')
17 if(!ref.isMsg(opts.list))
18 throw new Error('must have list property, a msg id')
19 if(!(opts.blocking === true || opts.following === true || opts.following == false))
20 throw new Error('must be blocking following, or unfollowing')
21 return Object.assign({}, opts, {
22 type: 'list/contact'
23 })
24}
25
26exports.subscribe = function (opts) {
27 if(!ref.isMsg(opts.list))
28 throw new Error('must have list property, a msg id')
29 if('boolean' !== typeof opts.subscribe)
30 throw new Error('must have boolean subscribe property')
31 return Object.assign({}, opts, {
32 type: 'list/subscribe'
33 })
34}
35
36
37

Built with git-ssb-web