Skip to content

Commit

Permalink
[push] null check
Browse files Browse the repository at this point in the history
  • Loading branch information
ar2rsawseen committed Nov 10, 2021
1 parent 91bd1e9 commit 6fab902
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions plugins/push/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,58 +139,60 @@ const PUSH_CACHE_GROUP = 'P';
});

plugins.register('/drill/preprocess_query', ({query, params}) => {
if (query.push) {
if (query.push.$nin) {
query.$and = query.push.$nin.map(tk => {
return {$or: [{[tk]: false}, {[tk]: {$exists: false}}]};
});
}
if (query.push.$in) {
let q = query.push.$in.map(tk => {
return {[tk]: true};
});
query.$or = q;
if (query) {
if (query.push) {
if (query.push.$nin) {
query.$and = query.push.$nin.map(tk => {
return {$or: [{[tk]: false}, {[tk]: {$exists: false}}]};
});
}
if (query.push.$in) {
let q = query.push.$in.map(tk => {
return {[tk]: true};
});
query.$or = q;
}
delete query.push;
}
delete query.push;
}

if (query.message) {
let mid = query.message.$in || query.message.$nin,
not = !!query.message.$nin;
if (query.message) {
let mid = query.message.$in || query.message.$nin,
not = !!query.message.$nin;

if (!mid) {
return;
}
if (!mid) {
return;
}

log.d(`removing message ${JSON.stringify(query.message)} from queryObject`);
delete query.message;
log.d(`removing message ${JSON.stringify(query.message)} from queryObject`);
delete query.message;

if (params && params.qstring.method === 'user_details') {
return new Promise((res, rej) => {
try {
mid = mid.map(common.db.ObjectID);
if (params && params.qstring.method === 'user_details') {
return new Promise((res, rej) => {
try {
mid = mid.map(common.db.ObjectID);

let q = {msgs: {$elemMatch: {'0': {$in: mid}}}};
if (not) {
q = {msgs: {$not: q.msgs}};
}
common.db.collection(`push_${params.app_id}`).find(q, {projection: {_id: 1}}).toArray((err, ids) => {
if (err) {
rej(err);
let q = {msgs: {$elemMatch: {'0': {$in: mid}}}};
if (not) {
q = {msgs: {$not: q.msgs}};
}
else {
ids = (ids || []).map(id => id._id);
query.uid = {$in: ids};
log.d(`filtered by message: uids out of ${ids.length}`);
res();
}
});
}
catch (e) {
console.log(e);
rej(e);
}
});
common.db.collection(`push_${params.app_id}`).find(q, {projection: {_id: 1}}).toArray((err, ids) => {
if (err) {
rej(err);
}
else {
ids = (ids || []).map(id => id._id);
query.uid = {$in: ids};
log.d(`filtered by message: uids out of ${ids.length}`);
res();
}
});
}
catch (e) {
console.log(e);
rej(e);
}
});
}
}
}
});
Expand Down

0 comments on commit 6fab902

Please sign in to comment.