git ssb

16+

Dominic / patchbay



Tree: 814717ae9da45083790dbf4847fb7a674daeac0c

Files: 814717ae9da45083790dbf4847fb7a674daeac0c / modules_core / suggest-mentions.js

2113 bytesRaw
1
2exports.needs = {
3 signified: 'first',
4 builtin_tabs: 'map',
5 avatar_image_src: 'first'
6}
7
8exports.gives = {
9 suggest_mentions: true,
10 suggest_search: true,
11 builtin_tabs: true
12}
13
14exports.create = function (api) {
15
16 return {
17 suggest_mentions,
18 suggest_search,
19 builtin_tabs: () => null
20 }
21
22 function suggest_mentions (word) {
23 return function (cb) {
24 if(!/^[%&@]\w/.test(word)) return cb()
25
26 api.signified(word, (err, names) => {
27 if(err) return cb(err)
28
29 cb(null, names.map(e => {
30 const { name, rank, id } = e
31 return {
32 title: name,
33 subtitle: `(${rank}) ${id.substring(0,10)}`,
34 value: '['+name+']('+id+')',
35 rank,
36 image: api.avatar_image_src(id),
37 showBoth: true
38 }
39 }))
40 })
41 }
42 }
43
44 function suggest_search (query) {
45 return function (cb) {
46 if(/^@\w/.test(query)) {
47 api.signified(query, (err, names) => {
48 if(err) return cb(err)
49
50 cb(null, names.map(e => {
51 const { name, rank, id } = e
52 return {
53 title: name,
54 subtitle: `(${rank}) ${id.substring(0,10)}`,
55 value: id,
56 rank,
57 image: api.avatar_image_src(id),
58 showBoth: true
59 }
60 }))
61 })
62 } else if (/^%\w/.test(query)) {
63 api.signified(query, (err, names) => {
64 if(err) return cb(err)
65
66 cb(null, names.map(e => {
67 const { name, rank, id } = e
68 return {
69 title: name,
70 subtitle: `(${rank}) ${id.substring(0,10)}`,
71 value: id,
72 rank
73 }
74 }))
75 })
76 } else if(/^\//.test(query)) {
77 var tabs = [].concat.apply([], api.builtin_tabs())
78 cb(null, tabs.filter(function (name) {
79 return name && name.substr(0, query.length) === query
80 }).map(function (name) {
81 return {
82 title: name,
83 value: name,
84 }
85 }))
86 } else cb()
87 }
88 }
89}
90

Built with git-ssb-web