Friends Notification
Starting Group Create Notification...
This commit is contained in:
@@ -17,6 +17,8 @@ const {MyGroup} = require('../models/mygroup');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
const i18n = require('i18n');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
@@ -476,7 +478,7 @@ UserSchema.statics.canHavePower = function(perm) {
|
||||
try {
|
||||
let consentito = false;
|
||||
if (User.isAdmin(perm) || User.isManager(perm) ||
|
||||
User.isEditor(perm) || User.isTutor(perm)) {
|
||||
User.isEditor(perm) || User.isFacilitatore(perm)) {
|
||||
consentito = true;
|
||||
}
|
||||
|
||||
@@ -531,7 +533,7 @@ UserSchema.statics.isDepartment = function(perm) {
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.isTutor = function(perm) {
|
||||
UserSchema.statics.isFacilitatore = function(perm) {
|
||||
try {
|
||||
return ((perm & shared_consts.Permissions.Facilitatore) ===
|
||||
shared_consts.Permissions.Facilitatore);
|
||||
@@ -1561,6 +1563,8 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
try {
|
||||
@@ -1595,12 +1599,31 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
update = {$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
|
||||
if (ris) {
|
||||
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);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
}catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Controlla se lui aveva già la mia amicizia
|
||||
@@ -1723,6 +1746,8 @@ UserSchema.statics.ifAlreadyInGroup = async function(idapp, usernameOrig, groupn
|
||||
|
||||
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
try {
|
||||
@@ -1743,7 +1768,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
|
||||
// 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);
|
||||
SendNotif.create(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]}}}};
|
||||
|
||||
Reference in New Issue
Block a user