Files: 44ae6e44757e6b0a0f31c47a15868511e1edea66 / modules / message.js
2005 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var pull = require('pull-stream') |
4 | |
5 | |
6 | |
7 | var plugs = require('../plugs') |
8 | var message_content = plugs.first(exports.message_content = []) |
9 | var avatar = plugs.first(exports.avatar = []) |
10 | var message_meta = plugs.map(exports.message_meta = []) |
11 | var message_action = plugs.map(exports.message_action = []) |
12 | var message_link = plugs.first(exports.message_link = []) |
13 | |
14 | var sbot_links = plugs.first(exports.sbot_links = []) |
15 | |
16 | exports.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(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