git ssb

0+

ev / minbase



Tree: f1cc08ac986f18880000b780dae6fb2043e76948

Files: f1cc08ac986f18880000b780dae6fb2043e76948 / modules / message.js

2103 bytesRaw
1var h = require('hyperscript')
2var pull = require('pull-stream')
3var timestamp = require('./helpers').timestamp
4var getStars = require('./getstars').getstars
5var messageLink = require('./helpers').message_link
6
7var avatar = require('./avatar')
8
9exports.needs = {
10 message_content: 'first',
11 message_content_mini: 'first',
12 message_action: 'map'
13}
14
15exports.gives = 'message_render'
16
17function message_content_mini_fallback(msg) {
18 return h('code', msg.value.content.type)
19}
20
21exports.create = function (api) {
22
23 function mini(msg, el) {
24 var div = h('div.message.message--mini',
25 h('div.row',
26 h('div.avatar', h('a', {href: '#' + msg.value.author}, avatar.name(msg.value.author), ''),
27 h('span.message_content', el)),
28 h('div.message_meta', timestamp(msg))
29 )
30 )
31 return div
32 }
33
34 return function (msg, sbot) {
35 var el = api.message_content_mini(msg)
36 if(el) return mini(msg, el)
37
38 var el = api.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 messageLink(key)
56 }))
57 ))
58
59 var msg = h('div.message',
60 h('div.title.row',
61 h('a', {href: '#' + msg.value.author },
62 h('div.avatar--thumbnail', avatar.image(msg.value.author)),
63 avatar.name(msg.value.author)
64 ),
65 h('div.message_meta', getStars(msg), timestamp(msg))
66 ),
67 h('div.column',
68 h('div.message_content.row', el),
69 h('div.message_actions.row',
70 h('div.actions', api.message_action(msg),
71 h('a', {href: '#' + msg.key}, 'Reply')
72 )
73 )
74 ),
75 backlinks
76 )
77 return msg
78 }
79}
80
81
82

Built with git-ssb-web