git ssb

0+

Piet / ssb-loomio



Tree: 89d04b0f0784096d39f86b2f8cd93579dabc8643

Files: 89d04b0f0784096d39f86b2f8cd93579dabc8643 / position / async / position.js

1584 bytesRaw
1const pull = require('pull-stream')
2const pullAsync = require('pull-async')
3const GetPoll = require('../../poll/async/get')
4const sort = require('ssb-sort')
5// var { link } = require('ssb-msg-schemas/util')
6//
7
8module.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 getPoll(content.root, (err, {positions}) => {
27 content.branch = sort.heads(positions)
28 cb(err, content)
29 })
30 } else {
31 cb(null, content)
32 }
33
34 // // NOTE mentions can be derived from text,
35 // // or we could leave it so you can manually notify people without having to at-mention spam the text
36 // if (mentions && (!Array.isArray(mentions) || mentions.length)) {
37 // mentions = links(mentions)
38 // if (!mentions || !mentions.length) { throw new Error('mentions are not valid links') }
39 // content.mentions = mentions
40 // }
41
42 // // NOTE recps should be derived from the poll I think
43 // if (recps && (!Array.isArray(recps) || recps.length)) {
44 // recps = links(recps)
45 // if (!recps || !recps.length) { throw new Error('recps are not valid links') }
46 // content.recps = recps
47 // }
48 }
49}
50

Built with git-ssb-web