git ssb

0+

ev / minbase



Tree: b62ecd6f843b26f37e70c7b6d65c71db35bbf922

Files: b62ecd6f843b26f37e70c7b6d65c71db35bbf922 / modules / message.js

2325 bytesRaw
1var h = require('hyperscript')
2var u = require('../util')
3var pull = require('pull-stream')
4
5exports.needs = {
6 message_content: 'first',
7 message_content_mini: 'first',
8 avatar: 'first',
9 avatar_name: 'first',
10 avatar_link: 'first',
11 message_meta: 'map',
12 message_action: 'map',
13 message_link: 'first'
14}
15
16exports.gives = 'message_render'
17
18function message_content_mini_fallback(msg) {
19 return h('code', msg.value.content.type)
20}
21
22exports.create = function (api) {
23
24 function mini(msg, el) {
25 var div = h('div.message.message--mini',
26 h('div.title',
27 h('div.message_meta', api.message_meta(msg)),
28 h('div.avatar', api.avatar(msg.value.author, 'thumbnail'))
29 ),
30 h('div.message_content', el)
31 )
32 div.setAttribute('tabindex', '0')
33 return div
34 }
35
36 return function (msg, sbot) {
37 var el = api.message_content_mini(msg)
38 if(el) return mini(msg, el)
39
40 var el = api.message_content(msg)
41 if(!el) return mini(msg, message_content_mini_fallback(msg))
42
43 var links = []
44 for(var k in CACHE) {
45 var _msg = CACHE[k]
46 if(Array.isArray(_msg.content.mentions)) {
47 for(var i = 0; i < _msg.content.mentions.length; i++)
48 if(_msg.content.mentions[i].link == msg.key)
49 links.push(k)
50 }
51 }
52
53 var backlinks = h('div.backlinks')
54 if(links.length)
55 backlinks.appendChild(h('label', 'backlinks:',
56 h('div', links.map(function (key) {
57 return api.message_link(key)
58 }))
59 ))
60
61 var msg = h('div.message',
62 h('div.title',
63 h('div.message_meta', api.message_meta(msg)),
64 h('div.avatar', api.avatar(msg.value.author, 'thumbnail'))
65 ),
66 h('div.message_content', el),
67 h('div.message_actions',
68 h('div.actions', api.message_action(msg),
69 h('a', {href: '#' + msg.key}, 'Reply')
70 )
71 ),
72 backlinks,
73 {onkeydown: function (ev) {
74 //on enter, hit first meta.
75 if(ev.keyCode == 13) {
76
77 // unless in an input
78 if (ev.target.nodeName === 'INPUT'
79 || ev.target.nodeName === 'TEXTAREA') return
80
81 msg.querySelector('.enter').click()
82 }
83 }}
84 )
85
86 // ); hyperscript does not seem to set attributes correctly.
87 msg.setAttribute('tabindex', '0')
88
89 return msg
90 }
91}
92
93
94

Built with git-ssb-web