git ssb

3+

dangerousbeans / scuttle-vue



Tree: 82418e8c0eab5c0b94532a1f8612097db1fc1bb4

Files: 82418e8c0eab5c0b94532a1f8612097db1fc1bb4 / modules / suggest-mentions.js

1636 bytesRaw
1var pull = require('pull-stream')
2
3function isImage (filename) {
4 return /\.(gif|jpg|png|svg)$/i.test(filename)
5}
6
7exports.needs = {
8 sbot_links2: 'first',
9 blob_url: 'first',
10 signified: 'first'
11}
12
13exports.gives = {
14 suggest_mentions: true,
15 suggest_search: true
16}
17
18exports.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