Files: 2c6e20555336c47eae846c5db7b268cf2a85c159 / modules_basic / suggest-mentions.js
1937 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 | builtin_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) { |
45 | return function (cb) { |
46 | if(/^[@%]\w/.test(query)) { |
47 | api.signified(query, function (_, names) { |
48 | cb(null, names.map(function (e) { |
49 | return { |
50 | title: e.name + ':'+e.id.substring(0, 10), |
51 | value: e.id, |
52 | subtitle: e.rank, |
53 | rank: e.rank |
54 | } |
55 | })) |
56 | }) |
57 | |
58 | } else if(/^\//.test(query)) { |
59 | var tabs = [].concat.apply([], api.builtin_tabs()) |
60 | cb(null, tabs.filter(function (name) { |
61 | return name.substr(0, query.length) === query |
62 | }).map(function (name) { |
63 | return { |
64 | title: name, |
65 | value: name, |
66 | } |
67 | })) |
68 | } else cb() |
69 | } |
70 | } |
71 | } |
72 | } |
73 |
Built with git-ssb-web