Files: 8c686fb2b73c28246604759c61d6636e2812d871 / apis / mentions.js
1592 bytesRaw
1 | var u = require('../util') |
2 | var explain = require('explain-error') |
3 | var getMentions = require('../mentions') |
4 | |
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 | }) |
18 | |
19 | function toPath () { |
20 | return '['+[].join.call(arguments, '][')+']' |
21 | } |
22 | |
23 | cb(null, [ |
24 | mentions.filter(function (e) { return e.link }) |
25 | .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 | ] |
44 | }) |
45 | ]) |
46 | }) |
47 | } |
48 | } |
49 | } |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 |
Built with git-ssb-web