Files: e927f30b2c24654a53dd64963385a9b705b9d8e0 / index.js
3021 bytesRaw
1 | var pull = require('pull-stream') |
2 | var sbot = require('./scuttlebot') |
3 | var hyperscroll = require('hyperscroll') |
4 | var More = require('pull-more') |
5 | var stream = require('hyperloadmore/stream') |
6 | var h = require('hyperscript') |
7 | var render = require('./render') |
8 | |
9 | var ref = require('ssb-ref') |
10 | |
11 | document.head.appendChild(h('style', require('./style.css.json'))) |
12 | |
13 | function hash () { |
14 | return window.location.hash.substring(1) |
15 | } |
16 | |
17 | var content = h('div.content') |
18 | |
19 | var screen = h('div#screen', {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}}) |
20 | |
21 | function 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 | |
100 | document.body.appendChild(screen) |
101 | route() |
102 | |
103 | window.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