Files: 14ac2ad367289482ef190e031665686d5734bf6a / app / page / threadShow.js
1644 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed, when } = require('mutant') |
3 | const last = require('lodash/last') |
4 | const get = require('lodash/get') |
5 | |
6 | exports.gives = nest('app.page.threadShow') |
7 | |
8 | exports.needs = nest({ |
9 | 'about.html.avatar': 'first', |
10 | 'app.html.sideNav': 'first', |
11 | 'app.html.thread': 'first', |
12 | 'message.html.compose': 'first', |
13 | 'unread.sync.markRead': 'first', |
14 | 'feed.obs.thread': 'first' |
15 | }) |
16 | |
17 | exports.create = (api) => { |
18 | return nest('app.page.threadShow', threadShow) |
19 | |
20 | function threadShow (location) { |
21 | // location = a thread (message, may be decorated with replies) |
22 | const { key, value } = location |
23 | const root = get(value, 'content.root', key) |
24 | const channel = get(value, 'content.channel') |
25 | |
26 | // unread state is set in here... |
27 | const thread = api.feed.obs.thread(root) |
28 | const subject = get(location, 'value.content.subject') |
29 | const recps = get(location, 'value.content.recps') |
30 | |
31 | const meta = { |
32 | type: 'post', |
33 | root, |
34 | branch: thread.lastId, |
35 | channel, |
36 | recps |
37 | } |
38 | const composer = api.message.html.compose({ meta, thread, shrink: false }) |
39 | |
40 | return h('Page -threadShow', [ |
41 | api.app.html.sideNav(location), |
42 | h('div.content', [ |
43 | h('header', [ |
44 | when(subject, h('h1', subject)), |
45 | Recipients(recps) |
46 | ]), |
47 | api.app.html.thread(thread), |
48 | composer |
49 | ]) |
50 | ]) |
51 | } |
52 | |
53 | function Recipients (recps) { |
54 | if (recps && recps.length > 2) { |
55 | return h('div.recps', recps.map(r => { |
56 | const recp = typeof r === 'string' ? r : r.link |
57 | return api.about.html.avatar(recp, 'tiny') |
58 | })) |
59 | } |
60 | } |
61 | } |
62 |
Built with git-ssb-web