Files: 05c5b4f2078be5153b1a4ff2c0f7455a930242b1 / modules / message.js
2414 bytesRaw
1 | var h = require('../lib/h') |
2 | |
3 | var plugs = require('patchbay/plugs') |
4 | var message_content = plugs.first(exports.message_content = []) |
5 | var message_content_mini = plugs.first(exports.message_content_mini = []) |
6 | var message_link = plugs.first(exports.message_link = []) |
7 | var avatar_image = plugs.first(exports.avatar_image = []) |
8 | var avatar_name = plugs.first(exports.avatar_name = []) |
9 | var avatar_link = plugs.first(exports.avatar_link = []) |
10 | var message_meta = plugs.map(exports.message_meta = []) |
11 | var message_main_meta = plugs.map(exports.message_main_meta = []) |
12 | var message_action = plugs.map(exports.message_action = []) |
13 | var contextMenu = require('../lib/context-menu') |
14 | |
15 | exports.message_render = function (msg, inContext) { |
16 | var elMini = message_content_mini(msg) |
17 | if (elMini) { |
18 | var div = h('Message', { |
19 | 'ev-contextmenu': contextMenu.bind(null, msg) |
20 | }, [ |
21 | h('header', [ |
22 | h('div', [ |
23 | avatar_link(msg.value.author, avatar_name(msg.value.author), ''), |
24 | ' ', elMini |
25 | ]), |
26 | h('div.message_meta.row', [message_meta(msg)]) |
27 | ]) |
28 | ]) |
29 | div.setAttribute('tabindex', '0') |
30 | return div |
31 | } |
32 | |
33 | var el = message_content(msg) |
34 | if (!el) return |
35 | |
36 | var classList = [] |
37 | var replyInfo = null |
38 | |
39 | if (msg.value.content.root) { |
40 | classList.push('-reply') |
41 | if (!inContext) { |
42 | replyInfo = h('span', ['in reply to ', message_link(msg.value.content.root)]) |
43 | } |
44 | } |
45 | |
46 | var element = h('Message', { |
47 | classList, |
48 | 'ev-contextmenu': contextMenu.bind(null, msg), |
49 | 'ev-keydown': function (ev) { |
50 | // on enter, hit first meta. |
51 | if (ev.keyCode === 13) { |
52 | element.querySelector('.enter').click() |
53 | } |
54 | } |
55 | }, [ |
56 | h('header', [ |
57 | h('div.main', [ |
58 | h('a.avatar', {href: `#${msg.value.author}`}, avatar_image(msg.value.author)), |
59 | h('div.main', [ |
60 | h('div.name', [ |
61 | h('a', {href: `#${msg.value.author}`}, avatar_name(msg.value.author)) |
62 | ]), |
63 | h('div.meta', [ |
64 | message_main_meta(msg), |
65 | ' ', replyInfo |
66 | ]) |
67 | ]) |
68 | ]), |
69 | h('div.meta', message_meta(msg)) |
70 | ]), |
71 | h('section', [el]), |
72 | h('footer', [ |
73 | h('div.actions', [ |
74 | message_action(msg), |
75 | h('a', {href: '#' + msg.key}, 'Reply') |
76 | ]) |
77 | ]) |
78 | ]) |
79 | |
80 | // ); hyperscript does not seem to set attributes correctly. |
81 | element.setAttribute('tabindex', '0') |
82 | |
83 | return element |
84 | } |
85 |
Built with git-ssb-web