Commit 3bd137609d70f9a0d68010c74ec5af5af8d59863
Merge pull request #303 from ssbc/ssb-friend-pub
Use ssb-friend-pubAnders Rune Jensen authored on 2/9/2019, 9:45:04 AM
GitHub committed on 2/9/2019, 9:45:04 AM
Parent: 1ce1d9f678f1a33c32dcd8dd0770feb8bd75d508
Parent: ea7fc909113d7b2840e137c3b29f8a26866da3a9
Files changed
app/html/settings/friend-pub.js | added |
app/html/settings/friend-pub.mcss | added |
app/sync/initialise/settings.js | changed |
config.js | changed |
package-lock.json | changed |
package.json | changed |
server.js | changed |
app/html/settings/friend-pub.js | ||
---|---|---|
@@ -1,0 +1,93 @@ | ||
1 … | +const nest = require('depnest') | |
2 … | +const { h, computed, onceTrue, Value } = require('mutant') | |
3 … | + | |
4 … | +exports.gives = nest({ | |
5 … | + 'app.html.settings': true | |
6 … | +}) | |
7 … | + | |
8 … | +exports.needs = nest({ | |
9 … | + 'about.html.image': 'first', | |
10 … | + 'about.obs.name': 'first', | |
11 … | + 'app.html.settings': 'map', | |
12 … | + 'sbot.obs.connection': 'first', | |
13 … | + 'settings.obs.get': 'first', | |
14 … | + 'settings.sync.set': 'first' | |
15 … | +}) | |
16 … | + | |
17 … | +exports.create = function (api) { | |
18 … | + return nest({ | |
19 … | + 'app.html.settings': pubHopConnections | |
20 … | + }) | |
21 … | + | |
22 … | + function pubHopConnections () { | |
23 … | + const pubHopAll = 3 | |
24 … | + const pubHopConnections = api.settings.obs.get('patchbay.pubHopConnections', pubHopAll) | |
25 … | + const changeHopSettings = (ev) => { | |
26 … | + api.settings.sync.set({ patchbay: { pubHopConnections: parseInt(ev.target.value) }}) | |
27 … | + | |
28 … | + alert("please restart patchbay for this to take effect") | |
29 … | + } | |
30 … | + | |
31 … | + let pubs = Value({}) | |
32 … | + | |
33 … | + const pubHopConnectionsText = computed([pubHopConnections], function(pubHopConnections) { | |
34 … | + pubHopConnections = parseInt(pubHopConnections) | |
35 … | + onceTrue(api.sbot.obs.connection, sbot => { | |
36 … | + if (pubHopConnections == pubHopAll) | |
37 … | + pubs.set([]) | |
38 … | + else | |
39 … | + sbot.friendPub.pubsWithinHops(pubHopConnections, (err, pubsInHops) => { | |
40 … | + pubs.set(pubsInHops) | |
41 … | + }) | |
42 … | + }) | |
43 … | + | |
44 … | + switch (pubHopConnections) { | |
45 … | + case 0: | |
46 … | + return "Own pub only" | |
47 … | + case 1: | |
48 … | + return "Pubs run by friends" | |
49 … | + case 2: | |
50 … | + return "Pubs run by friends of friends" | |
51 … | + default: // 3 | |
52 … | + return "All pubs" | |
53 … | + } | |
54 … | + }) | |
55 … | + | |
56 … | + function pubImageLink (id, ownerId) { | |
57 … | + return h('a', { | |
58 … | + href: id, | |
59 … | + title: computed([api.about.obs.name(id), api.about.obs.name(ownerId)], (name, ownerName) => { | |
60 … | + return '@' + name + ', owner ' + ownerName | |
61 … | + }) | |
62 … | + }, api.about.html.image(id)) | |
63 … | + } | |
64 … | + | |
65 … | + const pubsHtml = computed([pubs], function(pubs) { | |
66 … | + return Object.values(pubs).map(pub => pubImageLink(pub.id, pub.owner)) | |
67 … | + }) | |
68 … | + | |
69 … | + return { | |
70 … | + title: 'Pub within hops connections', | |
71 … | + body: h('FriendPub', [ | |
72 … | + h('div', [ | |
73 … | + 'Only connect to pubs run by a peer within a certain number of hops', | |
74 … | + h('input', { | |
75 … | + type: 'range', | |
76 … | + attributes: { list: 'datalist' }, | |
77 … | + min: 0, | |
78 … | + max: 3, | |
79 … | + value: pubHopConnections, | |
80 … | + 'ev-change': changeHopSettings | |
81 … | + }), | |
82 … | + h('datalist', { id: 'datalist' }, [ | |
83 … | + h('option', 0), | |
84 … | + h('option', 1), | |
85 … | + h('option', 2), | |
86 … | + h('option', 3)]), | |
87 … | + h('div', ["Current setting: ", pubHopConnectionsText]), | |
88 … | + h('div', pubsHtml) | |
89 … | + ]) | |
90 … | + ]) | |
91 … | + } | |
92 … | + } | |
93 … | +} |
app/html/settings/friend-pub.mcss | ||
---|---|---|
@@ -1,0 +1,8 @@ | ||
1 … | +FriendPub { | |
2 … | + div { | |
3 … | + input[type=range] { | |
4 … | + vertical-align: middle | |
5 … | + margin-left: 15px | |
6 … | + } | |
7 … | + } | |
8 … | +} |
app/sync/initialise/settings.js | ||
---|---|---|
@@ -18,9 +18,10 @@ | ||
18 | 18 … | saturation: 100, |
19 | 19 … | brightness: 100, |
20 | 20 … | contrast: 100 |
21 | 21 … | }, |
22 | - customStyles: defaultStyles() | |
22 … | + customStyles: defaultStyles(), | |
23 … | + pubHopConnections: 3 // all | |
23 | 24 … | }, |
24 | 25 … | filter: { |
25 | 26 … | exclude: { |
26 | 27 … | channels: '' |
config.js | |||
---|---|---|---|
@@ -1,8 +1,10 @@ | |||
1 | 1 … | const nest = require('depnest') | |
2 | 2 … | const Config = require('ssb-config/inject') | |
3 | 3 … | const Path = require('path') | |
4 | 4 … | const merge = require('lodash/merge') | |
5 … | +// settings not available in api yet, so we need to load it manually | ||
6 … | +const settings = require('patch-settings').patchSettings | ||
5 | 7 … | ||
6 | 8 … | exports.gives = nest('config.sync.load') | |
7 | 9 … | exports.create = (api) => { | |
8 | 10 … | var config | |
@@ -13,8 +15,9 @@ | |||
13 | 15 … | config = Config(process.env.ssb_appname || 'ssb') | |
14 | 16 … | ||
15 | 17 … | config = addSockets(config) | |
16 | 18 … | config = fixLocalhost(config) | |
19 … | + config = PubHopSettings(config) | ||
17 | 20 … | ||
18 | 21 … | return config | |
19 | 22 … | }) | |
20 | 23 … | } | |
@@ -42,4 +45,21 @@ | |||
42 | 45 … | config.connections.incoming.ws[0].host = '127.0.0.1' | |
43 | 46 … | config.host = '127.0.0.1' | |
44 | 47 … | return config | |
45 | 48 … | } | |
49 … | + | ||
50 … | +function PubHopSettings (config) { | ||
51 … | + const pubHopAll = 3 | ||
52 … | + let pubHopConnections = settings.create().settings.sync.get('patchbay.pubHopConnections', pubHopAll) | ||
53 … | + if (pubHopConnections != pubHopAll) { | ||
54 … | + return merge( | ||
55 … | + config, | ||
56 … | + { | ||
57 … | + friendPub: { hops: pubHopConnections }, | ||
58 … | + gossip: { | ||
59 … | + friends: true, | ||
60 … | + global: false | ||
61 … | + } | ||
62 … | + }) | ||
63 … | + } else | ||
64 … | + return config | ||
65 … | +} |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 589463 bytes New file size: 616412 bytes |
package.json | ||
---|---|---|
@@ -90,26 +90,27 @@ | ||
90 | 90 … | "setimmediate": "^1.0.5", |
91 | 91 … | "ssb-about": "^2.0.0", |
92 | 92 … | "ssb-backlinks": "^0.7.3", |
93 | 93 … | "ssb-blob-files": "^1.1.3", |
94 | - "ssb-blobs": "^1.1.6", | |
94 … | + "ssb-blobs": "^1.1.12", | |
95 | 95 … | "ssb-chess-db": "^1.0.5", |
96 | 96 … | "ssb-chess-mithril": "^1.0.7", |
97 | - "ssb-config": "^3.2.2", | |
98 | - "ssb-ebt": "^5.3.9", | |
97 … | + "ssb-config": "^3.2.3", | |
98 … | + "ssb-ebt": "^5.3.11", | |
99 … | + "ssb-friend-pub": "^1.0.4", | |
99 | 100 … | "ssb-friends": "^3.1.12", |
100 | - "ssb-gossip": "^1.0.4", | |
101 … | + "ssb-gossip": "^1.0.5", | |
101 | 102 … | "ssb-invite": "^2.0.3", |
102 | 103 … | "ssb-meme": "^1.0.4", |
103 | 104 … | "ssb-mentions": "^0.5.0", |
104 | 105 … | "ssb-mutual": "^0.1.0", |
105 | - "ssb-ooo": "^1.1.0", | |
106 … | + "ssb-ooo": "^1.1.1", | |
106 | 107 … | "ssb-private": "^0.2.3", |
107 | 108 … | "ssb-query": "^2.1.0", |
108 | 109 … | "ssb-ref": "^2.13.6", |
109 | 110 … | "ssb-replicate": "^1.0.4", |
110 | 111 … | "ssb-search": "^1.1.2", |
111 | - "ssb-server": "^14.0.3", | |
112 … | + "ssb-server": "^14.0.4", | |
112 | 113 … | "ssb-sort": "^1.1.0", |
113 | 114 … | "ssb-suggest": "^1.0.3", |
114 | 115 … | "ssb-unread": "^1.0.2", |
115 | 116 … | "ssb-uri": "^1.0.1", |
server.js | ||
---|---|---|
@@ -9,8 +9,9 @@ | ||
9 | 9 … | .use(require('ssb-server/plugins/master')) |
10 | 10 … | .use(require('ssb-server/plugins/logging')) |
11 | 11 … | .use(require('ssb-server/plugins/unix-socket')) |
12 | 12 … | .use(require('ssb-server/plugins/no-auth')) |
13 … | + .use(require('ssb-server/plugins/onion')) | |
13 | 14 … | .use(require('ssb-server/plugins/local')) |
14 | 15 … | |
15 | 16 … | .use(require('ssb-gossip')) |
16 | 17 … | .use(require('ssb-replicate')) |
@@ -23,8 +24,9 @@ | ||
23 | 24 … | .use(require('ssb-about')) |
24 | 25 … | .use(require('ssb-backlinks')) |
25 | 26 … | .use(require('ssb-chess-db')) |
26 | 27 … | .use(require('ssb-ebt')) |
28 … | + .use(require('ssb-friend-pub')) | |
27 | 29 … | .use(require('ssb-meme')) |
28 | 30 … | .use(require('ssb-private')) |
29 | 31 … | .use(require('ssb-query')) |
30 | 32 … | .use(require('ssb-search')) |
Built with git-ssb-web