2021-06-22 18:40:28 +02:00
|
|
|
import { HabboBroadcastMessageEvent, HotelWillShutdownEvent, ModeratorMessageEvent, MOTDNotificationEvent, NotificationDialogMessageEvent } from 'nitro-renderer';
|
|
|
|
import { FC, useCallback } from 'react';
|
2021-07-08 07:46:59 +02:00
|
|
|
import { NotificationCenterAlertEvent } from '../../events';
|
|
|
|
import { dispatchUiEvent } from '../../hooks/events';
|
2021-06-22 18:40:28 +02:00
|
|
|
import { CreateMessageHook } from '../../hooks/messages';
|
|
|
|
import { useNotificationCenterContext } from './context/NotificationCenterContext';
|
|
|
|
import { INotificationCenterMessageHandlerProps } from './NotificationCenterMessageHandler.types';
|
|
|
|
import { NotificationCenterActions } from './reducers/NotificationCenterReducer';
|
|
|
|
import { DialogMessageNotification } from './utils/DialogMessageNotification';
|
|
|
|
import { HotelWillShutdownNotification } from './utils/HotelWillShutdownNotification';
|
|
|
|
|
|
|
|
export const NotificationCenterMessageHandler: FC<INotificationCenterMessageHandlerProps> = props =>
|
|
|
|
{
|
|
|
|
const { dispatchNotificationCenterState = null } = useNotificationCenterContext();
|
|
|
|
|
|
|
|
const onHabboBroadcastMessageEvent = useCallback((event: HabboBroadcastMessageEvent) =>
|
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
2021-07-08 07:46:59 +02:00
|
|
|
dispatchUiEvent(new NotificationCenterAlertEvent(NotificationCenterAlertEvent.HOTEL_ALERT, [ parser.message ]));
|
|
|
|
}, []);
|
2021-06-22 18:40:28 +02:00
|
|
|
|
2021-07-08 07:46:59 +02:00
|
|
|
const onModeratorMessageEvent = useCallback((event: ModeratorMessageEvent) =>
|
2021-06-22 18:40:28 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
2021-07-08 07:46:59 +02:00
|
|
|
dispatchUiEvent(new NotificationCenterAlertEvent(NotificationCenterAlertEvent.HOTEL_ALERT, [ parser.message ], parser.link));
|
|
|
|
}, []);
|
2021-06-22 18:40:28 +02:00
|
|
|
|
2021-07-08 07:46:59 +02:00
|
|
|
const onMOTDNotificationEvent = useCallback((event: MOTDNotificationEvent) =>
|
2021-06-22 18:40:28 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
2021-07-08 07:46:59 +02:00
|
|
|
dispatchUiEvent(new NotificationCenterAlertEvent(NotificationCenterAlertEvent.HOTEL_ALERT, parser.messages));
|
|
|
|
}, []);
|
2021-06-22 18:40:28 +02:00
|
|
|
|
2021-07-08 07:46:59 +02:00
|
|
|
const onHotelWillShutdownEvent = useCallback((event: HotelWillShutdownEvent) =>
|
2021-06-22 18:40:28 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchNotificationCenterState({
|
|
|
|
type: NotificationCenterActions.ADD_NOTIFICATION,
|
|
|
|
payload: {
|
2021-07-08 07:46:59 +02:00
|
|
|
notification: new HotelWillShutdownNotification(parser.minutes)
|
2021-06-22 18:40:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [ dispatchNotificationCenterState ]);
|
|
|
|
|
2021-07-08 07:46:59 +02:00
|
|
|
const onNotificationDialogMessageEvent = useCallback((event: NotificationDialogMessageEvent) =>
|
2021-06-22 18:40:28 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchNotificationCenterState({
|
|
|
|
type: NotificationCenterActions.ADD_NOTIFICATION,
|
|
|
|
payload: {
|
2021-07-08 07:46:59 +02:00
|
|
|
notification: new DialogMessageNotification(parser.type, parser.parameters)
|
2021-06-22 18:40:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [ dispatchNotificationCenterState ]);
|
|
|
|
|
|
|
|
CreateMessageHook(HabboBroadcastMessageEvent, onHabboBroadcastMessageEvent);
|
|
|
|
CreateMessageHook(ModeratorMessageEvent, onModeratorMessageEvent);
|
|
|
|
CreateMessageHook(MOTDNotificationEvent, onMOTDNotificationEvent);
|
|
|
|
CreateMessageHook(HotelWillShutdownEvent, onHotelWillShutdownEvent);
|
2021-07-08 07:46:59 +02:00
|
|
|
CreateMessageHook(NotificationDialogMessageEvent, onNotificationDialogMessageEvent);
|
2021-06-22 18:40:28 +02:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|