Files: b7084484d5f38609520442861cc067351128dfa4 / sbot / index.js
2224 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 | |
11 | exports.name = 'patchwork' |
12 | exports.version = require('../package.json').version |
13 | exports.manifest = { |
14 | channels: 'source', |
15 | subscriptions: 'source', |
16 | roots: 'source', |
17 | latest: 'source', |
18 | linearSearch: 'source', |
19 | progress: 'source', |
20 | recentFeeds: 'source', |
21 | heartbeat: 'source', |
22 | |
23 | getSubscriptions: 'async', |
24 | getChannels: 'async', |
25 | |
26 | liveBacklinks: { |
27 | subscribe: 'sync', |
28 | unsubscribe: 'sync', |
29 | stream: 'source' |
30 | } |
31 | } |
32 | |
33 | exports.init = function (ssb, config) { |
34 | var progress = Progress(ssb, config) |
35 | var channels = Channels(ssb, config) |
36 | var subscriptions = Subscriptions(ssb, config) |
37 | var roots = Roots(ssb, config) |
38 | var search = Search(ssb, config) |
39 | var recentFeeds = RecentFeeds(ssb, config) |
40 | |
41 | pull( |
42 | ssb.friends.createFriendStream({live: false}), |
43 | pull.drain(() => {}, () => { |
44 | // don't assign peer friends until friends have loaded |
45 | ssb.friends.hops({start: ssb.id, hops: 2}, function (_, following) { |
46 | ssb.gossip.peers().forEach(function (peer) { |
47 | if (following[peer.key]) { |
48 | // we follow them, or follow someone that follows them! |
49 | ssb.gossip.add(peer, 'friends') |
50 | } else { |
51 | ssb.friends.hops({start: peer.key, hops: 2}, function (_, result) { |
52 | if (result && result[ssb.id]) { |
53 | // they follow us, or someone that follows us! |
54 | ssb.gossip.add(peer, 'friends') |
55 | } |
56 | }) |
57 | } |
58 | }) |
59 | }) |
60 | }) |
61 | ) |
62 | |
63 | return { |
64 | heartbeat: Heartbeat(ssb, config), |
65 | channels: channels.stream, |
66 | subscriptions: subscriptions.stream, |
67 | roots: roots.read, |
68 | latest: roots.latest, |
69 | progress: progress.stream, |
70 | recentFeeds: recentFeeds.stream, |
71 | linearSearch: search.linear, |
72 | getSubscriptions: subscriptions.get, |
73 | getChannels: channels.get, |
74 | liveBacklinks: LiveBacklinks(ssb, config) |
75 | } |
76 | } |
77 |
Built with git-ssb-web