Push Notification - always set latestUpdateTimestampMs Service worker will start notifying only about new changes once it starts. This also simplify current code. Release-Notes: skip Change-Id: I8188c3e460aea972761318c5211d1aafec911dc9
diff --git a/polygerrit-ui/app/utils/service-worker-util.ts b/polygerrit-ui/app/utils/service-worker-util.ts index 3cf0dce..eb547ea 100644 --- a/polygerrit-ui/app/utils/service-worker-util.ts +++ b/polygerrit-ui/app/utils/service-worker-util.ts
@@ -15,9 +15,8 @@ export function filterAttentionChangesAfter( changes: ParsedChangeInfo[], account: AccountDetailInfo, - latestUpdateTimestampMs?: number + latestUpdateTimestampMs: number ) { - if (!latestUpdateTimestampMs) return changes; return changes.filter(change => { const attention_set = change.attention_set![account._account_id!]; if (!attention_set.last_update) return false;
diff --git a/polygerrit-ui/app/workers/service-worker-class.ts b/polygerrit-ui/app/workers/service-worker-class.ts index c93dd2f..c469644 100644 --- a/polygerrit-ui/app/workers/service-worker-class.ts +++ b/polygerrit-ui/app/workers/service-worker-class.ts
@@ -16,7 +16,7 @@ export class ServiceWorker { constructor(private ctx: ServiceWorkerGlobalScope) {} - latestUpdateTimestampMs?: number; + latestUpdateTimestampMs = Date.now(); showNotification(change: ParsedChangeInfo, account: AccountDetailInfo) { const body = getReason(undefined, account, change); @@ -38,12 +38,10 @@ async getChangesToNotify(account: AccountDetailInfo) { // We throttle polling, since there can be many clients triggerring // always only one service worker. - if (this.latestUpdateTimestampMs) { - const durationFromLatestUpdateMS = - Date.now() - this.latestUpdateTimestampMs; - if (durationFromLatestUpdateMS < TRIGGER_NOTIFICATION_UPDATES_MS) { - return []; - } + const durationFromLatestUpdateMS = + Date.now() - this.latestUpdateTimestampMs; + if (durationFromLatestUpdateMS < TRIGGER_NOTIFICATION_UPDATES_MS) { + return []; } const prevLatestUpdateTimestampMs = this.latestUpdateTimestampMs; this.latestUpdateTimestampMs = Date.now();