diff --git a/packages/backend/src/core/NotificationService.ts b/packages/backend/src/core/NotificationService.ts index 68ad92f..69b04c1 100644 --- a/packages/backend/src/core/NotificationService.ts +++ b/packages/backend/src/core/NotificationService.ts @@ -21,6 +21,8 @@ import type { Config } from '@/config.js'; import { UserListService } from '@/core/UserListService.js'; import type { FilterUnionByProperty } from '@/types.js'; import { trackPromise } from '@/misc/promise-tracker.js'; +import { WebhookService } from './WebhookService.js'; +import { QueueService } from './QueueService.js'; @Injectable() export class NotificationService implements OnApplicationShutdown { @@ -42,6 +44,8 @@ export class NotificationService implements OnApplicationShutdown { private pushNotificationService: PushNotificationService, private cacheService: CacheService, private userListService: UserListService, + private webhookService: WebhookService, + private queueService: QueueService, ) { } @@ -175,6 +179,13 @@ export class NotificationService implements OnApplicationShutdown { const latestReadNotificationId = await this.redisClient.get(`latestReadNotification:${notifieeId}`); if (latestReadNotificationId && (latestReadNotificationId >= (await redisIdPromise)!)) return; + const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.userId === notifieeId && x.on.includes('notification')); + for (const webhook of webhooks) { + this.queueService.webhookDeliver(webhook, 'notification', { + notification: packed + }); + } + this.globalEventService.publishMainStream(notifieeId, 'unreadNotification', packed); this.pushNotificationService.pushNotification(notifieeId, 'notification', packed); diff --git a/packages/backend/src/models/Webhook.ts b/packages/backend/src/models/Webhook.ts index 2a727f8..c4d490e 100644 --- a/packages/backend/src/models/Webhook.ts +++ b/packages/backend/src/models/Webhook.ts @@ -7,7 +7,7 @@ import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typ import { id } from './util/id.js'; import { MiUser } from './User.js'; -export const webhookEventTypes = ['mention', 'unfollow', 'follow', 'followed', 'note', 'reply', 'renote', 'reaction', 'edited'] as const; +export const webhookEventTypes = ['mention', 'unfollow', 'follow', 'followed', 'note', 'reply', 'renote', 'reaction', 'edited', 'notification'] as const; @Entity('webhook') export class MiWebhook { diff --git a/packages/frontend/src/pages/settings/webhook.edit.vue b/packages/frontend/src/pages/settings/webhook.edit.vue index 99326c8..fbfabc4 100644 --- a/packages/frontend/src/pages/settings/webhook.edit.vue +++ b/packages/frontend/src/pages/settings/webhook.edit.vue @@ -29,6 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{ i18n.ts._webhookSettings._events.renote }} {{ i18n.ts._webhookSettings._events.reaction }} {{ i18n.ts._webhookSettings._events.mention }} + on notification @@ -75,6 +76,7 @@ const event_reply = ref(webhook.on.includes('reply')); const event_renote = ref(webhook.on.includes('renote')); const event_reaction = ref(webhook.on.includes('reaction')); const event_mention = ref(webhook.on.includes('mention')); +const event_notification = ref(webhook.on.includes('notification')); async function save(): Promise { const events = []; @@ -85,6 +87,7 @@ async function save(): Promise { if (event_renote.value) events.push('renote'); if (event_reaction.value) events.push('reaction'); if (event_mention.value) events.push('mention'); + if (event_notification.value) events.push('notification'); os.apiWithDialog('i/webhooks/update', { name: name.value, diff --git a/packages/frontend/src/pages/settings/webhook.new.vue b/packages/frontend/src/pages/settings/webhook.new.vue index 2993863..c2db510 100644 --- a/packages/frontend/src/pages/settings/webhook.new.vue +++ b/packages/frontend/src/pages/settings/webhook.new.vue @@ -29,6 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{ i18n.ts._webhookSettings._events.renote }} {{ i18n.ts._webhookSettings._events.reaction }} {{ i18n.ts._webhookSettings._events.mention }} + on notification @@ -59,6 +60,7 @@ const event_reply = ref(true); const event_renote = ref(true); const event_reaction = ref(true); const event_mention = ref(true); +const event_notification = ref(true); async function create(): Promise { const events = []; @@ -69,6 +71,7 @@ async function create(): Promise { if (event_renote.value) events.push('renote'); if (event_reaction.value) events.push('reaction'); if (event_mention.value) events.push('mention'); + if (event_notification.value) events.push('notification'); os.apiWithDialog('i/webhooks/create', { name: name.value,