开发者社区> 镜像站> NPM> ssb-unread
ssb-unread
A ssb-server plugin which tracks read / unread state of all received messages in a mutable level db. The intention is to provide a persistent store which can be referenced and contributed to by a plurality of client interfaces.
Last updated 5 months ago by mixmix .
AGPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ssb-unread 
SYNC missed versions from official npm registry.

ssb-unread

A ssb-server plugin which tracks read / unread state of all received messages in a mutable level db. The intention is to provide a persistent store which can be referenced and contributed to by a plurality of client interfaces.

Note that this unread state is "off-chain", as in it's not stored in your log, so others won't be able to see it, and if you lose your computer you won't be able to recover your unread record.

API

sbot.unread.isRead(key, cb)

Provide a message key and get a boolean response back in the callback

sbot.unread.markRead(key, cb)

mark a message key as read

Example Usage

var Server = require('ssb-server')
var Config = require('ssb-config/inject')

Server
  .use(require('ssb-server/plugins/master'))
  .use(require('ssb-unread'))   // <<

var server = Server(Config())

var msgId = '%fJ900xKrMIJ1NM09V05z++GLy92O9NP9Hh5hpM1MeA4=.sha256'
server.unread.isRead(msgId, (err, bool) => {
  console.log(msgId, 'has been read:', bool)
})

Example Usage (more complete)

// server.js 
var Server = require('ssb-server')
var Config = require('ssb-config/inject')

Server
  .use(require('ssb-server/plugins/master'))
  .use(require('ssb-backlinks'))
  .use(require('ssb-unread'))   // <<

var server = Server(Config())
// client.js  (connecting remotely from front end to back end)
var Client = require('ssb-client')
var Config = require('ssb-config/inject')
var pull = require('pull-stread')
var pullParallelMap = require('pull-paramap')

var config = Config()

Client(config.keys, config, (err, server) => {
  pull(
    pullMentions(server),
    pullParallelMap((msg, cb) => {
      server.unread.isRead(msg.key, (err, bool) => {
        if (bool) cb(null, null) // drop the read messages
        else cb(null, msg)
      })
    }, 5),
    pull.filter(Boolean), // filter out the null entries
    pull.take(20), // don't pull the whole database!
    pull.collect((err, unreadMentions) => {
      // ... do something
    })
  })
})

function pullMentions (server, feedId) {
  return server.backlinks.read({
    query: [{ 
      $filter: {
        dest: server.id, // mentions about me
      }
    }],
    reverse: true,
    live: false
  })
  // Note this likely needs validation + sorting!
}

Current Tags

  • 1.1.0                                ...           latest (5 months ago)

10 Versions

  • 1.1.0                                ...           5 months ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (5)
Dev Dependencies (1)
Dependents (2)