Files: 89e22f38502bc71de5434584a05d0545407c2336 / views.js
3202 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 | module.exports.logstream = function () { |
10 | var content = h('div.content') |
11 | |
12 | document.body.appendChild(h('div.screen', |
13 | {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}}, |
14 | hyperscroll(content) |
15 | )) |
16 | |
17 | function createStream (opts) { |
18 | return pull( |
19 | More(sbot.createLogStream, opts), |
20 | pull.map(function (msg) { |
21 | return h('div', render(msg)) |
22 | }) |
23 | ) |
24 | } |
25 | |
26 | pull( |
27 | createStream({old: false, limit: 10}), |
28 | stream.top(content) |
29 | ) |
30 | |
31 | pull( |
32 | createStream({reverse: true, live: false, limit: 10}), |
33 | stream.bottom(content) |
34 | ) |
35 | } |
36 | |
37 | var rawJSON = require('patchapp-raw/json') |
38 | |
39 | module.exports.rawstream = function () { |
40 | var content = h('div.content') |
41 | |
42 | document.body.appendChild(h('div.screen', |
43 | {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}}, |
44 | hyperscroll(content) |
45 | )) |
46 | |
47 | function createStream (opts) { |
48 | return pull( |
49 | More(sbot.createLogStream, opts), |
50 | pull.filter(function (data) { |
51 | return 'string' === typeof data.value.content.text |
52 | }), |
53 | pull.map(function (msg) { |
54 | return h('pre.raw__json', {id: msg.key}, rawJSON(msg)) |
55 | }) |
56 | ) |
57 | } |
58 | |
59 | pull( |
60 | createStream({old: false, limit: 10}), |
61 | stream.top(content) |
62 | ) |
63 | |
64 | pull( |
65 | createStream({reverse: true, live: false, limit: 10}), |
66 | stream.bottom(content) |
67 | ) |
68 | } |
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', 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 | } |
98 | |
99 | module.exports.get = function (src) { |
100 | var content = h('div.content') |
101 | |
102 | document.body.appendChild(h('div.screen', |
103 | {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}}, |
104 | hyperscroll(content) |
105 | )) |
106 | |
107 | sbot.get(src, function (err, data) { |
108 | if (err) {console.log('could not find message') } |
109 | data.value = data |
110 | console.log(data) |
111 | var root = src |
112 | if (data.value.content.root) |
113 | root = data.value.content.root |
114 | sbot.get(root, function (err, data) { |
115 | if (err) { console.log('could not find root')} |
116 | data.value = data |
117 | data.key = root |
118 | content.appendChild(h('div', render(data))) |
119 | pull( |
120 | sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}), |
121 | pull.drain(function (msg) { |
122 | console.log(msg) |
123 | if (msg.value) |
124 | content.appendChild(h('div', render(msg))) |
125 | }) |
126 | ) |
127 | }) |
128 | }) |
129 | } |
130 |
Built with git-ssb-web