git ssb

16+

Dominic / patchbay



Tree: 25a8b716544bd1f58eeba52a1feb6bb5a6eb78ae

Files: 25a8b716544bd1f58eeba52a1feb6bb5a6eb78ae / modules_basic / message.js

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

Built with git-ssb-web