Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Port to vanilla branch of ssb-browser-core #325

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fixdeps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# Fix module issues in dependencies.
sed -i '/"module"/d' node_modules/\@minireq/common/package.json
sed -i '/"module"/d' node_modules/\@minireq/node/package.json
sed -i '/"module"/d' node_modules/\@minireq/browser/package.json
12 changes: 6 additions & 6 deletions net.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SSB.syncFeedAfterFollow = function(feedId) {
}

SSB.syncFeedFromSequence = function(feedId, sequence, cb) {
let rpc = SSB.getPeer()
let rpc = SSB.helpers.getPeer()

var seqStart = sequence - 100
if (seqStart < 0)
Expand All @@ -31,7 +31,7 @@ SSB.syncFeedFromSequence = function(feedId, sequence, cb) {
}

SSB.syncFeedFromLatest = function(feedId, cb) {
let rpc = SSB.getPeer()
let rpc = SSB.helpers.getPeer()

console.time("downloading messages")

Expand Down Expand Up @@ -60,7 +60,7 @@ syncThread = function(messages, cb) {
// this uses https://github.com/arj03/ssb-partial-replication
SSB.getThread = function(msgId, cb) {
SSB.connectedWithData(() => {
let rpc = SSB.getPeer()
let rpc = SSB.helpers.getPeer()

rpc.partialReplication.getTangle(msgId, (err, messages) => {
if (err) return cb(err)
Expand Down Expand Up @@ -135,13 +135,13 @@ SSB.disconnected = function(cb) {
}

// Register for the connect event so we can keep track of it.
SSB.net.on('rpc:connect', (rpc) => {
SSB.on('rpc:connect', (rpc) => {
// Now we're connected. Run all the callbacks.
++SSB.activeConnections
runConnectedCallbacks()

// See if we're operating on a connection with actual data (not a room).
let connPeers = Array.from(SSB.net.conn.hub().entries())
let connPeers = Array.from(SSB.conn.hub().entries())
connPeers = connPeers.filter(([,x])=>!!x.key).map(([address,data])=>({
address,
data
Expand All @@ -167,6 +167,6 @@ SSB.net.on('rpc:connect', (rpc) => {

SSB.getOOO = function(msgId, cb) {
SSB.connectedWithData((rpc) => {
SSB.net.ooo.get(msgId, cb)
SSB.ooo.get(msgId, cb)
})
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"pull-cat": "^1.1.11",
"pull-stream": "^3.6.14",
"rimraf": "^3.0.2",
"ssb-browser-core": "^11.2.0",
"ssb-browser-core": "github:arj03/ssb-browser-core#vanilla",
"ssb-caps": "^1.1.0",
"ssb-keys-mnemonic": "^1.0.1",
"ssb-markdown": "^6.0.7",
Expand All @@ -42,7 +42,7 @@
"workbox-build": "^6.1.0"
},
"scripts": {
"postinstall": "./dedupe.sh",
"postinstall": "./dedupe.sh && ./fixdeps.sh",
"build": "mkdir -p build && NODE_ENV=production browserify -g envify -p esmify --full-paths ui/browser.js > build/bundle-ui.js && node write-dist.js",
"release": "mkdir -p build && NODE_ENV=production browserify -g envify -g uglifyify -p esmify ui/browser.js | terser -c passes=2 --safari10 -o build/bundle-ui.js && node write-dist.js",
"inline": "mkdir -p build && browserify -g uglifyify -p esmify ui/browser.js | terser -c passes=2 --ie8 --safari10 -o build/bundle-ui.js && node write-dist.js && ./convert-to-inline.sh",
Expand Down
8 changes: 5 additions & 3 deletions ssb-singleton-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ function extraModules(secretStack) {

function ssbLoaded() {
// add helper methods
SSB = window.singletonSSB
SSB = window.singletonSSB.SSB
require('./net')
require('./profile')
require('./search')

pull(SSB.net.conn.hub().listen(), pull.drain((ev) => {
pull(SSB.conn.hub().listen(), pull.drain((ev) => {
if (ev.type.indexOf("failed") >= 0)
console.warn("Connection error: ", ev)
}))
}

require('ssb-browser-core/ssb-singleton').init(config, extraModules, ssbLoaded)
const ssbSingleton = require('ssb-browser-core/ssb-singleton')
ssbSingleton.setup("/.ssb-lite", config, extraModules)
ssbSingleton.getSimpleSSBEventually(function() { return true }, ssbLoaded)
4 changes: 2 additions & 2 deletions ui/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@
if (app.$data.feedId == "") {
[ err, SSB ] = ssbSingleton.getSSB()

if (SSB && SSB.net && SSB.net.id)
app.$data.feedId = SSB.net.id
if (SSB && SSB.id)
app.$data.feedId = SSB.id
else
setTimeout(updateFeedId, 500)
}
Expand Down
2 changes: 1 addition & 1 deletion ui/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = function () {
},

loadMoreCB: function(err, SSB) {
const { where, and, or, channel, isPublic, type, descending, startFrom, paginate, toCallback } = SSB.dbOperators
const { where, and, or, channel, isPublic, type, descending, startFrom, paginate, toCallback } = SSB.db.operators
SSB.db.query(
where(
and(
Expand Down
2 changes: 1 addition & 1 deletion ui/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function (componentsState) {
},

renderChannelsCB: function(err, SSB) {
const { where, and, not, isPublic, type, channel, startFrom, paginate, descending, toCallback } = SSB.dbOperators
const { where, and, not, isPublic, type, channel, startFrom, paginate, descending, toCallback } = SSB.db.operators
document.body.classList.add('refreshing')

// Get favorite channels from preferences.
Expand Down
2 changes: 1 addition & 1 deletion ui/connected.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Vue.component('connected', {
})
setInterval(function() {
[ err, SSB ] = ssbSingleton.getSSB()
if (SSB && SSB.net.feedReplication) {
if (SSB && SSB.net && SSB.net.feedReplication) {
if (!self.initializedSSB) {
self.initializedSSB = true
self.onDisconnected()
Expand Down
50 changes: 25 additions & 25 deletions ui/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ module.exports = function () {

goOffline: function() {
[ err, SSB ] = ssbSingleton.getSSB()
if (!SSB || !SSB.net) {
if (!SSB) {
alert("Can't go offline right now. Couldn't lock database. Please make sure you're only running one instance of ssb-browser.")
return
}

localPrefs.setOfflineMode(true)
this.online = false
SSB.net.conn.stop()
SSB.conn.stop()
},

goOnline: function() {
[ err, SSB ] = ssbSingleton.getSSB()
if (!SSB || !SSB.net) {
if (!SSB) {
alert("Can't go online right now. Couldn't lock database. Please make sure you're only running one instance of ssb-browser.")
return
}

localPrefs.setOfflineMode(false)
this.online = true
SSB.net.conn.start()
SSB.conn.start()
},

onConnected: function() {
Expand Down Expand Up @@ -130,7 +130,7 @@ module.exports = function () {

add: function() {
[ err, SSB ] = ssbSingleton.getSSB()
if (!SSB || !SSB.net) {
if (!SSB) {
alert("Can't add peers right now. Couldn't lock database. Please make sure you're only running one instance of ssb-browser.")
return
}
Expand All @@ -141,28 +141,28 @@ module.exports = function () {
return
}
if (s[0] == 'dht') {
SSB.net.dhtInvite.start((err, success) => {
SSB.dhtInvite.start((err, success) => {
if (err)
alert("Unable to accept this invite - could not start the DHT connection system.")
else
SSB.net.dhtInvite.accept(this.address, () => {});
SSB.dhtInvite.accept(this.address, () => {});
})
}
else
SSB.net.connectAndRemember(this.address, {
SSB.helpers.connectAndRemember(this.address, {
key: '@' + s[s.length-1] + '.ed25519',
type: this.type
})
},
connectSuggested: function(suggestedPeer) {
[ err, SSB ] = ssbSingleton.getSSB()
if (!SSB || !SSB.net) {
if (!SSB) {
alert("Can't add peers right now. Couldn't lock database. Please make sure you're only running one instance of ssb-browser.")
return
}

var s = suggestedPeer.address.split(":")
SSB.net.connectAndRemember(suggestedPeer.address, {
SSB.helpers.connectAndRemember(suggestedPeer.address, {
key: '@' + s[s.length-1] + '.ed25519',
type: suggestedPeer.type
})
Expand All @@ -177,12 +177,12 @@ module.exports = function () {
},
connect: function(stagedPeer) {
[ err, SSB ] = ssbSingleton.getSSB()
if (!SSB || !SSB.net) {
if (!SSB) {
alert("Can't add peers right now. Couldn't lock database. Please make sure you're only running one instance of ssb-browser.")
return
}

SSB.net.connectAndRemember(stagedPeer.address, stagedPeer.data)
SSB.helpers.connectAndRemember(stagedPeer.address, stagedPeer.data)
this.updateSuggestedPeers()

// Ask about following.
Expand All @@ -201,30 +201,30 @@ module.exports = function () {
},
disconnect: function(peer) {
[ err, SSB ] = ssbSingleton.getSSB()
if (!SSB || !SSB.net) {
if (!SSB) {
alert("Can't disconnect peers right now. Couldn't lock database. Please make sure you're only running one instance of ssb-browser.")
return
}

SSB.net.conn.forget(peer.address)
SSB.net.conn.disconnect(peer.address)
SSB.conn.forget(peer.address)
SSB.conn.disconnect(peer.address)
this.updateSuggestedPeers()
},
createInvite: function() {
[ err, SSB ] = ssbSingleton.getSSB()
if (!SSB || !SSB.net) {
if (!SSB) {
alert("Can't create an invite right now. Couldn't lock database. Please make sure you're only running one instance of ssb-browser.")
return
}

if(SSB.net.dhtInvite) {
if(SSB.dhtInvite) {
this.inviteCode = "(Generating invite code...)";
var connectionsScreen = this;
SSB.net.dhtInvite.start((err, success) => {
SSB.dhtInvite.start((err, success) => {
if (err)
connectionsScreen.inviteCode = "Sorry. An invite code could not be generated. Could not start the DHT connection system. Please try again.";
else
SSB.net.dhtInvite.create((err, inviteCode) => {
SSB.dhtInvite.create((err, inviteCode) => {
if(err) {
connectionsScreen.inviteCode = "Sorry. An invite code could not be generated. Please try again.";
} else {
Expand All @@ -244,7 +244,7 @@ module.exports = function () {
renderConnections: function() {
var self = this
ssbSingleton.getSSBEventually(-1, () => { return self.componentStillLoaded },
(SSB) => { return SSB && SSB.net }, self.renderConnectionsCallback)
(SSB) => { return SSB }, self.renderConnectionsCallback)
},
renderConnectionsCallback: function(err, SSB) {
var self = this
Expand All @@ -269,7 +269,7 @@ module.exports = function () {
/* not working after updating to ssb-ebt 7
function updatePeerTS() {
// Last updated timestamp needs to be the maximum value from several sources.
SSB.net.ebt.peerStatus((err, ebtPeers) => {
SSB.ebt.peerStatus((err, ebtPeers) => {
for (p in self.peers) {
var ts = (self.peers[p].data.hubUpdated || 0)
ts = Math.max(ts, (self.peers[p].data.stateChange || 0))
Expand All @@ -283,15 +283,15 @@ module.exports = function () {
*/

pull(
SSB.net.conn.stagedPeers(),
SSB.conn.stagedPeers(),
pull.drain((entries) => {
self.stagedPeers = entries.filter(([, x]) => !!x.key).map(([address, data]) => ({ address, data }))
self.updateSuggestedPeers()
})
)

pull(
SSB.net.conn.peers(),
SSB.conn.peers(),
pull.drain((entries) => {
self.peers = entries.filter(([, x]) => !!x.key).map(([address, data]) => ({ address, data }))
//updatePeerTS()
Expand All @@ -315,14 +315,14 @@ module.exports = function () {
// This is a long-running process, so we need to make sure we're re-acquiring SSB in case the one we've been using goes away (parent window closed, for example).
[ err, SSB ] = ssbSingleton.getSSB()
if (!self.running) return
if (!SSB || !SSB.db || !SSB.net.feedReplication) {
if (!SSB || !SSB.db || !SSB.net || !SSB.net.feedReplication) {
setTimeout(updateDBStatus, 5000)
return
}

setTimeout(() => {
const status = Object.assign(SSB.db.getStatus().value, SSB.net.feedReplication.partialStatus())
const ebtStatus = SSB.net.ebt.peerStatus(SSB.net.id)
const ebtStatus = SSB.ebt.peerStatus(SSB.id)

//updatePeerTS()

Expand Down
2 changes: 1 addition & 1 deletion ui/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function () {
},

loadMoreCB: function(err, SSB) {
const { where, and, or, author, isPublic, type, descending, startFrom, paginate, toCallback } = SSB.dbOperators
const { where, and, or, author, isPublic, type, descending, startFrom, paginate, toCallback } = SSB.db.operators
try {
SSB.db.query(
where(
Expand Down
2 changes: 1 addition & 1 deletion ui/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.handleFileSelectParts = function(files, isPrivate, cb) {
isPrivate
}

SSB.blobFiles(files, SSB.net, opts, (err, res) => {
SSB.blobFiles(files, SSB, opts, (err, res) => {
cb(null, res)
})
}
Expand Down
6 changes: 3 additions & 3 deletions ui/markdown-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ Vue.component('markdown-editor', {
var link = ref.parseLink(res.link)
if (link.query && link.query.unbox) {
// Have to unbox it first.
SSB.net.blobs.privateGet(link.link, link.query.unbox, (err, newLink) => {
SSB.blobs.privateGet(link.link, link.query.unbox, (err, newLink) => {
self.blobUrlCache[res.link] = newLink
cb(res.link, res.name)
})
} else {
SSB.net.blobs.privateFsURL(res.link, (err, blobURL) => {
SSB.blobs.privateFsURL(res.link, (err, blobURL) => {
self.blobUrlCache[res.link] = blobURL
cb(res.link, res.name)
})
}
} else {
// Public blob.
SSB.net.blobs.fsURL(res.link, (err, blobURL) => {
SSB.blobs.fsURL(res.link, (err, blobURL) => {
self.blobUrlCache[res.link] = blobURL
cb(res.link, res.name)
})
Expand Down
6 changes: 3 additions & 3 deletions ui/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ const mdOpts = {
}

if (link.query && link.query.unbox) { // private
SSB.net.blobs.privateGet(link.link, link.query.unbox, replaceLink)
SSB.blobs.privateGet(link.link, link.query.unbox, replaceLink)
}
else {
SSB.net.blobs.localGet(link.link, replaceLink)
SSB.blobs.localGet(link.link, replaceLink)
}
}

Expand All @@ -51,7 +51,7 @@ const mdOpts = {
if (link && ref.isBlob(link.link)) {
// This has to be done synchronously, so this poses a bit of a challenge for concurrency support.
[ err, SSB ] = ssbSingleton.getSSB()
if (!SSB || !(imageURL = SSB.net.blobs.remoteURL(link.link)) || imageURL == '') {
if (!SSB || !(imageURL = SSB.blobs.remoteURL(link.link)) || imageURL == '') {
// We're not connected to a peer - generate a unique ID so at least we have something to replace.
imageURL = '/blobs/get/' + link.link
}
Expand Down
4 changes: 2 additions & 2 deletions ui/new-private-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ module.exports = function (state) {
self.registeredSSBChange = true
}

const { where, and, isPrivate, not, author, type, live, toPullStream } = SSB.dbOperators
const { where, and, isPrivate, not, author, type, live, toPullStream } = SSB.db.operators

pull(
SSB.db.query(
where(
and(
isPrivate(),
not(author(SSB.net.id))
not(author(SSB.id))
)
),
live(),
Expand Down
Loading