git ssb

16+

Dominic / patchbay



Tree: c17210ec353dee6e28ecd08ebdc1c50a65d99dec

Files: c17210ec353dee6e28ecd08ebdc1c50a65d99dec / modules / message.js

2036 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 avatar = plugs.first(exports.avatar = [])
10var message_meta = plugs.map(exports.message_meta = [])
11var message_action = plugs.map(exports.message_action = [])
12var message_link = plugs.first(exports.message_link = [])
13
14var sbot_links = plugs.first(exports.sbot_links = [])
15
16exports.message_render = function (msg, sbot) {
17 var el = message_content(msg)
18 if(!el) return
19
20 var links = []
21 for(var k in CACHE) {
22 var _msg = CACHE[k]
23 if(_msg.content.type == 'post' && Array.isArray(_msg.content.mentions)) {
24 for(var i = 0; i < _msg.content.mentions.length; i++)
25 if(_msg.content.mentions[i].link == msg.key)
26 links.push(k)
27 }
28 }
29
30 var backlinks = h('div.backlinks')
31 if(links.length)
32 backlinks.appendChild(h('label', 'backlinks:',
33 h('div', links.map(function (key) {
34 return message_link(key)
35 }))
36 ))
37
38
39// pull(
40// sbot_links({dest: msg.key, rel: 'mentions', keys: true}),
41// pull.collect(function (err, links) {
42// if(links.length)
43// backlinks.appendChild(h('label', 'backlinks:',
44// h('div', links.map(function (link) {
45// return message_link(link.key)
46// }))
47// ))
48// })
49// )
50
51 var msg = h('div.message',
52 h('div.title.row',
53 h('div.avatar', avatar(msg.value.author, 'thumbnail')),
54 h('div.message_meta.row', message_meta(msg))
55 ),
56 h('div.message_content', el),
57 h('div.message_actions.row',
58 h('div.actions', message_action(msg),
59 h('a', {href: '#' + msg.key}, 'Reply')
60 )
61 ),
62 backlinks,
63 {onkeydown: function (ev) {
64 //on enter, hit first meta.
65 if(ev.keyCode == 13) {
66 msg.querySelector('.enter').click()
67 }
68 }}
69 )
70
71 // ); hyperscript does not seem to set attributes correctly.
72 msg.setAttribute('tabindex', '0')
73
74 return msg
75}
76
77
78
79
80
81
82
83
84

Built with git-ssb-web