feat: show DMs for customers

This commit is contained in:
Vlad Stan 2023-03-16 18:34:56 +02:00
parent 482961a2ef
commit b45927a15d
4 changed files with 78 additions and 12 deletions

View file

@ -7,22 +7,23 @@ async function directMessages(path) {
data: function () {
return {
activePublicKey:
'186895a32209c3a92f0efaa7c65c3f8da690c75b952b815718c0d55d3eed821e',
customersPublicKeys: [],
activePublicKey: '',
messages: [],
newMessage: ''
}
},
methods: {
sendMessage: async function () {},
getDirectMessages: async function () {
if (!this.activePublicKey) {
getDirectMessages: async function (pubkey) {
if (!pubkey) {
this.messages = []
return
}
try {
const {data} = await LNbits.api.request(
'GET',
'/nostrmarket/api/v1/message/' + this.activePublicKey,
'/nostrmarket/api/v1/message/' + pubkey,
this.inkey
)
this.messages = data
@ -35,6 +36,19 @@ async function directMessages(path) {
LNbits.utils.notifyApiError(error)
}
},
getCustomersPublicKeys: async function () {
try {
const {data} = await LNbits.api.request(
'GET',
'/nostrmarket/api/v1/customers',
this.inkey
)
this.customersPublicKeys = data
console.log('### this.customersPublicKeys', this.customersPublicKeys)
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
sendDirectMesage: async function () {
try {
const {data} = await LNbits.api.request(
@ -54,6 +68,10 @@ async function directMessages(path) {
LNbits.utils.notifyApiError(error)
}
},
selectActiveCustomer: async function () {
console.log('### selectActiveCustomer', this.activePublicKey)
await this.getDirectMessages(this.activePublicKey)
},
focusOnChatBox: function (index) {
setTimeout(() => {
const lastChatBox = document.getElementsByClassName(
@ -66,7 +84,7 @@ async function directMessages(path) {
}
},
created: async function () {
await this.getDirectMessages()
await this.getCustomersPublicKeys()
}
})
}