diff options
| author | Marie <marie@kaifa.ch> | 2024-02-20 15:10:41 +0000 |
|---|---|---|
| committer | Amelia Yukii <amelia.yukii@shourai.de> | 2024-02-20 15:10:41 +0000 |
| commit | 4a13508da0a5d930b4d73bb4208df39a578e7796 (patch) | |
| tree | 4043fefdc93e3c66159d6a6ac565591fa25642ce /packages/backend/src/core | |
| parent | merge: Warn when missing alt text (!423) (diff) | |
| download | sharkey-4a13508da0a5d930b4d73bb4208df39a578e7796.tar.gz sharkey-4a13508da0a5d930b4d73bb4208df39a578e7796.tar.bz2 sharkey-4a13508da0a5d930b4d73bb4208df39a578e7796.zip | |
Note Edited notification type
Diffstat (limited to 'packages/backend/src/core')
| -rw-r--r-- | packages/backend/src/core/GlobalEventService.ts | 1 | ||||
| -rw-r--r-- | packages/backend/src/core/NoteEditService.ts | 61 | ||||
| -rw-r--r-- | packages/backend/src/core/entities/NotificationEntityService.ts | 4 |
3 files changed, 14 insertions, 52 deletions
diff --git a/packages/backend/src/core/GlobalEventService.ts b/packages/backend/src/core/GlobalEventService.ts index ab87bf9dee..e568cbf646 100644 --- a/packages/backend/src/core/GlobalEventService.ts +++ b/packages/backend/src/core/GlobalEventService.ts @@ -96,6 +96,7 @@ export interface MainEventTypes { announcementCreated: { announcement: Packed<'Announcement'>; }; + edited: Packed<'Note'>; } export interface DriveEventTypes { diff --git a/packages/backend/src/core/NoteEditService.ts b/packages/backend/src/core/NoteEditService.ts index b137295b0b..6a469c9634 100644 --- a/packages/backend/src/core/NoteEditService.ts +++ b/packages/backend/src/core/NoteEditService.ts @@ -52,7 +52,7 @@ import { isReply } from '@/misc/is-reply.js'; import { trackPromise } from '@/misc/promise-tracker.js'; import { isUserRelated } from '@/misc/is-user-related.js'; -type NotificationType = 'reply' | 'renote' | 'quote' | 'mention'; +type NotificationType = 'reply' | 'renote' | 'quote' | 'mention' | 'edited'; class NotificationManager { private notifier: { id: MiUser['id']; }; @@ -586,7 +586,7 @@ export class NoteEditService implements OnApplicationShutdown { } // Pack the note - const noteObj = await this.noteEntityService.pack(note, null, { skipHide: true }); + const noteObj = await this.noteEntityService.pack(note, null, { skipHide: true, withReactionAndUserPairCache: true }); if (data.poll != null) { this.globalEventService.publishNoteStream(note.id, 'updated', { cw: note.cw, @@ -612,7 +612,7 @@ export class NoteEditService implements OnApplicationShutdown { const nm = new NotificationManager(this.mutingsRepository, this.notificationService, user, note); - await this.createMentionedEvents(mentionedUsers, note, nm); + //await this.createMentionedEvents(mentionedUsers, note, nm); // If has in reply to note if (data.reply) { @@ -634,12 +634,12 @@ export class NoteEditService implements OnApplicationShutdown { const muted = isUserRelated(note, userIdsWhoMeMuting); if (!isThreadMuted && !muted) { - nm.push(data.reply.userId, 'reply'); - this.globalEventService.publishMainStream(data.reply.userId, 'reply', noteObj); + nm.push(data.reply.userId, 'edited'); + this.globalEventService.publishMainStream(data.reply.userId, 'edited', noteObj); - const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.userId === data.reply!.userId && x.on.includes('reply')); + const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.userId === data.reply!.userId && x.on.includes('edited')); for (const webhook of webhooks) { - this.queueService.webhookDeliver(webhook, 'reply', { + this.queueService.webhookDeliver(webhook, 'edited', { note: noteObj, }); } @@ -647,45 +647,6 @@ export class NoteEditService implements OnApplicationShutdown { } } - // If it is renote - if (data.renote) { - const type = this.isQuote(data) ? 'quote' : 'renote'; - - // Notify - if (data.renote.userHost === null) { - const isThreadMuted = await this.noteThreadMutingsRepository.exists({ - where: { - userId: data.renote.userId, - threadId: data.renote.threadId ?? data.renote.id, - }, - }); - - const [ - userIdsWhoMeMuting, - ] = data.renote.userId ? await Promise.all([ - this.cacheService.userMutingsCache.fetch(data.renote.userId), - ]) : [new Set<string>()]; - - const muted = isUserRelated(note, userIdsWhoMeMuting); - - if (!isThreadMuted && !muted) { - nm.push(data.renote.userId, type); - } - } - - // Publish event - if ((user.id !== data.renote.userId) && data.renote.userHost === null) { - this.globalEventService.publishMainStream(data.renote.userId, 'renote', noteObj); - - const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.userId === data.renote!.userId && x.on.includes('renote')); - for (const webhook of webhooks) { - this.queueService.webhookDeliver(webhook, 'renote', { - note: noteObj, - }); - } - } - } - nm.notify(); //#region AP deliver @@ -780,17 +741,17 @@ export class NoteEditService implements OnApplicationShutdown { detail: true, }); - this.globalEventService.publishMainStream(u.id, 'mention', detailPackedNote); + this.globalEventService.publishMainStream(u.id, 'edited', detailPackedNote); - const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.userId === u.id && x.on.includes('mention')); + const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.userId === u.id && x.on.includes('edited')); for (const webhook of webhooks) { - this.queueService.webhookDeliver(webhook, 'mention', { + this.queueService.webhookDeliver(webhook, 'edited', { note: detailPackedNote, }); } // Create notification - nm.push(u.id, 'mention'); + nm.push(u.id, 'edited'); } } diff --git a/packages/backend/src/core/entities/NotificationEntityService.ts b/packages/backend/src/core/entities/NotificationEntityService.ts index a572fe320c..7664c90491 100644 --- a/packages/backend/src/core/entities/NotificationEntityService.ts +++ b/packages/backend/src/core/entities/NotificationEntityService.ts @@ -20,8 +20,8 @@ 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', 'quote', 'reaction', 'pollEnded'] as (typeof notificationTypes[number])[]); -const NOTE_REQUIRED_GROUPED_NOTIFICATION_TYPES = new Set(['note', 'mention', 'reply', 'renote', 'renote:grouped', 'quote', 'reaction', 'reaction:grouped', 'pollEnded']); +const NOTE_REQUIRED_NOTIFICATION_TYPES = new Set(['note', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollEnded', 'edited'] as (typeof notificationTypes[number])[]); +const NOTE_REQUIRED_GROUPED_NOTIFICATION_TYPES = new Set(['note', 'mention', 'reply', 'renote', 'renote:grouped', 'quote', 'reaction', 'reaction:grouped', 'pollEnded', 'edited']); @Injectable() export class NotificationEntityService implements OnModuleInit { |