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

@@ -178,10 +178,12 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) {
newdescr = i18n.__('<strong>%s</strong> asked you for Friendship', userorig, mydescr);
tag = 'newfriend';
} else if ((recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) ||
(recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST)) {
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) {
newdescr = i18n.__('<strong>%s</strong> accepted your Friendship', userorig, mydescr);
tag = 'acceptedfriend';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST) {
newdescr = i18n.__('✅ You have accepted %s\' Friendship request!', userorig, mydescr);
tag = 'acceptedfriend';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REFUSED) {
newdescr = i18n.__('<strong>%s</strong> refused your Friendship', userorig, mydescr);
tag = 'refusedfriend';
@@ -470,12 +472,19 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
let typeidsearch = 0;
let dest = '';
let sender = myrecnotif.sender;
let newdest = myrecnotif.dest;
// Controllare se devo modificare un Notif già esistente !
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
typeidsearch = shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC;
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) {
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_ACCEPTED;
dest = myrecnotif.sender;
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST) {
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_ACCEPTED;
newdest = myrecnotif.sender;
sender = myrecnotif.dest;
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REFUSED) {
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_REFUSED;
dest = myrecnotif.sender;
@@ -539,6 +548,8 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
read: false,
descr: myrecnotif.descr,
datenotif: new Date(),
sender,
dest: newdest,
};
let query = {

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);
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,
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 {
if (!disablenotif) {
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);
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);
}
} catch (e) {
console.error('Notification : ', e);
}

View File

@@ -93,6 +93,11 @@ router.post('/', async (req, res) => {
const user = new User(body);
user.ipaddr = tools.getiPAddressUser(req);
user.email = user.email.trim();
user.username = user.username.trim();
user.name = user.name.trim();
user.surname = user.surname.trim();
if ((user.aportador_solidario === 'tuo_username') || (user.aportador_solidario === '{username}')) {
user.aportador_solidario = 'paoloar77';
}
@@ -243,6 +248,8 @@ router.post('/', async (req, res) => {
let recextra = null;
user.aportador_solidario = user.aportador_solidario.trim();
const id_aportador = await User.getIdByUsername(user.idapp, user.aportador_solidario);
if (id_aportador) {
user.aportador_solidario = await User.getRealUsernameByUsername(user.idapp, user.aportador_solidario);

View File

@@ -3966,7 +3966,7 @@ if (true) {
if (changed) {
const req = tools.getReqByPar(user.idapp, username_action);
await User.setFriendsCmd(req, user.idapp, data.username, userDest.username, shared_consts.FRIENDSCMD.SETFRIEND);
await User.setFriendsCmd(req, user.idapp, data.username, userDest.username, shared_consts.FRIENDSCMD.SETFRIEND, null, true);
await User.setaportador_solidario(user.idapp, data.username, userDest.username);