1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08: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 {
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);
}