apis/mentions.jsView |
---|
1 | 1 | var u = require('../util') |
2 | 2 | var explain = require('explain-error') |
3 | 3 | var getMentions = require('../mentions') |
4 | 4 | |
5 | | -module.exports = function (opts) { |
6 | | - var self = this |
7 | | - var api = this.api |
8 | | - return function (cb) { |
9 | | - getMentions(self.sbot, opts.text, function (err, mentions, ambigious) { |
10 | | - if(err) return cb(explain(err, 'could not load mentions')) |
11 | | - function toPath () { |
12 | | - return '['+[].join.call(arguments, '][')+']' |
13 | | - } |
14 | | - mentions |
15 | | - if(ambigious.length) |
16 | | - ambigious.forEach(function (e) { |
17 | | - mentions.push({name: e[0].name, link: e[0].id}) |
18 | | - }) |
| 5 | +module.exports = function (sbot) { |
| 6 | + return function (opts, apply) { |
| 7 | + return function (cb) { |
| 8 | + getMentions(sbot, opts.text, function (err, mentions, ambigious) { |
| 9 | + if(err) return cb(explain(err, 'could not load mentions')) |
| 10 | + function toPath () { |
| 11 | + return '['+[].join.call(arguments, '][')+']' |
| 12 | + } |
| 13 | + mentions |
| 14 | + if(ambigious.length) |
| 15 | + ambigious.forEach(function (e) { |
| 16 | + mentions.push({name: e[0].name, link: e[0].id}) |
| 17 | + }) |
19 | 18 | |
20 | | - function toPath () { |
21 | | - return '['+[].join.call(arguments, '][')+']' |
22 | | - } |
| 19 | + function toPath () { |
| 20 | + return '['+[].join.call(arguments, '][')+']' |
| 21 | + } |
23 | 22 | |
24 | 23 | |
25 | | - cb(null, [ |
26 | | - mentions.map(function (opts) { return api(['avatar'], opts) }), |
27 | | - u.createHiddenInputs({mentions: mentions}, 'content'), |
28 | | - ambigious.map(function (e, i) { |
29 | | - return [ |
30 | | - 'div.AmbigiousMentions', |
31 | | - e[0].name, |
32 | | - ['input', { |
33 | | - type: 'hidden', |
34 | | - name: toPath('content', 'mentions', mentions.length + i), |
35 | | - value: e[0].name |
36 | | - }], |
37 | | - ['select', { |
38 | | - name: toPath('content', 'mentions', mentions.length + i), |
39 | | - }, |
40 | | - e.map(function (e, i) { |
41 | | - return ['option', !i ? {selected: true, value: e.id} : {value: e.id}, e.id.substring(0, 12)+'...'] |
42 | | - }) |
| 24 | + cb(null, [ |
| 25 | + mentions.map(function (opts) { return apply('avatar', opts) }), |
| 26 | + u.createHiddenInputs({mentions: mentions}, 'content'), |
| 27 | + ambigious.map(function (e, i) { |
| 28 | + return [ |
| 29 | + 'div.AmbigiousMentions', |
| 30 | + e[0].name, |
| 31 | + ['input', { |
| 32 | + type: 'hidden', |
| 33 | + name: toPath('content', 'mentions', mentions.length + i), |
| 34 | + value: e[0].name |
| 35 | + }], |
| 36 | + ['select', { |
| 37 | + name: toPath('content', 'mentions', mentions.length + i), |
| 38 | + }, |
| 39 | + e.map(function (e, i) { |
| 40 | + return ['option', !i ? {selected: true, value: e.id} : {value: e.id}, e.id.substring(0, 12)+'...'] |
| 41 | + }) |
| 42 | + ] |
43 | 43 | ] |
44 | | - ] |
45 | | - }) |
46 | | - ]) |
47 | | - }) |
| 44 | + }) |
| 45 | + ]) |
| 46 | + }) |
| 47 | + } |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |