git ssb

0+

mixmix / ssb-unread



Commit 1e2909813f2b8817d7b212f23e16c6469125a36b

change api

mixmix committed on 7/29/2018, 11:33:54 AM
Parent: 7c6c408519e6fa6aa63c57ca89d36e72b2863797

Files changed

index.jschanged
index.jsView
@@ -8,12 +8,12 @@
88 module.exports = {
99 name: 'unread',
1010 version: require('./package.json').version,
1111 manifest: {
12- isUnread: 'async',
12 + isRead: 'async',
1313 markRead: 'async',
14- unreadObs: 'sync',
15- // stream: 'source'
14 + isReadObs: 'sync',
15 + // isUnreadThrough: 'source' // stream via this module to check unread state of msgs as you go?
1616 },
1717 init: function (server, config) {
1818
1919 mkdirp.sync(join(config.path, 'unread'))
@@ -21,29 +21,33 @@
2121 valueEncoding: charwise
2222 })
2323
2424 const STARTED_AT = 'startedAt'
25 + var startedAt
2526 db.get(STARTED_AT, (err, ts) => {
26- if (!ts) db.put(STARTED_AT, Date.now())
27-
28- // console.log(new Date(ts))
29- // db.put(STARTED_AT, Number(new Date(2018, 6, 1)))
27 + if (ts) {
28 + startedAt = ts
29 + return
30 + }
3031
31- // NOTE: just using flume to get an up to date list of all messages piped to ssb-unread!
32- const VERSION = 1
33- var queue = []
34- server._flumeUse('unread-dummy-index', flumeView(
35- VERSION,
36- (_, msg) => {
37- db.put(msg.key, null, noop)
38-
39- return _
40- }
41- ))
32 + startedAt = Date.now
33 + db.put(STARTED_AT, startedAt)
4234 })
4335
44- function isUnread (key, cb) {
45- return db.get(key, (err, ts) => {
36 + const VERSION = 0
37 + server._flumeUse('unread-dummy-index', flumeView(
38 + VERSION,
39 + (_, msg) => {
40 + db.put(msg.key, null, noop)
41 +
42 + return _
43 + // HACK: leveraging flume to access stream of newest messages
44 + }
45 + ))
46 +
47 + // should take key?
48 + function isRead (key, cb) {
49 + db.get(key, (err, ts) => {
4650 if (err) cb(err)
4751 else cb(null, Boolean(ts))
4852 })
4953 }
@@ -51,11 +55,11 @@
5155 function markRead (key, cb = noop) {
5256 db.put(key, Date.now(), cb)
5357 }
5458
55- function unreadObs (key) {
59 + function isReadObs (key) {
5660 const obs = Value(null)
57- isUnread(key, (err, state) => {
61 + isRead(key, (err, state) => {
5862 if (err) console.error(err)
5963 else obs.set(state)
6064 })
6165
@@ -65,11 +69,11 @@
6569 return obs
6670 }
6771
6872 return {
69- isUnread,
73 + isRead,
7074 markRead,
71- unreadObs
75 + isReadObs
7276 }
7377 }
7478 }
7579

Built with git-ssb-web