2021-07-22 16:14:27 +02:00
|
|
|
import { AdminMessageEventTypes, adminMessagesService } from "../Connexion/AdminMessagesService";
|
|
|
|
import { textMessageContentStore, textMessageVisibleStore } from "../Stores/TypeMessageStore/TextMessageStore";
|
|
|
|
import { soundPlayingStore } from "../Stores/SoundPlayingStore";
|
|
|
|
import { UPLOADER_URL } from "../Enum/EnvironmentVariable";
|
|
|
|
import { banMessageContentStore, banMessageVisibleStore } from "../Stores/TypeMessageStore/BanMessageStore";
|
2020-10-19 19:32:47 +02:00
|
|
|
|
2021-03-01 17:47:00 +01:00
|
|
|
class UserMessageManager {
|
|
|
|
receiveBannedMessageListener!: Function;
|
2020-10-19 19:32:47 +02:00
|
|
|
|
2021-03-01 17:47:00 +01:00
|
|
|
constructor() {
|
|
|
|
adminMessagesService.messageStream.subscribe((event) => {
|
2021-07-22 16:14:27 +02:00
|
|
|
textMessageVisibleStore.set(false);
|
|
|
|
banMessageVisibleStore.set(false);
|
|
|
|
if (event.type === AdminMessageEventTypes.admin) {
|
|
|
|
textMessageContentStore.set(event.text);
|
|
|
|
textMessageVisibleStore.set(true);
|
|
|
|
} else if (event.type === AdminMessageEventTypes.audio) {
|
|
|
|
soundPlayingStore.playSound(UPLOADER_URL + event.text);
|
|
|
|
} else if (event.type === AdminMessageEventTypes.ban) {
|
|
|
|
banMessageContentStore.set(event.text);
|
|
|
|
banMessageVisibleStore.set(true);
|
|
|
|
} else if (event.type === AdminMessageEventTypes.banned) {
|
|
|
|
banMessageContentStore.set(event.text);
|
|
|
|
banMessageVisibleStore.set(true);
|
2021-03-01 17:47:00 +01:00
|
|
|
this.receiveBannedMessageListener();
|
2021-01-25 14:10:16 +01:00
|
|
|
}
|
2021-07-22 16:14:27 +02:00
|
|
|
});
|
2021-01-25 14:10:16 +01:00
|
|
|
}
|
|
|
|
|
2021-07-22 16:14:27 +02:00
|
|
|
setReceiveBanListener(callback: Function) {
|
2021-03-01 17:47:00 +01:00
|
|
|
this.receiveBannedMessageListener = callback;
|
2020-10-19 19:32:47 +02:00
|
|
|
}
|
2021-03-01 17:47:00 +01:00
|
|
|
}
|
2021-07-22 16:14:27 +02:00
|
|
|
export const userMessageManager = new UserMessageManager();
|