Files: a6940a3d687c1a19beaf95c047f36bf32fbb8f2e / message / html / render / post.js
1042 bytesRaw
1 | var nest = require('depnest') |
2 | var h = require('mutant/h') |
3 | |
4 | exports.needs = nest({ |
5 | 'message.html': { |
6 | decorate: 'reduce', |
7 | layout: 'first', |
8 | link: 'first', |
9 | markdown: 'first' |
10 | } |
11 | }) |
12 | |
13 | exports.gives = nest('message.html.render') |
14 | |
15 | exports.create = function (api) { |
16 | return nest('message.html.render', function renderMessage (msg, opts) { |
17 | if (msg.value.content.type !== 'post') return |
18 | if (opts && opts.layout !== 'inbox') return |
19 | |
20 | var element = api.message.html.layout(msg, Object.assign({}, { |
21 | title: messageTitle(msg), |
22 | // content: messageContent(msg), // not needed |
23 | }, opts)) |
24 | |
25 | // decorate locally |
26 | if (msg.replies && msg.replies.length) { |
27 | element.dataset.root = msg.key |
28 | element.dataset.id = msg.replies[msg.replies.length-1].key |
29 | } else { |
30 | element.dataset.id = msg.key |
31 | } |
32 | |
33 | return element |
34 | }) |
35 | |
36 | function messageTitle (data) { |
37 | var root = data.value.content && data.value.content.root |
38 | return !root ? null : h('span', ['re: ', api.message.html.link(root)]) |
39 | } |
40 | } |
41 | |
42 |
Built with git-ssb-web