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