This commit is contained in:
payacom
2026-10-01 21:12:05 +03:30
parent 806471241e
commit d4ebc20aa8
41 changed files with 1015 additions and 135 deletions

View File

@@ -217,6 +217,7 @@ const {
} = require('./helpers/expiredMessages')
const { purgeInactiveChatRooms } = require('./controllers/application/chatRooms/chatRoomHelpers')
const { trackOfferMessageForCommission } = require('./utils/offerReplyGate')
const { needsUsernameAndPassword } = require('./utils/authSteps')
const {
parseViewOnce,
isViewOnceMediaType,
@@ -302,6 +303,22 @@ app.post('/api/v1/chat', [blockCheck, chatPeerBlock], async (req, res) => {
return res.status(422).json({ error: 'receiverId is required' })
}
if (needsUsernameAndPassword(req.user)) {
const alreadyChatting = await MessageModel.exists({
$or: [
{ senderId, receiverId },
{ senderId: receiverId, receiverId: senderId }
]
})
if (!alreadyChatting) {
return res.status(403).json({
error: true,
type: 'needs_username_password',
message: 'برای ارسال اولین پیام باید نام‌کاربری و رمز عبور خود را تکمیل کنید'
})
}
}
const payload = {
senderId,
receiverId,
@@ -412,6 +429,22 @@ app.post('/api/v1/chat/file', [blockCheck, chatPeerBlock], async (req, res) => {
return res.status(422).json({ error: 'receiverId is required' })
}
if (needsUsernameAndPassword(req.user)) {
const alreadyChatting = await MessageModel.exists({
$or: [
{ senderId, receiverId },
{ senderId: receiverId, receiverId: senderId }
]
})
if (!alreadyChatting) {
return res.status(403).json({
error: true,
type: 'needs_username_password',
message: 'برای ارسال اولین پیام باید نام‌کاربری و رمز عبور خود را تکمیل کنید'
})
}
}
if (viewOnceFlag && !isViewOnceMediaType(resolvedFileType)) {
return res.status(422).json({ error: 'View once is only for image, video, and voice' })
}