git ssb

16+

Dominic / patchbay



Tree: 96d0a60a7b7c41087f0c52c4ed0292f86ba7d4b1

Files: 96d0a60a7b7c41087f0c52c4ed0292f86ba7d4b1 / modules / thread.js

1242 bytesRaw
1var ui = require('../ui')
2var pull = require('pull-stream')
3var Cat = require('pull-cat')
4var Sort = require('pull-sort')
5var ref = require('ssb-ref')
6
7function 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
21function 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
42exports.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
50exports.message_render = []
51
52
53
54

Built with git-ssb-web