Files: 30b8296223f75e62735b9a3b804ff6d9f7c27697 / views.js
2870 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 compose = require('./compose') |
10 | |
11 | var content = h('div.content') |
12 | function screen () { |
13 | document.body.appendChild(h('div.screen', |
14 | {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}}, |
15 | hyperscroll(content) |
16 | )) |
17 | } |
18 | |
19 | module.exports.logstream = function () { |
20 | screen() |
21 | |
22 | function createStream (opts) { |
23 | return pull( |
24 | More(sbot.createLogStream, opts), |
25 | pull.map(function (msg) { |
26 | return h('div', render(msg)) |
27 | }) |
28 | ) |
29 | } |
30 | |
31 | pull( |
32 | createStream({old: false, limit: 10}), |
33 | stream.top(content) |
34 | ) |
35 | |
36 | pull( |
37 | createStream({reverse: true, live: false, limit: 10}), |
38 | stream.bottom(content) |
39 | ) |
40 | } |
41 | |
42 | var rawJSON = require('patchapp-raw/json') |
43 | |
44 | module.exports.rawstream = function () { |
45 | screen() |
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 | screen() |
72 | |
73 | function createStream (opts) { |
74 | return pull( |
75 | More(sbot.userStream, opts, ['value', 'sequence']), |
76 | pull.map(function (msg) { |
77 | return h('div', render(msg)) |
78 | }) |
79 | ) |
80 | } |
81 | |
82 | pull( |
83 | createStream({old: false, limit: 10, id: src}), |
84 | stream.top(content) |
85 | ) |
86 | |
87 | pull( |
88 | createStream({reverse: true, live: false, limit: 10, id: src}), |
89 | stream.bottom(content) |
90 | ) |
91 | |
92 | } |
93 | |
94 | module.exports.get = function (src) { |
95 | screen() |
96 | |
97 | sbot.get(src, function (err, data) { |
98 | if (err) {console.log('could not find message') } |
99 | data.value = data |
100 | console.log(data) |
101 | var root = src |
102 | if (data.value.content.root) |
103 | root = data.value.content.root |
104 | sbot.get(root, function (err, data) { |
105 | if (err) { console.log('could not find root')} |
106 | data.value = data |
107 | data.key = root |
108 | content.appendChild(h('div', render(data))) |
109 | pull( |
110 | sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}), |
111 | pull.drain(function (msg) { |
112 | console.log(msg) |
113 | if (msg.value) |
114 | content.appendChild(h('div', render(msg))) |
115 | }) |
116 | ) |
117 | }) |
118 | }) |
119 | } |
120 | |
121 | module.exports.compose = function () { |
122 | screen() |
123 | var opts = { |
124 | "root": null, |
125 | "type": "post" |
126 | } |
127 | content.appendChild(h('div.message', compose(opts))) |
128 | } |
129 |
Built with git-ssb-web