Files: b62ecd6f843b26f37e70c7b6d65c71db35bbf922 / modules / suggest-mentions.js
1658 bytesRaw
1 | var pull = require('pull-stream') |
2 | function isImage (filename) { |
3 | return /\.(gif|jpg|png|svg)$/i.test(filename) |
4 | } |
5 | |
6 | exports.needs = { |
7 | sbot_links2: 'first', |
8 | blob_url: 'first', |
9 | signified: 'first', |
10 | builtin_tabs: 'map' |
11 | } |
12 | |
13 | exports.gives = { |
14 | suggest_mentions: true, |
15 | suggest_search: true |
16 | } |
17 | |
18 | exports.create = function (api) { |
19 | |
20 | return { |
21 | suggest_mentions: function (word) { |
22 | return function (cb) { |
23 | if(!/^[%&@]\w/.test(word)) return cb() |
24 | |
25 | api.signified(word, function (err, names) { |
26 | if(err) cb(err) |
27 | else cb(null, names.map(function (e) { |
28 | return { |
29 | title: e.name + ': ' + e.id.substring(0,10)+' ('+e.rank+')', |
30 | value: '['+e.name+']('+e.id+')', |
31 | rank: e.rank, |
32 | //TODO: avatar images... |
33 | } |
34 | })) |
35 | }) |
36 | } |
37 | }, |
38 | |
39 | suggest_search: function (query) { |
40 | return function (cb) { |
41 | if(/^[@%]\w/.test(query)) { |
42 | api.signified(query, function (_, names) { |
43 | cb(null, names.map(function (e) { |
44 | return { |
45 | title: e.name + ':'+e.id.substring(0, 10), |
46 | value: e.id, |
47 | subtitle: e.rank, |
48 | rank: e.rank |
49 | } |
50 | })) |
51 | }) |
52 | |
53 | } else if(/^\//.test(query)) { |
54 | var tabs = [].concat.apply([], api.builtin_tabs()) |
55 | cb(null, tabs.filter(function (name) { |
56 | return name.substr(0, query.length) === query |
57 | }).map(function (name) { |
58 | return { |
59 | title: name, |
60 | value: name, |
61 | } |
62 | })) |
63 | } else cb() |
64 | } |
65 | } |
66 | } |
67 | } |
68 |
Built with git-ssb-web