Files: d951d83a8663076e0b94ed3ed7f6cbdd16e4b5bf / plugs / message / html / layout / mini.js
2871 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.html': { |
10 | link: 'first', |
11 | meta: 'map', |
12 | action: 'map', |
13 | timestamp: 'first' |
14 | }, |
15 | 'about.html.image': 'first' |
16 | }) |
17 | |
18 | exports.gives = nest('message.html.layout') |
19 | |
20 | exports.create = function (api) { |
21 | return nest('message.html.layout', layout) |
22 | |
23 | function layout (msg, opts) { |
24 | if (!(opts.layout === 'mini')) return |
25 | |
26 | var backlinks = opts.backlinks ? api.message.obs.backlinks(msg.key) : [] |
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 (!opts.previousId || (opts.previousId && last(branch) && opts.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 (opts.priority === 2) { |
43 | classList.push('-new') |
44 | } |
45 | |
46 | return h('div', { |
47 | classList |
48 | }, [ |
49 | messageHeader(msg, { |
50 | replyInfo, |
51 | priority: opts.priority, |
52 | miniContent: opts.miniContent |
53 | }), |
54 | h('section', [opts.content]), |
55 | computed(msg.key, (key) => { |
56 | if (ref.isMsg(key)) { |
57 | return h('footer', [ |
58 | h('div.actions', [ |
59 | api.message.html.action(msg) |
60 | ]) |
61 | ]) |
62 | } |
63 | }), |
64 | map(backlinks, backlink => { |
65 | return h('a.backlink', { |
66 | href: backlink, |
67 | title: backlink |
68 | }, [ |
69 | h('strong', 'Referenced from'), ' ', api.message.obs.name(backlink) |
70 | ]) |
71 | }) |
72 | ]) |
73 | |
74 | // scoped |
75 | |
76 | function messageHeader (msg, {replyInfo, priority, miniContent}) { |
77 | var additionalMeta = [] |
78 | if (opts.priority >= 2) { |
79 | additionalMeta.push(h('span.flag -new', {title: 'New Message'})) |
80 | } |
81 | return h('header', [ |
82 | h('div.main', [ |
83 | h('a.avatar', {href: `${msg.value.author}`}, [ |
84 | api.about.html.image(msg.value.author) |
85 | ]), |
86 | h('div.main', [ |
87 | h('div.name', [ |
88 | api.profile.html.person(msg.value.author) |
89 | ]), |
90 | h('div.meta', [ |
91 | miniContent, ' ', |
92 | replyInfo |
93 | ]) |
94 | ]) |
95 | ]), |
96 | h('div.meta', [ |
97 | api.message.html.meta(msg), |
98 | additionalMeta, |
99 | h('strong', api.message.html.timestamp(msg)) |
100 | ]) |
101 | ]) |
102 | } |
103 | } |
104 | } |
105 | |
106 | function last (array) { |
107 | if (Array.isArray(array)) { |
108 | return array[array.length - 1] |
109 | } else { |
110 | return array |
111 | } |
112 | } |
113 |
Built with git-ssb-web