git ssb

16+

Dominic / patchbay



Commit 3bd137609d70f9a0d68010c74ec5af5af8d59863

Merge pull request #303 from ssbc/ssb-friend-pub

Use ssb-friend-pub
Anders 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.jsadded
app/html/settings/friend-pub.mcssadded
app/sync/initialise/settings.jschanged
config.jschanged
package-lock.jsonchanged
package.jsonchanged
server.jschanged
app/html/settings/friend-pub.jsView
@@ -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.mcssView
@@ -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.jsView
@@ -18,9 +18,10 @@
1818 saturation: 100,
1919 brightness: 100,
2020 contrast: 100
2121 },
22- customStyles: defaultStyles()
22 + customStyles: defaultStyles(),
23 + pubHopConnections: 3 // all
2324 },
2425 filter: {
2526 exclude: {
2627 channels: ''
config.jsView
@@ -1,8 +1,10 @@
11 const nest = require('depnest')
22 const Config = require('ssb-config/inject')
33 const Path = require('path')
44 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
57
68 exports.gives = nest('config.sync.load')
79 exports.create = (api) => {
810 var config
@@ -13,8 +15,9 @@
1315 config = Config(process.env.ssb_appname || 'ssb')
1416
1517 config = addSockets(config)
1618 config = fixLocalhost(config)
19 + config = PubHopSettings(config)
1720
1821 return config
1922 })
2023 }
@@ -42,4 +45,21 @@
4245 config.connections.incoming.ws[0].host = '127.0.0.1'
4346 config.host = '127.0.0.1'
4447 return config
4548 }
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.jsonView
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.jsonView
@@ -90,26 +90,27 @@
9090 "setimmediate": "^1.0.5",
9191 "ssb-about": "^2.0.0",
9292 "ssb-backlinks": "^0.7.3",
9393 "ssb-blob-files": "^1.1.3",
94- "ssb-blobs": "^1.1.6",
94 + "ssb-blobs": "^1.1.12",
9595 "ssb-chess-db": "^1.0.5",
9696 "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",
99100 "ssb-friends": "^3.1.12",
100- "ssb-gossip": "^1.0.4",
101 + "ssb-gossip": "^1.0.5",
101102 "ssb-invite": "^2.0.3",
102103 "ssb-meme": "^1.0.4",
103104 "ssb-mentions": "^0.5.0",
104105 "ssb-mutual": "^0.1.0",
105- "ssb-ooo": "^1.1.0",
106 + "ssb-ooo": "^1.1.1",
106107 "ssb-private": "^0.2.3",
107108 "ssb-query": "^2.1.0",
108109 "ssb-ref": "^2.13.6",
109110 "ssb-replicate": "^1.0.4",
110111 "ssb-search": "^1.1.2",
111- "ssb-server": "^14.0.3",
112 + "ssb-server": "^14.0.4",
112113 "ssb-sort": "^1.1.0",
113114 "ssb-suggest": "^1.0.3",
114115 "ssb-unread": "^1.0.2",
115116 "ssb-uri": "^1.0.1",
server.jsView
@@ -9,8 +9,9 @@
99 .use(require('ssb-server/plugins/master'))
1010 .use(require('ssb-server/plugins/logging'))
1111 .use(require('ssb-server/plugins/unix-socket'))
1212 .use(require('ssb-server/plugins/no-auth'))
13 + .use(require('ssb-server/plugins/onion'))
1314 .use(require('ssb-server/plugins/local'))
1415
1516 .use(require('ssb-gossip'))
1617 .use(require('ssb-replicate'))
@@ -23,8 +24,9 @@
2324 .use(require('ssb-about'))
2425 .use(require('ssb-backlinks'))
2526 .use(require('ssb-chess-db'))
2627 .use(require('ssb-ebt'))
28 + .use(require('ssb-friend-pub'))
2729 .use(require('ssb-meme'))
2830 .use(require('ssb-private'))
2931 .use(require('ssb-query'))
3032 .use(require('ssb-search'))

Built with git-ssb-web