git ssb

0+

Piet / ssb-loomio



Tree: 81f8f8f4fc3b67a1fc26efcfeebed05d1ed7c223

Files: 81f8f8f4fc3b67a1fc26efcfeebed05d1ed7c223 / README.md

2548 bytesRaw

scuttle-poll

Create and vote on polls on ssb

background details relevant to understanding what this module does

repos:

Usage

var isPoll = require('scuttle-poll/isPoll')

isPoll(msg)
// => Boolean
var scuttle = require('scuttle-poll')(server)

var opts = {
  title: 'where shall we have our community meeting?'
  choices: [
    'in person',
    'talky.io',
    'mumble',
  ]
}
scuttle.poll.async.publishChooseOne(opts, (err, poll) => {
  if (err) throw err

  var myPosition 
  scuttle.position.async.publishPosition(myPosition, cb)
})

where server is a scuttlebot instance (or a remote connection provided by ssb-client)

Note - server can also be an observeable which resolves to a scuttlebot instance (this is more experimental, it will turn your sync functions into obs functions)

API

var Scuttle = require('scuttle-poll')
var scuttle = Scuttle(server)

Methods

scuttle.poll.sync.isPoll(msg) => Boolean

takes a msg or the contents of a msg

scuttle.poll.async.publishChooseOne(opts, cb)

where opts is an object of form:

{
  title: String,    // required
  choices: Array,   // required
  body: String,
}

and cb is a callback of signature (err, newPollMsg)

Install

With npm installed, run

$ npm install scuttle-poll

Schemas

Poll

Poll message content

{
  type:       'poll',          // required
  pollDetails: PollDetails     // required
  title:       String,         // required
  closesAt:    Integer         // required
  body:        String,
  channel,
  mentions,
  recps
}

Where PollDetails is an object which has the details needed for each type of poll: Dot, Proposal, Score

Dot vote PollDetails

{
  type: 'dot', // required
  maxStanceScore: 'Integer >= 0', // required
  maxChoiceScore: 'Integer >= 0', //optional
  choices: Array, // required
}

Proposal PollDetails

{
  type: 'proposal', // required
  proposal: String, // required
}

Score PollDetails

{
  type: 'score', // required
  maxChoiceScore: 'Integer >= 0', //required
  choices: Array, // required
}

Position



Acknowledgments

scuttle-poll was inspired by Loomio! Massive thanks to Rob Guthrie and James Kiesel for spending time giving us a brain dump of their data model.

See Also

License

MIT

Built with git-ssb-web