git ssb

0+

mixmix / ssb-unread



Commit 6b0e3d2a1e43d3efa7bfab274588c5b8acd70f16

pollish for the inital release

mixmix committed on 8/15/2018, 9:25:24 AM
Parent: 1e2909813f2b8817d7b212f23e16c6469125a36b

Files changed

README.mdchanged
index.jschanged
package-lock.jsonchanged
package.jsonchanged
README.mdView
@@ -1,1 +1,28 @@
1-# ssb-unread
1 +# ssb-unread
2 +
3 +A scuttlebot plugin which tracks read / unread state of all received messages in a mutable level db.
4 +The intention is to provide a persistent store which can be referenced and contributed to by a plurality of client interfaces.
5 +
6 +## Install
7 +
8 +```js
9 +var sbot = require('scuttlebot')
10 + .use(require('scuttlebot/plugins/master'))
11 + .use(require('scuttlebot/plugins/gossip'))
12 + .use(require('scuttlebot/plugins/replicate'))
13 + .use(require('scuttlebot/plugins/invite'))
14 + .use(require('scuttlebot/plugins/local'))
15 + .use(require('ssb-unread')) // <<
16 + .call(null, config)
17 +```
18 +
19 +## API
20 +
21 +### `sbot.unread.isRead(key, cb)`
22 +
23 +provide a message key and get a boolean response back in the callback
24 +
25 +### `sbot.unread.markRead(key, cb)`
26 +
27 +mark a message key as read
28 +
index.jsView
@@ -2,17 +2,16 @@
22 const mkdirp = require('mkdirp')
33 const { join } = require('path')
44 const level = require('level')
55 const charwise = require('charwise')
6-const Value = require('mutant/value')
6 +const { isMsg } = require('ssb-ref')
77
88 module.exports = {
99 name: 'unread',
1010 version: require('./package.json').version,
1111 manifest: {
1212 isRead: 'async',
1313 markRead: 'async',
14- isReadObs: 'sync',
1514 // isUnreadThrough: 'source' // stream via this module to check unread state of msgs as you go?
1615 },
1716 init: function (server, config) {
1817
@@ -20,21 +19,11 @@
2019 const db = level(join(config.path, 'unread'), {
2120 valueEncoding: charwise
2221 })
2322
24- const STARTED_AT = 'startedAt'
25- var startedAt
26- db.get(STARTED_AT, (err, ts) => {
27- if (ts) {
28- startedAt = ts
29- return
30- }
23 + markDbBirth(db)
3124
32- startedAt = Date.now
33- db.put(STARTED_AT, startedAt)
34- })
35-
36- const VERSION = 0
25 + const VERSION = 1
3726 server._flumeUse('unread-dummy-index', flumeView(
3827 VERSION,
3928 (_, msg) => {
4029 db.put(msg.key, null, noop)
@@ -43,38 +32,41 @@
4332 // HACK: leveraging flume to access stream of newest messages
4433 }
4534 ))
4635
47- // should take key?
4836 function isRead (key, cb) {
37 + if (!isMsg(key)) return cb(null, new Error('ssb-unread requires a valid message key')
38 +
4939 db.get(key, (err, ts) => {
5040 if (err) cb(err)
5141 else cb(null, Boolean(ts))
5242 })
5343 }
5444
5545 function markRead (key, cb = noop) {
46 + if (!isMsg(key)) return cb(null, new Error('ssb-unread requires a valid message key')
47 +
5648 db.put(key, Date.now(), cb)
5749 }
5850
59- function isReadObs (key) {
60- const obs = Value(null)
61- isRead(key, (err, state) => {
62- if (err) console.error(err)
63- else obs.set(state)
64- })
65-
66- // remember pull-level
67- // - could use for live updating ?
68-
69- return obs
70- }
71-
7251 return {
7352 isRead,
7453 markRead,
75- isReadObs
7654 }
7755 }
7856 }
7957
58 +function markDbBirth (db) {
59 + const STARTED_AT = 'startedAt'
60 + var startedAt
61 + db.get(STARTED_AT, (err, ts) => {
62 + if (ts) {
63 + startedAt = ts
64 + return
65 + }
66 +
67 + startedAt = Date.now
68 + db.put(STARTED_AT, startedAt)
69 + })
70 +}
71 +
8072 function noop () {}
package-lock.jsonView
@@ -54,13 +54,8 @@
5454 "readable-stream": "^2.3.5",
5555 "safe-buffer": "^5.1.1"
5656 }
5757 },
58- "browser-split": {
59- "version": "0.0.1",
60- "resolved": "https://registry.npmjs.org/browser-split/-/browser-split-0.0.1.tgz",
61- "integrity": "sha1-ewl1dPjj6tYG+0Zk5krf3aKYGpM="
62- },
6358 "buffer-alloc": {
6459 "version": "1.2.0",
6560 "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz",
6661 "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==",
@@ -247,16 +242,26 @@
247242 "version": "1.3.5",
248243 "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
249244 "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw=="
250245 },
246 + "ip": {
247 + "version": "1.1.5",
248 + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
249 + "integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
250 + },
251251 "is-fullwidth-code-point": {
252252 "version": "1.0.0",
253253 "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
254254 "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
255255 "requires": {
256256 "number-is-nan": "^1.0.0"
257257 }
258258 },
259 + "is-valid-domain": {
260 + "version": "0.0.5",
261 + "resolved": "https://registry.npmjs.org/is-valid-domain/-/is-valid-domain-0.0.5.tgz",
262 + "integrity": "sha1-SOcDGfy0MAkjbpazf5hDiJzntRM="
263 + },
259264 "isarray": {
260265 "version": "1.0.0",
261266 "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
262267 "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
@@ -350,17 +355,8 @@
350355 "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
351356 }
352357 }
353358 },
354- "mutant": {
355- "version": "3.22.1",
356- "resolved": "https://registry.npmjs.org/mutant/-/mutant-3.22.1.tgz",
357- "integrity": "sha1-kEh1RvcAs8KKqApD0c99M48wdYE=",
358- "requires": {
359- "browser-split": "0.0.1",
360- "xtend": "^4.0.1"
361- }
362- },
363359 "nan": {
364360 "version": "2.10.0",
365361 "resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
366362 "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA=="
@@ -540,8 +536,17 @@
540536 "once": "^1.3.1",
541537 "simple-concat": "^1.0.0"
542538 }
543539 },
540 + "ssb-ref": {
541 + "version": "2.11.1",
542 + "resolved": "https://registry.npmjs.org/ssb-ref/-/ssb-ref-2.11.1.tgz",
543 + "integrity": "sha512-K3L9hJ1v0HrH8abtEKiBkdeabHVaws+CS81mZqUfhR84i0dlYhiIIDwqeLxUj/1mLcsZPF3gMKPsFCUr7UAdMA==",
544 + "requires": {
545 + "ip": "^1.1.3",
546 + "is-valid-domain": "~0.0.1"
547 + }
548 + },
544549 "string-width": {
545550 "version": "1.0.2",
546551 "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
547552 "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
package.jsonView
@@ -21,7 +21,7 @@
2121 "charwise": "^3.0.1",
2222 "flumeview-reduce": "^1.3.13",
2323 "level": "^4.0.0",
2424 "mkdirp": "^0.5.1",
25- "mutant": "^3.22.1"
25 + "ssb-ref": "^2.11.1"
2626 }
2727 }

Built with git-ssb-web