notifications
This commit is contained in:
@@ -15,6 +15,7 @@ interface TaskDigestPayload {
|
||||
tasksUrl: string;
|
||||
todayTasks: TaskDigestEmailItem[];
|
||||
overdueTasks: TaskDigestEmailItem[];
|
||||
notificationTag?: string;
|
||||
}
|
||||
|
||||
interface TaskDigestPayloadResult {
|
||||
@@ -101,7 +102,13 @@ export class TaskDigestService {
|
||||
const slot = this.currentSlot(now) ?? 'morning';
|
||||
const dateKey = this.dateKey(now);
|
||||
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 = {
|
||||
message: 'Task notification test processed.',
|
||||
date: dateKey,
|
||||
@@ -190,6 +197,7 @@ export class TaskDigestService {
|
||||
slot: TaskDigestSlot,
|
||||
dateKey: string,
|
||||
includeFallbackTask: boolean,
|
||||
notificationTag?: string,
|
||||
): Promise<TaskDigestPayloadResult> {
|
||||
const tasks = await this.tasksRepository.find({
|
||||
where: {
|
||||
@@ -224,6 +232,7 @@ export class TaskDigestService {
|
||||
tasksUrl: this.tasksUrl(),
|
||||
todayTasks: mappedTodayTasks,
|
||||
overdueTasks: mappedOverdueTasks,
|
||||
notificationTag,
|
||||
},
|
||||
taskCount: tasks.length + (usedFallbackTask ? 1 : 0),
|
||||
usedFallbackTask,
|
||||
|
||||
@@ -15,6 +15,7 @@ interface TaskDigestPushPayload {
|
||||
tasksUrl: string;
|
||||
todayTasks: TaskDigestEmailItem[];
|
||||
overdueTasks: TaskDigestEmailItem[];
|
||||
notificationTag?: string;
|
||||
}
|
||||
|
||||
export interface TaskPushDigestResult {
|
||||
@@ -135,6 +136,10 @@ export class TaskPushService {
|
||||
await webPush.sendNotification(
|
||||
this.toPushSubscription(subscription),
|
||||
JSON.stringify(this.toNotificationPayload(payload)),
|
||||
{
|
||||
TTL: 60 * 60,
|
||||
urgency: 'high',
|
||||
},
|
||||
);
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -191,7 +196,7 @@ export class TaskPushService {
|
||||
title,
|
||||
body: parts.join(', '),
|
||||
url: payload.tasksUrl,
|
||||
tag: `task-digest-${payload.slot}-${payload.date}`,
|
||||
tag: payload.notificationTag ?? `task-digest-${payload.slot}-${payload.date}`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user