Files: 47416e4ca950ed7de91562f1c6ede9486e4aa6d9 / plugs / message / html / layout / default.js
1859 bytesRaw
1 | const { when, h } = require('mutant') |
2 | var nest = require('depnest') |
3 | |
4 | exports.needs = nest({ |
5 | 'profile.html.person': 'first', |
6 | 'message.html': { |
7 | link: 'first', |
8 | meta: 'map', |
9 | action: 'map', |
10 | timestamp: 'first' |
11 | }, |
12 | 'about.html.image': 'first' |
13 | }) |
14 | |
15 | exports.gives = nest('message.html.layout') |
16 | |
17 | exports.create = function (api) { |
18 | return nest('message.html.layout', layout) |
19 | |
20 | function layout (msg, opts) { |
21 | if (!(opts.layout === undefined || opts.layout === 'default' || opts.layout === 'mini')) return |
22 | |
23 | var classList = ['Message'] |
24 | var replyInfo = null |
25 | |
26 | if (msg.value.content.root) { |
27 | classList.push('-reply') |
28 | var branch = msg.value.content.branch |
29 | if (branch) { |
30 | if (!opts.previousId || (opts.previousId && last(branch) && opts.previousId !== last(branch))) { |
31 | replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))]) |
32 | } |
33 | } |
34 | } |
35 | |
36 | return h('div', { |
37 | classList |
38 | }, [ |
39 | messageHeader(msg, replyInfo), |
40 | h('section', [opts.content]), |
41 | when(msg.key, h('footer', [ |
42 | h('div.actions', [ |
43 | api.message.html.action(msg) |
44 | ]) |
45 | ])) |
46 | ]) |
47 | |
48 | // scoped |
49 | |
50 | function messageHeader (msg, replyInfo) { |
51 | return h('header', [ |
52 | h('div.main', [ |
53 | h('a.avatar', {href: `${msg.value.author}`}, [ |
54 | api.about.html.image(msg.value.author) |
55 | ]), |
56 | h('div.main', [ |
57 | h('div.name', [ |
58 | api.profile.html.person(msg.value.author) |
59 | ]), |
60 | h('div.meta', [ |
61 | api.message.html.timestamp(msg), ' ', replyInfo |
62 | ]) |
63 | ]) |
64 | ]), |
65 | h('div.meta', api.message.html.meta(msg)) |
66 | ]) |
67 | } |
68 | } |
69 | } |
70 | |
71 | function last (array) { |
72 | if (Array.isArray(array)) { |
73 | return array[array.length - 1] |
74 | } else { |
75 | return array |
76 | } |
77 | } |
78 |
Built with git-ssb-web