git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 3d32dd2cc4892720337acdff65bf871556608561

Files: 3d32dd2cc4892720337acdff65bf871556608561 / plugs / message / html / layout / default.js

2480 bytesRaw
1const { when, h, map, computed } = require('mutant')
2var nest = require('depnest')
3var ref = require('ssb-ref')
4
5exports.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
18exports.gives = nest('message.html.layout')
19
20exports.create = function (api) {
21 return nest('message.html.layout', layout)
22
23 function layout (msg, opts) {
24 if (!(opts.layout === undefined || opts.layout === 'default')) return
25
26 var backlinks = opts.backlinks ? api.message.obs.backlinks(msg.key) : []
27 var classList = ['Message']
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 return h('div', {
43 classList
44 }, [
45 messageHeader(msg, replyInfo),
46 h('section', [opts.content]),
47 map(backlinks, backlink => {
48 return h('a.backlink', {
49 href: backlink,
50 title: backlink
51 }, [
52 h('strong', 'Referenced from'), ' ', api.message.obs.name(backlink)
53 ])
54 }),
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 ])
65
66 // scoped
67
68 function messageHeader (msg, replyInfo) {
69 return h('header', [
70 h('div.main', [
71 h('a.avatar', {href: `${msg.value.author}`}, [
72 api.about.html.image(msg.value.author)
73 ]),
74 h('div.main', [
75 h('div.name', [
76 api.profile.html.person(msg.value.author)
77 ]),
78 h('div.meta', [
79 api.message.html.timestamp(msg), ' ', replyInfo
80 ])
81 ])
82 ]),
83 h('div.meta', api.message.html.meta(msg))
84 ])
85 }
86 }
87}
88
89function last (array) {
90 if (Array.isArray(array)) {
91 return array[array.length - 1]
92 } else {
93 return array
94 }
95}
96

Built with git-ssb-web