Files: d50d366baa6cc2cb6d544429e5f100b7b0c6d604 / modules_basic / message / backlinks.js
1013 bytesRaw
1 | const fs = require('fs') |
2 | const h = require('../../h') |
3 | |
4 | exports.needs = { |
5 | message_name: 'first' |
6 | } |
7 | |
8 | exports.gives = { |
9 | message_backlinks: true, |
10 | mcss: true |
11 | } |
12 | |
13 | exports.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