Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6ab2c21
Add 'create invite' button
Powersource May 30, 2019
21f0705
Merge remote-tracking branch 'origin/master' into use-peer-invites
Powersource Jul 6, 2019
17dd8c3
Update package-lock
Powersource Jul 6, 2019
133d8c7
Add a sheet for creating peer invites
Powersource Jul 6, 2019
75e374f
Merge branch 'master' of github.com:ssbc/patchwork into use-peer-invites
Powersource Jul 10, 2019
8b00ebf
Install ssb-friends
Powersource Jul 10, 2019
0407b8f
Get getNearbyPubs to work
Powersource Jul 10, 2019
f2bc4f7
Merge branch 'master' of github.com:ssbc/patchwork into use-peer-invites
Powersource Jul 13, 2019
752d5b8
Remove commented line
Powersource Jul 13, 2019
a34648d
Merge remote-tracking branch 'origin/master' into use-peer-invites
Powersource Mar 1, 2020
176c392
Bump stuff in package.json
Powersource Mar 1, 2020
25b8a52
Add creation of peer-invites
Powersource Mar 1, 2020
ac14aa1
Try to allow opening of invites
Powersource Mar 2, 2020
26b5d26
Merge remote-tracking branch 'origin/master' into use-peer-invites
Powersource Apr 3, 2020
0b53a25
Do basic rendering of invite info
Powersource Apr 3, 2020
dc87fb2
Merge remote-tracking branch 'origin/master' into use-peer-invites
Powersource Apr 18, 2020
f9c28e8
Sort of get using invites to work?
Powersource Apr 18, 2020
ca09366
Disable input after we've started processing the input
Powersource Apr 18, 2020
bc26e41
Use the correct function 🤦
Powersource Apr 18, 2020
69c0597
Fix error function
Powersource Apr 18, 2020
bef50ef
Remove duplicate friends import
Powersource Apr 18, 2020
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
1 change: 1 addition & 0 deletions lib/depject/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module.exports = {
invite: {
dhtAcceptSheet: require('./invite/dhtAcceptSheet.js'),
dhtCreateSheet: require('./invite/dhtCreateSheet.js'),
peerCreateSheet: require('./invite/peerCreateSheet.js'),
invite: require('./invite/invite.js'),
sheet: require('./invite/sheet.js')
},
Expand Down
23 changes: 21 additions & 2 deletions lib/depject/invite/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
const ref = require('ssb-ref')
const ssbClient = require('ssb-client')
const roomUtils = require('ssb-room/utils')
const Value = require('mutant/value')
const { onceTrue, Value } = require('mutant')
const nest = require('depnest')

exports.needs = nest({
'sbot.async.publish': 'first',
'sbot.async.connRememberConnect': 'first',
'contact.async.followerOf': 'first',
'keys.sync.id': 'first',
'config.sync.load': 'first'
'config.sync.load': 'first',
'sbot.obs.connection': 'first'
})

exports.gives = nest({
Expand All @@ -28,6 +29,24 @@ exports.create = function (api) {
return
}

if (invite.startsWith('inv:')) {
// likely a peer invite
console.log('using a peer invite')


onceTrue(api.sbot.obs.connection, (ssb) => {
ssb.peerInvites.openInvite(invite, (err, data) => {
if (err) return cb(err)

console.log('invite data:', data)
progress.set('Invite found')
cb(null, data)
})
})

return progress
}

const data = ref.parseInvite(invite)
const id = api.keys.sync.id()
const config = api.config.sync.load()
Expand Down
82 changes: 82 additions & 0 deletions lib/depject/invite/peerCreateSheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var { h, when, Value, onceTrue } = require('mutant')
var nest = require('depnest')
var electron = require('electron')

exports.needs = nest({
'sheet.display': 'first',
'intl.sync.i18n': 'first',
'sbot.obs.connection': 'first'
})

exports.gives = nest('peerInvite.create.sheet')

exports.create = function (api) {
const i18n = api.intl.sync.i18n
return nest('peerInvite.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('Create an invite that your friend can use to find you. You need to be followed by a pub with support for "peer invites".')]
),
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.')
])
]),
h('button', {
'ev-click': () => {
creating.set(true)
onceTrue(api.sbot.obs.connection, (ssb) => {
ssb.peerInvites.create({}, (err, code) => {
if (err) {
creating.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 {
creating.set(false)
console.log('res', code)
inviteCode.set(code)
}
})
})
console.log('boop')
}
}, [ when(creating, i18n('Please wait...'), i18n('Create 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)
}
97 changes: 74 additions & 23 deletions lib/depject/invite/sheet.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { h, when, Value, Proxy } = require('mutant')
const { h, when, Value, Proxy, onceTrue, computed } = require('mutant')
const nest = require('depnest')
const electron = require('electron')

exports.needs = nest({
'sheet.display': 'first',
'invite.async.accept': 'first',
'intl.sync.i18n': 'first'
'intl.sync.i18n': 'first',
'sbot.obs.connection': 'first'
})

exports.gives = nest('invite.sheet')
Expand All @@ -16,13 +17,17 @@ exports.create = function (api) {
api.sheet.display(close => {
const publishing = Value()
const publishStatus = Proxy()
const foundPeerInvite = Value(false)
const inviteInfo = Value('')

const input = h('input', {
style: {
'font-size': '200%',
'margin-top': '20px',
width: '100%'
},
disabled: computed([publishing, foundPeerInvite],
(pub, found) => pub || found),
placeholder: i18n('paste invite code here')
})
setTimeout(() => {
Expand All @@ -39,33 +44,67 @@ exports.create = function (api) {
style: {
'font-weight': 'normal'
}
}, [i18n('By default, Patchwork will only see other users that are on the same local area network as you.')]),
}, [
when(foundPeerInvite, 'Found peer invite',
i18n('By default, Patchwork will only see other users that are on the same local area network as you.')
)
]),
h('div', [
i18n('In order to share with users on the internet, you need to be invited to a pub server or a room server.')
when(foundPeerInvite, inviteInfo,
i18n('In order to share with users on the internet, you need to be invited to a pub server or a room server.')
)
]),
input
]),
footer: [
h('button -save', {
disabled: publishing,
'ev-click': () => {
publishing.set(true)
publishStatus.set(api.invite.async.accept(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
when(foundPeerInvite,
h('button -save', {
disabled: publishing,
'ev-click': () => {
// when we've showed info from peer invite and the user have
// clicked that they want to use the invite

publishing.set(true)
console.log('"using" peer invite')
onceTrue(api.sbot.obs.connection, ssb => {
ssb.peerInvites.acceptInvite(input.value.trim(), err => {
if (err) {
publishing.set(true)
showErr(err, api)
} else {
console.log('peer invite used!')
close()
}
})
} else {
close()
}
}))
}
}, [when(publishing, publishStatus, i18n('Redeem Invite'))]),
})
}
},
'Accept Invite'),
h('button -save', {
disabled: publishing,
'ev-click': () => {
publishing.set(true)
publishStatus.set(api.invite.async.accept(input.value.trim(), (err, info) => {
if (err) {
publishing.set(false)
showErr(err, api)
} else {
if (info) {
// if info is there then we're dealing with a peer invite

console.log('info:', info)
inviteInfo.set(JSON.stringify(info.opened, null, 2))
publishing.set(false)
foundPeerInvite.set(true)
} else {
close()
}
}
}))
}
},
[when(publishing, publishStatus, i18n('Redeem Invite'))])
),
h('button -cancel', {
'ev-click': close
}, i18n('Cancel'))
Expand All @@ -75,6 +114,18 @@ exports.create = function (api) {
})
}

function showErr (err, api) {
const i18n = api.intl.sync.i18n
console.error('failed to use invite:', err)
showDialog({
type: 'error',
title: i18n('Error'),
buttons: [i18n('OK')],
message: i18n('An error occurred while attempting to redeem invite.'),
detail: err.message
})
}

function showDialog (opts) {
electron.remote.dialog.showMessageBox(electron.remote.getCurrentWindow(), opts)
}
12 changes: 9 additions & 3 deletions lib/depject/page/html/render/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports.needs = nest({
'invite.sheet': 'first',
'dhtInvite.accept.sheet': 'first',
'dhtInvite.create.sheet': 'first',
'peerInvite.create.sheet': 'first',

'message.html.compose': 'first',
'message.async.publish': 'first',
Expand Down Expand Up @@ -113,9 +114,14 @@ exports.create = function (api) {
return recent.filter(x => x !== id && !ignoreFeeds.some(f => f.includes(x))).slice(0, 10)
})
return [
h('button -pub -full', {
'ev-click': api.invite.sheet
}, i18n('+ Join Server')),
h('SplitButton', [
h('button -invites', {
'ev-click': api.peerInvite.create.sheet
}, i18n('Create Invite')),
h('button -invites', {
'ev-click': api.invite.sheet
}, i18n('Accept Invite'))
]),

// disabling DHT invites until they work in sbot@13
//
Expand Down
3 changes: 3 additions & 0 deletions lib/server-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const createSbot = require('secret-stack')()
.use(require('ssb-search'))
.use(require('ssb-ws'))
.use(require('ssb-tags'))
.use(require('ssb-device-address'))
.use(require('ssb-identities'))
.use(require('ssb-peer-invites'))
.use(require('ssb-ebt'))
.use(require('./plugins'))

Expand Down
5 changes: 4 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,8 @@
"Connections": "Connections",
"Connect": "Connect",
"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.",
"nl": "nl"
"nl": "nl",
"Create an invite that your friend can use to find you. You need to be followed by a pub with support for \"peer invites\".": "Create an invite that your friend can use to find you. You need to be followed by a pub with support for \"peer invites\".",
"Give this invite code to one friend.": "Give this invite code to one friend.",
"An error occurred while attempting to create invite.": "An error occurred while attempting to create invite."
}
Loading