git ssb

10+

Matt McKegg / patchwork



Tree: 4cc30d67ab2fb4e8d20b9119e9e8b6a37ef09f81

Files: 4cc30d67ab2fb4e8d20b9119e9e8b6a37ef09f81 / sbot / index.js

2224 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')
10
11exports.name = 'patchwork'
12exports.version = require('../package.json').version
13exports.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
33exports.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