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

View File

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

View File

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

View File

@@ -3966,7 +3966,7 @@ if (true) {
if (changed) { if (changed) {
const req = tools.getReqByPar(user.idapp, username_action); 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); await User.setaportador_solidario(user.idapp, data.username, userDest.username);