Files: d092b707950e5fda7d051ad6913a8cbd99c22955 / plugs / message / html / layout / default.js
1945 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 | if (!opts.previousId) { |
29 | replyInfo = h('span', ['in reply to ', api.message.html.link(msg.value.content.root)]) |
30 | } else if (opts.previousId && last(msg.value.content.branch) && opts.previousId !== last(msg.value.content.branch)) { |
31 | replyInfo = h('span', ['in reply to ', api.message.html.link(last(msg.value.content.branch))]) |
32 | } |
33 | } |
34 | |
35 | return h('div', { |
36 | classList |
37 | }, [ |
38 | messageHeader(msg, replyInfo), |
39 | h('section', [opts.content]), |
40 | when(msg.key, h('footer', [ |
41 | h('div.actions', [ |
42 | api.message.html.action(msg) |
43 | ]) |
44 | ])) |
45 | ]) |
46 | |
47 | // scoped |
48 | |
49 | function messageHeader (msg, replyInfo) { |
50 | return h('header', [ |
51 | h('div.main', [ |
52 | h('a.avatar', {href: `${msg.value.author}`}, [ |
53 | api.about.html.image(msg.value.author) |
54 | ]), |
55 | h('div.main', [ |
56 | h('div.name', [ |
57 | api.profile.html.person(msg.value.author) |
58 | ]), |
59 | h('div.meta', [ |
60 | api.message.html.timestamp(msg), ' ', replyInfo |
61 | ]) |
62 | ]) |
63 | ]), |
64 | h('div.meta', api.message.html.meta(msg)) |
65 | ]) |
66 | } |
67 | } |
68 | } |
69 | |
70 | function last (array) { |
71 | if (Array.isArray(array)) { |
72 | return array[array.length - 1] |
73 | } else { |
74 | return array |
75 | } |
76 | } |
77 |
Built with git-ssb-web