full app
This commit is contained in:
@@ -68,7 +68,7 @@ async function enrichMessage(message) {
|
||||
})
|
||||
}
|
||||
|
||||
function emitChatEvents(io, message, senderId, receiverId) {
|
||||
function emitChatEvents(io, message, senderId, receiverId, pushOverride) {
|
||||
const sid = normalizeId(senderId)
|
||||
const rid = normalizeId(receiverId)
|
||||
const payload = normalizeMessagePayload(
|
||||
@@ -86,21 +86,22 @@ function emitChatEvents(io, message, senderId, receiverId) {
|
||||
message: payload
|
||||
})
|
||||
|
||||
sendChatPushNotification(sid, rid).catch(() => {})
|
||||
sendChatPushNotification(sid, rid, pushOverride).catch(() => {})
|
||||
}
|
||||
|
||||
// پیامها E2EE هستن (رمزنگاری سرتاسر) — سرور محتوا رو نمیبینه و نباید توی پوش هم نشونش بده،
|
||||
// فقط اسم فرستنده + یه متن ثابت. عین همین تابع برای همهی مسیرهای emitChatEvents (چت مستقیم،
|
||||
// پاسخ استوری، اشتراکگذاری پست/محصول توی چت) صدا زده میشه
|
||||
async function sendChatPushNotification(senderId, receiverId) {
|
||||
// پیامهای متنیِ معمولی E2EE هستن (رمزنگاری سرتاسر) — سرور محتوا رو نمیبینه و نباید توی
|
||||
// پوش هم نشونش بده، فقط اسم فرستنده + یه متن ثابت. اما اشتراکگذاریِ پست/محصول (که خودِ
|
||||
// سرور با دادهٔ واقعیِ دیتابیس میسازه، نه متنِ رمزنگاریشدهٔ کاربر) میتونه با pushOverride
|
||||
// نوع/متنِ دقیقتری بفرسته (نگاه کن به فراخوانیها توی engagementController.js/shopProductController.js)
|
||||
async function sendChatPushNotification(senderId, receiverId, pushOverride = {}) {
|
||||
const sender = await UserModel.findById(senderId).select('first_name last_name user_name profile_image').lean()
|
||||
if (!sender) return
|
||||
const name = `${sender.first_name || ''} ${sender.last_name || ''}`.trim() || sender.user_name || 'کاربر'
|
||||
await sendPushToUser(receiverId, {
|
||||
title: name,
|
||||
description: 'یک پیام جدید برای شما ارسال کرد',
|
||||
type: 'chat_message',
|
||||
data: { project_post_id: senderId },
|
||||
description: pushOverride.description || 'یک پیام جدید برای شما ارسال کرد',
|
||||
type: pushOverride.type || 'chat_message',
|
||||
data: { project_post_id: senderId, link: `/settings/chats/${sender.user_name || ''}/${senderId}` },
|
||||
image: buildStorageUrl(sender.profile_image) || undefined
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user