git ssb

10+

Matt McKegg / patchwork



Tree: d951d83a8663076e0b94ed3ed7f6cbdd16e4b5bf

Files: d951d83a8663076e0b94ed3ed7f6cbdd16e4b5bf / plugs / message / html / layout / default.js

2815 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 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 }),
53 h('section', [opts.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 map(backlinks, backlink => {
64 return h('a.backlink', {
65 href: backlink,
66 title: backlink
67 }, [
68 h('strong', 'Referenced from'), ' ', api.message.obs.name(backlink)
69 ])
70 })
71 ])
72
73 // scoped
74
75 function messageHeader (msg, {replyInfo, priority}) {
76 var additionalMeta = []
77 if (opts.priority >= 2) {
78 additionalMeta.push(h('span.flag -new', {title: 'New Message'}))
79 }
80 return h('header', [
81 h('div.main', [
82 h('a.avatar', {href: `${msg.value.author}`}, [
83 api.about.html.image(msg.value.author)
84 ]),
85 h('div.main', [
86 h('div.name', [
87 api.profile.html.person(msg.value.author)
88 ]),
89 h('div.meta', [
90 api.message.html.timestamp(msg), ' ',
91 replyInfo
92 ])
93 ])
94 ]),
95 h('div.meta', [
96 api.message.html.meta(msg),
97 additionalMeta
98 ])
99 ])
100 }
101 }
102}
103
104function last (array) {
105 if (Array.isArray(array)) {
106 return array[array.length - 1]
107 } else {
108 return array
109 }
110}
111

Built with git-ssb-web