git ssb

16+

Dominic / patchbay



Tree: 787f858837541c7b94531c9b98603402cfb7f06b

Files: 787f858837541c7b94531c9b98603402cfb7f06b / modules_basic / message.js

2177 bytesRaw
1var fs = require('fs')
2var Path = require('path')
3var pull = require('pull-stream')
4var u = require('../util')
5var h = require('../h')
6
7exports.needs = {
8 avatar_name: 'first',
9 avatar_link: 'first',
10 message_meta: 'map',
11 message_action: 'map',
12 message_link: 'first',
13 message_backlinks: 'first',
14 message_author: 'first',
15 message_content: 'first',
16 message_content_mini: 'first',
17 message_footer: 'first'
18}
19
20exports.gives = {
21 message_render: true,
22 mcss: true
23}
24
25exports.create = function (api) {
26 return {
27 message_render,
28 mcss: () => fs.readFileSync(Path.join(__dirname, 'message.mcss'))
29 }
30
31 function message_render (msg, sbot) {
32 var content = api.message_content_mini(msg)
33 if (content) return mini(msg, content)
34
35 content = api.message_content(msg)
36 if (!content) return mini(msg, message_content_mini_fallback(msg))
37
38 return h('Message', {
39 'ev-keydown': navigateToMessageOnEnter,
40 attributes: {
41 tabindex: '0'
42 }
43 }, [
44 h('header.author', api.message_author(msg)),
45 h('section.meta', api.message_meta(msg)),
46 h('section.content', content),
47 h('section.action', api.message_action(msg)),
48 h('footer.backlinks', api.message_backlinks(msg))
49 ])
50
51 function navigateToMessageOnEnter (ev) {
52 // on enter, hit first meta.
53 if(ev.keyCode == 13) {
54
55 // unless in an input
56 if (ev.target.nodeName === 'INPUT'
57 || ev.target.nodeName === 'TEXTAREA') return
58
59 // HACK! (mw)
60 // there's no exported api to open a new tab. :/
61 // it's only done in `app.js` module in an`onhashchange` handler.
62 // sooooooo yeah this shit for now :)
63 var wtf = h('a', { href: `#${msg.key}` })
64 msgEl.appendChild(wtf)
65 wtf.click()
66 }
67 }
68 }
69
70 function mini(msg, el) {
71 return h('Message -mini', {
72 attributes: {
73 tabindex: '0'
74 }
75 }, [
76 h('header.author', api.message_author(msg, { size: 'mini' })),
77 h('section.meta', api.message_meta(msg)),
78 h('section.content', el)
79 ])
80 }
81}
82
83
84function message_content_mini_fallback(msg) {
85 return h('code', msg.value.content.type)
86}
87

Built with git-ssb-web