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