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