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