Files: 697e3e1780dfe42cdc94d4e26e2788489ddfb896 / modules_basic / suggest-mentions.js
1430 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 | var builtin_tabs = require('../plugs').map(exports.builtin_tabs = []) |
10 | |
11 | exports.suggest_mentions = function (word, cb) { |
12 | if(!/^[%&@]\w/.test(word)) return cb() |
13 | |
14 | |
15 | signified(word, function (err, names) { |
16 | if(err) cb(err) |
17 | else cb(null, names.map(function (e) { |
18 | return { |
19 | title: e.name + ': ' + e.id.substring(0,10)+' ('+e.rank+')', |
20 | value: '['+e.name+']('+e.id+')', |
21 | rank: e.rank, |
22 | //TODO: avatar images... |
23 | } |
24 | })) |
25 | }) |
26 | } |
27 | |
28 | exports.suggest_search = function (query, cb) { |
29 | if(/^[@%]\w/.test(query)) { |
30 | signified(query, function (_, names) { |
31 | cb(null, names.map(function (e) { |
32 | return { |
33 | title: e.name + ':'+e.id.substring(0, 10), |
34 | value: e.id, |
35 | subtitle: e.rank, |
36 | rank: e.rank |
37 | } |
38 | })) |
39 | }) |
40 | |
41 | } else if(/^\//.test(query)) { |
42 | var tabs = [].concat.apply([], builtin_tabs()) |
43 | cb(null, tabs.filter(function (name) { |
44 | return name.substr(0, query.length) === query |
45 | }).map(function (name) { |
46 | return { |
47 | title: name, |
48 | value: name, |
49 | } |
50 | })) |
51 | } else cb() |
52 | } |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 |
Built with git-ssb-web