git ssb

2+

mixmix / ticktack



Commit 673c7a2d4beb3d140d4a72dc921e63e7f985f873

disable localStorage thread cache

Dominic Tarr committed on 8/14/2017, 1:06:17 PM
Parent: 4dbb2a6693e61517c65a6eb549c9f0d8acf437b7

Files changed

state/obs.jschanged
state/obs.jsView
@@ -8,35 +8,38 @@
88 function isObject (o) {
99 return 'object' === typeof o
1010 }
1111
12-exports.gives = nest('state.obs.threads', true)
12+exports.gives = nest({
13+ 'state.obs.threads': true,
14+ 'state.obs.channel': true
15+})
1316
1417 exports.needs = nest({
1518 'message.sync.unbox': 'first',
16- 'sbot.pull.log': 'first'
19+ 'sbot.pull.log': 'first',
20+ 'feed.pull.channel': 'first'
1721 })
1822
1923 exports.create = function (api) {
2024 var threadsObs
2125
22- function createStateObs (threadReduce, createStream, initial) {
23- var lastTimestamp = initial ? initial.last : Date.now()
24- var firstTimestamp = initial ? initial.first || Date.now() : Date.now()
26+ function createStateObs (reduce, createStream, opts, initial) {
27+ var lastTimestamp = opts.last || Date.now()
28+ var firstTimestamp = opts.first || Date.now()
2529
2630 function unbox () {
2731 return pull(
2832 pull.map(function (data) {
29-// lastTimestamp = data.timestamp
3033 if(isObject(data.value.content)) return data
3134 return api.message.sync.unbox(data)
3235 }),
3336 pull.filter(Boolean)
3437 )
3538 }
3639
37- var threadsObs = PullObv(
38- threadReduce,
40+ var obs = PullObv(
41+ reduce,
3942 pull(
4043 Next(function () {
4144 return createStream({reverse: true, limit: 500, lt: lastTimestamp})
4245 }),
@@ -58,47 +61,72 @@
5861 }),
5962 pull.drain(function (data) {
6063 if(data.sync) return
6164 firstTimestamp = data.timestamp
62- threadsObs.set(threadReduce(threadsObs.value, data))
65+ obs.set(reduce(threadsObs.value, data))
6366 })
6467 )
6568
66- return threadsObs
69+ return obs
6770 }
6871
6972
70- return nest('state.obs.threads', function buildThreadObs() {
71- if(threadsObs) return threadsObs
73+ return nest({
74+ 'state.obs.channel': function (channel) {
7275
73-// var initial
74-// try { initial = JSON.parse(localStorage.threadsState) }
75-// catch (_) { }
76-//
76+ return createStateObs(
77+ threadReduce,
78+ function (opts) {
79+ return opts.reverse ?
80+ api.feed.pull.channel(channel)(opts):
81+ pull(api.sbot.pull.log(opts), pull.filter(function (data) {
82+ if(data.sync) return false
83+ return data.value.content.channel === channel
84+ }))
85+ },
86+ {}
87+ )
7788
78- initial = {}
89+ var channelObs = PullObv(
90+ threadReduce,
91+ createChannelStream({reverse: true, limit: 1000})
92+ )
7993
80- threadsObs = createStateObs(threadReduce, api.sbot.pull.log, initial)
8194
82- threadsObs(function (threadsState) {
83- if(threadsState.ended && threadsState.ended !== true)
84- console.error('threadObs error:', threadsState.ended)
85- })
95+ },
96+ 'state.obs.threads': function buildThreadObs() {
97+ if(threadsObs) return threadsObs
8698
87-// var timer
88-// //keep localStorage up to date
89-// threadsObs(function (threadsState) {
90-// if(timer) return
91-// timer = setTimeout(function () {
92-// timer = null
93-// threadsState.last = lastTimestamp
94-// console.log('save state')
95-// localStorage.threadsState = JSON.stringify(threadsState)
96-// }, 1000)
97-// })
98-//
99+ // DISABLE localStorage cache. mainly disabling this to make debugging the other stuff
100+ // easier. maybe re-enable this later? also, should this be for every channel too? not sure.
99101
100- return threadsObs
102+ // var initial
103+ // try { initial = JSON.parse(localStorage.threadsState) }
104+ // catch (_) { }
105+
106+ initial = {}
107+
108+ threadsObs = createStateObs(threadReduce, api.sbot.pull.log, initial, {})
109+
110+ threadsObs(function (threadsState) {
111+ if(threadsState.ended && threadsState.ended !== true)
112+ console.error('threadObs error:', threadsState.ended)
113+ })
114+
115+ // var timer
116+ // //keep localStorage up to date
117+ // threadsObs(function (threadsState) {
118+ // if(timer) return
119+ // timer = setTimeout(function () {
120+ // timer = null
121+ // threadsState.last = lastTimestamp
122+ // console.log('save state')
123+ // localStorage.threadsState = JSON.stringify(threadsState)
124+ // }, 1000)
125+ // })
126+
127+ return threadsObs
128+ }
101129 })
102130 }
103131
104132

Built with git-ssb-web