diff --git a/static/components/direct-messages/direct-messages.js b/static/components/direct-messages/direct-messages.js
index 9020cad..a9c58ef 100644
--- a/static/components/direct-messages/direct-messages.js
+++ b/static/components/direct-messages/direct-messages.js
@@ -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()
}
})
}
diff --git a/views_api.py b/views_api.py
index 1934b42..bc3a9e3 100644
--- a/views_api.py
+++ b/views_api.py
@@ -39,6 +39,8 @@ from .crud import (
get_orders_for_stall,
get_product,
get_products,
+ get_public_keys_for_direct_messages,
+ get_public_keys_for_orders,
get_stall,
get_stalls,
get_zone,
@@ -727,6 +729,35 @@ async def api_create_message(
)
+######################################## CUSTOMERS ########################################
+
+
+@nostrmarket_ext.get("/api/v1/customers")
+async def api_create_message(
+ wallet: WalletTypeInfo = Depends(get_key_type),
+) -> DirectMessage:
+ try:
+ merchant = await get_merchant_for_user(wallet.wallet.user)
+ assert merchant, f"Merchant cannot be found"
+
+ dm_pubkeys = await get_public_keys_for_direct_messages(merchant.id)
+ orders_pubkeys = await get_public_keys_for_orders(merchant.id)
+
+ return list(dict.fromkeys(dm_pubkeys + orders_pubkeys))
+
+ except AssertionError as ex:
+ raise HTTPException(
+ status_code=HTTPStatus.BAD_REQUEST,
+ detail=str(ex),
+ )
+ except Exception as ex:
+ logger.warning(ex)
+ raise HTTPException(
+ status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
+ detail="Cannot create message",
+ )
+
+
######################################## OTHER ########################################