git ssb

16+

Dominic / patchbay



Tree: 3f6f0c96bdbbd8307fb9e5459b6857870001abfc

Files: 3f6f0c96bdbbd8307fb9e5459b6857870001abfc / modules_basic / suggest-mentions.js

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

Built with git-ssb-web