Files: 627bb1ceef39b5cccd4915b82591d2b085d4716e / modules / message.js
1550 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var pull = require('pull-stream') |
4 | |
5 | |
6 | |
7 | var plugs = require('../plugs') |
8 | var message_content = plugs.first(exports.message_content = []) |
9 | var avatar = plugs.first(exports.avatar = []) |
10 | var message_meta = plugs.map(exports.message_meta = []) |
11 | var message_action = plugs.map(exports.message_action = []) |
12 | var message_link = plugs.first(exports.message_link = []) |
13 | |
14 | var sbot_links = plugs.first(exports.sbot_links = []) |
15 | |
16 | exports.message_render = function (msg, sbot) { |
17 | var el = message_content(msg) |
18 | if(!el) return |
19 | |
20 | var backlinks = h('div.backlinks') |
21 | |
22 | pull( |
23 | sbot_links({dest: msg.key, rel: 'mentions', keys: true}), |
24 | pull.collect(function (err, links) { |
25 | if(links.length) |
26 | backlinks.appendChild(h('label', 'backlinks:', |
27 | h('div', links.map(function (link) { |
28 | return message_link(link.key) |
29 | })) |
30 | )) |
31 | }) |
32 | ) |
33 | |
34 | var msg = h('div.message', |
35 | h('div.title.row', |
36 | h('div.avatar', avatar(msg.value.author)), |
37 | h('div.message_meta.row', message_meta(msg)) |
38 | ), |
39 | h('div.message_content', el), |
40 | h('div.message_actions.row', |
41 | h('div.actions', message_action(msg), ' ', |
42 | h('a', {href: '#' + msg.key}, 'Reply') |
43 | ) |
44 | ), |
45 | backlinks, |
46 | {onkeydown: function (ev) { |
47 | //on enter, hit first meta. |
48 | if(ev.keyCode == 13) { |
49 | msg.querySelector('.enter').click() |
50 | } |
51 | }} |
52 | ) |
53 | |
54 | // ); hyperscript does not seem to set attributes correctly. |
55 | msg.setAttribute('tabindex', '0') |
56 | |
57 | return msg |
58 | } |
59 | |
60 | |
61 | |
62 | |
63 | |
64 |
Built with git-ssb-web