Files: a985a4d720c6d68c96dba230b7c58072d5663d71 / modules_basic / message-backlinks.js
838 bytesRaw
1 | const fs = require('fs') |
2 | const h = require('../h') |
3 | |
4 | exports.gives = { |
5 | message_backlinks: true, |
6 | mcss: true |
7 | } |
8 | |
9 | exports.create = function (api) { |
10 | return { |
11 | message_backlinks, |
12 | mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') |
13 | } |
14 | |
15 | function message_backlinks (msg) { |
16 | var links = [] |
17 | for(var k in CACHE) { |
18 | var _msg = CACHE[k] |
19 | var mentions = _msg.content.mentions |
20 | |
21 | if(Array.isArray(mentions)) { |
22 | for(var i = 0; i < mentions.length; i++) |
23 | if(mentions[i].link == msg.key) |
24 | links.push(k) |
25 | } |
26 | } |
27 | |
28 | if (links.length === 0) return null |
29 | |
30 | return h('MessageBacklinks', [ |
31 | h('header', 'backlinks:'), |
32 | h('ul', links.map(link => { |
33 | return h('li', [ |
34 | h('a -backlink', { href: `#${link}` }, link) |
35 | ]) |
36 | })) |
37 | ]) |
38 | } |
39 | } |
40 |
Built with git-ssb-web