full app
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
const NotificationModel = require('../models/NotificationModel')
|
||||
const UserModel = require('../models/UserModel')
|
||||
const { notifyUser } = require('./notifyUser')
|
||||
const { buildStorageUrl } = require('./storageUrl')
|
||||
|
||||
// همون الگوی services/*Cron.js — چون این تابع مستقیم از کنترلر صدا زده میشه (نه یه
|
||||
// جاب زمانبندیشده)، io از index.js با همین setIo تزریق میشه تا notifyUser بتونه
|
||||
// رویداد سوکت لحظهای هم بفرسته، نه فقط ردیف دیتابیس/پوش
|
||||
let ioInstance = null
|
||||
function setIo (io) {
|
||||
ioInstance = io
|
||||
}
|
||||
|
||||
const createTagNotifications = async ({ taggerId, taggedUserIds, postId }) => {
|
||||
try {
|
||||
@@ -10,19 +19,20 @@ const createTagNotifications = async ({ taggerId, taggedUserIds, postId }) => {
|
||||
)
|
||||
if (!uniqueIds.length) return
|
||||
|
||||
const tagger = await UserModel.findById(taggerId).select('user_name')
|
||||
const tagger = await UserModel.findById(taggerId).select('user_name profile_image')
|
||||
const taggerUsername = tagger?.user_name || 'کاربر'
|
||||
const message = `${taggerUsername} شما را در پستی نشانهگذاری کرد.`
|
||||
const taggerImage = buildStorageUrl(tagger?.profile_image) || undefined
|
||||
|
||||
await Promise.all(
|
||||
uniqueIds.map((userId) =>
|
||||
NotificationModel.create({
|
||||
user_id: userId,
|
||||
notifyUser(ioInstance, userId, {
|
||||
type: 'post_tag',
|
||||
title: taggerUsername,
|
||||
description: 'در پستی از شما نام برد',
|
||||
project_post_id: postId,
|
||||
actor_id: taggerId,
|
||||
type: 'post_tag',
|
||||
title: message,
|
||||
description: message
|
||||
image: taggerImage,
|
||||
link: `/posts/${postId}`
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -32,5 +42,6 @@ const createTagNotifications = async ({ taggerId, taggedUserIds, postId }) => {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createTagNotifications
|
||||
createTagNotifications,
|
||||
setIo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user