Files: 78c1c971ce74b33515d5785a53347186166297db / sbot / index.js
2247 bytesRaw
1 | var Channels = require('./channels') |
2 | var Heartbeat = require('./heartbeat') |
3 | var Subscriptions = require('./subscriptions') |
4 | var Roots = require('./roots') |
5 | var Progress = require('./progress') |
6 | var Search = require('./search') |
7 | var RecentFeeds = require('./recent-feeds') |
8 | var LiveBacklinks = require('./live-backlinks') |
9 | var pull = require('pull-stream') |
10 | var ref = require('ssb-ref') |
11 | |
12 | exports.name = 'patchwork' |
13 | exports.version = require('../package.json').version |
14 | exports.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 | |
36 | exports.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