|
1 | 1 | const common = require('../../../api/utils/common'),
|
2 | 2 | countlyCommon = require('../../../api/lib/countly.common.js'),
|
3 |
| - log = common.log('push:api:drill'); |
| 3 | + log = common.log('push:api:drill'), |
| 4 | + { FIELDS_TITLES } = require('./send/platforms'); |
4 | 5 |
|
5 | 6 | module.exports.drillAddPushEvents = ({uid, params, events, event}) => {
|
6 | 7 | return new Promise((res, rej) => {
|
@@ -113,7 +114,7 @@ const toIdsMappers = {
|
113 | 114 | };
|
114 | 115 |
|
115 | 116 | module.exports.drillPreprocessQuery = async function({query, params}) {
|
116 |
| - if (query && params) { |
| 117 | + if (query && params && params.qstring && params.qstring.event === '[CLY]_push_action') { |
117 | 118 | if (query.$or) {
|
118 | 119 | for (let i = 0; i < query.$or.length; i++) {
|
119 | 120 | let q = query.$or[i];
|
@@ -162,6 +163,67 @@ module.exports.drillPreprocessQuery = async function({query, params}) {
|
162 | 163 | // delete query.push;
|
163 | 164 | // }
|
164 | 165 | }
|
| 166 | + else if (query && params) { |
| 167 | + if (query.message) { |
| 168 | + let q = messageQuery(query.message); |
| 169 | + |
| 170 | + if (!q) { |
| 171 | + return; |
| 172 | + } |
| 173 | + |
| 174 | + log.d(`removing message ${JSON.stringify(query.message)} from queryObject`); |
| 175 | + delete query.message; |
| 176 | + |
| 177 | + try { |
| 178 | + let ids = await common.db.collection(`push_${params.app_id}`).find(q, {projection: {_id: 1}}).toArray(); |
| 179 | + ids = (ids || []).map(id => id._id); |
| 180 | + query.uid = {$in: ids}; |
| 181 | + log.d(`filtered by message: uids out of ${ids.length}`); |
| 182 | + } |
| 183 | + catch (e) { |
| 184 | + log.e(e); |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + if (query.push) { |
| 189 | + let q; |
| 190 | + if (query.push.$nin) { |
| 191 | + q = { |
| 192 | + $and: query.push.$nin.map(tk => { |
| 193 | + return {[tk]: {$exists: false}}; |
| 194 | + }) |
| 195 | + }; |
| 196 | + } |
| 197 | + if (query.push.$in) { |
| 198 | + q = { |
| 199 | + $or: query.push.$in.map(tk => { |
| 200 | + return {[tk]: {$exists: true}}; |
| 201 | + }) |
| 202 | + }; |
| 203 | + } |
| 204 | + if (query.push.$regex) { |
| 205 | + q = Object.keys(FIELDS_TITLES).filter(k => query.push.$regex.test(FIELDS_TITLES[k])).map(tk => { |
| 206 | + return {[tk]: {$exists: true}}; |
| 207 | + }); |
| 208 | + } |
| 209 | + |
| 210 | + delete query.push; |
| 211 | + |
| 212 | + if (q) { |
| 213 | + if (query.$or) { |
| 214 | + query.$and = [query.$or, q]; |
| 215 | + } |
| 216 | + else if (query.$and) { |
| 217 | + query.$and = [query.$and, q]; |
| 218 | + } |
| 219 | + else { |
| 220 | + for (let k in q) { |
| 221 | + query[k] = q[k]; |
| 222 | + } |
| 223 | + } |
| 224 | + } |
| 225 | + } |
| 226 | + } |
165 | 227 | };
|
166 | 228 |
|
167 | 229 | // module.exports.drillPreprocessQuery = ({query, params}) => {
|
|
0 commit comments