Friendship Accepted and Refused (notification updated)
This commit is contained in:
@@ -12,5 +12,6 @@
|
||||
"<strong>%s</strong> new Service: %s": "<strong>%s</strong> new Service: %s",
|
||||
"OPEN PAGE": "OPEN PAGE",
|
||||
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> asked you for Friendship",
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> accepted your Friendship"
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> accepted your Friendship",
|
||||
"<strong>%s</strong> refused your Friendship": "<strong>%s</strong> refused your Friendship"
|
||||
}
|
||||
|
||||
@@ -7,5 +7,6 @@
|
||||
"<strong>%s</strong> new Service: %s": "<strong>%s</strong> nuovo Servizio: %s",
|
||||
"OPEN PAGE": "APRI PAGINA",
|
||||
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> ti ha chiesto l'Amicizia",
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> ha accettato l'Amicizia"
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> ha accettato l'Amicizia",
|
||||
"<strong>%s</strong> refused your Friendship": "<strong>%s</strong> ha rifiutato l'Amicizia"
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1597,8 +1597,7 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
const req = tools.getReqByPar(idapp, usernameOrig);
|
||||
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);
|
||||
|
||||
update = {$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
@@ -1677,6 +1676,10 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.CANCEL_REQ_FRIEND) {
|
||||
|
||||
// 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 this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo la Richiesta di Amicizia da lui
|
||||
ris = await this.removeFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
@@ -1737,6 +1740,11 @@ 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},
|
||||
|
||||
@@ -1063,6 +1063,7 @@ router.get('/loadsite/:userId/:idapp/:vers', authenticate_noerror,
|
||||
let version = tools.getVersionint(versionstr);
|
||||
|
||||
load(req, res, version);
|
||||
|
||||
});
|
||||
|
||||
function load(req, res, version) {
|
||||
@@ -1496,9 +1497,10 @@ function uploadFile(req, res, version) {
|
||||
sharp(newname, {failOnError: false}).
|
||||
resize({
|
||||
width: 512,
|
||||
height: 512,
|
||||
fit: sharp.fit.cover,
|
||||
position: sharp.strategy.entropy,
|
||||
// height: 512,
|
||||
//fit: sharp.fit.cover,
|
||||
fit: sharp.fit.contain,
|
||||
// position: sharp.strategy.entropy,
|
||||
}).withMetadata().toFile(resized_img, function(err) {
|
||||
|
||||
// console.log('3) Ridimensionata Immagine ' + newname, 'in', resized_img);
|
||||
|
||||
@@ -26,7 +26,7 @@ const isValidSaveRequest = (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
router.post('/', authenticate, async (req, res) => {
|
||||
// console.log('req.body.others', req.body.others);
|
||||
|
||||
if (!isValidSaveRequest(req, res)) {
|
||||
@@ -39,7 +39,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
subscriptionModel.browser = req.get('User-Agent');
|
||||
|
||||
// Find if already exist
|
||||
Subscription.findOne({
|
||||
await Subscription.findOne({
|
||||
userId: subscriptionModel.userId,
|
||||
access: subscriptionModel.access,
|
||||
browser: subscriptionModel.browser,
|
||||
|
||||
@@ -898,7 +898,7 @@ module.exports = {
|
||||
const req = this.getReqByPar(idapp, usernameOrig);
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
SendNotif.createNewNotifToSingleUser(req, null, username, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC);
|
||||
SendNotif.createNewNotifToSingleUser(req, null, {usernameDest: username}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC);
|
||||
|
||||
if (userrecDest) {
|
||||
sendmynotif = false; // non lo rimandare 2 volte !
|
||||
|
||||
@@ -287,6 +287,12 @@ module.exports = {
|
||||
NEW_ADV_SECTOR: 32,
|
||||
},
|
||||
|
||||
StatusNotifs: {
|
||||
STATUS_FRIENDS_ACCEPTED: 1,
|
||||
STATUS_FRIENDS_REFUSED: 2,
|
||||
|
||||
},
|
||||
|
||||
TypeNotifs: {
|
||||
TYPEDIR_BACHECA: 1,
|
||||
ID_BACHECA_NEW_GOOD: 1,
|
||||
@@ -299,12 +305,17 @@ module.exports = {
|
||||
TYPEDIR_FRIENDS: 3,
|
||||
ID_FRIENDS_NEW_REC: 1,
|
||||
ID_FRIENDS_ACCEPTED: 2,
|
||||
ID_FRIENDS_REFUSED: 3,
|
||||
|
||||
TYPEDIR_CIRCUITS: 4,
|
||||
TYPEDIR_GROUPS: 4,
|
||||
ID_GROUP_NEW_REC: 1,
|
||||
ID_GROUP_ACCEPTED: 2,
|
||||
|
||||
TYPEDIR_BOOKING: 5,
|
||||
TYPEDIR_CIRCUITS: 5,
|
||||
|
||||
TYPEDIR_MSGS: 6,
|
||||
TYPEDIR_BOOKING: 6,
|
||||
|
||||
TYPEDIR_MSGS: 7,
|
||||
ID_MSGS_NEW_REC: 1,
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user