Files: 944aabb813d4b39e34dc79a025bb30fa8db414ec / modules_basic / suggest-mentions.js
1453 bytesRaw
1 | var pull = require('pull-stream') |
2 | function isImage (filename) { |
3 | return /\.(gif|jpg|png|svg)$/i.test(filename) |
4 | } |
5 | |
6 | var sbot_links2 = require('../plugs').first(exports.sbot_links2 = []) |
7 | var blob_url = require('../plugs').first(exports.blob_url = []) |
8 | var signified = require('../plugs').first(exports.signified = []) |
9 | |
10 | exports.suggest_mentions = function (word, cb) { |
11 | if(!/^[%&@]\w/.test(word)) return cb() |
12 | |
13 | |
14 | signified(word, function (err, names) { |
15 | if(err) cb(err) |
16 | else cb(null, names.map(function (e) { |
17 | return { |
18 | title: e.name + ': ' + e.id.substring(0,10)+' ('+e.rank+')', |
19 | value: '['+e.name+']('+e.id+')', |
20 | rank: e.rank, |
21 | //TODO: avatar images... |
22 | } |
23 | })) |
24 | }) |
25 | } |
26 | |
27 | //TODO: this list should be generated from plugs |
28 | var builtinTabs = [ |
29 | '/public', '/private', '/notifications', |
30 | '/network', '/query', '/versions' |
31 | ].map(function (name) { |
32 | return { |
33 | title: name, |
34 | value: name, |
35 | } |
36 | }) |
37 | |
38 | exports.suggest_search = function (query, cb) { |
39 | if(/^[@%]\w/.test(query)) { |
40 | 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 | cb(null, builtinTabs.filter(function (name) { |
53 | return name.value.substr(0, query.length) === query |
54 | })) |
55 | } else cb() |
56 | } |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 |
Built with git-ssb-web