git ssb

0+

ev / minbase



Tree: f1cc08ac986f18880000b780dae6fb2043e76948

Files: f1cc08ac986f18880000b780dae6fb2043e76948 / modules / suggest-mentions.js

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

Built with git-ssb-web