git ssb

10+

Matt McKegg / patchwork



Tree: a821b0ce884300e8ff3901678c19c6827e1189e9

Files: a821b0ce884300e8ff3901678c19c6827e1189e9 / modules / message.js

2472 bytesRaw
1var h = require('../lib/h')
2var when = require('@mmckegg/mutant/when')
3
4var plugs = require('patchbay/plugs')
5var message_content = plugs.first(exports.message_content = [])
6var message_content_mini = plugs.first(exports.message_content_mini = [])
7var message_link = plugs.first(exports.message_link = [])
8var avatar_image = plugs.first(exports.avatar_image = [])
9var avatar_name = plugs.first(exports.avatar_name = [])
10var avatar_link = plugs.first(exports.avatar_link = [])
11var message_meta = plugs.map(exports.message_meta = [])
12var message_main_meta = plugs.map(exports.message_main_meta = [])
13var message_action = plugs.map(exports.message_action = [])
14var contextMenu = require('../lib/context-menu')
15
16exports.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