Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit e0870c4

Browse files
Merge pull request #1219 from ssbc/rooms
Add support for SSB Rooms
2 parents 6373f5b + b709637 commit e0870c4

File tree

9 files changed

+471
-32
lines changed

9 files changed

+471
-32
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ function setupContext (appName, opts, cb) {
219219
ssbConfig.remote = `unix:${socketPath}:~noauth:${pubkey}`
220220
}
221221

222+
// Support rooms
223+
ssbConfig.connections.incoming.tunnel = [{ scope: 'public', transform: 'shs' }]
224+
ssbConfig.connections.outgoing.tunnel = [{ transform: 'shs' }]
225+
222226
const redactedConfig = JSON.parse(JSON.stringify(ssbConfig))
223227
redactedConfig.keys.private = null
224228
console.dir(redactedConfig, { depth: null })

lib/depject/invite/invite.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22
const ref = require('ssb-ref')
33
const ssbClient = require('ssb-client')
4+
const roomUtils = require('ssb-room/utils')
45
const Value = require('mutant/value')
56
const nest = require('depnest')
67

@@ -20,6 +21,13 @@ exports.gives = nest({
2021
exports.create = function (api) {
2122
function accept (invite, cb) {
2223
const progress = Value('Connecting...')
24+
25+
if (roomUtils.isInvite(invite)) {
26+
const address = roomUtils.inviteToAddress(invite)
27+
api.sbot.async.connRememberConnect(address, { type: 'room' }, cb)
28+
return
29+
}
30+
2331
const data = ref.parseInvite(invite)
2432
const id = api.keys.sync.id()
2533
const config = api.config.sync.load()

lib/depject/invite/sheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ exports.create = function (api) {
4141
}
4242
}, [i18n('By default, Patchwork will only see other users that are on the same local area network as you.')]),
4343
h('div', [
44-
i18n('In order to share with users on the internet, you need to be invited to a pub server.')
44+
i18n('In order to share with users on the internet, you need to be invited to a pub server or a room server.')
4545
]),
4646
input
4747
]),

lib/depject/page/html/render/public.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ exports.create = function (api) {
113113
return [
114114
h('button -pub -full', {
115115
'ev-click': api.invite.sheet
116-
}, i18n('+ Join Pub')),
116+
}, i18n('+ Join Server')),
117117

118118
// disabling DHT invites until they work in sbot@13
119119
//
@@ -151,7 +151,7 @@ exports.create = function (api) {
151151

152152
PeerList(localPeers, i18n('Local')),
153153
SuggestedPeerList(stagedPeers, i18n('Possible connections')),
154-
PeerList(connectedPubs, i18n('Connected Pubs')),
154+
PeerList(connectedPubs, i18n('Connections')),
155155

156156
when(computed(whoToFollow, x => x.length), h('h2', i18n('Who to follow'))),
157157
when(following.sync,

lib/plugins/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ exports.init = function (ssb, config) {
107107
if (value.sync && config.gossip && config.gossip.prune) {
108108
// clean up pubs announced by peers more than 2 hops away if `--gossip.prune=true`
109109
ssb.conn.query().peersConnectable('db').forEach(([addr, data]) => {
110-
if (!discovered.has(data.key)) {
110+
if (!discovered.has(data.key) && data.type === 'pub') {
111111
ssb.conn.forget(addr)
112112
}
113113
})
@@ -116,14 +116,22 @@ exports.init = function (ssb, config) {
116116
if (!value.content) return
117117
const address = value.content.address
118118
if (replicating.has(value.author) && address && ref.isFeed(address.key)) {
119+
// ignore blocked pubs
119120
const blocking = graph && graph[ssb.id] && graph[ssb.id][address.key] === false
120-
if (!blocking) {
121-
discovered.add(address.key)
122-
try {
123-
const msAddr = ref.toMultiServerAddress(address)
124-
ssb.conn.remember(msAddr, { type: 'pub', key: address.key, autoconnect: true })
125-
} catch (err) {}
121+
if (blocking) return
122+
// make multiserver address as a string
123+
let msAddr
124+
try {
125+
msAddr = ref.toMultiServerAddress(address)
126+
} catch (err) {
127+
return
126128
}
129+
// do not override room entries even if people declared them to be pubs
130+
const oldEntry = ssb.conn.db().get(msAddr)
131+
if (oldEntry && oldEntry.type === 'room') return
132+
// add pub to the CONN database
133+
discovered.add(address.key)
134+
ssb.conn.remember(msAddr, { type: 'pub', key: address.key, autoconnect: true })
127135
}
128136
})
129137
)

lib/server-process.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const createSbot = require('secret-stack')()
3333
.use(require('ssb-backlinks'))
3434
.use(require('ssb-about'))
3535
.use(require('ssb-private'))
36+
.use(require('ssb-room/tunnel/client'))
3637
// .use(require('ssb-dht-invite')) // this one must come before dhtTransport
3738
// .use(dhtTransport)
3839
.use(require('ssb-invite'))

locales/en.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"For help, see the 'Getting Started' guide at ": "For help, see the 'Getting Started' guide at ",
99
"update": "update",
1010
"updates": "updates",
11-
"+ Join Pub": "+ Join Pub",
11+
"+ Join Server": "+ Join Server",
1212
"Active Channels": "Active Channels",
1313
"More Channels...": "More Channels...",
1414
"Local": "Local",
@@ -316,5 +316,7 @@
316316
"Attending": "Attending",
317317
"Attending Gatherings": "Attending Gatherings",
318318
"Possible connections": "Possible connections",
319-
"Connect": "Connect"
320-
}
319+
"Connections": "Connections",
320+
"Connect": "Connect",
321+
"In order to share with users on the internet, you need to be invited to a pub server or a room server.": "In order to share with users on the internet, you need to be invited to a pub server or a room server."
322+
}

0 commit comments

Comments
 (0)