Commit 4dbb2a6693e61517c65a6eb549c9f0d8acf437b7
there is a bug with live channel streams, using this work-around for now
Dominic Tarr committed on 8/14/2017, 12:58:40 PMParent: f72dd7d62b01eb6de4d424c0a1d47a4814ef6599
Files changed
state/obs.js | changed |
state/obs.js | ||
---|---|---|
@@ -18,24 +18,25 @@ | ||
18 | 18 | |
19 | 19 | exports.create = function (api) { |
20 | 20 | var threadsObs |
21 | 21 | |
22 | - function createStateObs (reduce, createStream, opts, initial) { | |
23 | - var lastTimestamp = opts.last || Date.now() | |
24 | - var firstTimestamp = opts.first || Date.now() | |
22 | + function createStateObs (threadReduce, createStream, initial) { | |
23 | + var lastTimestamp = initial ? initial.last : Date.now() | |
24 | + var firstTimestamp = initial ? initial.first || Date.now() : Date.now() | |
25 | 25 | |
26 | 26 | function unbox () { |
27 | 27 | return pull( |
28 | 28 | pull.map(function (data) { |
29 | +// lastTimestamp = data.timestamp | |
29 | 30 | if(isObject(data.value.content)) return data |
30 | 31 | return api.message.sync.unbox(data) |
31 | 32 | }), |
32 | 33 | pull.filter(Boolean) |
33 | 34 | ) |
34 | 35 | } |
35 | 36 | |
36 | - var obs = PullObv( | |
37 | - reduce, | |
37 | + var threadsObs = PullObv( | |
38 | + threadReduce, | |
38 | 39 | pull( |
39 | 40 | Next(function () { |
40 | 41 | return createStream({reverse: true, limit: 500, lt: lastTimestamp}) |
41 | 42 | }), |
@@ -57,13 +58,13 @@ | ||
57 | 58 | }), |
58 | 59 | pull.drain(function (data) { |
59 | 60 | if(data.sync) return |
60 | 61 | firstTimestamp = data.timestamp |
61 | - obs.set(reduce(threadsObs.value, data)) | |
62 | + threadsObs.set(threadReduce(threadsObs.value, data)) | |
62 | 63 | }) |
63 | 64 | ) |
64 | 65 | |
65 | - return obs | |
66 | + return threadsObs | |
66 | 67 | } |
67 | 68 | |
68 | 69 | |
69 | 70 | return nest('state.obs.threads', function buildThreadObs() { |
@@ -75,9 +76,9 @@ | ||
75 | 76 | // |
76 | 77 | |
77 | 78 | initial = {} |
78 | 79 | |
79 | - threadsObs = createStateObs(threadReduce, api.sbot.pull.log, initial, {}) | |
80 | + threadsObs = createStateObs(threadReduce, api.sbot.pull.log, initial) | |
80 | 81 | |
81 | 82 | threadsObs(function (threadsState) { |
82 | 83 | if(threadsState.ended && threadsState.ended !== true) |
83 | 84 | console.error('threadObs error:', threadsState.ended) |
@@ -102,7 +103,4 @@ | ||
102 | 103 | |
103 | 104 | |
104 | 105 | |
105 | 106 | |
106 | - | |
107 | - | |
108 | - |
Built with git-ssb-web