From 1c2dae811b7b511f0346d86b1c7331a80b2af611 Mon Sep 17 00:00:00 2001 From: cel Date: Wed, 19 Apr 2017 02:34:56 -0700 Subject: Reformat private message recipients input --- lib/serve.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/serve.js b/lib/serve.js index d3a1a6b..f9c954c 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -48,6 +48,14 @@ function encodeDispositionFilename(fname) { return '"' + encodeURIComponent(fname) + '"' } +function uniques() { + var set = {} + return function (item) { + if (set[item]) return false + return set[item] = true + } +} + function Serve(app, req, res) { this.app = app this.req = req @@ -1183,18 +1191,20 @@ Serve.prototype.composer = function (opts, cb) { .filter(function (mention) { return mention.link === '@' }) - .filter(function (mention) { - if (unknownMentionNames[mention.name]) return false - unknownMentionNames[mention.name] = true - return true - }) .map(function (mention) { - var name = mention.name - var fullName = mention.link + name - var id = formNames[name] || self.app.getReverseNameSync(fullName) - return {name: name, fullName: fullName, id: id} + return mention.name + }) + .filter(uniques()) + .map(function (name) { + var id = formNames[name] || self.app.getReverseNameSync('@' + name) + return {name: name, id: id} }) + // strip content other than feed ids from the recps field + if (data.recps) { + data.recps = u.extractFeedIds(data.recps).filter(uniques()).join(', ') + } + var done = multicb({pluck: 1, spread: true}) done()(null, h('section.composer', h('form', {method: 'post', action: opts.id ? '#' + opts.id : '', @@ -1218,7 +1228,7 @@ Serve.prototype.composer = function (opts, cb) { h('div', h('em', 'names:')), h('ul.mentions', unknownMentions.map(function (mention) { return h('li', - h('code', mention.fullName), ': ', + h('code', '@' + mention.name), ': ', h('input', {name: 'mention_name', type: 'hidden', value: mention.name}), h('input.mention-id-input', {name: 'mention_id', @@ -1264,8 +1274,7 @@ Serve.prototype.composer = function (opts, cb) { } else if (mention.link === '@') { // bare feed name var name = mention.name - var fullName = mention.link + name - var id = formNames[name] || self.app.getReverseNameSync(fullName) + var id = formNames[name] || self.app.getReverseNameSync('@' + name) if (id) mention.link = id else return false } -- cgit v1.2.3