git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 3bf3c7aca4c5ebf780ce5daee70c769f82f5ca26

Files: 3bf3c7aca4c5ebf780ce5daee70c769f82f5ca26 / views.js

2450 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')
8var ref = require('ssb-ref')
9
10var compose = require('./compose')
11
12function hash () {
13 return window.location.hash.substring(1)
14}
15
16module.exports = function () {
17 var src = hash()
18
19 if (ref.isFeed(src)) {
20 var content = h('div.content')
21 var screen = document.getElementById('screen')
22 screen.appendChild(hyperscroll(content))
23 function createStream (opts) {
24 return pull(
25 More(sbot.userStream, opts, ['value', 'sequence']),
26 pull.map(function (msg) {
27 return h('div', render(msg))
28 })
29 )
30 }
31
32 pull(
33 createStream({old: false, limit: 10, id: src}),
34 stream.top(content)
35 )
36
37 pull(
38 createStream({reverse: true, live: false, limit: 10, id: src}),
39 stream.bottom(content)
40 )
41
42
43 } else if (ref.isMsg(src)) {
44 var content = h('div.content')
45 var screen = document.getElementById('screen')
46 screen.appendChild(hyperscroll(content))
47 sbot.get(src, function (err, data) {
48 if (err) {console.log('could not find message') }
49 data.value = data
50 console.log(data)
51 var root = src
52 if (data.value.content.root)
53 root = data.value.content.root
54 sbot.get(root, function (err, data) {
55 if (err) { console.log('could not find root')}
56 data.value = data
57 data.key = root
58 content.appendChild(h('div', render(data)))
59 pull(
60 sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
61 pull.drain(function (msg) {
62 console.log(msg)
63 if (msg.value)
64 content.appendChild(h('div', render(msg)))
65 })
66 )
67 })
68 })
69 } else {
70 var content = h('div.content')
71 var screen = document.getElementById('screen')
72 screen.appendChild(hyperscroll(content))
73 function createStream (opts) {
74 return pull(
75 More(sbot.createLogStream, opts),
76 pull.map(function (msg) {
77 return h('div', render(msg))
78 })
79 )
80 }
81
82 pull(
83 createStream({old: false, limit: 10}),
84 stream.top(content)
85 )
86
87 pull(
88 createStream({reverse: true, live: false, limit: 10}),
89 stream.bottom(content)
90 )
91
92 }
93}
94
95
96

Built with git-ssb-web