diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2022-12-04 15:03:09 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2022-12-04 15:03:09 +0900 |
| commit | bbb49457f9fb5d46402e913c92ebf77722cad6ff (patch) | |
| tree | 8ef285bcbab2c3a4a89d0a624a802d76a2864fed /packages/backend/src/core/WebhookService.ts | |
| parent | :art: (diff) | |
| download | sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.tar.gz sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.tar.bz2 sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.zip | |
refactor: introduce bindThis decorator to bind this automaticaly
Diffstat (limited to 'packages/backend/src/core/WebhookService.ts')
| -rw-r--r-- | packages/backend/src/core/WebhookService.ts | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/packages/backend/src/core/WebhookService.ts b/packages/backend/src/core/WebhookService.ts index 1a690314f8..91a39f1359 100644 --- a/packages/backend/src/core/WebhookService.ts +++ b/packages/backend/src/core/WebhookService.ts @@ -4,6 +4,7 @@ import type { WebhooksRepository } from '@/models/index.js'; import type { Webhook } from '@/models/entities/Webhook.js'; import { DI } from '@/di-symbols.js'; import type { OnApplicationShutdown } from '@nestjs/common'; +import { bindThis } from '@/decorators.js'; @Injectable() export class WebhookService implements OnApplicationShutdown { @@ -17,10 +18,11 @@ export class WebhookService implements OnApplicationShutdown { @Inject(DI.webhooksRepository) private webhooksRepository: WebhooksRepository, ) { - this.onMessage = this.onMessage.bind(this); + //this.onMessage = this.onMessage.bind(this); this.redisSubscriber.on('message', this.onMessage); } + @bindThis public async getActiveWebhooks() { if (!this.webhooksFetched) { this.webhooks = await this.webhooksRepository.findBy({ @@ -32,6 +34,7 @@ export class WebhookService implements OnApplicationShutdown { return this.webhooks; } + @bindThis private async onMessage(_: string, data: string): Promise<void> { const obj = JSON.parse(data); @@ -64,6 +67,7 @@ export class WebhookService implements OnApplicationShutdown { } } + @bindThis public onApplicationShutdown(signal?: string | undefined) { this.redisSubscriber.off('message', this.onMessage); } |