git ssb

16+

Dominic / patchbay



Commit da4ee60db3eb59749ab43aa220207d68fe5d99c6

enable opening + acceptance of peer-invites

mixmix committed on 7/5/2019, 7:54:04 AM
Parent: efdafe9ae6b7e67b523bb966a61bc97335a784dd

Files changed

app/page/network/invite-peer.jschanged
package-lock.jsonchanged
package.jsonchanged
app/page/network/invite-peer.jsView
@@ -7,13 +7,15 @@
77 }
88
99 module.exports = function InvitePeer ({ connection }) {
1010 const state = {
11- // use: {
12- // invite: Value(),
13- // processing: Value(false),
14- // result: Value(null)
15- // },
11 + use: {
12 + invite: Value(),
13 + opening: Value(false),
14 + message: Value(null),
15 + accepting: Value(false),
16 + result: Value(null)
17 + },
1618 create: {
1719 input: {
1820 private: Value(),
1921 reveal: Value()
@@ -24,27 +26,43 @@
2426 }
2527 }
2628
2729 const body = h('InvitePeer', [
28- // h('div.use', [
29- // h('input', {
30- // 'placeholder': 'peer invite code',
31- // 'ev-input': handleInviteCode
32- // }),
33- // computed([state.use.invite, state.use.processing], (invite, processing) => {
34- // if (processing) return h('i.fa.fa-spinner.fa-pulse')
35- // if (invite) return h('button -primary', { 'ev-click': useInvite }, 'use invite')
30 + h('div.use', [
31 + h('input', {
32 + 'placeholder': 'peer invite code',
33 + 'ev-input': handleInput
34 + }),
35 + h('div.actions', computed(
36 + [state.use.invite, state.use.opening, state.use.message, state.use.accepting],
37 + (invite, opening, message, accepting) => {
38 + if (opening || accepting) {
39 + return [
40 + h('button', { disabled: 'disabled' }, [
41 + h('i.fa.fa-spinner.fa-pulse')
42 + ])
43 + ]
44 + }
3645
37- // return h('button', { disabled: 'disabled', title: 'not a valid invite code' }, 'use invite')
38- // }),
39- // computed(state.use.result, result => {
40- // if (result === null) return
46 + return [
47 + message && message.private ? h('div.private', message.private) : '',
48 + message && message.reveal ? h('div.private', message.reveal) : '',
49 + message
50 + ? h('button -primary', { 'ev-click': acceptInvite }, 'accept invitation')
51 + : invite
52 + ? h('button -primary', { 'ev-click': openInvite }, 'use invite')
53 + : h('button', { disabled: 'disabled', title: 'not a valid invite code' }, 'use invite')
54 + ]
55 + }
56 + )),
57 + computed(state.use.result, result => {
58 + if (result === null) return
4159
42- // return result
43- // ? h('i.fa.fa-check')
44- // : h('i.fa.fa-times')
45- // })
46- // ]),
60 + return result
61 + ? h('i.fa.fa-check')
62 + : h('i.fa.fa-times')
63 + })
64 + ]),
4765 h('div.create', [
4866 h('textarea.private', {
4967 placeholder: 'private message to your friend',
5068 'ev-input': (ev) => state.create.input.private.set(ev.target.value)
@@ -93,40 +111,59 @@
93111 })
94112 })
95113 }
96114
97- // function handleInviteCode (ev) {
98- // state.use.result.set(null)
99- // const invite = ev.target.value.replace(/^\s*"?/, '').replace(/"?\s*$/, '')
100- // if (!isInvite(invite)) {
101- // state.use.invite.set()
102- // return
103- // }
115 + function handleInput (ev) {
116 + state.use.result.set(null)
117 + const invite = ev.target.value.replace(/^\s*"?/, '').replace(/"?\s*$/, '')
104118
105- // ev.target.value = invite
106- // state.use.invite.set(invite)
107- // }
119 + if (!isInvite(invite)) return
108120
109- // function useInvite () {
110- // state.use.processing.set(true)
121 + ev.target.value = invite
122 + state.use.invite.set(invite)
123 + }
111124
112- // onceTrue(connection, server => {
113- // // TODO use peerInvites
114- // server.invite.accept(resolve(state.invite), (err, data) => {
115- // state.inviteProcessing.set(false)
116- // state.invite.set()
125 + function openInvite () {
126 + state.use.opening.set(true)
117127
118- // if (err) {
119- // state.use.result.set(false)
120- // console.error(err)
121- // return
122- // }
123- // state.use.result.set(true)
124- // console.log(data)
125- // })
126- // })
127- // }
128 + console.log('openInvite', resolve(state.use.invite))
129 + onceTrue(connection, server => {
130 + server.peerInvites.openInvite(resolve(state.use.invite), (err, msg, opened) => {
131 + state.use.opening.set(false)
132 + if (err) {
133 + state.use.result.set(false)
134 + console.error(err)
135 + return
136 + }
128137
138 + console.log(err, msg, opened) // NOTE no opened arriving ...
139 + // HACK
140 + const m = opened || {
141 + private: 'kiaora gorgeous, welcome'
142 + }
143 + state.use.message.set(m)
144 + })
145 + })
146 + }
147 +
148 + function acceptInvite () {
149 + state.use.accepting.set(true)
150 +
151 + onceTrue(connection, server => {
152 + server.peerInvites.acceptInvite(resolve(state.use.invite), (err, confirm) => {
153 + state.use.accepting.set(false)
154 + if (err) {
155 + state.use.result.set(false)
156 + console.error(err)
157 + return
158 + }
159 +
160 + console.log('peerInvites.acceptInvite worked:', confirm)
161 + state.use.result.set(true)
162 + })
163 + })
164 + }
165 +
129166 return {
130167 title: 'peer invites',
131168 body
132169 }
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 766493 bytes
New file size: 766493 bytes
package.jsonView
@@ -112,9 +112,9 @@
112112 "ssb-meme": "^1.0.4",
113113 "ssb-mentions": "^0.5.0",
114114 "ssb-mutual": "^0.1.0",
115115 "ssb-ooo": "^1.1.1",
116- "ssb-peer-invites": "^1.2.0",
116 + "ssb-peer-invites": "^1.2.2",
117117 "ssb-private": "^0.2.3",
118118 "ssb-query": "^2.1.0",
119119 "ssb-ref": "^2.13.6",
120120 "ssb-replicate": "^1.3.0",

Built with git-ssb-web