You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
978 B
38 lines
978 B
import logger from '../../logger';
|
|
import type { NotificationAgent, NotificationPayload } from './agents/agent';
|
|
|
|
export enum Notification {
|
|
MEDIA_PENDING = 2,
|
|
MEDIA_APPROVED = 4,
|
|
MEDIA_AVAILABLE = 8,
|
|
MEDIA_FAILED = 16,
|
|
TEST_NOTIFICATION = 32,
|
|
}
|
|
|
|
class NotificationManager {
|
|
private activeAgents: NotificationAgent[] = [];
|
|
|
|
public registerAgents = (agents: NotificationAgent[]): void => {
|
|
this.activeAgents = [...this.activeAgents, ...agents];
|
|
logger.info('Registered Notification Agents', { label: 'Notifications' });
|
|
};
|
|
|
|
public sendNotification(
|
|
type: Notification,
|
|
payload: NotificationPayload
|
|
): void {
|
|
logger.info(`Sending notification for ${Notification[type]}`, {
|
|
label: 'Notifications',
|
|
});
|
|
this.activeAgents.forEach((agent) => {
|
|
if (agent.shouldSend(type)) {
|
|
agent.send(type, payload);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
const notificationManager = new NotificationManager();
|
|
|
|
export default notificationManager;
|