-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add messenger extensibility to extensions #753
- Loading branch information
Showing
7 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {IExtensionMessengers} from './IExtension'; | ||
import {DynamicConfig} from '../../../common/entities/DynamicConfig'; | ||
import {MediaDTOWithThPath, Messenger} from '../messenger/Messenger'; | ||
import {ExtensionMessenger} from '../messenger/ExtensionMessenger'; | ||
import {MessengerRepository} from '../messenger/MessengerRepository'; | ||
import {ILogger} from '../../Logger'; | ||
|
||
export class ExtensionMessengerHandler implements IExtensionMessengers { | ||
|
||
messengers: Messenger[] = []; | ||
|
||
|
||
constructor(private readonly extLogger: ILogger) { | ||
} | ||
|
||
|
||
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); | ||
const em = new ExtensionMessenger(name, config, callbacks); | ||
this.messengers.push(em); | ||
MessengerRepository.Instance.register(em); | ||
} | ||
|
||
cleanUp() { | ||
this.extLogger.silly('Removing Messenger'); | ||
this.messengers.forEach(m => MessengerRepository.Instance.remove(m)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {MediaDTOWithThPath, Messenger} from './Messenger'; | ||
import {DynamicConfig} from '../../../common/entities/DynamicConfig'; | ||
|
||
export class ExtensionMessenger<C extends Record<string, unknown> = Record<string, unknown>> extends Messenger<C> { | ||
|
||
constructor(public readonly Name: string, | ||
public readonly ConfigTemplate: DynamicConfig[], | ||
private readonly callbacks: { sendMedia: (config: C, media: MediaDTOWithThPath[]) => Promise<void> }) { | ||
super(); | ||
} | ||
|
||
protected sendMedia(config: C, media: MediaDTOWithThPath[]): Promise<void> { | ||
return this.callbacks.sendMedia(config, media); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters