git ssb

2+

ev / mvd



Tree: 2bf2f02ab2d149f038ff4ecd1e5e19c925b558fd

Files: 2bf2f02ab2d149f038ff4ecd1e5e19c925b558fd / views.js

3239 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 var opts = {
21 "type": 'post',
22 "placeholder": 'Write a mutable message'
23 }
24
25 var content = h('div.content',
26 h('div.message', compose(opts))
27 )
28
29 function mainscreen () {
30 document.body.appendChild(h('div.screen',
31 {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
32 hyperscroll(content)
33 ))
34 }
35
36 mainscreen()
37
38 function createStream (opts) {
39 return pull(
40 More(sbot.createLogStream, opts),
41 pull.map(function (msg) {
42 return h('div', render(msg))
43 })
44 )
45 }
46
47 pull(
48 createStream({old: false, limit: 10}),
49 stream.top(content)
50 )
51
52 pull(
53 createStream({reverse: true, live: false, limit: 10}),
54 stream.bottom(content)
55 )
56}
57
58var rawJSON = require('patchapp-raw/json')
59
60module.exports.rawstream = function () {
61 screen()
62
63 function createStream (opts) {
64 return pull(
65 More(sbot.createLogStream, opts),
66 pull.filter(function (data) {
67 return 'string' === typeof data.value.content.text
68 }),
69 pull.map(function (msg) {
70 return h('pre.raw__json', {id: msg.key}, rawJSON(msg))
71 })
72 )
73 }
74
75 pull(
76 createStream({old: false, limit: 10}),
77 stream.top(content)
78 )
79
80 pull(
81 createStream({reverse: true, live: false, limit: 10}),
82 stream.bottom(content)
83 )
84}
85
86module.exports.userstream = function (src) {
87 screen()
88
89 function createStream (opts) {
90 return pull(
91 More(sbot.userStream, opts, ['value', 'sequence']),
92 pull.map(function (msg) {
93 return h('div', render(msg))
94 })
95 )
96 }
97
98 pull(
99 createStream({old: false, limit: 10, id: src}),
100 stream.top(content)
101 )
102
103 pull(
104 createStream({reverse: true, live: false, limit: 10, id: src}),
105 stream.bottom(content)
106 )
107
108}
109
110module.exports.get = function (src) {
111 screen()
112
113 sbot.get(src, function (err, data) {
114 if (err) {console.log('could not find message') }
115 data.value = data
116 console.log(data)
117 var root = src
118 if (data.value.content.root)
119 root = data.value.content.root
120 sbot.get(root, function (err, data) {
121 if (err) { console.log('could not find root')}
122 data.value = data
123 data.key = root
124 content.appendChild(h('div', render(data)))
125 pull(
126 sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
127 pull.drain(function (msg) {
128 console.log(msg)
129 if (msg.value)
130 content.appendChild(h('div', render(msg)))
131 })
132 )
133 })
134 })
135}
136
137module.exports.compose = function () {
138 screen()
139 var opts = {
140 "root": null,
141 "type": "post"
142 }
143 content.appendChild(h('div.message', compose(opts)))
144}
145

Built with git-ssb-web