Files: 134d423c26820a78c6bbfbc506df577e0673b6b2 / modules / thread.js
1242 bytesRaw
1 | var ui = require('../ui') |
2 | var pull = require('pull-stream') |
3 | var Cat = require('pull-cat') |
4 | var Sort = require('pull-sort') |
5 | var ref = require('ssb-ref') |
6 | |
7 | function once (cont) { |
8 | var ended = false |
9 | return function (abort, cb) { |
10 | if(abort) return cb(abort) |
11 | else if (ended) return cb(ended) |
12 | else |
13 | cont(function (err, data) { |
14 | if(err) return cb(ended = err) |
15 | ended = true |
16 | cb(null, data) |
17 | }) |
18 | } |
19 | } |
20 | |
21 | function threadStream (root, sbot ) { |
22 | //in this case, it's inconvienent that panel only takes |
23 | //a stream. maybe it would be better to accept an array? |
24 | |
25 | return pull( |
26 | Cat([ |
27 | once(function (cb) { |
28 | sbot.get(root, function (err, value) { |
29 | cb(err, {key: root, value: value}) |
30 | }) |
31 | }), |
32 | sbot.links({rel: 'root', dest: root, values: true, keys: true}) |
33 | ]), |
34 | Sort(function (a, b) { |
35 | //THIS IS WRONG AND HAS KNOWN BUGS!!! |
36 | //TODO: sort by cryptographic causal ordering. |
37 | return a.value.timestamp - b.value.timestamp |
38 | }) |
39 | ) |
40 | } |
41 | |
42 | exports.screen_view = function (id, sbot) { |
43 | if(ref.isMsg(id)) |
44 | return ui.createStream( |
45 | threadStream(id, sbot), |
46 | ui.createRenderers(exports.message_render, sbot) |
47 | ) |
48 | } |
49 | |
50 | exports.message_render = [] |
51 | |
52 | |
53 | |
54 |
Built with git-ssb-web