Notifica Telegram e Push quando mandi la stretta di mano

This commit is contained in:
Surya Paolo
2023-06-07 10:14:57 +02:00
parent 84328e7bcd
commit 9e499b8f43
7 changed files with 106 additions and 52 deletions

View File

@@ -2165,7 +2165,7 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
//}
} else if (cmd === shared_consts.FRIENDSCMD.SETHANDSHAKE) {
// Aggiungo la Stretta di mano a lui
const foundIfAlreadyFriend = await User.findOne({
const foundIfAlreadyHandshake = await User.findOne({
idapp,
username: usernameDest,
'profile.handshake': {
@@ -2175,7 +2175,7 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
let rec = null;
if (!foundIfAlreadyFriend) {
if (!foundIfAlreadyHandshake) {
update = {
$push: {
'profile.handshake': {
@@ -2186,12 +2186,28 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
};
rec = await User.updateOne({ idapp, username: usernameDest }, update);
if (!disablenotif) {
// Send a notification to the DESTINATION HANDSHAKE !
let req = tools.getReqByPar(idapp, usernameOrig);
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED);
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true, usernameOrig);
let req = tools.getReqByPar(idapp, usernameOrig);
if (rec) {
try {
if (!disablenotif) {
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
const msgDest = i18n.__({ phrase: 'HANDSHAKE_CONFIRMED', locale: userDest.lang }, usernameDest);
const msgOrig = i18n.__({ phrase: 'HANDSHAKE_ACCEPTED', locale: user.lang }, usernameOrig);
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
}
} catch (e) {
console.error('Notification : ', e);
}
}
// Send a notification to the DESTINATION HANDSHAKE !
// await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, false, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
// shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED);
}
const userprofile = await User.getInfoFriendByUsername(idapp, usernameDest);
@@ -3409,8 +3425,8 @@ UserSchema.statics.getNameSurnameById = async function (idapp, userId) {
UserSchema.statics.getusersManagers = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.manage_telegram': true },
// Int32 mongodb 6.0
return await User.find({ idapp, 'profile.manage_telegram': true , perm: { $bitsAnySet: 0b010 } },
{ username: 1, 'profile.teleg_id': 1, perm: 1 }).then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -3418,6 +3434,19 @@ UserSchema.statics.getusersManagers = async function (idapp) {
});
};
UserSchema.statics.getusersAdmin = async function (idapp) {
const User = this;
// Int32 mongodb 6.0
return await User.find({ idapp, 'profile.manage_telegram': true, perm: { $bitsAnySet: 0b001 } },
{ username: 1, 'profile.teleg_id': 1, perm: 1 }).then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
console.error('getusersAdmin', e);
});
};
UserSchema.statics.getusersRespList = async function (idapp) {
const User = this;
@@ -3500,7 +3529,7 @@ UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) {
}, { 'profile.teleg_id': 1 }).then((rec) => {
return (!!rec && rec.profile.teleg_id === idtelegram);
}).catch((e) => {
console.error('getusersManagers', e);
console.error('isManagerByIdTeleg', e);
return false;
});
};