git ssb

16+

Dominic / patchbay



Tree: 9ae49c99c4e15aee20a0b51e586caccd37d33d1e

Files: 9ae49c99c4e15aee20a0b51e586caccd37d33d1e / modules / thread.js

2168 bytesRaw
1var ui = require('../ui')
2var pull = require('pull-stream')
3var Cat = require('pull-cat')
4var sort = require('ssb-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 getThread (root, sbot, cb) {
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(Cat([
29 once(function (cb) {
30 sbot.get(root, function (err, value) {
31 cb(err, {key: root, value: value})
32 })
33 }),
34 sbot.links({rel: 'root', dest: root, values: true, keys: true})
35 ]), pull.collect(cb))
36}
37
38function unbox(msg) {
39 return u.first(exports.message_unbox, function (fn) {
40 return fn(msg)
41 })
42}
43
44exports.screen_view = function (id, sbot) {
45 if(ref.isMsg(id)) {
46 var div = h('div.column', {style: {'overflow-y': 'auto'}})
47 var render = ui.createRenderers(exports.message_render, sbot)
48
49 getThread(id, sbot, function (err, thread) {
50 thread = thread.map(function (msg) {
51 return 'string' === typeof msg.value.content ? unbox(msg) : msg
52 })
53
54 if(err) return div.appendChild(h('pre', err.stack))
55 sort(thread).map(render).forEach(function (el) {
56 div.appendChild(el)
57 })
58
59 var branches = sort.heads(thread)
60 var meta = {
61 root: id,
62 branch: branches.length > 1 ? branches : branches[0]
63 }
64 var recps = thread[0].value.content.recps
65 if(recps && thread[0].value.private)
66 meta.recps = recps
67
68 console.log('recipients', thread[0].value.content.recps)
69
70 div.appendChild(
71 h('div',
72 u.decorate(exports.message_compose, meta, function (d, e, v) {
73 return d(e, v, sbot)
74 }))
75 )
76 })
77
78 return div
79 }
80
81}
82
83exports.message_render = []
84exports.message_compose = []
85exports.message_unbox = []
86
87
88
89

Built with git-ssb-web