- Accepted and Refused Group Entering
- Report a User
This commit is contained in:
@@ -181,6 +181,15 @@ const UserSchema = new mongoose.Schema({
|
||||
date_blocked: {
|
||||
type: Date,
|
||||
},
|
||||
reported: {
|
||||
type: Boolean,
|
||||
},
|
||||
username_who_report: {
|
||||
type: String,
|
||||
},
|
||||
date_report: {
|
||||
type: Date,
|
||||
},
|
||||
non_voglio_imbarcarmi: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -386,7 +395,7 @@ const UserSchema = new mongoose.Schema({
|
||||
notif_sector_goods: [
|
||||
{
|
||||
type: Number,
|
||||
}]
|
||||
}],
|
||||
},
|
||||
})
|
||||
;
|
||||
@@ -693,6 +702,7 @@ UserSchema.statics.getUserShortDataByUsername = async function(idapp, username)
|
||||
name: 1,
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
reported: 1,
|
||||
sospeso: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
@@ -1355,6 +1365,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
username: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
reported: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
date_reg: 1,
|
||||
@@ -1372,6 +1383,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
reported: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
'profile.nationality': 1,
|
||||
@@ -1405,6 +1417,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
reported: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
notask_verif: 1,
|
||||
@@ -1559,19 +1572,26 @@ UserSchema.statics.removeReqFriend = async function(
|
||||
{$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}});
|
||||
};
|
||||
|
||||
UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameDest, cmd, value) {
|
||||
UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, usernameDest, cmd, value) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
if (!req) {
|
||||
req = tools.getReqByPar(idapp, usernameOrig);
|
||||
}
|
||||
|
||||
const username_action = req.user.username;
|
||||
let username_worked = usernameDest;
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
try {
|
||||
if (cmd === shared_consts.FRIENDSCMD.SETTRUST) {
|
||||
|
||||
// Aggiungi alle amicizie
|
||||
await this.setFriendsCmd(idapp, usernameOrig, usernameDest,
|
||||
await this.setFriendsCmd(req, idapp, usernameOrig, usernameDest,
|
||||
shared_consts.FRIENDSCMD.SETFRIEND, value);
|
||||
|
||||
return User.updateOne({idapp, username: usernameDest},
|
||||
@@ -1601,11 +1621,13 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
// 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);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED);
|
||||
|
||||
// Send a notification to the SENDER FRIENDSHIP !
|
||||
req = tools.getReqByPar(idapp, usernameOrig);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST);
|
||||
|
||||
update = {$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
@@ -1614,12 +1636,12 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
try {
|
||||
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
|
||||
const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
|
||||
const msgOrig = i18n.__({phrase: '✅ %s accepted your Friendship request !', locale: user.lang}, usernameOrig)
|
||||
const msgDest = i18n.__({phrase: "✅ You have accepted %s' Friendship request!", locale: userDest.lang}, usernameDest);
|
||||
const msgOrig = i18n.__({phrase: '✅ %s accepted your Friendship request !', locale: user.lang}, usernameOrig);
|
||||
const msgDest = i18n.__({phrase: '✅ You have accepted %s\' Friendship request!', locale: userDest.lang}, usernameDest);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
}
|
||||
}
|
||||
@@ -1701,7 +1723,8 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_REFUSED);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REFUSED);
|
||||
|
||||
await this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo la Richiesta di Amicizia da lui
|
||||
ris = await this.removeFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da me
|
||||
@@ -1723,6 +1746,38 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
date_blocked: new Date(),
|
||||
},
|
||||
});
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.REPORT_USER) {
|
||||
|
||||
username_worked = usernameDest;
|
||||
|
||||
// Segnalo la persona
|
||||
ris = await User.updateOne({idapp, username: username_worked}, {
|
||||
$set: {
|
||||
reported: true,
|
||||
username_who_report: usernameOrig,
|
||||
date_report: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
if (ris) {
|
||||
// Send a notification to the DESTINATION!
|
||||
// Sei stato segnalato da %s per comportamenti non idonei. Contatta %s per chiarimenti
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||
|
||||
// Send a notification to the SENDER !
|
||||
// Hai segnalato %s da %s per comportamenti non idonei.
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: username_action, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||
|
||||
if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) {
|
||||
// Send a notification to the Admin
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
|
||||
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error: ', e);
|
||||
@@ -1744,9 +1799,19 @@ UserSchema.statics.ifAlreadyInGroup = async function(idapp, usernameOrig, groupn
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
||||
UserSchema.statics.countUsersInGroup = async function(idapp, groupnameDest) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
// Controllo se è stato già inserito
|
||||
return User.countDocuments({
|
||||
idapp,
|
||||
'profile.mygroups': {
|
||||
$elemMatch: {groupname: {$eq: groupnameDest}},
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
@@ -1765,11 +1830,6 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
SendNotif.createNewNotifToSingleUser(req, null, {usernameDest:'', groupnameDest}, true, shared_consts.TypeNotifs.TYPEDIR_GROUPS, shared_consts.TypeNotifs.ID_GROUP_ACCEPTED);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}};
|
||||
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest},
|
||||
@@ -1779,7 +1839,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona e agli Admin
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, username_action);
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, value, true, username_action);
|
||||
ris = await MyGroup.getInfoGroupByGroupname(idapp, groupnameDest);
|
||||
}
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
|
||||
@@ -1807,12 +1867,14 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, username_action);
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, true, username_action);
|
||||
}
|
||||
} else {
|
||||
if (foundIfAlreadyAskGroup) {
|
||||
ris = await this.removeFromMyGroups(idapp, usernameOrig,
|
||||
groupnameDest); // Rimuovo il Gruppo da me
|
||||
ris = await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo il Gruppo da me
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1825,13 +1887,24 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
ris = await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
console.log('ris', ris);
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REFUSE_REQ_GROUP) {
|
||||
|
||||
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo la richiesta di entrare nel gruppo
|
||||
console.log('ris', ris);
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.DELETE_GROUP) {
|
||||
|
||||
ris = await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona e agli Admin
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, username_action);
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
|
||||
}
|
||||
ris = await MyGroup.deleteGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
@@ -1854,7 +1927,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
},
|
||||
});
|
||||
//++Todo: Send Notification to Admin and Group's manager
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, true, username_action);
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, groupnameDest, cmd, false, true, username_action);
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -1872,6 +1945,7 @@ function getWhatToShow(idapp, username) {
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
reported: 1,
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
notask_verif: 1,
|
||||
|
||||
Reference in New Issue
Block a user