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