Files: 13a24855e9dbf2ac1ca5713ab8be039818662114 / modules / suggest-mentions.js
1198 bytesRaw
1 | var pull = require('pull-stream') |
2 | var cont = require('cont') |
3 | function isImage (filename) { |
4 | return /\.(gif|jpg|png|svg)$/i.test(filename) |
5 | } |
6 | |
7 | var sbot_links2 = require('../plugs').first(exports.sbot_links2 = []) |
8 | |
9 | exports.suggest = cont.to(function (word, cb) { |
10 | if(!/^[@%&!]/.test(word[0])) return cb() |
11 | if(word.length < 2) return cb() |
12 | |
13 | var sigil = word[0] |
14 | var embed = ((sigil === '!') ? '!' : '') |
15 | if(embed) sigil = '&' |
16 | if(word[0] !== '@') word = word.substring(1) |
17 | |
18 | pull( |
19 | sbot_links2({query: [ |
20 | {$filter: {rel: ['mentions', {$prefix: word}], dest: {$prefix: sigil}}}, |
21 | {$reduce: {id: 'dest', name: ['rel', 1], rank: {$count: true}}} |
22 | ]}), |
23 | pull.collect(function (err, ary) { |
24 | |
25 | ary = ary |
26 | .filter(function (e) { |
27 | if(!embed) return true |
28 | return isImage(e.name) |
29 | }).sort(function (a, b) { |
30 | return b.rank - a.rank |
31 | }).map(function (e) { |
32 | return { |
33 | title: e.name + ': ' + e.id.substring(0,10)+' ('+e.rank+')', |
34 | value: embed+'['+e.name+']('+e.id+')', |
35 | rank: e.rank, |
36 | image: isImage(e.name) ? 'http://localhost:7777/'+e.id : undefined |
37 | } |
38 | }) |
39 | cb(null, ary) |
40 | }) |
41 | ) |
42 | }) |
43 | |
44 |
Built with git-ssb-web