git ssb

16+

Dominic / patchbay



Tree: 968dba2f62d9e537fe3cd9013e6faa8f753e38a2

Files: 968dba2f62d9e537fe3cd9013e6faa8f753e38a2 / modules_basic / message.js

2208 bytesRaw
1const fs = require('fs')
2const pull = require('pull-stream')
3const u = require('../util')
4const h = require('../h')
5
6exports.needs = {
7 avatar_name: 'first',
8 avatar_link: 'first',
9 message_action: 'map',
10 message_author: 'first',
11 message_backlinks: 'first',
12 message_content: 'first',
13 message_content_mini: 'first',
14 message_title: '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(__filename.replace(/js$/, 'mcss'), 'utf8')
28 }
29
30 function message_render (msg) {
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.title', api.message_title(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
88

Built with git-ssb-web