git ssb

16+

Dominic / patchbay



Tree: 52a6d8a8df089abd1131e52adf418fdf6595f98a

Files: 52a6d8a8df089abd1131e52adf418fdf6595f98a / modules_core / suggest-mentions.js

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

Built with git-ssb-web