git ssb

10+

Matt McKegg / patchwork



Tree: d170e66ba2918935e031c59b154e8a2b42afb08e

Files: d170e66ba2918935e031c59b154e8a2b42afb08e / sbot / index.js

2247 bytesRaw
1var Channels = require('./channels')
2var Heartbeat = require('./heartbeat')
3var Subscriptions = require('./subscriptions')
4var Roots = require('./roots')
5var Progress = require('./progress')
6var Search = require('./search')
7var RecentFeeds = require('./recent-feeds')
8var LiveBacklinks = require('./live-backlinks')
9var pull = require('pull-stream')
10var ref = require('ssb-ref')
11
12exports.name = 'patchwork'
13exports.version = require('../package.json').version
14exports.manifest = {
15 channels: 'source',
16 subscriptions: 'source',
17 roots: 'source',
18 latest: 'source',
19 linearSearch: 'source',
20 progress: 'source',
21 recentFeeds: 'source',
22 heartbeat: 'source',
23
24 getSubscriptions: 'async',
25 getChannels: 'async',
26
27 liveBacklinks: {
28 subscribe: 'sync',
29 unsubscribe: 'sync',
30 stream: 'source'
31 },
32
33 disconnect: 'async'
34}
35
36exports.init = function (ssb, config) {
37 var progress = Progress(ssb, config)
38 var channels = Channels(ssb, config)
39 var subscriptions = Subscriptions(ssb, config)
40 var roots = Roots(ssb, config)
41 var search = Search(ssb, config)
42 var recentFeeds = RecentFeeds(ssb, config)
43
44 // prioritize pubs that we actually follow
45 pull(
46 ssb.friends.createFriendStream({hops: 1, live: false}),
47 pull.collect((err, contacts) => {
48 if (!err) {
49 ssb.gossip.peers().forEach(function (peer) {
50 if (contacts.includes(peer.key)) {
51 ssb.gossip.add(peer, 'friends')
52 }
53 })
54 }
55 })
56 )
57
58 return {
59 heartbeat: Heartbeat(ssb, config),
60 channels: channels.stream,
61 subscriptions: subscriptions.stream,
62 roots: roots.read,
63 latest: roots.latest,
64 progress: progress.stream,
65 recentFeeds: recentFeeds.stream,
66 linearSearch: search.linear,
67 getSubscriptions: subscriptions.get,
68 getChannels: channels.get,
69 liveBacklinks: LiveBacklinks(ssb, config),
70
71 disconnect: function (opts, cb) {
72 if (ref.isFeed(opts)) opts = {key: opts}
73 if (opts && (opts.key || opts.host)) {
74 ssb.gossip.peers().find(peer => {
75 if (peer.state === 'connected' && (peer.key === opts.key || peer.host === opts.host)) {
76 ssb.gossip.disconnect(peer, cb)
77 return true
78 }
79 })
80 }
81 }
82 }
83}
84

Built with git-ssb-web