notifications
This commit is contained in:
@@ -15,6 +15,7 @@ interface TaskDigestPayload {
|
|||||||
tasksUrl: string;
|
tasksUrl: string;
|
||||||
todayTasks: TaskDigestEmailItem[];
|
todayTasks: TaskDigestEmailItem[];
|
||||||
overdueTasks: TaskDigestEmailItem[];
|
overdueTasks: TaskDigestEmailItem[];
|
||||||
|
notificationTag?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TaskDigestPayloadResult {
|
interface TaskDigestPayloadResult {
|
||||||
@@ -101,7 +102,13 @@ export class TaskDigestService {
|
|||||||
const slot = this.currentSlot(now) ?? 'morning';
|
const slot = this.currentSlot(now) ?? 'morning';
|
||||||
const dateKey = this.dateKey(now);
|
const dateKey = this.dateKey(now);
|
||||||
const { payload, taskCount, usedFallbackTask } =
|
const { payload, taskCount, usedFallbackTask } =
|
||||||
await this.buildDigestPayload(user.id, slot, dateKey, true);
|
await this.buildDigestPayload(
|
||||||
|
user.id,
|
||||||
|
slot,
|
||||||
|
dateKey,
|
||||||
|
true,
|
||||||
|
`task-digest-test-${dateKey}-${Date.now()}`,
|
||||||
|
);
|
||||||
const result: TaskNotificationTestResult = {
|
const result: TaskNotificationTestResult = {
|
||||||
message: 'Task notification test processed.',
|
message: 'Task notification test processed.',
|
||||||
date: dateKey,
|
date: dateKey,
|
||||||
@@ -190,6 +197,7 @@ export class TaskDigestService {
|
|||||||
slot: TaskDigestSlot,
|
slot: TaskDigestSlot,
|
||||||
dateKey: string,
|
dateKey: string,
|
||||||
includeFallbackTask: boolean,
|
includeFallbackTask: boolean,
|
||||||
|
notificationTag?: string,
|
||||||
): Promise<TaskDigestPayloadResult> {
|
): Promise<TaskDigestPayloadResult> {
|
||||||
const tasks = await this.tasksRepository.find({
|
const tasks = await this.tasksRepository.find({
|
||||||
where: {
|
where: {
|
||||||
@@ -224,6 +232,7 @@ export class TaskDigestService {
|
|||||||
tasksUrl: this.tasksUrl(),
|
tasksUrl: this.tasksUrl(),
|
||||||
todayTasks: mappedTodayTasks,
|
todayTasks: mappedTodayTasks,
|
||||||
overdueTasks: mappedOverdueTasks,
|
overdueTasks: mappedOverdueTasks,
|
||||||
|
notificationTag,
|
||||||
},
|
},
|
||||||
taskCount: tasks.length + (usedFallbackTask ? 1 : 0),
|
taskCount: tasks.length + (usedFallbackTask ? 1 : 0),
|
||||||
usedFallbackTask,
|
usedFallbackTask,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ interface TaskDigestPushPayload {
|
|||||||
tasksUrl: string;
|
tasksUrl: string;
|
||||||
todayTasks: TaskDigestEmailItem[];
|
todayTasks: TaskDigestEmailItem[];
|
||||||
overdueTasks: TaskDigestEmailItem[];
|
overdueTasks: TaskDigestEmailItem[];
|
||||||
|
notificationTag?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TaskPushDigestResult {
|
export interface TaskPushDigestResult {
|
||||||
@@ -135,6 +136,10 @@ export class TaskPushService {
|
|||||||
await webPush.sendNotification(
|
await webPush.sendNotification(
|
||||||
this.toPushSubscription(subscription),
|
this.toPushSubscription(subscription),
|
||||||
JSON.stringify(this.toNotificationPayload(payload)),
|
JSON.stringify(this.toNotificationPayload(payload)),
|
||||||
|
{
|
||||||
|
TTL: 60 * 60,
|
||||||
|
urgency: 'high',
|
||||||
|
},
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -191,7 +196,7 @@ export class TaskPushService {
|
|||||||
title,
|
title,
|
||||||
body: parts.join(', '),
|
body: parts.join(', '),
|
||||||
url: payload.tasksUrl,
|
url: payload.tasksUrl,
|
||||||
tag: `task-digest-${payload.slot}-${payload.date}`,
|
tag: payload.notificationTag ?? `task-digest-${payload.slot}-${payload.date}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const CACHE_NAME = 'listify-shell-v2';
|
const CACHE_NAME = 'listify-shell-v3';
|
||||||
const SHELL_ASSETS = ['/', '/index.html', '/manifest.webmanifest', '/pwa-icon.svg'];
|
const SHELL_ASSETS = ['/', '/index.html', '/manifest.webmanifest', '/pwa-icon.svg'];
|
||||||
|
|
||||||
self.addEventListener('install', (event) => {
|
self.addEventListener('install', (event) => {
|
||||||
@@ -73,6 +73,9 @@ self.addEventListener('push', (event) => {
|
|||||||
const options = {
|
const options = {
|
||||||
body: payload.body || 'Du hast offene Tasks.',
|
body: payload.body || 'Du hast offene Tasks.',
|
||||||
tag: payload.tag || 'listify-task-digest',
|
tag: payload.tag || 'listify-task-digest',
|
||||||
|
renotify: true,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
vibrate: [120, 80, 120],
|
||||||
icon: '/pwa-icon.svg',
|
icon: '/pwa-icon.svg',
|
||||||
badge: '/pwa-icon.svg',
|
badge: '/pwa-icon.svg',
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
Reference in New Issue
Block a user