Commit 1e2909813f2b8817d7b212f23e16c6469125a36b
change api
mixmix committed on 7/29/2018, 11:33:54 AMParent: 7c6c408519e6fa6aa63c57ca89d36e72b2863797
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -8,12 +8,12 @@ | ||
8 | 8 … | module.exports = { |
9 | 9 … | name: 'unread', |
10 | 10 … | version: require('./package.json').version, |
11 | 11 … | manifest: { |
12 | - isUnread: 'async', | |
12 … | + isRead: 'async', | |
13 | 13 … | 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? | |
16 | 16 … | }, |
17 | 17 … | init: function (server, config) { |
18 | 18 … | |
19 | 19 … | mkdirp.sync(join(config.path, 'unread')) |
@@ -21,29 +21,33 @@ | ||
21 | 21 … | valueEncoding: charwise |
22 | 22 … | }) |
23 | 23 … | |
24 | 24 … | const STARTED_AT = 'startedAt' |
25 … | + var startedAt | |
25 | 26 … | 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 … | + } | |
30 | 31 … | |
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) | |
42 | 34 … | }) |
43 | 35 … | |
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) => { | |
46 | 50 … | if (err) cb(err) |
47 | 51 … | else cb(null, Boolean(ts)) |
48 | 52 … | }) |
49 | 53 … | } |
@@ -51,11 +55,11 @@ | ||
51 | 55 … | function markRead (key, cb = noop) { |
52 | 56 … | db.put(key, Date.now(), cb) |
53 | 57 … | } |
54 | 58 … | |
55 | - function unreadObs (key) { | |
59 … | + function isReadObs (key) { | |
56 | 60 … | const obs = Value(null) |
57 | - isUnread(key, (err, state) => { | |
61 … | + isRead(key, (err, state) => { | |
58 | 62 … | if (err) console.error(err) |
59 | 63 … | else obs.set(state) |
60 | 64 … | }) |
61 | 65 … | |
@@ -65,11 +69,11 @@ | ||
65 | 69 … | return obs |
66 | 70 … | } |
67 | 71 … | |
68 | 72 … | return { |
69 | - isUnread, | |
73 … | + isRead, | |
70 | 74 … | markRead, |
71 | - unreadObs | |
75 … | + isReadObs | |
72 | 76 … | } |
73 | 77 … | } |
74 | 78 … | } |
75 | 79 … |
Built with git-ssb-web