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:
parent
79817820c9
commit
f551509fee
@ -17,7 +17,12 @@ export class ExtensionMessengerHandler implements IExtensionMessengers {
|
|||||||
addMessenger<C extends Record<string, unknown>>(name: string, config: DynamicConfig[], callbacks: {
|
addMessenger<C extends Record<string, unknown>>(name: string, config: DynamicConfig[], callbacks: {
|
||||||
sendMedia: (config: C, media: MediaDTOWithThPath[]) => Promise<void>
|
sendMedia: (config: C, media: MediaDTOWithThPath[]) => Promise<void>
|
||||||
}): 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);
|
const em = new ExtensionMessenger(name, config, callbacks);
|
||||||
this.messengers.push(em);
|
this.messengers.push(em);
|
||||||
MessengerRepository.Instance.register(em);
|
MessengerRepository.Instance.register(em);
|
||||||
|
@ -18,7 +18,7 @@ export class MessengerRepository {
|
|||||||
return Object.values(this.messengers);
|
return Object.values(this.messengers);
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(m: Messenger<Record<string, unknown>>): void {
|
remove(m: { Name: string }): void {
|
||||||
if (!this.messengers[m.Name]) {
|
if (!this.messengers[m.Name]) {
|
||||||
throw new Error('Messenger does not exist:' + m.Name);
|
throw new Error('Messenger does not exist:' + m.Name);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user