++Strette di Mano
This commit is contained in:
@@ -1496,6 +1496,17 @@ UserSchema.statics.isMyFriend = async function (idapp, username, myusername) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.isMyHandShake = async function (idapp, username, myusername) {
|
||||
|
||||
const myhandshake = await User.getUsernameHandShakeByUsername(idapp, myusername);
|
||||
if (myhandshake) {
|
||||
return await myhandshake.includes(username);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserProfileByUsername = async function (
|
||||
idapp, username, myusername, usaSuperPower, myperm = '') {
|
||||
const User = this;
|
||||
@@ -1554,6 +1565,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
|
||||
'profile.born_province': 1,
|
||||
'profile.born_country': 1,
|
||||
'profile.calc': 1,
|
||||
'profile.req_handshake': 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.friends': 1,
|
||||
email: 1,
|
||||
@@ -1598,6 +1610,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
|
||||
'profile.born_country': 1,
|
||||
'profile.calc': 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.req_handshake': 1,
|
||||
'profile.friends': 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
@@ -1642,6 +1655,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
|
||||
'profile.born_country': 1,
|
||||
'profile.calc': 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.req_handshake': 1,
|
||||
'profile.friends': 1,
|
||||
'mycities': 1,
|
||||
'comune': 1,
|
||||
@@ -1911,12 +1925,12 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
// 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);
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST);
|
||||
|
||||
// Send a notification to the SENDER FRIENDSHIP !
|
||||
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);
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED);
|
||||
|
||||
}
|
||||
|
||||
@@ -1928,11 +1942,11 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
if (!disablenotif) {
|
||||
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
|
||||
const user = await User.getRecLangAndIdByUsername(idapp, 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);
|
||||
const msgDest = i18n.__({ phrase: '✅ %s accepted your Friendship request !', locale: userDest.lang }, usernameDest);
|
||||
const msgOrig = i18n.__({ phrase: '✅ You have accepted %s\' Friendship request!', locale: user.lang }, usernameOrig);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgDest);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgOrig);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
@@ -1989,15 +2003,15 @@ 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 !
|
||||
// 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);
|
||||
shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED_MY_REQUEST);
|
||||
|
||||
// Send a notification to the SENDER HANDSHAKEHIP !
|
||||
req = tools.getReqByPar(idapp, usernameDest);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: usernameOrig }, true, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
|
||||
shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED_MY_REQUEST);
|
||||
shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED);
|
||||
|
||||
}
|
||||
|
||||
@@ -2009,11 +2023,11 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
if (!disablenotif) {
|
||||
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
|
||||
const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
|
||||
const msgDest = i18n.__({ phrase: '✅ %s accepted your HandShake request !', locale: user.lang }, usernameOrig);
|
||||
const msgOrig = i18n.__({ phrase: '✅ You have accepted %s\' HandShake request!', locale: userDest.lang }, usernameDest);
|
||||
const msgDest = i18n.__({ phrase: '✅ %s accepted your HandShake request !', locale: userDest.lang }, usernameDest);
|
||||
const msgOrig = i18n.__({ phrase: '✅ You have accepted %s HandShake request!', locale: user.lang }, usernameOrig);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgDest);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgOrig);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
@@ -2778,6 +2792,7 @@ function getWhatToShow(idapp, username) {
|
||||
date_reg: 1,
|
||||
'profile.friends': 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.req_handshake': 1,
|
||||
};
|
||||
|
||||
}
|
||||
@@ -2896,6 +2911,8 @@ UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
listRequestFriends: [],
|
||||
listTrusted: [],
|
||||
listSentRequestFriends: [],
|
||||
listSentRequestHandShake: [],
|
||||
listRequestHandShake: [],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4494,12 +4511,12 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
let myuser = await User.findOne({ idapp, username });
|
||||
let myuser = await User.findOne({ idapp, username }).lean();
|
||||
if (myuser) {
|
||||
myuserextra = await User.addExtraInfo(idapp, myuser);
|
||||
}
|
||||
|
||||
return myuser._doc.profile;
|
||||
return myuser.profile;
|
||||
|
||||
};
|
||||
UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
@@ -4507,8 +4524,8 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
try {
|
||||
|
||||
try {
|
||||
if (recUser._doc.profile && recUser._doc.profile.notifs && recUser._doc.profile.notifs.length <= 0) {
|
||||
recUser._doc.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
||||
if (recUser.profile && recUser.profile.notifs && recUser.profile.notifs.length <= 0) {
|
||||
recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
||||
await recUser.save();
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -4525,7 +4542,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, { username: 1 }).lean();
|
||||
|
||||
recUser._doc.profile.asked_friends = listSentMyRequestFriends
|
||||
recUser.profile.asked_friends = listSentMyRequestFriends
|
||||
? listSentMyRequestFriends
|
||||
: [];
|
||||
|
||||
@@ -4539,7 +4556,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, { username: 1 }).lean();
|
||||
|
||||
recUser._doc.profile.asked_handshake = listSentMyRequestHandShake
|
||||
recUser.profile.asked_handshake = listSentMyRequestHandShake
|
||||
? listSentMyRequestHandShake
|
||||
: [];
|
||||
|
||||
@@ -4553,7 +4570,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, MyGroup.getWhatToShow_Unknown()).lean();
|
||||
|
||||
recUser._doc.profile.asked_groups = listSentMyRequestGroups
|
||||
recUser.profile.asked_groups = listSentMyRequestGroups
|
||||
? listSentMyRequestGroups
|
||||
: [];
|
||||
|
||||
@@ -4567,7 +4584,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, MyGroup.getWhatToShow_Unknown()).lean();
|
||||
|
||||
recUser._doc.profile.refused_groups = listRefusedGroups
|
||||
recUser.profile.refused_groups = listRefusedGroups
|
||||
? listRefusedGroups
|
||||
: [];
|
||||
|
||||
@@ -4581,7 +4598,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}).lean();
|
||||
|
||||
recUser._doc.profile.manage_mygroups = listManageGroups
|
||||
recUser.profile.manage_mygroups = listManageGroups
|
||||
? listManageGroups
|
||||
: [];
|
||||
|
||||
@@ -4591,14 +4608,14 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
|
||||
const useraccounts = await Account.getUserAccounts(idapp, recUser.username);
|
||||
|
||||
recUser._doc.profile = { ...recUser._doc.profile, ...circuitobj, useraccounts };
|
||||
recUser.profile = { ...recUser.profile, ...circuitobj, useraccounts };
|
||||
|
||||
recUser._doc.calcstat = await User.calculateStat(idapp, recUser.username);
|
||||
recUser.calcstat = await User.calculateStat(idapp, recUser.username);
|
||||
|
||||
recUser._doc.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
|
||||
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
|
||||
|
||||
|
||||
return recUser._doc;
|
||||
return recUser;
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err addExtraInfo', e);
|
||||
|
||||
Reference in New Issue
Block a user