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