git ssb

16+

Dominic / patchbay



Tree: fbcc653a737540377581d8ad192c343352ae4818

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

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

Built with git-ssb-web