git ssb

10+

Matt McKegg / patchwork



Tree: 1b66c47afdef9e153462cf94ef615c9b15f47c84

Files: 1b66c47afdef9e153462cf94ef615c9b15f47c84 / plugs / message / html / layout / default.js

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

Built with git-ssb-web