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