git ssb

2+

ev / mvd



Tree: a4b97d03ce9156f38cf2335b8ca41d935bb91615

Files: a4b97d03ce9156f38cf2335b8ca41d935bb91615 / views.js

2870 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 compose = require('./compose')
10
11var content = h('div.content')
12function 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
19module.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
42var rawJSON = require('patchapp-raw/json')
43
44module.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
70module.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
94module.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
121module.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