From 1d3c8253981fba2d431df2f5cc12dd78b21d37bc Mon Sep 17 00:00:00 2001 From: Marie Date: Mon, 4 Nov 2024 11:22:37 +0100 Subject: upd: add notification for when scheduled note gets posted --- .../src/core/entities/NotificationEntityService.ts | 2 +- packages/backend/src/models/Notification.ts | 5 +++++ .../backend/src/models/json-schema/notification.ts | 25 ++++++++++++++++++++++ .../processors/ScheduleNotePostProcessorService.ts | 5 ++++- packages/backend/src/types.ts | 1 + 5 files changed, 36 insertions(+), 2 deletions(-) (limited to 'packages/backend/src') diff --git a/packages/backend/src/core/entities/NotificationEntityService.ts b/packages/backend/src/core/entities/NotificationEntityService.ts index 447d95cc68..31a9809323 100644 --- a/packages/backend/src/core/entities/NotificationEntityService.ts +++ b/packages/backend/src/core/entities/NotificationEntityService.ts @@ -20,7 +20,7 @@ import type { OnModuleInit } from '@nestjs/common'; import type { UserEntityService } from './UserEntityService.js'; import type { NoteEntityService } from './NoteEntityService.js'; -const NOTE_REQUIRED_NOTIFICATION_TYPES = new Set(['note', 'mention', 'reply', 'renote', 'renote:grouped', 'quote', 'reaction', 'reaction:grouped', 'pollEnded', 'edited'] as (typeof groupedNotificationTypes[number])[]); +const NOTE_REQUIRED_NOTIFICATION_TYPES = new Set(['note', 'mention', 'reply', 'renote', 'renote:grouped', 'quote', 'reaction', 'reaction:grouped', 'pollEnded', 'edited', 'scheduledNotePosted'] as (typeof groupedNotificationTypes[number])[]); @Injectable() export class NotificationEntityService implements OnModuleInit { diff --git a/packages/backend/src/models/Notification.ts b/packages/backend/src/models/Notification.ts index 5003e02d96..53003a0a5a 100644 --- a/packages/backend/src/models/Notification.ts +++ b/packages/backend/src/models/Notification.ts @@ -127,6 +127,11 @@ export type MiNotification = { id: string; createdAt: string; reason: string; +} | { + type: 'scheduledNotePosted'; + id: string; + createdAt: string; + noteId: MiNote['id']; }; export type MiGroupedNotification = MiNotification | { diff --git a/packages/backend/src/models/json-schema/notification.ts b/packages/backend/src/models/json-schema/notification.ts index 69bd9531ec..26498e3e9d 100644 --- a/packages/backend/src/models/json-schema/notification.ts +++ b/packages/backend/src/models/json-schema/notification.ts @@ -383,6 +383,31 @@ export const packedNotificationSchema = { optional: false, nullable: false, }, }, + }, { + type: 'object', + properties: { + ...baseSchema.properties, + type: { + type: 'string', + optional: false, nullable: false, + enum: ['scheduledNotePosted'], + }, + user: { + type: 'object', + ref: 'UserLite', + optional: false, nullable: false, + }, + userId: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + note: { + type: 'object', + ref: 'Note', + optional: false, nullable: false, + }, + }, }, { type: 'object', properties: { diff --git a/packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts b/packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts index 59e23b865e..f281b0ed7b 100644 --- a/packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts +++ b/packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts @@ -107,7 +107,7 @@ export class ScheduleNotePostProcessorService { return; } - await this.noteCreateService.create(me, { + const createdNote = await this.noteCreateService.create(me, { ...note, createdAt: new Date(), files, @@ -121,6 +121,9 @@ export class ScheduleNotePostProcessorService { channel, }); await this.noteScheduleRepository.remove(data); + this.notificationService.createNotification(me.id, 'scheduledNotePosted', { + noteId: createdNote.id, + }); } }); } diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 7930129002..95f049f768 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -36,6 +36,7 @@ export const notificationTypes = [ 'achievementEarned', 'exportCompleted', 'scheduledNoteFailed', + 'scheduledNotePosted', 'app', 'test', ] as const; -- cgit v1.2.3-freya