fix: messages and notif Friends Accepteded

This commit is contained in:
Surya Paolo
2022-12-17 22:12:13 +01:00
parent c07e6f214d
commit cfa8569fd9
4 changed files with 41 additions and 18 deletions

View File

@@ -1814,7 +1814,7 @@ UserSchema.statics.removeReqFriend = async function (
{ $pull: { 'profile.req_friends': { username: { $in: [usernameDest] } } } });
};
UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value) {
UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
const { SendNotif } = require('../models/sendnotif');
@@ -1861,28 +1861,33 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
};
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
// Send a notification to the DESTINATION FRIENDSHIP !
let req = tools.getReqByPar(idapp, usernameOrig);
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED);
if (!disablenotif) {
// Send a notification to the DESTINATION FRIENDSHIP !
let req = tools.getReqByPar(idapp, usernameOrig);
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED);
// Send a notification to the SENDER FRIENDSHIP !
req = tools.getReqByPar(idapp, usernameOrig);
await SendNotif.createNewNotifToSingleUser(req, null, { usernameOrig }, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST);
// Send a notification to the SENDER FRIENDSHIP !
req = tools.getReqByPar(idapp, usernameDest);
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: usernameOrig }, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST);
}
update = { $pull: { 'profile.req_friends': { username: { $in: [usernameDest] } } } };
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
if (ris) {
try {
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
const msgOrig = i18n.__({ phrase: '✅ %s accepted your Friendship request !', locale: user.lang }, usernameDest);
const msgDest = i18n.__({ phrase: '✅ You have accepted %s\' Friendship request!', locale: userDest.lang }, usernameOrig);
if (!disablenotif) {
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
const msgDest = i18n.__({ phrase: '✅ %s accepted your Friendship request !', locale: user.lang }, usernameOrig);
const msgOrig = i18n.__({ phrase: '✅ You have accepted %s\' Friendship request!', locale: userDest.lang }, usernameDest);
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgDest);
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgOrig);
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgDest);
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgOrig);
}
} catch (e) {
console.error('Notification : ', e);
}