Files: 7ec8576dc1fa3f5fd84478f8aa7f3ea3c6805c81 / message / html / layout / default.js
2088 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Value } = require('mutant') |
3 | const { isMsg } = require('ssb-ref') |
4 | |
5 | exports.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 | |
16 | exports.gives = nest('message.html.layout') |
17 | |
18 | exports.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