git ssb

16+

Dominic / patchbay



Tree: 8dfd53f6b3b313f0e6bf9db8230c208c1f91937c

Files: 8dfd53f6b3b313f0e6bf9db8230c208c1f91937c / modules_basic / message / backlinks.js

1013 bytesRaw
1const fs = require('fs')
2const h = require('../../h')
3
4exports.needs = {
5 message_name: 'first'
6}
7
8exports.gives = {
9 message_backlinks: true,
10 mcss: true
11}
12
13exports.create = function (api) {
14 return {
15 message_backlinks,
16 mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8')
17 }
18
19 function message_backlinks (msg) {
20 var links = []
21 for(var k in CACHE) {
22 var _msg = CACHE[k]
23 var mentions = _msg.content.mentions
24
25 if(Array.isArray(mentions)) {
26 for(var i = 0; i < mentions.length; i++)
27 if(mentions[i].link == msg.key)
28 links.push(k)
29 }
30 }
31
32 if (links.length === 0) return null
33
34 var hrefList = h('ul')
35 links.forEach(link => {
36 api.message_name(link, (err, name) => {
37 if (err) throw err
38 hrefList.appendChild(h('li',
39 h('a -backlink', { href: `#${link}` }, name)
40 ))
41 })
42 })
43 return h('MessageBacklinks', [
44 h('header', 'backlinks:'),
45 hrefList
46 ])
47 }
48}
49

Built with git-ssb-web