git ssb

2+

ev / mvd



Tree: 92356a528f5ff97e1c7fef2de7e424d314c959ca

Files: 92356a528f5ff97e1c7fef2de7e424d314c959ca / index.js

3021 bytesRaw
1var pull = require('pull-stream')
2var sbot = require('./scuttlebot')
3var hyperscroll = require('hyperscroll')
4var More = require('pull-more')
5var stream = require('hyperloadmore/stream')
6var h = require('hyperscript')
7var render = require('./render')
8
9var ref = require('ssb-ref')
10
11document.head.appendChild(h('style', require('./style.css.json')))
12
13function hash () {
14 return window.location.hash.substring(1)
15}
16
17var content = h('div.content')
18
19var screen = h('div#screen', {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}})
20
21function route () {
22 var src = hash()
23
24 if (ref.isFeed(src)) {
25 var content = h('div.content')
26 var screen = document.getElementById('screen')
27 screen.appendChild(hyperscroll(content))
28 function createStream (opts) {
29 return pull(
30 More(sbot.userStream, opts, ['value', 'sequence']),
31 pull.map(function (msg) {
32 return h('div', render(msg))
33 })
34 )
35 }
36
37 pull(
38 createStream({old: false, limit: 10, id: src}),
39 stream.top(content)
40 )
41
42 pull(
43 createStream({reverse: true, live: false, limit: 10, id: src}),
44 stream.bottom(content)
45 )
46
47
48 } else if (ref.isMsg(src)) {
49 var content = h('div.content')
50 var screen = document.getElementById('screen')
51 screen.appendChild(hyperscroll(content))
52 sbot.get(src, function (err, data) {
53 if (err) {console.log('could not find message') }
54 data.value = data
55 console.log(data)
56 var root = src
57 if (data.value.content.root)
58 root = data.value.content.root
59 sbot.get(root, function (err, data) {
60 if (err) { console.log('could not find root')}
61 data.value = data
62 data.key = root
63 content.appendChild(h('div', render(data)))
64 pull(
65 sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
66 pull.drain(function (msg) {
67 console.log(msg)
68 if (msg.value)
69 content.appendChild(h('div', render(msg)))
70 })
71 )
72 })
73 })
74 } else {
75 var content = h('div.content')
76 var screen = document.getElementById('screen')
77 screen.appendChild(hyperscroll(content))
78 function createStream (opts) {
79 return pull(
80 More(sbot.createLogStream, opts),
81 pull.map(function (msg) {
82 return h('div', render(msg))
83 })
84 )
85 }
86
87 pull(
88 createStream({old: false, limit: 10}),
89 stream.top(content)
90 )
91
92 pull(
93 createStream({reverse: true, live: false, limit: 10}),
94 stream.bottom(content)
95 )
96
97 }
98}
99
100document.body.appendChild(screen)
101route()
102
103window.onhashchange = function () {
104 //var content = h('div.content')
105 var screen = document.getElementById('screen')
106 var newscreen = h('div#screen', {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}})
107
108 //if(_screen != null)
109 console.log(screen)
110 screen.parentNode.replaceChild(newscreen, screen)
111 route()
112}
113
114

Built with git-ssb-web