Files: 74fe7cba24a1be16ab96edeb828f80c1740bef44 / modules_basic / message.js
3563 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var pull = require('pull-stream') |
4 | |
5 | //var plugs = require('../plugs') |
6 | // |
7 | //var message_content = plugs.first(exports.message_content = []) |
8 | //var message_content_mini = plugs.first(exports.message_content_mini = []) |
9 | // |
10 | //var avatar = plugs.first(exports.avatar = []) |
11 | //var avatar_name = plugs.first(exports.avatar_name = []) |
12 | //var avatar_link = plugs.first(exports.avatar_link = []) |
13 | //var message_meta = plugs.map(exports.message_meta = []) |
14 | //var message_action = plugs.map(exports.message_action = []) |
15 | //var message_link = plugs.first(exports.message_link = []) |
16 | // |
17 | //var sbot_links = plugs.first(exports.sbot_links = []) |
18 | |
19 | exports.needs = { |
20 | message_content: 'first', |
21 | message_content_mini: 'first', |
22 | avatar: 'first', |
23 | avatar_name: 'first', |
24 | avatar_link: 'first', |
25 | avatar_image_link: 'first', |
26 | message_meta: 'map', |
27 | message_action: 'map', |
28 | message_link: 'first', |
29 | // sbot_links: 'first' |
30 | } |
31 | |
32 | exports.gives = 'message_render' |
33 | |
34 | function message_content_mini_fallback(msg) { |
35 | return h('code', msg.value.content.type) |
36 | } |
37 | |
38 | exports.create = function (api) { |
39 | |
40 | function mini(msg, el) { |
41 | var div = h('div.message.message--mini', |
42 | h('div.col-md-12', |
43 | h('div', |
44 | api.avatar(msg.value.author, 'avatar-small'), |
45 | h('span.message_content', el)), |
46 | h('div.message_meta.pull-right.text-muted', api.message_meta(msg)) |
47 | ) |
48 | ) |
49 | div.setAttribute('tabindex', '0') |
50 | return div |
51 | } |
52 | |
53 | return function (msg, sbot) { |
54 | var el = api.message_content_mini(msg) |
55 | if(el) return mini(msg, el) |
56 | |
57 | var el = api.message_content(msg) |
58 | if(!el) return mini(msg, message_content_mini_fallback(msg)) |
59 | |
60 | var links = [] |
61 | for(var k in CACHE) { |
62 | var _msg = CACHE[k] |
63 | if(Array.isArray(_msg.content.mentions)) { |
64 | for(var i = 0; i < _msg.content.mentions.length; i++) |
65 | if(_msg.content.mentions[i].link == msg.key) |
66 | links.push(k) |
67 | } |
68 | } |
69 | |
70 | var backlinks = h('div.backlinks') |
71 | if(links.length) |
72 | backlinks.appendChild(h('label', 'backlinks:', |
73 | h('div', links.map(function (key) { |
74 | return api.message_link(key) |
75 | })) |
76 | )) |
77 | |
78 | |
79 | // pull( |
80 | // sbot_links({dest: msg.key, rel: 'mentions', keys: true}), |
81 | // pull.collect(function (err, links) { |
82 | // if(links.length) |
83 | // backlinks.appendChild(h('label', 'backlinks:', |
84 | // h('div', links.map(function (link) { |
85 | // return message_link(link.key) |
86 | // })) |
87 | // )) |
88 | // }) |
89 | // ) |
90 | |
91 | |
92 | var msg = h('div.panel.panel-default', h('div.panel-body', h('div.media', |
93 | h('div.media-left', |
94 | api.avatar_image_link(msg.value.author, 'media-object.avatar') |
95 | ), |
96 | h('div.media-body', |
97 | h('h4.media-heading', |
98 | h('a', {href:'#'+msg.value.author}, api.avatar_name(msg.value.author)), |
99 | h('small.pull-right.text-muted', api.message_meta(msg)) |
100 | ), |
101 | el, |
102 | h('div.message_actions', |
103 | h('div.actions', api.message_action(msg), ' ', |
104 | h('a', {href: '#' + msg.key}, 'Reply') |
105 | ) |
106 | )), |
107 | backlinks, |
108 | {onkeydown: function (ev) { |
109 | //on enter, hit first meta. |
110 | if(ev.keyCode == 13) { |
111 | |
112 | // unless in an input |
113 | if (ev.target.nodeName === 'INPUT' |
114 | || ev.target.nodeName === 'TEXTAREA') return |
115 | |
116 | msg.querySelector('.enter').click() |
117 | } |
118 | }} |
119 | |
120 | ))) |
121 | |
122 | // ); hyperscript does not seem to set attributes correctly. |
123 | msg.setAttribute('tabindex', '0') |
124 | |
125 | return msg |
126 | } |
127 | } |
128 |
Built with git-ssb-web