git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 05dc0664a7d196eeab3f1883b04f917b5b944013

Files: 05dc0664a7d196eeab3f1883b04f917b5b944013 / plugs / message / html / layout / default.js

2684 bytesRaw
1const { 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.obs.author': 'first',
10 'message.html': {
11 link: 'first',
12 meta: 'map',
13 action: 'map',
14 timestamp: 'first',
15 backlinks: 'first'
16 },
17 'about.html.image': 'first',
18 'intl.sync.i18n': 'first',
19})
20
21exports.gives = nest('message.html.layout')
22
23exports.create = function (api) {
24 const i18n = api.intl.sync.i18n
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
97function 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