summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/UserWebhookService.ts
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-10-18 21:14:49 +0000
committerdakkar <dakkar@thenautilus.net>2024-10-18 21:14:49 +0000
commitba17776b1961376b5369aa775e8910a227cc02ec (patch)
tree0d0579dd911a6c9b74ebc84195cacf10eafe0918 /packages/backend/src/core/UserWebhookService.ts
parentmerge: Allow logged in users to refresh polls (!686) (diff)
parentMerge branch 'develop' into feature/2024.9.0 (diff)
downloadsharkey-ba17776b1961376b5369aa775e8910a227cc02ec.tar.gz
sharkey-ba17776b1961376b5369aa775e8910a227cc02ec.tar.bz2
sharkey-ba17776b1961376b5369aa775e8910a227cc02ec.zip
merge: version 2024.9.0 (!675)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/675 Approved-by: Julia <julia@insertdomain.name> Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/core/UserWebhookService.ts')
-rw-r--r--packages/backend/src/core/UserWebhookService.ts29
1 files changed, 27 insertions, 2 deletions
diff --git a/packages/backend/src/core/UserWebhookService.ts b/packages/backend/src/core/UserWebhookService.ts
index e96bfeea95..8a40a53688 100644
--- a/packages/backend/src/core/UserWebhookService.ts
+++ b/packages/backend/src/core/UserWebhookService.ts
@@ -5,8 +5,8 @@
import { Inject, Injectable } from '@nestjs/common';
import * as Redis from 'ioredis';
-import type { WebhooksRepository } from '@/models/_.js';
-import type { MiWebhook } from '@/models/Webhook.js';
+import { type WebhooksRepository } from '@/models/_.js';
+import { MiWebhook } from '@/models/Webhook.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { GlobalEvents } from '@/core/GlobalEventService.js';
@@ -38,6 +38,31 @@ export class UserWebhookService implements OnApplicationShutdown {
return this.activeWebhooks;
}
+ /**
+ * UserWebhook の一覧を取得する.
+ */
+ @bindThis
+ public fetchWebhooks(params?: {
+ ids?: MiWebhook['id'][];
+ isActive?: MiWebhook['active'];
+ on?: MiWebhook['on'];
+ }): Promise<MiWebhook[]> {
+ const query = this.webhooksRepository.createQueryBuilder('webhook');
+ if (params) {
+ if (params.ids && params.ids.length > 0) {
+ query.andWhere('webhook.id IN (:...ids)', { ids: params.ids });
+ }
+ if (params.isActive !== undefined) {
+ query.andWhere('webhook.active = :isActive', { isActive: params.isActive });
+ }
+ if (params.on && params.on.length > 0) {
+ query.andWhere(':on <@ webhook.on', { on: params.on });
+ }
+ }
+
+ return query.getMany();
+ }
+
@bindThis
private async onMessage(_: string, data: string): Promise<void> {
const obj = JSON.parse(data);