git ssb

16+

Dominic / patchbay



Tree: 9d629c55b19f5dc728643731fffb36dac23c0eca

Files: 9d629c55b19f5dc728643731fffb36dac23c0eca / modules / thread.js

1767 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')
6var h = require('hyperscript')
7var u = require('../util')
8var Scroller = require('pull-scroll')
9
10function once (cont) {
11 var ended = false
12 return function (abort, cb) {
13 if(abort) return cb(abort)
14 else if (ended) return cb(ended)
15 else
16 cont(function (err, data) {
17 if(err) return cb(ended = err)
18 ended = true
19 cb(null, data)
20 })
21 }
22}
23
24function threadStream (root, sbot ) {
25 //in this case, it's inconvienent that panel only takes
26 //a stream. maybe it would be better to accept an array?
27
28 return pull(
29 Cat([
30 once(function (cb) {
31 sbot.get(root, function (err, value) {
32 cb(err, {key: root, value: value})
33 })
34 }),
35 sbot.links({rel: 'root', dest: root, values: true, keys: true})
36 ]),
37 Sort(function (a, b) {
38 //THIS IS WRONG AND HAS KNOWN BUGS!!!
39 //TODO: sort by cryptographic causal ordering.
40 return a.value.timestamp - b.value.timestamp
41 })
42 )
43}
44
45exports.screen_view = function (id, sbot) {
46 if(ref.isMsg(id)) {
47 var content = h('div.column')
48 var div = h('div.column', {style: {'overflow':'auto'}},
49 h('div', content),
50 u.decorate(exports.message_compose, {root: id}, function (d, e, v) {
51 return d(e, v, sbot)
52 })
53 )
54 var render = ui.createRenderers(exports.message_render, sbot)
55
56 pull(
57 threadStream(id, sbot),
58 Scroller(div, content, render, false, false)
59 )
60
61 return div
62 }
63
64 return ui.createStream(
65 ui.createRenderers(exports.message_render, sbot)
66 )
67}
68
69exports.message_render = []
70exports.message_compose = []
71
72
73
74
75
76
77
78
79

Built with git-ssb-web