git ssb

10+

Matt McKegg / patchwork



Tree: ee234ad644780313d6a36bed781c9df63d190563

Files: ee234ad644780313d6a36bed781c9df63d190563 / plugs / message / html / layout / mini.js

3193 bytesRaw
1const { h, 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 'contact.obs.following': 'first',
10 'keys.sync.id': 'first',
11 'message.html': {
12 link: 'first',
13 meta: 'map',
14 action: 'map',
15 timestamp: 'first',
16 backlinks: 'first'
17 },
18 'about.html.image': 'first',
19 'intl.sync.i18n': 'first'
20})
21
22exports.gives = nest('message.html.layout')
23
24exports.create = function (api) {
25 const i18n = api.intl.sync.i18n
26 var yourFollows = null
27
28 // to get sync follows
29 setImmediate(() => {
30 var yourId = api.keys.sync.id()
31 yourFollows = api.contact.obs.following(yourId)
32 })
33
34 return nest('message.html.layout', layout)
35
36 function layout (msg, {layout, previousId, priority, miniContent, content, includeReferences, includeForks = true}) {
37 if (!(layout === 'mini')) return
38
39 var classList = ['Message -mini']
40
41 if (yourFollows && yourFollows().includes(msg.value.author)) {
42 classList.push('-following')
43 }
44
45 var replyInfo = null
46
47 if (msg.value.content.root) {
48 classList.push('-reply')
49 var branch = msg.value.content.branch
50 if (branch) {
51 if (!previousId || (previousId && last(branch) && previousId !== last(branch))) {
52 replyInfo = h('span', ['in reply to ', api.message.html.link(last(branch))])
53 }
54 }
55 } else if (msg.value.content.project) {
56 replyInfo = h('span', ['on ', api.message.html.link(msg.value.content.project)])
57 }
58
59 if (priority === 2) {
60 classList.push('-new')
61 }
62
63 return h('div', {
64 classList
65 }, [
66 messageHeader(msg, {
67 replyInfo, priority, miniContent
68 }),
69 h('section', [content]),
70 computed(msg.key, (key) => {
71 if (ref.isMsg(key)) {
72 return h('footer', [
73 h('div.actions', [
74 api.message.html.action(msg)
75 ])
76 ])
77 }
78 }),
79 api.message.html.backlinks(msg, {includeReferences, includeForks})
80 ])
81
82 // scoped
83
84 function messageHeader (msg, {replyInfo, priority, miniContent}) {
85 var yourId = api.keys.sync.id()
86 var additionalMeta = []
87 if (priority >= 2) {
88 additionalMeta.push(h('span.flag -new', {title: 'New Message'}))
89 }
90 return h('header', [
91 h('div.main', [
92 h('a.avatar', {href: `${msg.value.author}`}, [
93 api.about.html.image(msg.value.author)
94 ]),
95 h('div.main', [
96 h('div.name', [
97 api.profile.html.person(msg.value.author),
98 msg.value.author === yourId ? [' ', h('span.you', {}, i18n('(you)'))] : null
99 ]),
100 h('div.meta', [
101 miniContent, ' ',
102 replyInfo
103 ])
104 ])
105 ]),
106 h('div.meta', [
107 api.message.html.meta(msg),
108 additionalMeta,
109 h('strong', api.message.html.timestamp(msg))
110 ])
111 ])
112 }
113 }
114}
115
116function last (array) {
117 if (Array.isArray(array)) {
118 return array[array.length - 1]
119 } else {
120 return array
121 }
122}
123

Built with git-ssb-web