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