Commit 0c6c12007098f6766a4f76b84752768ccdb1c922
mcss style classes, and avatars
Dominic Tarr committed on 8/9/2017, 11:09:33 PMParent: 4fc83b113e397a9b2782e14cb7a6fa31ed7ca1c5
Files changed
app/page/home.js | changed |
app/page/home.js | ||
---|---|---|
@@ -1,30 +1,41 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | 2 | const { h } = require('mutant') |
3 | 3 | const {threadReduce} = require('ssb-reduce-stream') |
4 | 4 | const pull = require('pull-stream') |
5 | +const when = require('mutant/when') | |
5 | 6 | |
6 | 7 | exports.gives = nest('app.page.home') |
7 | 8 | |
8 | 9 | exports.needs = nest({ |
9 | 10 | 'feed.pull.public': 'first', |
10 | 11 | 'app.html.nav': 'first', |
11 | 12 | 'history.sync.push': 'first', |
13 | + 'message.sync.unbox': 'first', | |
14 | + 'about.html.image': 'first', | |
12 | 15 | }) |
13 | 16 | |
14 | 17 | function firstLine (text) { |
15 | 18 | if(text.length < 80 && !~text.indexOf('\n')) return text |
16 | 19 | |
17 | 20 | return text.split('\n')[0].substring(0, 80) |
18 | 21 | } |
19 | 22 | |
23 | +function isObject (o) { | |
24 | + return o && 'object' === typeof o | |
25 | +} | |
26 | + | |
27 | +function isString (s) { | |
28 | + return 'string' == typeof s | |
29 | +} | |
30 | + | |
20 | 31 | exports.create = (api) => { |
21 | 32 | return nest('app.page.home', home) |
22 | 33 | |
23 | 34 | function home (location) { |
24 | 35 | // location here can expected to be: { page: 'home' } |
25 | 36 | |
26 | - var div = h('div', []) | |
37 | + var div = h('Home', []) | |
27 | 38 | |
28 | 39 | function subject (msg) { |
29 | 40 | return firstLine(msg.content.subject || msg.content.text) |
30 | 41 | } |
@@ -38,28 +49,59 @@ | ||
38 | 49 | if(!thread.value) { |
39 | 50 | |
40 | 51 | } |
41 | 52 | if(!thread.value) return |
42 | - return h('div.ThreadLink', link(thread), [ | |
43 | - h('h2', name), | |
44 | - h('div.subject', [subject(thread.value)]), | |
45 | - reply ? h('div.reply', [subject(reply.value)]) : null | |
53 | + return h('ThreadLink', link(thread), [ | |
54 | + name, | |
55 | + h('Subject', [subject(thread.value)]), | |
56 | + reply ? h('Reply', [subject(reply.value)]) : null | |
46 | 57 | ] |
47 | 58 | ) |
48 | 59 | } |
49 | 60 | |
61 | + function threadGroup (threads, obj, toName) { | |
62 | + var div = h('Group') | |
63 | + for(var k in obj) { | |
64 | + var id = obj[k] | |
65 | + var thread = threads.roots[id] | |
66 | + if(threads.roots[id] && threads.roots[id].value) { | |
67 | + //throw new Error('missing thread:'+id+' for channel:'+k) | |
68 | + var el = item(toName(k, thread), thread) | |
69 | + if(el) div.appendChild(el) | |
70 | + } | |
71 | + } | |
72 | + return div | |
73 | + } | |
74 | + | |
50 | 75 | pull( |
51 | 76 | api.feed.pull.public({reverse: true, limit: 1000}), |
52 | 77 | pull.through(console.log), |
53 | 78 | pull.collect(function (err, messages) { |
54 | - var threads = messages.reduce(threadReduce, null) | |
55 | - for(var k in threads.channels) { | |
56 | - var id = threads.channels[k] | |
57 | - if(!threads.roots[id]) throw new Error('missing thread:'+id+' for channel:'+k) | |
58 | - var el = item(k, threads.roots[id]) | |
59 | - if(el) | |
60 | - div.appendChild(el) | |
61 | - } | |
79 | + | |
80 | + var threads = messages.map(function (data) { | |
81 | + if(isObject(data.value.content)) return data | |
82 | + return api.message.sync.unbox(data) | |
83 | + }).filter(Boolean).reduce(threadReduce, null) | |
84 | + | |
85 | + div.appendChild(threadGroup( | |
86 | + threads, | |
87 | + threads.private, | |
88 | + function (_, msg) { | |
89 | + console.log(msg) | |
90 | + if(!msg.value) debugger | |
91 | + return h('Recps', | |
92 | + msg.value.content.recps.map(function (link) { | |
93 | + return api.about.html.image(isString(link) ? link : link.link) | |
94 | + }) | |
95 | + ) | |
96 | + } | |
97 | + )) | |
98 | + | |
99 | + div.appendChild(threadGroup( | |
100 | + threads, | |
101 | + threads.channels, | |
102 | + ch => h('h2.Title', '#'+ch) | |
103 | + )) | |
62 | 104 | }) |
63 | 105 | ) |
64 | 106 | |
65 | 107 | return h('Page -home', [ |
@@ -70,4 +112,5 @@ | ||
70 | 112 | } |
71 | 113 | } |
72 | 114 | |
73 | 115 | |
116 | + |
Built with git-ssb-web