diff options
Diffstat (limited to 'packages/backend/src/services/note/create.ts')
| -rw-r--r-- | packages/backend/src/services/note/create.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 2ed194b7e9..6f373aaf45 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -35,9 +35,11 @@ import { Channel } from '@/models/entities/channel.js'; import { normalizeForSearch } from '@/misc/normalize-for-search.js'; import { getAntennas } from '@/misc/antenna-cache.js'; import { endedPollNotificationQueue } from '@/queue/queues.js'; +import { webhookDeliver } from '@/queue/index.js'; import { Cache } from '@/misc/cache.js'; import { UserProfile } from '@/models/entities/user-profile.js'; import { db } from '@/db/postgre.js'; +import { getActiveWebhooks } from '@/misc/webhook-cache.js'; const mutedWordsCache = new Cache<{ userId: UserProfile['userId']; mutedWords: UserProfile['mutedWords']; }[]>(1000 * 60 * 5); @@ -345,6 +347,16 @@ export default async (user: { id: User['id']; username: User['username']; host: publishNotesStream(noteObj); + getActiveWebhooks().then(webhooks => { + webhooks = webhooks.filter(x => x.userId === user.id && x.on.includes('note')); + for (const webhook of webhooks) { + webhookDeliver(webhook, { + type: 'note', + note: noteObj, + }); + } + }); + const nm = new NotificationManager(user, note); const nmRelatedPromises = []; @@ -365,6 +377,14 @@ export default async (user: { id: User['id']; username: User['username']; host: if (!threadMuted) { nm.push(data.reply.userId, 'reply'); publishMainStream(data.reply.userId, 'reply', noteObj); + + const webhooks = (await getActiveWebhooks()).filter(x => x.userId === data.reply!.userId && x.on.includes('reply')); + for (const webhook of webhooks) { + webhookDeliver(webhook, { + type: 'reply', + note: noteObj, + }); + } } } } @@ -384,6 +404,14 @@ export default async (user: { id: User['id']; username: User['username']; host: // Publish event if ((user.id !== data.renote.userId) && data.renote.userHost === null) { publishMainStream(data.renote.userId, 'renote', noteObj); + + const webhooks = (await getActiveWebhooks()).filter(x => x.userId === data.renote!.userId && x.on.includes('renote')); + for (const webhook of webhooks) { + webhookDeliver(webhook, { + type: 'renote', + note: noteObj, + }); + } } } @@ -620,6 +648,14 @@ async function createMentionedEvents(mentionedUsers: MinimumUser[], note: Note, publishMainStream(u.id, 'mention', detailPackedNote); + const webhooks = (await getActiveWebhooks()).filter(x => x.userId === u.id && x.on.includes('mention')); + for (const webhook of webhooks) { + webhookDeliver(webhook, { + type: 'mention', + note: detailPackedNote, + }); + } + // Create notification nm.push(u.id, 'mention'); } |