ver: 0.5.55
Strette di Mano OK
This commit is contained in:
@@ -385,12 +385,6 @@ const UserSchema = new mongoose.Schema({
|
||||
username: { type: String },
|
||||
date: { type: Date },
|
||||
}], // username
|
||||
req_handshake: [
|
||||
{
|
||||
_id: false,
|
||||
username: { type: String },
|
||||
date: { type: Date },
|
||||
}], // username
|
||||
mygroups: [
|
||||
{
|
||||
_id: false,
|
||||
@@ -1565,7 +1559,6 @@ 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,
|
||||
@@ -1610,7 +1603,6 @@ 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,
|
||||
@@ -1655,7 +1647,6 @@ 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,
|
||||
@@ -1789,13 +1780,6 @@ UserSchema.statics.getUsernameFriendsByUsername = async function (
|
||||
return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
|
||||
'friends');
|
||||
|
||||
};
|
||||
UserSchema.statics.getUsernameReqHandShakeByUsername = async function (
|
||||
idapp, username) {
|
||||
|
||||
return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
|
||||
'req_handshake');
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsernameHandShakeByUsername = async function (
|
||||
@@ -1867,13 +1851,6 @@ UserSchema.statics.removeReqFriend = async function (
|
||||
{ $pull: { 'profile.req_friends': { username: { $in: [usernameDest] } } } });
|
||||
};
|
||||
|
||||
// Rimuovo la Stretta di Mano
|
||||
UserSchema.statics.removeReqHandShake = async function (
|
||||
idapp, username, usernameDest) {
|
||||
return await User.updateOne({ idapp, username: username },
|
||||
{ $pull: { 'profile.req_handshake': { username: { $in: [usernameDest] } } } });
|
||||
};
|
||||
|
||||
UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
@@ -2004,52 +1981,12 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
|
||||
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_MY_REQUEST);
|
||||
let req = tools.getReqByPar(idapp, usernameDest);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: usernameOrig }, true, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
|
||||
shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED);
|
||||
}
|
||||
|
||||
if (ris) {
|
||||
try {
|
||||
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: userDest.lang }, usernameDest);
|
||||
const msgOrig = i18n.__({ phrase: '✅ You have accepted %s HandShake request!', locale: user.lang }, usernameOrig);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Controlla se lui aveva già la mia amicizia
|
||||
const foundIfAlreadyFriend2 = await User.findOne({
|
||||
idapp,
|
||||
username: usernameDest,
|
||||
'profile.handshake': {
|
||||
$elemMatch: { username: { $eq: usernameOrig } },
|
||||
},
|
||||
}, { _id: 1 }).lean();
|
||||
|
||||
if (!foundIfAlreadyFriend2) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.handshake': {
|
||||
username: usernameOrig,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await User.updateOne({ idapp, username: usernameDest }, update);
|
||||
|
||||
this.removeReqHandShake(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da me
|
||||
this.removeReqHandShake(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da te
|
||||
}
|
||||
//if (ris) {
|
||||
ris = await User.getInfoFriendByUsername(idapp, usernameDest);
|
||||
//}
|
||||
@@ -2080,42 +2017,6 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true, usernameOrig);
|
||||
}
|
||||
}
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.REQHANDSHAKE) {
|
||||
// Aggiungo la richiesta di Amicizia a me
|
||||
const foundIfAlreadyAskFriend = await User.findOne({
|
||||
idapp,
|
||||
username: usernameDest,
|
||||
'profile.req_handshake': {
|
||||
$elemMatch: { username: { $eq: usernameOrig } },
|
||||
},
|
||||
}, { _id: 1 }).lean();
|
||||
|
||||
if (value) {
|
||||
if (!foundIfAlreadyAskFriend) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.req_handshake': {
|
||||
username: usernameOrig,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await User.updateOne({ idapp, username: usernameDest }, update);
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona
|
||||
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true, usernameOrig);
|
||||
}
|
||||
} else {
|
||||
if (foundIfAlreadyAskFriend) {
|
||||
ris = await this.removeReqHandShake(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da me
|
||||
}
|
||||
}
|
||||
|
||||
// if (ris) {
|
||||
ris = await User.getInfoAskFriendByUsername(idapp, usernameDest);
|
||||
// }
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS) {
|
||||
|
||||
// Rimuovi anche le eventuali richieste di Amicizia !
|
||||
@@ -2127,7 +2028,7 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.REMOVE_FROM_MYHANDSHAKE) {
|
||||
|
||||
ris = await this.removeHandShake(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da lui
|
||||
ris = await this.removeHandShake(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da lui
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.CANCEL_REQ_FRIEND) {
|
||||
|
||||
@@ -2136,16 +2037,6 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REFUSED);
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.CANCEL_REQ_HANDSHAKE) {
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
|
||||
shared_consts.TypeNotifs.ID_HANDSHAKE_REFUSED);
|
||||
|
||||
await this.removeReqHandShake(idapp, usernameDest, usernameOrig); // Rimuovo la Richiesta di Amicizia da lui
|
||||
ris = await this.removeHandShake(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.BLOCK_USER) {
|
||||
|
||||
await this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo la Richiesta di Amicizia da lui
|
||||
@@ -2775,7 +2666,6 @@ function getWhatToShow(idapp, username) {
|
||||
date_reg: 1,
|
||||
'profile.friends': 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.req_handshake': 1,
|
||||
};
|
||||
|
||||
}
|
||||
@@ -2869,22 +2759,6 @@ UserSchema.statics.getAskedFriendsByUsername = async function (idapp, username)
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getAskedHandShakeByUsername = async function (idapp, username) {
|
||||
|
||||
const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username);
|
||||
|
||||
return await User.find({
|
||||
idapp,
|
||||
'profile.req_handshake': {
|
||||
$elemMatch: { username: { $eq: username } },
|
||||
},
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown).then((rec) => {
|
||||
|
||||
//return rec.map(m => m.username);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
|
||||
@@ -2894,8 +2768,6 @@ UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
listRequestFriends: [],
|
||||
listTrusted: [],
|
||||
listSentRequestFriends: [],
|
||||
listSentRequestHandShake: [],
|
||||
listRequestHandShake: [],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2908,8 +2780,6 @@ UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
idapp, username);
|
||||
const arrUsernameHandShake = await User.getUsernameHandShakeByUsername(idapp,
|
||||
username);
|
||||
const arrUsernameReqHandShake = await User.getUsernameReqHandShakeByUsername(
|
||||
idapp, username);
|
||||
|
||||
let listFriends = await User.find({
|
||||
idapp,
|
||||
@@ -2935,14 +2805,6 @@ UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
let listRequestHandShake = await User.find({
|
||||
idapp,
|
||||
username: { $in: arrUsernameReqHandShake },
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
let listSentRequestFriends = await User.find({
|
||||
idapp,
|
||||
'profile.req_friends': {
|
||||
@@ -2953,16 +2815,6 @@ UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
let listSentRequestHandShake = await User.find({
|
||||
idapp,
|
||||
'profile.req_handshake': {
|
||||
$elemMatch: { username: { $eq: username } },
|
||||
},
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
let listTrusted = await User.find({
|
||||
idapp, aportador_solidario: username,
|
||||
'profile.teleg_id': { $gt: 0 },
|
||||
@@ -2975,10 +2827,8 @@ UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
listFriends,
|
||||
listHandShake,
|
||||
listRequestFriends,
|
||||
listRequestHandShake,
|
||||
listTrusted,
|
||||
listSentRequestFriends,
|
||||
listSentRequestHandShake,
|
||||
};
|
||||
|
||||
} catch (e) {
|
||||
@@ -2989,10 +2839,8 @@ UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
listFriends: [],
|
||||
listHandShake: [],
|
||||
listRequestFriends: [],
|
||||
listRequestHandShake: [],
|
||||
listTrusted: [],
|
||||
listSentRequestFriends: [],
|
||||
listSentRequestHandShake: [],
|
||||
|
||||
};
|
||||
};
|
||||
@@ -4152,7 +4000,8 @@ UserSchema.statics.getQueryUsersStretteDiMano = function (idapp) {
|
||||
const query = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
idapp: "13",
|
||||
'profile.handshake': { $exists: true },
|
||||
$or: [
|
||||
{
|
||||
deleted: {
|
||||
@@ -4168,22 +4017,16 @@ UserSchema.statics.getQueryUsersStretteDiMano = function (idapp) {
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$group: {
|
||||
_id: "$profile.handshake",
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: { "count": { $gte: 2 } }
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
count: -1,
|
||||
},
|
||||
$group:
|
||||
{
|
||||
_id: "$username",
|
||||
count:
|
||||
{ $sum: { $size: "$profile.handshake" } }
|
||||
}
|
||||
},
|
||||
{ $sort: { count: -1 } },
|
||||
{ $limit: 20 },
|
||||
{
|
||||
$lookup: {
|
||||
@@ -4604,20 +4447,20 @@ UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
|
||||
|
||||
let myuser = await User.findOne({ idapp, username }).lean();
|
||||
if (myuser) {
|
||||
myuserextra = await User.addExtraInfo(idapp, myuser);
|
||||
myuserextra = await User.addExtraInfo(idapp, myuser, null);
|
||||
}
|
||||
|
||||
return myuser.profile;
|
||||
|
||||
};
|
||||
UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
if (recUser.profile && recUser.profile.notifs && recUser.profile.notifs.length <= 0) {
|
||||
if (recUserSave && recUser.profile && recUser.profile.notifs && recUser.profile.notifs.length <= 0) {
|
||||
recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
||||
await recUser.save();
|
||||
await recUserSave.save();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err addExtraInfo notifs ', e);
|
||||
@@ -4637,20 +4480,6 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser) {
|
||||
? listSentMyRequestFriends
|
||||
: [];
|
||||
|
||||
const listSentMyRequestHandShake = await User.find({
|
||||
idapp,
|
||||
'profile.req_handshake': {
|
||||
$elemMatch: { username: { $eq: recUser.username } },
|
||||
},
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, { username: 1 }).lean();
|
||||
|
||||
recUser.profile.asked_handshake = listSentMyRequestHandShake
|
||||
? listSentMyRequestHandShake
|
||||
: [];
|
||||
|
||||
const listSentMyRequestGroups = await MyGroup.find({
|
||||
idapp,
|
||||
'req_users': {
|
||||
|
||||
Reference in New Issue
Block a user