Click per mandare un messaggio al Destinatario dei RIS, se non è entrato ancora in RIS ITALIA.
This commit is contained in:
@@ -450,6 +450,9 @@ const UserSchema = new mongoose.Schema({
|
||||
noCircuit: {
|
||||
type: Boolean,
|
||||
},
|
||||
noCircIta: {
|
||||
type: Boolean,
|
||||
},
|
||||
noFoto: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -1899,9 +1902,26 @@ UserSchema.statics.removeFromCircuits = async function (idapp, username, circuit
|
||||
update = { $pull: { req_users: { username: { $in: [username] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
return await User.updateOne({ idapp, username },
|
||||
const ris = await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.mycircuits': { circuitname: { $in: [circuitname] } } } });
|
||||
|
||||
|
||||
const circuitId = await Circuit.getCircuitIdByName(idapp, circuitname);
|
||||
let remove = false;
|
||||
|
||||
// Se il mio account non è stato utilizzato, allora lo cancello anche questo
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false, false, '', '');
|
||||
if (myaccount && myaccount.totTransato === 0) {
|
||||
remove = true;
|
||||
} else {
|
||||
remove = true;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
await Account.removeAccount(myaccount._id);
|
||||
}
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
// Aggiungo il Circuito
|
||||
@@ -2329,6 +2349,86 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
return ris;
|
||||
};
|
||||
|
||||
UserSchema.statics.sendCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const cl = telegrambot.getclTelegByidapp(idapp);
|
||||
|
||||
if (!req) {
|
||||
req = tools.getReqByPar(idapp, usernameOrig);
|
||||
}
|
||||
|
||||
const myuser = await User.getUserByUsername(idapp, usernameOrig);
|
||||
const recuserDest = await User.getUserByUsername(idapp, usernameDest);
|
||||
|
||||
const langdest = recuserDest.lang;
|
||||
const telegid = recuserDest.profile.teleg_id;
|
||||
|
||||
let userId = recuserDest._id;
|
||||
let title = tools.getNomeAppByIdApp(idapp);
|
||||
let keyb = null;
|
||||
let descr = '';
|
||||
|
||||
let send_notif = false;
|
||||
let send_msgTelegramBot = false;
|
||||
let actions = [];
|
||||
let popupOnApp = '';
|
||||
|
||||
let ris = null;
|
||||
|
||||
try {
|
||||
if (cmd === shared_consts.CallFunz.ENTRA_RIS_ITALIA) {
|
||||
mycircuitOrig = await Circuit.getCircuitMyProvince(idapp, usernameOrig);
|
||||
descr = i18n.__({ phrase: 'SENDMSG_ENTRA_IN_RISO_ITALIA', locale: langdest }, usernameDest, usernameOrig, mycircuitOrig);
|
||||
msgtelegram = descr;
|
||||
|
||||
openUrl = '/circuit/ris_italia';
|
||||
bottone = i18n.__({ phrase: 'CIRCUIT_OPEN_RISITALIA', locale: langdest });
|
||||
tag = 'risitalia';
|
||||
|
||||
send_notif = true;
|
||||
send_msgTelegramBot = true;
|
||||
|
||||
keyb = cl.getInlineKeyboard(langdest, [
|
||||
{
|
||||
text: bottone,
|
||||
url: tools.getHostByIdApp(idapp) + openUrl,
|
||||
// callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
|
||||
// groupid,
|
||||
},
|
||||
]);
|
||||
|
||||
popupOnApp = 'Messaggio inviato al destinatario';
|
||||
|
||||
}
|
||||
|
||||
if (send_notif) {
|
||||
// SEND PUSH NOTIFICATION
|
||||
await tools.sendNotificationToUser(userId, title, descr, openUrl, '', tag, actions);
|
||||
}
|
||||
|
||||
// Invia Msg
|
||||
if (send_msgTelegramBot && msgtelegram) {
|
||||
await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, msgtelegram, undefined, undefined, true, keyb);
|
||||
}
|
||||
|
||||
const userprofile = await User.getInfoFriendByUsername(idapp, usernameDest);
|
||||
const myuser = await User.getInfoFriendByUsername(idapp, usernameOrig);
|
||||
|
||||
ris = { userprofile, myuser, popupOnApp, result: true };
|
||||
|
||||
} catch (e) {
|
||||
popupOnApp = e;
|
||||
ris = { popupOnApp };
|
||||
console.error('Error sendCmd: ', e);
|
||||
}
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
UserSchema.statics.ifAlreadyInGroup = async function (idapp, usernameOrig, groupnameDest) {
|
||||
|
||||
// Controllo se è stato già inserito
|
||||
@@ -4839,7 +4939,7 @@ UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
|
||||
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, version) {
|
||||
|
||||
try {
|
||||
tools.startTimeLog('addExtraInfo')
|
||||
// tools.startTimeLog('addExtraInfo')
|
||||
|
||||
if (version) {
|
||||
let versattualeuser = 0;
|
||||
@@ -4938,7 +5038,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
|
||||
|
||||
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
|
||||
|
||||
tools.endTimeLog('addExtraInfo')
|
||||
// tools.endTimeLog('addExtraInfo')
|
||||
|
||||
return recUser;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user