Files: 82d1bb1396515575dc15b40dff81c0bb7ecf07b8 / plugs / message / html / layout / mini.js
2659 bytesRaw
1 | const { h, 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.html': { |
10 | link: 'first', |
11 | meta: 'map', |
12 | action: 'map', |
13 | timestamp: 'first', |
14 | backlinks: 'first' |
15 | }, |
16 | 'about.html.image': 'first' |
17 | }) |
18 | |
19 | exports.gives = nest('message.html.layout') |
20 | |
21 | exports.create = function (api) { |
22 | return nest('message.html.layout', layout) |
23 | |
24 | function layout (msg, {layout, previousId, priority, miniContent, content, includeReferences, includeForks = true}) { |
25 | if (!(layout === 'mini')) return |
26 | |
27 | var classList = ['Message -mini'] |
28 | var replyInfo = null |
29 | |
30 | if (msg.value.content.root) { |
31 | classList.push('-reply') |
32 | var branch = msg.value.content.branch |
33 | if (branch) { |
34 | if (!previousId || (previousId && last(branch) && previousId !== last(branch))) { |
35 | replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))]) |
36 | } |
37 | } |
38 | } else if (msg.value.content.project) { |
39 | replyInfo = h('span', ['on ', api.message.html.link(msg.value.content.project)]) |
40 | } |
41 | |
42 | if (priority === 2) { |
43 | classList.push('-new') |
44 | } |
45 | |
46 | return h('div', { |
47 | classList |
48 | }, [ |
49 | messageHeader(msg, { |
50 | replyInfo, priority, miniContent |
51 | }), |
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, includeForks}) |
63 | ]) |
64 | |
65 | // scoped |
66 | |
67 | function messageHeader (msg, {replyInfo, priority, miniContent}) { |
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 | miniContent, ' ', |
83 | replyInfo |
84 | ]) |
85 | ]) |
86 | ]), |
87 | h('div.meta', [ |
88 | api.message.html.meta(msg), |
89 | additionalMeta, |
90 | h('strong', api.message.html.timestamp(msg)) |
91 | ]) |
92 | ]) |
93 | } |
94 | } |
95 | } |
96 | |
97 | function last (array) { |
98 | if (Array.isArray(array)) { |
99 | return array[array.length - 1] |
100 | } else { |
101 | return array |
102 | } |
103 | } |
104 |
Built with git-ssb-web