Click per mandare un messaggio al Destinatario dei RIS, se non è entrato ancora in RIS ITALIA.
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
"FRIEND_UNBLOCKED_YOU": "Hai riattivato %s.",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY": "❇️👥 🧍♂️ Abilita fido a %s nel '%s':",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY_BYGROUP": "❇️👥 🧍♂️ Abilita fido nel Circuito al gruppo %s:",
|
||||
"CIRCUIT_OPEN_RISITALIA": "Apri il Circuito RIS Italia e chiedi di entrare",
|
||||
"CIRCUIT_REQUEST_TO_ENTER": "%s è entrato nel %s (con %s iscritti) ed è in attesa di essere abilitato al Fido (è stato invitato da %s)",
|
||||
"CIRCUIT_ADMINS": "Gli amministratori del circuito sono %s:\n%s",
|
||||
"CIRCUIT_WHERE_IS_PRESENT": "\nAttualmente è presente in: %s",
|
||||
@@ -105,5 +106,6 @@
|
||||
"SET_ATTEND_OTHERS": "%s e altre %s persone hanno detto che Parteciperanno all'evento: %s",
|
||||
"DATEDAYONLY": "%s dalle %s alle %s",
|
||||
"DATE_2DAYS": "%s dalle %s fino a %s alle %s",
|
||||
"CLICCA_QUI": "CLICCA QUI"
|
||||
"SENDMSG_ENTRA_IN_RISO_ITALIA": "Ciao %s!<br>%s che appartiene al <em>%s</em> vuole inviarti dei RIS. Per poterli ricevere dovete entrambi utilizzare il <strong>Circuito RIS Italia</strong>.",
|
||||
"CLICCA_QUI": "CLICCA QUI"
|
||||
}
|
||||
@@ -640,12 +640,15 @@ AccountSchema.statics.updateQtaMax = async function (idapp, username, groupname,
|
||||
};
|
||||
|
||||
AccountSchema.statics.getAccountsCircuitiNazionali = async function (idapp) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const circuit = await Circuit.find({ idapp, showAlways: true });
|
||||
|
||||
return Account.find({ idapp, circuitId: circuit.id });
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateAccountCircuitoNazionaleByLimiti = async function (idapp, circuitId, fidoConcesso, qta_maxConcessa) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
try {
|
||||
const accounts = await this.getAccountsCircuitiNazionali(idapp);
|
||||
@@ -714,11 +717,19 @@ AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username,
|
||||
|
||||
// Rimuovi dagli Admin del Account
|
||||
AccountSchema.statics.removeAdminOfAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
return await Circuit.updateOne({ idapp, username, circuitId },
|
||||
{ $pull: { people: { username: { $in: [person_username] } } } });
|
||||
};
|
||||
|
||||
// Rimuovi l'account
|
||||
AccountSchema.statics.removeAccount = async function (accountId) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
return await Circuit.deleteOne({ _id: accountId});
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateSaldoAndTransato_AllAccounts = async function (idapp) {
|
||||
|
||||
const recaccounts = await Account.find({ idapp });
|
||||
|
||||
@@ -478,6 +478,23 @@ CircuitSchema.statics.getCircuitByName = async function (idapp, name) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitIdByName = async function (idapp, name) {
|
||||
|
||||
const myfind = {
|
||||
idapp,
|
||||
name,
|
||||
};
|
||||
|
||||
try {
|
||||
const circuit = await Circuit.findOne(myfind);
|
||||
return (!!circuit ? circuit._id : 0);
|
||||
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitByProvince = async function (idapp, strProv) {
|
||||
|
||||
const myfind = {
|
||||
@@ -924,6 +941,28 @@ CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, val
|
||||
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.getCircuitMyProvince = async function (idapp, username) {
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const myuser = await User.getUserByUsername(idapp, username);
|
||||
|
||||
try {
|
||||
const circuit = await this.getCircuitByProvince(idapp, myuser.profile.resid_province);
|
||||
|
||||
if (circuit) {
|
||||
if (await User.ifAlreadyInCircuit(idapp, username, circuit.name)) {
|
||||
return circuit.name;
|
||||
}
|
||||
}
|
||||
|
||||
return '[nessun Circuito]';
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, province) {
|
||||
const { User } = require('../models/user');
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -777,6 +777,29 @@ router.post('/friends/cmd', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/sendcmd', authenticate, async (req, res) => {
|
||||
const usernameLogged = req.user.username;
|
||||
const idapp = req.body.idapp;
|
||||
const locale = req.body.locale;
|
||||
let usernameOrig = req.body.usernameOrig;
|
||||
let usernameDest = req.body.usernameDest;
|
||||
const cmd = req.body.cmd;
|
||||
const value = req.body.value;
|
||||
|
||||
usernameOrig = await User.getRealUsernameByUsername(idapp, usernameOrig);
|
||||
usernameDest = await User.getRealUsernameByUsername(idapp, usernameDest);
|
||||
|
||||
return User.sendCmd(req, idapp, usernameOrig, usernameDest, cmd, value).
|
||||
then((ris) => {
|
||||
res.send(ris);
|
||||
}).
|
||||
catch((e) => {
|
||||
tools.mylog('ERRORE IN sendcmd: ' + e.message);
|
||||
res.status(400).send();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
router.post('/groups/cmd', authenticate, (req, res) => {
|
||||
const usernameLogged = req.user.username;
|
||||
const idapp = req.body.idapp;
|
||||
@@ -1521,6 +1544,9 @@ async function eseguiDbOpUser(idapp, mydata, locale, req, res) {
|
||||
} else if (mydata.dbop === 'noCircuit') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id },
|
||||
{ $set: { 'profile.noCircuit': mydata.value } });
|
||||
} else if (mydata.dbop === 'noCircIta') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id },
|
||||
{ $set: { 'profile.noCircIta': mydata.value } });
|
||||
} else if (mydata.dbop === 'noFoto') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id },
|
||||
{ $set: { 'profile.noFoto': mydata.value } });
|
||||
|
||||
@@ -760,6 +760,11 @@ const MyTelegramBot = {
|
||||
return FormDaMostrare;
|
||||
},
|
||||
|
||||
getclTelegByidapp: function (idapp) {
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
return cl;
|
||||
},
|
||||
|
||||
getCiao: function (idapp, username, lang) {
|
||||
return tools.gettranslate('CIAO', lang) + ' ' + username + '!\n';
|
||||
},
|
||||
@@ -834,8 +839,13 @@ const MyTelegramBot = {
|
||||
const langdest = myuser.lang;
|
||||
const telegid = myuser.profile.teleg_id;
|
||||
|
||||
let userrecDest = await User.getUserShortDataByUsername(idapp, userDest);
|
||||
let userId = userrecDest._id;
|
||||
let title = this.getNomeAppByIdApp(idapp);
|
||||
let keyb = null;
|
||||
let domanda = '';
|
||||
let send_notif = false;
|
||||
let actions = [];
|
||||
|
||||
const struserinfomsg = tools.getUserInfoMsg(idapp, myuser);
|
||||
|
||||
@@ -913,7 +923,7 @@ const MyTelegramBot = {
|
||||
} else {
|
||||
domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest }, myuser.username, name) + '<br>' + struserinfomsg;
|
||||
|
||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||
const keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||
{
|
||||
text: '✅ Abilita fido a ' + myuser.username,
|
||||
callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
|
||||
@@ -928,6 +938,11 @@ const MyTelegramBot = {
|
||||
}
|
||||
}
|
||||
|
||||
if (send_notif) {
|
||||
// SEND PUSH NOTIFICATION
|
||||
await this.sendNotificationToUser(userId, title, descr, openUrl, '', tag, actions);
|
||||
}
|
||||
|
||||
// Invia Msg
|
||||
if (domanda) {
|
||||
const teleg_id = await User.TelegIdByUsername(idapp, userDest);
|
||||
@@ -4288,6 +4303,10 @@ if (true) {
|
||||
|
||||
}
|
||||
}
|
||||
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.ENTRA_RIS_ITALIA) {
|
||||
|
||||
url = '';
|
||||
bot.answerCallbackQuery(callbackQuery.id, { url });
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -907,6 +907,7 @@ module.exports = {
|
||||
let openUrl = '/';
|
||||
let tag = '';
|
||||
let actions = [];
|
||||
let domanda = '';
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.FRIENDSCMD.REQFRIEND) {
|
||||
descr = printf(this.get__('RICHIESTA_AMICIZIA', lang), usernameOrig);
|
||||
@@ -940,7 +941,7 @@ module.exports = {
|
||||
|
||||
const idtelegram = await User.TelegIdByUsername(idapp, username);
|
||||
|
||||
await telegrambot.sendMsgTelegramByIdTelegram(idapp, idtelegram, descr);
|
||||
await telegrambot.sendMsgTelegramByIdTelegram(idapp, idtelegram, descr + domanda, undefined, undefined, true, keyb);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
@@ -340,6 +340,7 @@ module.exports = {
|
||||
RICHIESTA_HANDSHAKE: 16,
|
||||
RICHIESTA_CIRCUIT: 20,
|
||||
RICHIESTA_FIDO: 25,
|
||||
ENTRA_RIS_ITALIA: 30,
|
||||
},
|
||||
|
||||
OrderStatus: {
|
||||
|
||||
Reference in New Issue
Block a user