Skip to content

Commit 74e3037

Browse files
authored
Merge pull request #6229 from Countly/SER-2425-timezone-aware-push-notifications-are-not-working-for-focusrite
[SER-2425] User timezones were not being projected
2 parents 47d1984 + eeced7b commit 74e3037

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

plugins/push/api/send/audience.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ class Audience {
178178
if (!project.tk) {
179179
project.tk = 1;
180180
}
181+
if (!project.tz) {
182+
project.tz = 1;
183+
}
181184
steps.push({$project: project});
182185
}
183186

@@ -424,7 +427,7 @@ class PlainApiMapper extends Mapper {
424427
map(user, date, c, offset = 0) {
425428
let d = date.getTime();
426429
if (this.trigger.tz) {
427-
let utz = (user.tz === undefined || user.tz === null ? this.offset || 0 : user.tz || 0) * 60000;
430+
let utz = (user.tz === undefined || user.tz === null ? this.offset || 0 : parseFloat(user.tz) || 0) * 60000;
428431
d = date.getTime() - this.trigger.sctz * 60000 - utz;
429432

430433
if (d < Date.now()) {

plugins/push/api/send/data/const.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const MEDIA_MIME_ANDROID = [
2727

2828
const DEFAULTS = {
2929
schedule_ahead: 5 * 60000, // schedule job needs to be scheduled this much ms prior to the job date
30+
schedule_ahead_tz: 24 * 60 * 60000, // schedule job needs to be scheduled this much ms prior to the job date if we send in users' timezones
3031
queue_insert_batch: 100000, // insert into "push" collection in batches of 100 000 records
3132
max_media_size: 1024 * 1024 // 1Mb is a very conservative limit for media attachments
3233
};

plugins/push/api/send/data/message.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ class Message extends Mongoable {
532532
*/
533533
get needsScheduling() {
534534
return this.state === State.Created && this.triggers.filter(t => t.kind === TriggerKind.Plain &&
535-
(!t.delayed || (t.delayed && t.start.getTime() > Date.now() - 5 * 60000))).length > 0;
535+
(!t.delayed || (t.delayed && !t.tz && t.start.getTime() > Date.now() - DEFAULTS.schedule_ahead) || (t.delayed && t.tz && t.start.getTime() > Date.now() - DEFAULTS.schedule_ahead_tz))).length > 0;
536536
}
537537

538538
/**
@@ -659,7 +659,10 @@ class Message extends Mongoable {
659659
}
660660
});
661661
}
662-
let date = plain.delayed ? plain.start.getTime() - DEFAULTS.schedule_ahead : Date.now();
662+
let date = Date.now();
663+
if (plain.delayed) {
664+
date = plain.start.getTime() - (plain.tz ? DEFAULTS.schedule_ahead_tz : DEFAULTS.schedule_ahead);
665+
}
663666
await require('../../../../../api/parts/jobs').job('push:schedule', {mid: this._id, aid: this.app}).replace().once(date);
664667
}
665668
if (this.triggerAutoOrApi() && (this.is(State.Done) || this.state === State.Created)) {

0 commit comments

Comments
 (0)