full app
This commit is contained in:
@@ -8,20 +8,30 @@ const { sendPushToUser } = require('./pushNotification')
|
||||
* همچنین یه پوش FCM هم برای گوشی کاربر میفرسته — این تنها نقطهایه که باعث میشه
|
||||
* همهی نوتیفیکیشنهایی که از این تابع رد میشن بهصورت پوش هم نمایش داده بشن
|
||||
*/
|
||||
async function notifyUser (io, userId, { type, title, description, project_post_id, actor_id } = {}) {
|
||||
await NotificationModel.create({ user_id: userId, type, title, description, project_post_id, actor_id })
|
||||
async function notifyUser (io, userId, { type, title, description, project_post_id, actor_id, image, link, actorUsername } = {}) {
|
||||
await NotificationModel.create({ user_id: userId, type, title, description, project_post_id, actor_id, image })
|
||||
|
||||
if (io) {
|
||||
try {
|
||||
io.to(`user:${String(userId)}`).emit('notification', { type, title, description })
|
||||
io.to(`user:${String(userId)}`).emit('notification', { type, title, description, image })
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
const data = {}
|
||||
if (project_post_id) data.project_post_id = String(project_post_id)
|
||||
// مسیرِ نسبیِ آماده (وقتی خودِ فراخوان از قبل username/id لازم رو داره) — سرویسورکرِ
|
||||
// وب دیگه لازم نیست خودش لوکاپِ اضافه بزنه تا بفهمه دقیقاً کجا باز کنه
|
||||
if (link) data.link = link
|
||||
// یوزرنیمِ عاملِ نوتیف (مثلاً صاحبِ استوری برای story_mention) — اندروید بدونِ این
|
||||
// مجبور بود یه درخواستِ اضافه بزنه تا از رویِ آیدی به یوزرنیم برسه
|
||||
if (actorUsername) data.actorUsername = actorUsername
|
||||
|
||||
sendPushToUser(userId, {
|
||||
title,
|
||||
description,
|
||||
type,
|
||||
data: project_post_id ? { project_post_id: String(project_post_id) } : undefined
|
||||
data: Object.keys(data).length ? data : undefined,
|
||||
image
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user