git ssb

16+

Dominic / patchbay



Tree: 7da1b2adbfa620cd35e8dcf31baf0f7d82bc9874

Files: 7da1b2adbfa620cd35e8dcf31baf0f7d82bc9874 / modules_basic / message.js

2589 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 msg.querySelector('.enter').click()
83 }
84 }}
85 )
86
87 // ); hyperscript does not seem to set attributes correctly.
88 msg.setAttribute('tabindex', '0')
89
90 return msg
91}
92
93
94
95
96
97
98
99
100

Built with git-ssb-web