git ssb

16+

Dominic / patchbay



Tree: 9916a3c063184f892f6b76d2865ecd6b8b3af8b8

Files: 9916a3c063184f892f6b76d2865ecd6b8b3af8b8 / modules / message.js

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

Built with git-ssb-web