views.jsView |
---|
4 | 4 | var More = require('pull-more') |
5 | 5 | var stream = require('hyperloadmore/stream') |
6 | 6 | var h = require('hyperscript') |
7 | 7 | var render = require('./render') |
| 8 | +var ref = require('ssb-ref') |
8 | 9 | |
9 | 10 | var compose = require('./compose') |
10 | 11 | |
11 | | -var content = h('div.content') |
12 | | -function screen () { |
13 | | - document.body.appendChild(h('div.screen', |
14 | | - {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}}, |
15 | | - hyperscroll(content) |
16 | | - )) |
| 12 | +function hash () { |
| 13 | + return window.location.hash.substring(1) |
17 | 14 | } |
18 | 15 | |
19 | | -module.exports.logstream = function () { |
20 | | - var opts = { |
21 | | - "type": 'post', |
22 | | - "placeholder": 'Write a mutable message' |
23 | | - } |
| 16 | +module.exports = function () { |
| 17 | + var src = hash() |
24 | 18 | |
25 | | - var content = h('div.content', |
26 | | - h('div.message', compose(opts)) |
27 | | - ) |
| 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 | + } |
28 | 31 | |
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 | | - } |
| 32 | + pull( |
| 33 | + createStream({old: false, limit: 10, id: src}), |
| 34 | + stream.top(content) |
| 35 | + ) |
35 | 36 | |
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 | | - }) |
| 37 | + pull( |
| 38 | + createStream({reverse: true, live: false, limit: 10, id: src}), |
| 39 | + stream.bottom(content) |
44 | 40 | ) |
45 | | - } |
46 | 41 | |
47 | | - pull( |
48 | | - createStream({old: false, limit: 10}), |
49 | | - stream.top(content) |
50 | | - ) |
51 | 42 | |
52 | | - pull( |
53 | | - createStream({reverse: true, live: false, limit: 10}), |
54 | | - stream.bottom(content) |
55 | | - ) |
56 | | -} |
| 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 | + } |
57 | 81 | |
58 | | -var rawJSON = require('patchapp-raw/json') |
| 82 | + pull( |
| 83 | + createStream({old: false, limit: 10}), |
| 84 | + stream.top(content) |
| 85 | + ) |
59 | 86 | |
60 | | -module.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 | | - }) |
| 87 | + pull( |
| 88 | + createStream({reverse: true, live: false, limit: 10}), |
| 89 | + stream.bottom(content) |
72 | 90 | ) |
73 | | - } |
74 | 91 | |
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 | | - |
86 | | -module.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 | 92 | } |
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 | 93 | } |
109 | 94 | |
110 | | -module.exports.get = function (src) { |
111 | | - screen() |
112 | 95 | |
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 | | - |
137 | | -module.exports.compose = function () { |
138 | | - screen() |
139 | | - var opts = { |
140 | | - "root": null, |
141 | | - "type": "post" |
142 | | - } |
143 | | - content.appendChild(h('div.message', compose(opts))) |
144 | | -} |