Skip to content

Commit 6820df7

Browse files
authored
Merge pull request #4297 from Countly/feature/push-recurring-3
[push] User Profiles querying by push tokens & messages
2 parents a9fd7f4 + 47b7f2f commit 6820df7

File tree

7 files changed

+98
-9
lines changed

7 files changed

+98
-9
lines changed

bin/upgrade/23.06/scripts/push_drop_indexes.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ pluginManager.dbConnection('countly').then(async(db) => {
77
fields_appusers = fields(platforms, true);
88
console.log(`Dropping indexes for ${apps.length} apps`);
99
for (let app of apps) {
10-
await db.collection(`app_users${app._id}`).dropIndexes(fields_appusers);
10+
for (let field of fields_appusers) {
11+
try {
12+
await db.collection(`app_users${app._id}`).dropIndex(field);
13+
}
14+
catch (e) {
15+
// do nothing
16+
}
17+
}
1118
console.log('Dropped indexes for ', app._id);
1219
}
1320
console.log('Dropping indexes DONE');

plugins/push/api/api-drill.js

+64-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const common = require('../../../api/utils/common'),
22
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');
45

56
module.exports.drillAddPushEvents = ({uid, params, events, event}) => {
67
return new Promise((res, rej) => {
@@ -113,7 +114,7 @@ const toIdsMappers = {
113114
};
114115

115116
module.exports.drillPreprocessQuery = async function({query, params}) {
116-
if (query && params) {
117+
if (query && params && params.qstring && params.qstring.event === '[CLY]_push_action') {
117118
if (query.$or) {
118119
for (let i = 0; i < query.$or.length; i++) {
119120
let q = query.$or[i];
@@ -162,6 +163,67 @@ module.exports.drillPreprocessQuery = async function({query, params}) {
162163
// delete query.push;
163164
// }
164165
}
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+
}
165227
};
166228

167229
// module.exports.drillPreprocessQuery = ({query, params}) => {

plugins/push/api/send/platforms/a.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ const FIELDS = {
410410
* A number comes from SDK, we need to map it into smth like tkip/tkid/tkia
411411
*/
412412
const FIELDS_TITLES = {
413-
'0': 'FCM Token',
413+
'0': 'Android Firebase Token',
414414
};
415415

416416
/**

plugins/push/api/send/platforms/h.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ const FIELDS = {
512512
* A number comes from SDK, we need to map it into smth like tkhp/tkht
513513
*/
514514
const FIELDS_TITLES = {
515-
'0': 'HMS Token',
515+
'0': 'Android Huawei Token',
516516
};
517517

518518
/**

plugins/push/api/send/platforms/i.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ const FIELDS = {
5050
* A number comes from SDK, we need to map it into smth like tkip/tkid/tkia
5151
*/
5252
const FIELDS_TITLES = {
53-
'0': 'APN Production Token', // prod
54-
'1': 'APN Development Token', // debug
55-
'2': 'APN AdHoc / TestFlight Token', // ad hoc
53+
'0': 'iOS Production Token', // prod
54+
'1': 'iOS Development Token', // debug
55+
'2': 'iOS AdHoc / TestFlight Token', // ad hoc
5656
};
5757

5858
/**

plugins/push/frontend/public/javascripts/countly.models.js

+20
Original file line numberDiff line numberDiff line change
@@ -3275,4 +3275,24 @@
32753275
destroy: false,
32763276
});
32773277
};
3278+
3279+
var TT = {
3280+
tkid: 'iOS Development Token',
3281+
tkia: 'iOS Ad Hoc / TestFlight Token',
3282+
tkip: 'iOS Production Token',
3283+
tkap: 'Android Firebase Token',
3284+
tkhp: 'Android Huawei Token'
3285+
};
3286+
3287+
countlyPushNotification.getTokenTypes = function() {
3288+
return Object.keys(TT);
3289+
};
3290+
3291+
countlyPushNotification.getTokenNames = function() {
3292+
return Object.values(TT);
3293+
};
3294+
3295+
countlyPushNotification.getTokenName = function(type) {
3296+
return TT[type];
3297+
};
32783298
}(window.countlyPushNotification = window.countlyPushNotification || {}));

plugins/push/frontend/public/javascripts/countly.views.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@
21382138
var queryData = {message: {"$nin": [this.pushNotification._id]}};
21392139
var $in = [];
21402140
if (this.pushNotification.user) {
2141-
queryData.user = this.pushNotification.user;
2141+
Object.assign(queryData, JSON.parse(this.pushNotification.user));
21422142
}
21432143
if (this.pushNotification.locations && this.pushNotification.locations.length) {
21442144
queryData.geo = {"$in": this.pushNotification.locations};

0 commit comments

Comments
 (0)