git ssb

16+

Dominic / patchbay



Tree: 7bfc8ffe94be45777d9884bcd5c9db880dcc2d97

Files: 7bfc8ffe94be45777d9884bcd5c9db880dcc2d97 / modules_basic / message.js

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

Built with git-ssb-web