1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-23 01:27:14 +02:00

Messenger handler should override when adding #784

This commit is contained in:
Patrik J. Braun 2024-03-09 01:16:38 +01:00
parent 79817820c9
commit f551509fee
2 changed files with 7 additions and 2 deletions

View File

@ -17,7 +17,12 @@ export class ExtensionMessengerHandler implements IExtensionMessengers {
addMessenger<C extends Record<string, unknown>>(name: string, config: DynamicConfig[], callbacks: {
sendMedia: (config: C, media: MediaDTOWithThPath[]) => Promise<void>
}): 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);

View File

@ -18,7 +18,7 @@ export class MessengerRepository {
return Object.values(this.messengers);
}
remove(m: Messenger<Record<string, unknown>>): void {
remove(m: { Name: string }): void {
if (!this.messengers[m.Name]) {
throw new Error('Messenger does not exist:' + m.Name);
}