git ssb

16+

Dominic / patchbay



Tree: 7c8e28be85762984790fb8433e8ceb84c5ccf8e5

Files: 7c8e28be85762984790fb8433e8ceb84c5ccf8e5 / modules_basic / message.js

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

Built with git-ssb-web