Friendship Accepted and Refused (notification updated)
This commit is contained in:
@@ -25,15 +25,19 @@ const sendNotifSchema = new Schema({
|
||||
},
|
||||
typedir: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
typeid: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
sender: { // mittente
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
dest: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
@@ -49,6 +53,7 @@ const sendNotifSchema = new Schema({
|
||||
},
|
||||
status: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
read: {
|
||||
type: Boolean,
|
||||
@@ -142,6 +147,15 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
newdescr = i18n.__('<strong>%s</strong> asked you for Friendship', userorig, mydescr);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) {
|
||||
newdescr = i18n.__('<strong>%s</strong> accepted your Friendship', userorig, mydescr);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REFUSED) {
|
||||
newdescr = i18n.__('<strong>%s</strong> refused your Friendship', userorig, mydescr);
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
recnotif.openUrl = '/group/' + paramsObj.groupNameDest;
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) {
|
||||
newdescr = i18n.__('<strong>%s</strong> asked you for Friendship', userorig, mydescr);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
|
||||
newdescr = i18n.__('<strong>%s</strong> accepted your Friendship', userorig, mydescr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +244,46 @@ sendNotifSchema.statics.saveAndSendNotif = function(myrecnotif, req, res, user)
|
||||
});
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.saveNotif = function(myrecnotif) {
|
||||
sendNotifSchema.statics.saveNotif = async function(myrecnotif) {
|
||||
|
||||
const SendNotif = this;
|
||||
|
||||
let newstatus = 0;
|
||||
let typeidsearch = 0;
|
||||
// Controllare se devo modificare un Notif già esistente !
|
||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC;
|
||||
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_ACCEPTED;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_REFUSED) {
|
||||
newstatus = shared_consts.StatusNotifs.STATUS_FRIENDS_REFUSED;
|
||||
}
|
||||
if (newstatus) {
|
||||
const fields_to_update = {
|
||||
status: newstatus,
|
||||
read: true,
|
||||
};
|
||||
|
||||
const query = {
|
||||
idapp: myrecnotif.idapp,
|
||||
typedir: myrecnotif.typedir,
|
||||
typeid: typeidsearch,
|
||||
dest: myrecnotif.sender,
|
||||
deleted: false,
|
||||
status: 0,
|
||||
};
|
||||
|
||||
// Cerca il record e se lo trova lo aggiorna
|
||||
const myrec = await SendNotif.findOneAndUpdate(query, {$set: fields_to_update}, {
|
||||
new: false,
|
||||
returnNewDocument: true
|
||||
});
|
||||
|
||||
if (myrec) {
|
||||
return myrec._doc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
myrecnotif._id = new ObjectID();
|
||||
if (!myrecnotif.openUrl) {
|
||||
@@ -250,6 +303,7 @@ sendNotifSchema.statics.saveNotif = function(myrecnotif) {
|
||||
console.log(e.message);
|
||||
return null;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getDefaultRec = function(req) {
|
||||
@@ -294,7 +348,7 @@ sendNotifSchema.statics.createNewNotification = async function(req, res, table,
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, usernameDest, onlysave, typedir, typeid) {
|
||||
sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, paramsObj, onlysave, typedir, typeid) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -303,7 +357,7 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, us
|
||||
myrecnotif.typedir = typedir;
|
||||
myrecnotif.typeid = typeid;
|
||||
|
||||
await SendNotif.sendToSingleUserDest(myrecnotif, req, res, usernameDest, onlysave);
|
||||
await SendNotif.sendToSingleUserDest(myrecnotif, req, res, paramsObj, onlysave);
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -416,14 +470,15 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req,
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, res, usernameDest, onlysave) {
|
||||
sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, res, paramsObj, onlysave) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
|
||||
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
||||
|
||||
myrecnotif.dest = usernameDest;
|
||||
myrecnotif.dest = paramsObj.usernameDest;
|
||||
myrecnotif.paramsObj = paramsObj;
|
||||
if (onlysave) {
|
||||
await SendNotif.saveNotif(myrecnotif);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user