diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/lib/serve.js b/lib/serve.js index 1f86188..fcc737e 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -81,7 +81,9 @@ Serve.prototype.go = function () { }) }) busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) { - data[fieldname] = val + if (!(fieldname in data)) data[fieldname] = val + else if (Array.isArray(data[fieldname])) data[fieldname].push(val) + else data[fieldname] = [data[fieldname], val] }) this.req.pipe(busboy) } else { @@ -830,6 +832,13 @@ Serve.prototype.composer = function (opts, cb) { } var channel = data.channel != null ? data.channel : opts.channel + var formNames = {} + var mentionIds = u.toArray(data.mention_id) + var mentionNames = u.toArray(data.mention_name) + for (var i = 0; i < mentionIds.length && i < mentionNames.length; i++) { + formNames[mentionNames[i]] = u.extractFeedIds(mentionIds[i])[0] + } + var done = multicb({pluck: 1, spread: true}) done()(null, h('section.composer', h('form', {method: 'post', action: opts.id ? '#' + opts.id : '', @@ -877,6 +886,7 @@ Serve.prototype.composer = function (opts, cb) { function preview(raw, cb) { var myId = self.app.sbot.id var content + var unknownMentions = [] try { content = JSON.parse(data.text) } catch (err) { @@ -887,21 +897,29 @@ Serve.prototype.composer = function (opts, cb) { } var mentions = ssbMentions(data.text) if (mentions.length) { - content.mentions = mentions.map(function (mention) { + content.mentions = mentions.filter(function (mention) { var blob = blobs[mention.link] if (blob) { if (!isNaN(blob.size)) mention.size = blob.size if (blob.type && blob.type !== 'application/octet-stream') mention.type = blob.type + } else if (/^[@%&]$/.test(mention.link)) { + // bare mention + var name = mention.name + var fullName = mention.link + name + var id = formNames[name] || self.app.getReverseNameSync(fullName) + unknownMentions.push({name: name, fullName: fullName, id: id}) + if (id) mention.link = id + else return false } - return mention + return true }) } if (data.recps != null) { if (opts.recps) return cb(new Error('got recps in opts and data')) content.recps = [myId] - String(data.recps).replace(u.ssbRefRegex, function (recp) { + u.extractFeedIds(data.recps).forEach(function (recp) { if (content.recps.indexOf(recp) === -1) content.recps.push(recp) }) } else { @@ -934,6 +952,17 @@ Serve.prototype.composer = function (opts, cb) { value: JSON.stringify(content)}), h('div', h('em', 'draft:')), msgContainer, + unknownMentions.length > 0 ? [ + h('div', h('em', 'names:')), + h('ul', unknownMentions.map(function (mention) { + return h('li', + h('code', mention.fullName), ': ', + h('input', {name: 'mention_name', type: 'hidden', + value: mention.name}), + h('input.mention-id-input', {name: 'mention_id', + value: mention.id, placeholder: 'id'})) + })) + ] : '', h('div.composer-actions', h('input', {type: 'submit', name: 'action', value: 'publish'}) ) @@ -948,7 +977,7 @@ Serve.prototype.composer = function (opts, cb) { return cb(), u.renderError(e) } var done = multicb({pluck: 1, spread: true}) - toArray(content && content.mentions).forEach(function (mention) { + u.toArray(content && content.mentions).forEach(function (mention) { if (mention.link && mention.link[0] === '&' && !isNaN(mention.size)) self.app.pushBlob(mention.link, done()) }) |