feat: one pool to rule them all (WIP)
This commit is contained in:
parent
aefe43f8a8
commit
47adf676e2
4 changed files with 12 additions and 5 deletions
|
|
@ -5,13 +5,12 @@ async function chatDialog(path) {
|
||||||
name: 'chat-dialog',
|
name: 'chat-dialog',
|
||||||
template,
|
template,
|
||||||
|
|
||||||
props: ['account', 'merchant', 'relays'],
|
props: ['account', 'merchant', 'relays', 'pool'],
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
dialog: false,
|
dialog: false,
|
||||||
isChat: true,
|
isChat: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
pool: null,
|
|
||||||
nostrMessages: [],
|
nostrMessages: [],
|
||||||
newMessage: '',
|
newMessage: '',
|
||||||
ordersTable: {
|
ordersTable: {
|
||||||
|
|
@ -82,11 +81,10 @@ async function chatDialog(path) {
|
||||||
},
|
},
|
||||||
async closeDialog() {
|
async closeDialog() {
|
||||||
this.dialog = false
|
this.dialog = false
|
||||||
await this.pool.close(Array.from(this.relays))
|
await this.sub.unsub()
|
||||||
},
|
},
|
||||||
async startPool() {
|
async startPool() {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.pool = new NostrTools.SimplePool()
|
|
||||||
let messagesMap = new Map()
|
let messagesMap = new Map()
|
||||||
let sub = this.pool.sub(Array.from(this.relays), [
|
let sub = this.pool.sub(Array.from(this.relays), [
|
||||||
{
|
{
|
||||||
|
|
@ -98,6 +96,7 @@ async function chatDialog(path) {
|
||||||
'#p': [this.account.pubkey]
|
'#p': [this.account.pubkey]
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
sub.on('eose', () => {
|
sub.on('eose', () => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.nostrMessages = Array.from(messagesMap.values())
|
this.nostrMessages = Array.from(messagesMap.values())
|
||||||
|
|
@ -133,6 +132,7 @@ async function chatDialog(path) {
|
||||||
console.error('Unable to decrypt message!')
|
console.error('Unable to decrypt message!')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
this.sub = sub
|
||||||
},
|
},
|
||||||
async sendMessage() {
|
async sendMessage() {
|
||||||
if (this.newMessage && this.newMessage.length < 1) return
|
if (this.newMessage && this.newMessage.length < 1) return
|
||||||
|
|
@ -146,6 +146,10 @@ async function chatDialog(path) {
|
||||||
}
|
}
|
||||||
event.id = NostrTools.getEventHash(event)
|
event.id = NostrTools.getEventHash(event)
|
||||||
event.sig = this.signEvent(event)
|
event.sig = this.signEvent(event)
|
||||||
|
// This doesn't work yet
|
||||||
|
// this.pool.publish(Array.from(this.relays), event)
|
||||||
|
// this.newMessage = ''
|
||||||
|
// We need this hack
|
||||||
for (const url of Array.from(this.relays)) {
|
for (const url of Array.from(this.relays)) {
|
||||||
try {
|
try {
|
||||||
let relay = NostrTools.relayInit(url)
|
let relay = NostrTools.relayInit(url)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
:account="account ? account : dropIn"
|
:account="account ? account : dropIn"
|
||||||
:merchant="stall.pubkey"
|
:merchant="stall.pubkey"
|
||||||
:relays="relays"
|
:relays="relays"
|
||||||
|
:pool="pool"
|
||||||
/>
|
/>
|
||||||
<shopping-cart
|
<shopping-cart
|
||||||
:cart="cart"
|
:cart="cart"
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ async function customerStall(path) {
|
||||||
'products',
|
'products',
|
||||||
'product-detail',
|
'product-detail',
|
||||||
'change-page',
|
'change-page',
|
||||||
'relays'
|
'relays',
|
||||||
|
'pool'
|
||||||
],
|
],
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,7 @@
|
||||||
:product-detail="activeProduct"
|
:product-detail="activeProduct"
|
||||||
:relays="relays"
|
:relays="relays"
|
||||||
:account="account"
|
:account="account"
|
||||||
|
:pool="pool"
|
||||||
@change-page="navigateTo"
|
@change-page="navigateTo"
|
||||||
></customer-stall>
|
></customer-stall>
|
||||||
<customer-market
|
<customer-market
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue