git ssb

2+

mixmix / ticktack



Commit c98c520dc293d99e6462eda47eb8183248adcf78

simpler unread state

Dominic Tarr committed on 8/17/2017, 5:11:24 AM
Parent: 3fc0d209961f54388d2c9d9096675af5c1f12a6c

Files changed

unread.jschanged
unread.jsView
@@ -1,6 +1,6 @@
11 var nest = require('depnest')
2-var BloomFilter = require('jsbloom').filter
2+//var BloomFilter = require('jsbloom').filter
33
44 exports.gives = nest({
55 'unread.sync.isUnread': true,
66 'unread.sync.markRead': true,
@@ -14,42 +14,58 @@
1414 if(localStorage.unread) {
1515 try {
1616 unread = JSON.parse(localStorage.unread)
1717 } catch (err) {}
18+ }
19+ if(!unread)
20+ unread = {timestamp: Date.now()}
1821
19- if(!unread) {
20- unread = {timestamp: Date.now()}
21- }
22+ unread.timestamp = unread.timestamp || Date.now()
2223
23- if(!unread.filter) {
24- unread.filter = new Filter(10000, 0.001)
25- }
26- else {
27- var filter = new BloomFilter(10000, 0.001)
28- filter.importData(unread.filter)
29- unread.filter = filter
30- }
24+ if(!unread.filter)
25+ unread.filter = {}
26+
27+ var timer
28+ function save () {
29+ if(timer) return
30+
31+ timer = setTimeout(function () {
32+ timer = null
33+ console.log("SAVE")
34+ localStorage.unread = JSON.stringify(unread)
35+ }, 2e3)
3136 }
3237
3338 function isUnread(msg) {
3439 //ignore messages which do not have timestamps
3540 if(!msg.timestamp) return false
3641 if(msg.timestamp < unread.timestamp) return false
37- return !unread.filter.checkEntry(msg.key)
42+ if(unread.filter[msg.key]) {
43+ return false
44+ }
45+ return true
3846 }
3947
40- function addRead(msg) {
41- unread.filter.addEntry(msg.key)
48+ function markRead(msg) {
49+ if('string' === typeof msg.key) {
50+ //if(isUnread(msg)) {
51+ unread.filter[msg.key] = true
52+ save()
53+ return true
54+ //}
55+
56+ }
4257 }
4358
44- document.body.onunload = function () {
45- localStorage.unread = JSON.stringify({
46- timestamp: unread.timestamp,
47- filter: unread.filter.exportData()
48- })
49- }
59+ document.body.onunload = save
5060
5161 return nest({
5262 'unread.sync.isUnread': isUnread,
5363 'unread.sync.markRead': markRead
5464 })
5565 }
66+
67+
68+
69+
70+
71+

Built with git-ssb-web