-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
39 lines (36 loc) · 985 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var appName = process.env.ssb_appname || 'ssb'
var pull = require('pull-stream')
module.exports = {
name: 'notifier',
version: '1.0.0',
manifest: {
notify: 'sync'
},
init: function (sbot, config, cb) {
var notify
var conf = config && config.notifier || {}
var logOpts = {old: false}
if (!isNaN(conf.recent)) {
logOpts.old = true
logOpts.gte = Date.now() - conf.recent
}
require('./notifier')(appName, function (err, _notify) {
if (err) return console.error('[notifier]', err.message || err)
notify = _notify
pull(
sbot.createLogStream(logOpts),
require('./notifications')(sbot, sbot.id),
pull.drain(notify, function (err) {
if (cb) cb(err)
else console.error('[notifier]', err)
})
)
})
return {
notify: function (notification) {
if (notify) notify(notification)
else console.log('[notifier]', notification)
}
}
}
}