git ssb

16+

Dominic / patchbay



Tree: b14b55a7a3856306e323ecdb3adc3afde89f3dab

Files: b14b55a7a3856306e323ecdb3adc3afde89f3dab / message / html / layout / default.js

2333 bytesRaw
1const nest = require('depnest')
2const { h, Value } = require('mutant')
3// const { isMsg } = require('ssb-ref')
4
5exports.needs = nest({
6 'about.html.avatar': 'first',
7 'keys.sync.id': 'first',
8 'message.html.author': 'first',
9 'message.html.backlinks': 'first',
10 'message.html.like': 'first',
11 'message.html.meta': 'map',
12 'message.html.quote': 'first',
13 'message.html.reply': 'first',
14 'message.html.timestamp': 'first',
15 'sbot.async.run': 'first'
16})
17
18exports.gives = nest('message.html.layout')
19
20exports.create = (api) => {
21 return nest('message.html.layout', messageLayout)
22
23 function messageLayout (msg, opts = {}) {
24 if (!(opts.layout === undefined || opts.layout === 'default')) return
25 const { showUnread = true, showTitle } = opts
26
27 var { author, timestamp, like, meta, backlinks, quote, reply } = api.message.html
28
29 var rawMessage = Value(null)
30
31 var el = h('Message -default',
32 { attributes: { tabindex: '0' } }, // needed to be able to navigate and show focus()
33 [
34 h('section.left', [
35 h('div.avatar', {}, api.about.html.avatar(msg.value.author)),
36 h('div.author', {}, author(msg)),
37 h('div.timestamp', {}, timestamp(msg))
38 ]),
39
40 h('section.body', [
41 showTitle ? h('div.title', {}, opts.title) : null,
42 h('div.content', {}, opts.content),
43 h('footer.backlinks', {}, backlinks(msg)),
44 h('div.raw-content', rawMessage)
45 ]),
46
47 h('section.right', [
48 h('div.meta', {}, meta(msg, { rawMessage })),
49 // isMsg(msg.key) ? // don't show actions if no msg.key
50 h('div.actions', [
51 like(msg),
52 quote(msg),
53 reply(msg)
54 ])
55 ])
56 ]
57 )
58
59 // UnreadFeature (search codebase for this if extracting)
60 if (showUnread && !myMessage(msg)) {
61 api.sbot.async.run(server => {
62 server.unread.isRead(msg.key, (err, isRead) => {
63 if (err) console.error(err)
64
65 if (!isRead) el.classList.add('-unread')
66 else el.classList.add('-read')
67 })
68 })
69 }
70 // ^ this could be in message/html/decorate
71 // but would require opts to be passed to decorators in patchcore
72
73 return el
74 }
75
76 function myMessage (msg) {
77 return msg.value.author === api.keys.sync.id()
78 }
79}
80

Built with git-ssb-web