var ssbRef = require('ssb-ref') var mlib = require('ssb-msgs') exports.new = function (project, title, text) { if (!ssbRef.isLink(project)) throw new Error('invalid project id') var msg = { type: 'issue', project: project } if (text == null) { text = title title = null } if (title) { if (typeof title === 'string') msg.title = title else throw new Error('invalid issue title') } if (text) { if (typeof text === 'string') msg.text = text else throw new Error('invalid issue text') } return msg } exports.edit = function (id, opts) { if (!ssbRef.isMsg(id)) throw new Error('invalid issue id') var msg = { type: 'issue-edit', issues: [{ link: id }] } if (opts.open != null) msg.issues[0].open = opts.open if (opts.title != null) msg.issues[0].title = opts.title return msg } exports.close = function (id) { return exports.edit(id, {open: false}) } exports.reopen = function (id) { return exports.edit(id, {open: true}) } function editMsg(msg, id, open) { if (!ssbRef.isMsg(id)) throw new Error('invalid issue id') ;(msg.issues || (msg.issues = [])).push({ link: id, open: open }) return msg } exports.reopens = function (msg, id) { return editMsg(msg, id, true) } exports.closes = function (msg, id) { return editMsg(msg, id, false) }