Files: 934aacc8386594385eab23772a38b11406625294 / views.js
3948 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 config = require('./config')() |
11 | |
12 | var fs = require('fs') |
13 | |
14 | var compose = require('./compose') |
15 | |
16 | function hash () { |
17 | return window.location.hash.substring(1) |
18 | } |
19 | |
20 | module.exports = function () { |
21 | var src = hash() |
22 | |
23 | if (ref.isFeed(src)) { |
24 | var content = h('div.content') |
25 | var screen = document.getElementById('screen') |
26 | screen.appendChild(hyperscroll(content)) |
27 | function createStream (opts) { |
28 | return pull( |
29 | More(sbot.userStream, opts, ['value', 'sequence']), |
30 | pull.map(function (msg) { |
31 | return render(msg) |
32 | }) |
33 | ) |
34 | } |
35 | |
36 | pull( |
37 | createStream({old: false, limit: 10, id: src}), |
38 | stream.top(content) |
39 | ) |
40 | |
41 | pull( |
42 | createStream({reverse: true, live: false, limit: 10, id: src}), |
43 | stream.bottom(content) |
44 | ) |
45 | |
46 | |
47 | } else if (ref.isMsg(src)) { |
48 | var content = h('div.content') |
49 | var screen = document.getElementById('screen') |
50 | screen.appendChild(hyperscroll(content)) |
51 | sbot.get(src, function (err, data) { |
52 | if (err) {console.log('could not find message') } |
53 | data.value = data |
54 | console.log(data) |
55 | var root = src |
56 | if (data.value.content.root) |
57 | root = data.value.content.root |
58 | sbot.get(root, function (err, data) { |
59 | if (err) { console.log('could not find root')} |
60 | data.value = data |
61 | data.key = root |
62 | content.appendChild(render(data)) |
63 | pull( |
64 | sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}), |
65 | pull.drain(function (msg) { |
66 | console.log(msg) |
67 | if (msg.value) |
68 | content.appendChild(render(msg)) |
69 | }) |
70 | ) |
71 | }) |
72 | }) |
73 | } |
74 | |
75 | else if (src == 'about') { |
76 | |
77 | var screen = document.getElementById('screen') |
78 | |
79 | var about = require('./about') |
80 | |
81 | var content = h('div.content', about) |
82 | |
83 | screen.appendChild(hyperscroll(content)) |
84 | } |
85 | |
86 | else if (src == 'key') { |
87 | var screen = document.getElementById('screen') |
88 | |
89 | var importKey = h('textarea.import', {placeholder: 'Import a new public/private key', name: 'textarea', style: 'width: 97%; height: 100px;'}) |
90 | |
91 | var content = h('div.content', |
92 | h('div.message#key', |
93 | h('h1', 'Your Key'), |
94 | h('p', {innerHTML: 'Your public/private key is: <pre><code>' + localStorage[config.caps.shs + '/secret'] + '</code></pre>'}, |
95 | h('button.btn', {onclick: function (e){ |
96 | localStorage[config.caps.shs +'/secret'] = '' |
97 | alert('Your public/private key has been deleted') |
98 | e.preventDefault() |
99 | location.hash = "" |
100 | location.reload() |
101 | }}, 'Delete Key') |
102 | ), |
103 | h('hr'), |
104 | h('form', |
105 | importKey, |
106 | h('button.btn', {onclick: function (e){ |
107 | if(importKey.value) { |
108 | localStorage[config.caps.shs + '/secret'] = importKey.value.replace(/\s+/g, ' ') |
109 | e.preventDefault() |
110 | alert('Your public/private key has been updated') |
111 | } |
112 | location.hash = "" |
113 | location.reload() |
114 | }}, 'Import key'), |
115 | ) |
116 | ) |
117 | ) |
118 | |
119 | screen.appendChild(hyperscroll(content)) |
120 | |
121 | } else { |
122 | var content = h('div.content') |
123 | var screen = document.getElementById('screen') |
124 | screen.appendChild(hyperscroll(content)) |
125 | function createStream (opts) { |
126 | return pull( |
127 | More(sbot.createLogStream, opts), |
128 | pull.map(function (msg) { |
129 | return render(msg) |
130 | }) |
131 | ) |
132 | } |
133 | |
134 | pull( |
135 | createStream({old: false, limit: 10}), |
136 | stream.top(content) |
137 | ) |
138 | |
139 | pull( |
140 | createStream({reverse: true, live: false, limit: 10}), |
141 | stream.bottom(content) |
142 | ) |
143 | |
144 | } |
145 | } |
146 | |
147 | |
148 |
Built with git-ssb-web