Files: ea9a423663b274022b27c3a9574fc2dfefa5b165 / poll / sync / poll.js
1533 bytesRaw
1 | // var { link } = require('ssb-msg-schemas/util') |
2 | const {versionStrings: {V1_SCHEMA_VERSION_STRING}} = require('ssb-poll-schema') |
3 | |
4 | function Poll ({ details, title, closesAt, body, channel, recps, mentions }) { |
5 | var content = { type: 'poll', details, title, closesAt, version: V1_SCHEMA_VERSION_STRING } |
6 | |
7 | if (body) content.body = body |
8 | |
9 | // if (root) { |
10 | // root = link(root) |
11 | // if (!root) { throw new Error('root is not a valid link') } |
12 | // content.root = root |
13 | // } |
14 | // if (branch) { |
15 | // if (!root) { throw new Error('root is not a valid link') } |
16 | // branch = Array.isArray(branch) ? branch.map(link) : link(branch) |
17 | // if (!branch) { throw new Error('branch is not a valid link') } |
18 | // content.branch = branch |
19 | // } |
20 | // |
21 | // // NOTE mentions can be derived from text, |
22 | // // or we could leave it so you can manually notify people without having to at-mention spam the text |
23 | // if (mentions && (!Array.isArray(mentions) || mentions.length)) { |
24 | // mentions = links(mentions) |
25 | // if (!mentions || !mentions.length) { throw new Error('mentions are not valid links') } |
26 | // content.mentions = mentions |
27 | // } |
28 | // if (recps && (!Array.isArray(recps) || recps.length)) { |
29 | // recps = links(recps) |
30 | // if (!recps || !recps.length) { throw new Error('recps are not valid links') } |
31 | // content.recps = recps |
32 | // } |
33 | if (channel) { |
34 | if (typeof channel !== 'string') { throw new Error('channel must be a string') } |
35 | content.channel = channel |
36 | } |
37 | |
38 | return content |
39 | } |
40 | |
41 | module.exports = Poll |
42 |
Built with git-ssb-web