From f551509fee76d4e07251de27e230a924ed099d7b Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 9 Mar 2024 01:16:38 +0100 Subject: [PATCH] Messenger handler should override when adding #784 --- src/backend/model/extension/ExtensionMessengerHandler.ts | 7 ++++++- src/backend/model/messenger/MessengerRepository.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/model/extension/ExtensionMessengerHandler.ts b/src/backend/model/extension/ExtensionMessengerHandler.ts index ff7aeddb..2ff04304 100644 --- a/src/backend/model/extension/ExtensionMessengerHandler.ts +++ b/src/backend/model/extension/ExtensionMessengerHandler.ts @@ -17,7 +17,12 @@ export class ExtensionMessengerHandler implements IExtensionMessengers { addMessenger>(name: string, config: DynamicConfig[], callbacks: { sendMedia: (config: C, media: MediaDTOWithThPath[]) => Promise }): void { - this.extLogger.silly('Adding new Messenger:', name); + if (MessengerRepository.Instance.get(name)) { + this.extLogger.silly('Messenger already exist. Overriding it:', name); + MessengerRepository.Instance.remove({Name: name}); + } else { + this.extLogger.silly('Adding new Messenger:', name); + } const em = new ExtensionMessenger(name, config, callbacks); this.messengers.push(em); MessengerRepository.Instance.register(em); diff --git a/src/backend/model/messenger/MessengerRepository.ts b/src/backend/model/messenger/MessengerRepository.ts index 31a98163..fadc6abf 100644 --- a/src/backend/model/messenger/MessengerRepository.ts +++ b/src/backend/model/messenger/MessengerRepository.ts @@ -18,7 +18,7 @@ export class MessengerRepository { return Object.values(this.messengers); } - remove(m: Messenger>): void { + remove(m: { Name: string }): void { if (!this.messengers[m.Name]) { throw new Error('Messenger does not exist:' + m.Name); }