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