Add shop-chat push notifications and a "send shop to users" endpoint
- shop-chat messages (buyer <-> shop owner) never sent any push notification at all — sendShopChatPushNotification (chatHelpers.js) now fires on every send, mirroring the existing regular-chat push path; data payload carries shop_id/buyer_id/sender_role so clients can route directly to the thread - New POST /shops/:id/send, mirroring the existing shop-product send endpoint — lets a user share a shop itself (not just one product) into a regular chat message as a sharedShop payload Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,32 @@ async function sendChatPushNotification(senderId, receiverId) {
|
||||
})
|
||||
}
|
||||
|
||||
// چتِ فروشگاه (خریدار <-> مالکِ فروشگاه) قبلاً هیچ پوشی نمیفرستاد — کاملاً جدا از
|
||||
// sendChatPushNotification بالا چون فرستنده میتونه «فروشگاه» باشه، نه یه کاربرِ ساده،
|
||||
// پس تایتل/عکسِ نوتیف باید از روی نقشِ فرستنده (shop یا buyer) انتخاب بشه
|
||||
async function sendShopChatPushNotification({ shop, senderId, senderRole, receiverId, buyerId }) {
|
||||
let title
|
||||
let image
|
||||
if (senderRole === 'shop') {
|
||||
title = shop?.name || 'فروشگاه'
|
||||
image = buildStorageUrl(shop?.logo) || undefined
|
||||
} else {
|
||||
const sender = await UserModel.findById(senderId).select('first_name last_name user_name profile_image').lean()
|
||||
if (!sender) return
|
||||
title = `${sender.first_name || ''} ${sender.last_name || ''}`.trim() || sender.user_name || 'کاربر'
|
||||
image = buildStorageUrl(sender.profile_image) || undefined
|
||||
}
|
||||
await sendPushToUser(receiverId, {
|
||||
title,
|
||||
description: 'یک پیام جدید برای شما ارسال کرد',
|
||||
type: 'shop_chat_message',
|
||||
// buyer_id همیشه لازمه تا مالکِ فروشگاه (که میتونه چند نخِ گفتگو با خریدارهای مختلف
|
||||
// داشته باشه) بدونه دقیقاً کدوم نخ رو باز کنه؛ برای خودِ خریدار هم همون id خودشه
|
||||
data: { shop_id: String(shop?._id || ''), sender_role: senderRole, buyer_id: String(buyerId || '') },
|
||||
image
|
||||
})
|
||||
}
|
||||
|
||||
function parseForwardedContent(content) {
|
||||
if (!content) return { body: '', forwardedFrom: null }
|
||||
|
||||
@@ -138,5 +164,6 @@ module.exports = {
|
||||
formatTimeOnly,
|
||||
enrichMessage,
|
||||
emitChatEvents,
|
||||
parseForwardedContent
|
||||
parseForwardedContent,
|
||||
sendShopChatPushNotification
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user