git ssb

2+

mixmix / ticktack



Commit 0c6c12007098f6766a4f76b84752768ccdb1c922

mcss style classes, and avatars

Dominic Tarr committed on 8/9/2017, 11:09:33 PM
Parent: 4fc83b113e397a9b2782e14cb7a6fa31ed7ca1c5

Files changed

app/page/home.jschanged
app/page/home.jsView
@@ -1,30 +1,41 @@
11 const nest = require('depnest')
22 const { h } = require('mutant')
33 const {threadReduce} = require('ssb-reduce-stream')
44 const pull = require('pull-stream')
5+const when = require('mutant/when')
56
67 exports.gives = nest('app.page.home')
78
89 exports.needs = nest({
910 'feed.pull.public': 'first',
1011 'app.html.nav': 'first',
1112 'history.sync.push': 'first',
13+ 'message.sync.unbox': 'first',
14+ 'about.html.image': 'first',
1215 })
1316
1417 function firstLine (text) {
1518 if(text.length < 80 && !~text.indexOf('\n')) return text
1619
1720 return text.split('\n')[0].substring(0, 80)
1821 }
1922
23+function isObject (o) {
24+ return o && 'object' === typeof o
25+}
26+
27+function isString (s) {
28+ return 'string' == typeof s
29+}
30+
2031 exports.create = (api) => {
2132 return nest('app.page.home', home)
2233
2334 function home (location) {
2435 // location here can expected to be: { page: 'home' }
2536
26- var div = h('div', [])
37+ var div = h('Home', [])
2738
2839 function subject (msg) {
2940 return firstLine(msg.content.subject || msg.content.text)
3041 }
@@ -38,28 +49,59 @@
3849 if(!thread.value) {
3950
4051 }
4152 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
4657 ]
4758 )
4859 }
4960
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+
5075 pull(
5176 api.feed.pull.public({reverse: true, limit: 1000}),
5277 pull.through(console.log),
5378 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+ ))
62104 })
63105 )
64106
65107 return h('Page -home', [
@@ -70,4 +112,5 @@
70112 }
71113 }
72114
73115
116+

Built with git-ssb-web