Files: e0439586cabe63fc84e88ff400edb18470cdec52 / message / html / render / post.js
1237 bytesRaw
1 | var h = require('mutant/h') |
2 | var nest = require('depnest') |
3 | var extend = require('xtend') |
4 | |
5 | exports.needs = nest({ |
6 | 'message.html': { |
7 | decorate: 'reduce', |
8 | layout: 'first', |
9 | link: 'first', |
10 | markdown: 'first' |
11 | } |
12 | }) |
13 | |
14 | exports.gives = nest({ |
15 | 'message.html': { |
16 | canRender: true, |
17 | render: true |
18 | } |
19 | }) |
20 | |
21 | exports.create = function (api) { |
22 | return nest('message.html', { |
23 | canRender: isRenderable, |
24 | render: function (msg, opts) { |
25 | if (!isRenderable(msg)) return |
26 | var element = api.message.html.layout(msg, extend({ |
27 | title: messageTitle(msg), |
28 | content: msg.isBlocked ? 'Content of a blocked user' : messageContent(msg), |
29 | layout: 'default' |
30 | }, opts)) |
31 | |
32 | return api.message.html.decorate(element, { |
33 | msg |
34 | }) |
35 | } |
36 | }) |
37 | |
38 | function isRenderable (msg) { |
39 | return (msg.value.content.type === 'post') ? true : undefined |
40 | } |
41 | |
42 | function messageContent (data) { |
43 | if (!data.value.content || !data.value.content.text) return |
44 | return h('div', {}, api.message.html.markdown(data.value.content)) |
45 | } |
46 | |
47 | function messageTitle (data) { |
48 | var root = data.value.content && data.value.content.root |
49 | return !root ? null : h('span', ['re: ', api.message.html.link(root)]) |
50 | } |
51 | } |
52 |
Built with git-ssb-web