Notifiche - Tutti - non letti
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
mongoose.level = 'F';
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const sendNotifSchema = new Schema({
|
||||
@@ -27,6 +27,9 @@ const sendNotifSchema = new Schema({
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
link: {
|
||||
type: String,
|
||||
},
|
||||
datenotif: {
|
||||
type: Date,
|
||||
},
|
||||
@@ -35,36 +38,62 @@ const sendNotifSchema = new Schema({
|
||||
},
|
||||
read: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
default: false,
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
default: false,
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
sendNotifSchema.statics.setNotifAsRead = function(idapp, username, idnotif) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
|
||||
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp) {
|
||||
if (idnotif) {
|
||||
return SendNotif.findOneAndUpdate({
|
||||
$and: [
|
||||
{idapp},
|
||||
{dest: username},
|
||||
{'_id': idnotif},
|
||||
],
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
|
||||
}, {$set: {read: true}}, {new: false}).then((ret) => {
|
||||
return !!ret;
|
||||
}).catch((err) => {
|
||||
console.error('err', err);
|
||||
});
|
||||
}
|
||||
}catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function(username, lastdataread, idapp) {
|
||||
const SendNotif = this;
|
||||
|
||||
return SendNotif.find({
|
||||
$and: [
|
||||
{ idapp },
|
||||
{ 'dest': username },
|
||||
{ 'datenotif': {$gt: new Date(lastdataread)} },
|
||||
]
|
||||
}).then((arrnotif) => {
|
||||
{idapp},
|
||||
{'dest': username},
|
||||
{'datenotif': {$gt: new Date(lastdataread)}},
|
||||
],
|
||||
}).lean().sort({datenotif: -1}).then((arrnotif) => {
|
||||
console.log('arrnotif', arrnotif.length);
|
||||
return arrnotif
|
||||
return arrnotif;
|
||||
}).catch((err) => {
|
||||
console.error('err', err);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.findLastGroupByUserIdAndIdApp = function (username, idapp) {
|
||||
sendNotifSchema.statics.findLastGroupByUserIdAndIdApp = function(username, idapp) {
|
||||
const SendNotif = this;
|
||||
|
||||
return SendNotif.aggregate([
|
||||
@@ -72,36 +101,34 @@ sendNotifSchema.statics.findLastGroupByUserIdAndIdApp = function (username, idap
|
||||
$match: {
|
||||
idapp,
|
||||
dest: username,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{
|
||||
_id: "$dest",
|
||||
descr: { $last: "$message" },
|
||||
datenotif: { $last: "$datenotif" },
|
||||
read: { $last: "$read" }
|
||||
}
|
||||
{
|
||||
_id: '$dest',
|
||||
descr: {$last: '$message'},
|
||||
datenotif: {$last: '$datenotif'},
|
||||
read: {$last: '$read'},
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
$sort: { datenotif: -1 }
|
||||
$sort: {datenotif: -1},
|
||||
},
|
||||
])
|
||||
.then((arrnotif) => {
|
||||
// Remove duplicate
|
||||
// Exclude my chat
|
||||
const myarr = arrnotif.filter((ris) => ris._id !== username);
|
||||
// console.table(myarr);
|
||||
return myarr
|
||||
]).then((arrnotif) => {
|
||||
// Remove duplicate
|
||||
// Exclude my chat
|
||||
const myarr = arrnotif.filter((ris) => ris._id !== username);
|
||||
// console.table(myarr);
|
||||
return myarr;
|
||||
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
const SendNotif = mongoose.model('SendNotif', sendNotifSchema);
|
||||
|
||||
module.exports = { SendNotif: SendNotif };
|
||||
module.exports = {SendNotif: SendNotif};
|
||||
|
||||
@@ -358,10 +358,13 @@ const UserSchema = new mongoose.Schema({
|
||||
date: {type: Date},
|
||||
}], // username
|
||||
|
||||
notifs: {
|
||||
type: Number,
|
||||
default: 1,
|
||||
},
|
||||
notifs: [
|
||||
{
|
||||
_id: false,
|
||||
dir: {type: Number},
|
||||
value: {type: Number},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
;
|
||||
@@ -1350,7 +1353,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
'profile.nationality': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.mygroups': 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.biografia': 1,
|
||||
'profile.teleg_id': 1,
|
||||
@@ -1384,7 +1387,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
verified_by_aportador: 1,
|
||||
notask_verif: 1,
|
||||
'profile.nationality': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.mygroups': 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.biografia': 1,
|
||||
'profile.teleg_id': 1,
|
||||
@@ -1774,7 +1777,6 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
ris = await MyGroup.deleteGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
console.log('ris', ris);
|
||||
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.CANCEL_REQ_GROUP) {
|
||||
|
||||
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
@@ -1814,7 +1816,7 @@ function getWhatToShow(idapp, username) {
|
||||
verified_by_aportador: 1,
|
||||
notask_verif: 1,
|
||||
'profile.nationality': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.mygroups': 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.biografia': 1,
|
||||
'profile.username_telegram': 1,
|
||||
@@ -2706,8 +2708,8 @@ UserSchema.statics.getUsersAutorizzare = async function(idapp) {
|
||||
const myfind = {
|
||||
idapp,
|
||||
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||
'profile.teleg_id': { $gt: 0 },
|
||||
verified_by_aportador: { $exists: false },
|
||||
'profile.teleg_id': {$gt: 0},
|
||||
verified_by_aportador: {$exists: false},
|
||||
};
|
||||
|
||||
return User.count(myfind);
|
||||
|
||||
Reference in New Issue
Block a user