diff --git a/frontend/src/app/pages/altitude/chat/components/chat-info/chat-info.component.ts b/frontend/src/app/pages/altitude/chat/components/chat-info/chat-info.component.ts index fecd53c..8eced1e 100644 --- a/frontend/src/app/pages/altitude/chat/components/chat-info/chat-info.component.ts +++ b/frontend/src/app/pages/altitude/chat/components/chat-info/chat-info.component.ts @@ -22,11 +22,7 @@ export class ChatInfoComponent { protected readonly getServerTextColor = getServerTextColor; public enableNotifications() { - this.notificationService.requestPermission().then( - () => { - this.notificationService.enableNotifications(this.selectedServer()); - } - ); + this.notificationService.enableNotifications(this.selectedServer()); } public disableNotifications() { diff --git a/frontend/src/app/pages/altitude/chat/service/chat-notification.service.ts b/frontend/src/app/pages/altitude/chat/service/chat-notification.service.ts index 187bbe8..0589180 100644 --- a/frontend/src/app/pages/altitude/chat/service/chat-notification.service.ts +++ b/frontend/src/app/pages/altitude/chat/service/chat-notification.service.ts @@ -8,43 +8,13 @@ export class NotificationService { private readonly _notificationEnabled = signal>( this.getStoredNotificationSettings() ); - public readonly notificationEnabled = this._notificationEnabled.asReadonly(); - async requestPermission(): Promise { - if (!('Notification' in window)) { - console.log('This browser does not support notifications'); - return false; - } - - if (Notification.permission === 'granted') { - return true; - } - - if (Notification.permission === 'denied') { - console.log('Notification permission was denied'); - return false; - } - - const permission = await Notification.requestPermission(); - if (permission === 'granted') { - this.enableSound() - return true - } - return false; - } - - notify(server: string, title: string, body: string | null) { + public notify(server: string) { if (!this.isNotificationEnabled(server)) { return; } - if (Notification.permission === 'granted') { - if (body === null) { - new Notification(title); - } else { - new Notification(title, {body}); - } - this.playSound(); - } + this.playSound(); + } private enableSound() { @@ -72,11 +42,12 @@ export class NotificationService { return this._notificationEnabled()[server]; } - enableNotifications(server: string) { + public enableNotifications(server: string) { this.setNotificationEnabled(server, true); + this.enableSound() } - disableNotifications(server: string) { + public disableNotifications(server: string) { this.setNotificationEnabled(server, false); } diff --git a/frontend/src/app/pages/altitude/chat/service/chat.service.ts b/frontend/src/app/pages/altitude/chat/service/chat.service.ts index 577a3cf..14c459d 100644 --- a/frontend/src/app/pages/altitude/chat/service/chat.service.ts +++ b/frontend/src/app/pages/altitude/chat/service/chat.service.ts @@ -7,11 +7,6 @@ import {normalizeComponent} from '@pages/altitude/chat/mini-message/normalize.ut import {ChatServer} from '@pages/altitude/chat/objects/chat-server.object'; import {NotificationService} from '@pages/altitude/chat/service/chat-notification.service'; -export interface ChatEvent { - type: string; - data: any; -} - interface SsePayloadEvent { data: string; } @@ -60,14 +55,10 @@ export class ChatService implements OnDestroy { find.unreadMessages++; } }) - const messagesByServer = chatMessages.reduce>((acc, message) => { - acc[message.server] = (acc[message.server] ?? 0) + 1; - return acc; - }, {}); - - Object.entries(messagesByServer).forEach(([server, messageCount]) => { - this.notificationService.notify(server, `New messages`, `(${messageCount}) new messages in ${server}`); - }); + new Set(chatMessages.map(message => message.server)) + .forEach((server) => { + this.notificationService.notify(server); + }); }); source.onerror = (err) => {