git ssb

2+

ev / mvd



Commit 22845e6da7a120adb2b33163b4a7f46979fcc97b

render user feeds

Ev Bogue committed on 4/21/2018, 3:33:16 AM
Parent: a2dab3bb4322fa816841339b9e65a07099a69c5a

Files changed

index.jschanged
scuttlebot.jschanged
views.jschanged
index.jsView
@@ -1,17 +1,23 @@
11 var h = require('hyperscript')
22
33 var views = require('./views')
44
5 +var ref = require('ssb-ref')
6 +
57 document.head.appendChild(h('style', require('./style.css.json')))
68
7-var src = window.location.hash
9 +var src = window.location.hash.substring(1)
810
911 window.onhashchange = function () {
1012 window.location.reload()
1113 }
1214
13-if (src == '#raw') {
15 +console.log(src)
16 +
17 +if (src == 'raw') {
1418 views.rawstream()
19 +} else if (ref.isFeed(src)) {
20 + views.userstream(src)
1521 } else {
1622 views.logstream()
1723 }
scuttlebot.jsView
@@ -40,8 +40,16 @@
4040 CACHE[e.key] = CACHE[e.key] || e.value
4141 })
4242 )
4343 }),
44 + userStream: rec.source(function (config) {
45 + return pull(
46 + sbot.createUserStream(config),
47 + pull.through(function (e) {
48 + CACHE[e.key] = CACHE[e.key] || e.value
49 + })
50 + )
51 + }),
4452 query: rec.source(function (query) {
4553 return sbot.query.read(query)
4654 })
4755 }
views.jsView
@@ -65,4 +65,33 @@
6565 createStream({reverse: true, live: false, limit: 10}),
6666 stream.bottom(content)
6767 )
6868 }
69 +
70 +module.exports.userstream = function (src) {
71 + var content = h('div.content')
72 +
73 + document.body.appendChild(h('div.screen',
74 + {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
75 + hyperscroll(content)
76 + ))
77 +
78 + function createStream (opts) {
79 + return pull(
80 + More(sbot.userStream, opts, ['value', 'sequence']),
81 + pull.map(function (msg) {
82 + return h('div.message', render(msg))
83 + })
84 + )
85 + }
86 +
87 + pull(
88 + createStream({old: false, limit: 10, id: src}),
89 + stream.top(content)
90 + )
91 +
92 + pull(
93 + createStream({reverse: true, live: false, limit: 10, id: src}),
94 + stream.bottom(content)
95 + )
96 +
97 +}

Built with git-ssb-web