feat: send simple DM

This commit is contained in:
Vlad Stan 2023-05-05 13:00:09 +03:00
parent 77f7c0b18f
commit 5d906c1fda
4 changed files with 122 additions and 6 deletions

View file

@ -159,7 +159,7 @@
filled
rows="3"
type="textarea"
label="Test Message"
label="Test Message *"
></q-input>
</div>
</div>
@ -181,7 +181,7 @@
<div class="col-3"></div>
<div class="col-9">
<q-badge color="yellow" text-color="black">
<span>This is the recipient of the message</span>
<span>This is the recipient of the message. Field required.</span>
</q-badge>
</div>
</div>
@ -189,6 +189,7 @@
<div class="col-12">
<q-btn
:disabled="!testData.recieverPublicKey || !testData.message"
@click="sendTestMessage"
unelevated
color="primary"
class="float-right"
@ -197,6 +198,25 @@
</div>
</div>
</q-card-section>
<q-separator></q-separator>
<q-card-section>
<div class="row q-mt-md">
<div class="col-3">
<span>Sent Data:</span>
</div>
<div class="col-9">
<q-input
outlined
v-model="testData.sentData"
dense
filled
readonly
rows="5"
type="textarea"
></q-input>
</div>
</div>
</q-card-section>
</q-card>
</div>
@ -258,9 +278,12 @@
nostrrelayLinks: [],
filter: '',
testData: {
wsConnection: null,
senderPrivateKey: null,
recieverPublicKey: null,
message: null
message: null,
sentData: '',
receivedData: ''
},
relayTable: {
columns: [
@ -368,6 +391,64 @@
LNbits.utils.notifyApiError(error)
})
},
sendTestMessage: async function(){
try {
const {data} = await LNbits.api.request(
'PUT',
'/nostrclient/api/v1/relay/test?usr=' + this.g.user.id,
this.g.user.wallets[0].adminkey,
{
sender_private_key: this.testData.senderPrivateKey,
reciever_public_key: this.testData.recieverPublicKey,
message: this.testData.message
}
)
console.log('### data', data)
this.testData.senderPrivateKey = data.private_key
this.$q.localStorage.set('lnbits.nostrclient.senderPrivateKey', data.private_key || '')
const event = JSON.parse(data.event_json)[1]
console.log('### event', event)
this.sendDataToWebSocket(data.event_json)
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
sendDataToWebSocket: async function (data){
try {
if (!this.testData.wsConnection) {
this.connectToWebsocket()
}
this.testData.wsConnection.send(data)
this.testData.sentData = data + '\n' + this.testData.sentData
} catch (error) {
this.$q.notify({
timeout: 5000,
type: 'warning',
message: 'Failed to connect to websocket',
caption: `${error}`
})
}
},
connectToWebsocket: function () {
const scheme = location.protocol === 'http:' ? 'ws' : 'wss'
const port = location.port ? `:${location.port}` : ''
const wsUrl = `${scheme}://${document.domain}${port}/nostrclient/api/v1/relay`
this.testData.wsConnection = new WebSocket(wsUrl)
wsConnection.onmessage = async e => {
// const data = JSON.parse(e.data)
console.log('### onmessage', e.data)
}
wsConnection.onerror = async e => {
// const data = JSON.parse(e.data)
console.log('### onerror', e.data)
}
wsConnection.onclose = async e => {
// const data = JSON.parse(e.data)
console.log('### onclose', e.data)
}
},
exportlnurldeviceCSV: function () {
var self = this
LNbits.utils.exportCSV(self.relayTable.columns, this.nostrLinks)
@ -377,6 +458,7 @@
var self = this
this.getRelays()
setInterval(this.getRelays, 5000)
this.testData.senderPrivateKey = this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || ''
}
})
</script>