Permalink
Browse files

Add support for DHT invites

  • Loading branch information...
stripedpajamas committed Oct 1, 2018
1 parent 263fed1 commit d82f6949ccb7dd4ee7ebcf327a233cdd9c78d57a
@@ -167,6 +167,14 @@ function setupContext (appName, opts, cb) {
friends: {
dunbar: 150,
hops: 2 // down from 3
},
connections: { // to support DHT invites
incoming: {
dht: [{ scope: 'public', transform: 'shs', port: 8423 }]
},
outgoing: {
dht: [{ transform: 'shs' }]
}
}
}, opts))
@@ -263,5 +263,13 @@
"one": "Your message has %s recipient",
"other": "Your message has %s recipients"
},
"Please go back and remove some of the recipients.": "Please go back and remove some of the recipients."
"Please go back and remove some of the recipients.": "Please go back and remove some of the recipients.",
"Create Invite": "Create Invite",
"Accept Invite": "Accept Invite",
"Connect directly to friends currently online, using a peer-to-peer technology called \"Distributed Hash Table\"": "Connect directly to friends currently online, using a peer-to-peer technology called \"Distributed Hash Table\"",
"Give this invite code to one friend. ": "Give this invite code to one friend. ",
"You will sync when you are both online.": "You will sync when you are both online.",
"Please wait...": "Please wait...",
"Create DHT Invite": "Create DHT Invite",
"Redeeming...": "Redeeming..."
}
@@ -0,0 +1,76 @@
var {h, when, Value, Proxy} = require('mutant')
var nest = require('depnest')
var electron = require('electron')
exports.needs = nest({
'sheet.display': 'first',
'sbot.async.acceptDHT': 'first',
'intl.sync.i18n': 'first'
})
exports.gives = nest('dhtInvite.accept.sheet')
exports.create = function (api) {
const i18n = api.intl.sync.i18n
return nest('dhtInvite.accept.sheet', function () {
api.sheet.display(close => {
var publishing = Value()
var input = h('input', {
style: {
'font-size': '200%',
'margin-top': '20px',
'width': '100%'
},
placeholder: i18n('paste invite code here')
})
setTimeout(() => {
input.focus()
input.select()
}, 5)
return {
content: h('div', {
style: {
padding: '20px'
}
}, [
h('h2', {
style: {
'font-weight': 'normal'
}
}, [i18n('Connect directly to friends currently online, using a peer-to-peer technology called "Distributed Hash Table"')]),
input
]),
footer: [
h('button -save', {
disabled: publishing,
'ev-click': () => {
publishing.set(true)
api.sbot.async.acceptDHT(input.value.trim(), (err) => {
if (err) {
publishing.set(false)
showDialog({
type: 'error',
title: i18n('Error'),
buttons: [i18n('OK')],
message: i18n('An error occurred while attempting to redeem invite.'),
detail: err.message
})
} else {
close()
}
})
}
}, [ when(publishing, i18n('Redeeming...'), i18n('Redeem Invite')) ]),
h('button -cancel', {
'ev-click': close
}, i18n('Cancel'))
]
}
})
})
}
function showDialog (opts) {
electron.remote.dialog.showMessageBox(electron.remote.getCurrentWindow(), opts)
}
@@ -0,0 +1,77 @@
var {h, when, Value} = require('mutant')
var nest = require('depnest')
var electron = require('electron')
exports.needs = nest({
'sheet.display': 'first',
'sbot.async.createDHT': 'first',
'intl.sync.i18n': 'first'
})
exports.gives = nest('dhtInvite.create.sheet')
exports.create = function (api) {
const i18n = api.intl.sync.i18n
return nest('dhtInvite.create.sheet', function () {
api.sheet.display(close => {
var creating = Value()
var inviteCode = Value()
return {
content: h('div', {
style: {
padding: '20px',
display: 'grid'
}
}, [
h('h2', { style: { 'font-weight': 'normal' } },
[i18n('Connect directly to friends currently online, using a peer-to-peer technology called "Distributed Hash Table"')]
),
when(inviteCode,
h('div', [
h('div', {
style: {
'word-break': 'break-all',
'font-family': 'monospace',
'font-size': '18px',
'user-select': 'all'
}
}, [inviteCode]),
h('h2', [
i18n('Give this invite code to one friend. '),
i18n('You will sync when you are both online.')
])
]),
h('button', {
'ev-click': () => {
api.sbot.async.createDHT((err, code) => {
if (err) {
created.set(false)
showDialog({
type: 'error',
title: i18n('Error'),
buttons: [i18n('OK')],
message: i18n('An error occurred while attempting to create invite.'),
detail: err.message
})
} else {
inviteCode.set(code)
}
})
}
}, [ when(creating, i18n('Please wait...'), i18n('Create DHT Invite')) ])
)
]),
footer: [
h('button -cancel', {
'ev-click': close
}, when(inviteCode, i18n('Close'), i18n('Cancel')))
]
}
})
})
}
function showDialog (opts) {
electron.remote.dialog.showMessageBox(electron.remote.getCurrentWindow(), opts)
}
@@ -16,6 +16,8 @@ exports.needs = nest({
'about.html.image': 'first',
'about.obs.name': 'first',
'invite.sheet': 'first',
'dhtInvite.accept.sheet': 'first',
'dhtInvite.create.sheet': 'first',
'message.html.compose': 'first',
'message.async.publish': 'first',
@@ -68,7 +70,6 @@ exports.create = function (api) {
noFollowersWarning()
]
var getStream = (opts) => {
if (opts.lt != null && !opts.lt.marker) {
// if an lt has been specified that is not a marker, assume stream is finished
@@ -193,6 +194,12 @@ exports.create = function (api) {
h('button -pub -full', {
'ev-click': api.invite.sheet
}, i18n('+ Join Pub')),
h('button -pub -half', {
'ev-click': api.dhtInvite.create.sheet
}, i18n('Create Invite')),
h('button -pub -half', {
'ev-click': api.dhtInvite.accept.sheet
}, i18n('Accept Invite')),
when(loading, [ h('Loading') ], [
when(computed(channels, x => x.length), h('h2', i18n('Active Channels'))),
h('div', {
@@ -26,7 +26,9 @@ exports.gives = {
publish: true,
addBlob: true,
gossipConnect: true,
friendsGet: true
friendsGet: true,
acceptDHT: true,
createDHT: true
},
pull: {
log: true,
@@ -207,6 +209,12 @@ exports.create = function (api) {
}),
friendsGet: rec.async(function (opts, cb) {
sbot.friends.get(opts, cb)
}),
acceptDHT: rec.async(function (opts, cb) {
sbot.dhtInvite.accept(opts, cb)
}),
createDHT: rec.async(function (cb) {
sbot.dhtInvite.create(cb)
})
},
pull: {
Oops, something went wrong.

0 comments on commit d82f694

Please sign in to comment.