git ssb

0+

Piet / ssb-loomio



Tree: 5f55ad219f72d734cb27efc4d543d507f1fd04ae

Files: 5f55ad219f72d734cb27efc4d543d507f1fd04ae / poll / async / buildUpdatedClosingTime.js

2026 bytesRaw
1const pull = require('pull-stream')
2const pullAsync = require('pull-async')
3const { heads } = require('ssb-sort')
4const { isMsg } = require('ssb-ref')
5const { isPoll, isPollUpdate, versionStrings: {V1_SCHEMA_VERSION_STRING} } = require('ssb-poll-schema')
6
7module.exports = function (server) {
8 return function UpdatedClosingTime ({ poll, mentions, recps, closesAt }, cb) {
9 if (!isPoll(poll) && !isMsg(poll)) return cb(new Error('UpdatedClosingTime factory expects a valid poll'))
10
11 // NOTE - getPoll has to be required here to avoid circular deps
12 const getPoll = require('../../poll/async/get')(server)
13
14 pull(
15 pullAsync(cb => {
16 getPoll(typeof poll === 'string' ? poll : poll.key, cb)
17 }),
18 pull.map(build),
19 pull.drain(update => {
20 if (!isPollUpdate(update)) return cb(isPollUpdate.errors)
21
22 cb(null, update)
23 })
24 )
25
26 function build (poll) {
27 // NOTE - poll here is a decorated poll
28 const content = {
29 type: 'poll-update',
30 version: V1_SCHEMA_VERSION_STRING,
31 root: poll.key,
32 closesAt
33 }
34
35 content.branch = heads(poll.positions.concat(poll))
36
37 if (recps) content.recps = recps
38 if (mentions) content.mentions = mentions
39 if (poll.channel) content.channel = poll.channel
40 if (mentions) content.mentions = mentions
41
42 return content
43 }
44 }
45}
46
47// // NOTE mentions can be derived from text,
48// // or we could leave it so you can manually notify people without having to at-mention spam the text
49// if (mentions && (!Array.isArray(mentions) || mentions.length)) {
50// mentions = links(mentions)
51// if (!mentions || !mentions.length) { throw new Error('mentions are not valid links') }
52// content.mentions = mentions
53// }
54
55// // NOTE recps should be derived from the poll I think
56// if (recps && (!Array.isArray(recps) || recps.length)) {
57// recps = links(recps)
58// if (!recps || !recps.length) { throw new Error('recps are not valid links') }
59// content.recps = recps
60// }
61

Built with git-ssb-web