Files: 793444db02289c9a688dd7301e70f700cedbdd3d / views.js
2687 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 | else if (src == 'about') { |
73 | |
74 | var screen = document.getElementById('screen') |
75 | |
76 | var about = require('./about') |
77 | |
78 | var content = h('div.content', about) |
79 | |
80 | screen.appendChild(hyperscroll(content)) |
81 | } |
82 | else { |
83 | var content = h('div.content') |
84 | var screen = document.getElementById('screen') |
85 | screen.appendChild(hyperscroll(content)) |
86 | function createStream (opts) { |
87 | return pull( |
88 | More(sbot.createLogStream, opts), |
89 | pull.map(function (msg) { |
90 | return h('div', render(msg)) |
91 | }) |
92 | ) |
93 | } |
94 | |
95 | pull( |
96 | createStream({old: false, limit: 10}), |
97 | stream.top(content) |
98 | ) |
99 | |
100 | pull( |
101 | createStream({reverse: true, live: false, limit: 10}), |
102 | stream.bottom(content) |
103 | ) |
104 | |
105 | } |
106 | } |
107 | |
108 | |
109 |
Built with git-ssb-web