Files: 1fe8a8808eb5537d88dcaf30930d6d57f2986822 / position / async / position.js
1704 bytesRaw
1 | const pull = require('pull-stream') |
2 | const pullAsync = require('pull-async') |
3 | const GetPoll = require('../../poll/async/get') |
4 | const sort = require('ssb-sort') |
5 | // var { link } = require('ssb-msg-schemas/util') |
6 | // |
7 | |
8 | module.exports = function (server) { |
9 | const getPoll = GetPoll(server) |
10 | |
11 | return function Position ({ poll = {}, details, reason, channel, mentions }, cb) { |
12 | const content = { |
13 | type: 'position', |
14 | root: typeof poll === 'string' ? poll : poll.key, |
15 | details |
16 | } |
17 | |
18 | if (reason) content.reason = reason |
19 | |
20 | if (channel) { |
21 | if (typeof channel !== 'string') { throw new Error('channel must be a string') } |
22 | content.channel = channel |
23 | } |
24 | |
25 | if (content.root && server) { |
26 | pull( |
27 | pullAsync(cb => { |
28 | getPoll(content.root, cb) |
29 | }), |
30 | pull.drain(({positions}) => { |
31 | console.log(positions) |
32 | content.branch = sort.heads(positions) |
33 | cb(null, content) |
34 | }) |
35 | ) |
36 | } else { |
37 | cb(null, content) |
38 | } |
39 | |
40 | // // NOTE mentions can be derived from text, |
41 | // // or we could leave it so you can manually notify people without having to at-mention spam the text |
42 | // if (mentions && (!Array.isArray(mentions) || mentions.length)) { |
43 | // mentions = links(mentions) |
44 | // if (!mentions || !mentions.length) { throw new Error('mentions are not valid links') } |
45 | // content.mentions = mentions |
46 | // } |
47 | |
48 | // // NOTE recps should be derived from the poll I think |
49 | // if (recps && (!Array.isArray(recps) || recps.length)) { |
50 | // recps = links(recps) |
51 | // if (!recps || !recps.length) { throw new Error('recps are not valid links') } |
52 | // content.recps = recps |
53 | // } |
54 | } |
55 | } |
56 |
Built with git-ssb-web