From 8f9aea2e0fa219f70d0cf57d5b23e4cb196e5b82 Mon Sep 17 00:00:00 2001 From: akastijn Date: Sat, 1 Aug 2026 20:47:34 +0200 Subject: [PATCH] Refactor ChatService and ChannelListComponent: integrate `ChatService` into `ChannelListComponent`, rename `partieId` to `partyId`, update party and DM name mappings in UI, and remove debug log in AuthService. --- .../controllers/chat/ChatInfoController.java | 8 +++++++- .../channel-list/channel-list.component.html | 11 +++++++++-- .../channel-list/channel-list.component.ts | 4 +++- .../altitude/chat/service/chat.service.ts | 18 +++++++++--------- frontend/src/app/services/auth.service.ts | 1 - .../resources/schemas/chat_info/chat_info.yml | 9 ++++++++- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/chat/ChatInfoController.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/chat/ChatInfoController.java index 4a8a359..f30d413 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/chat/ChatInfoController.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/chat/ChatInfoController.java @@ -1,6 +1,7 @@ package com.alttd.altitudeweb.controllers.chat; import com.alttd.altitudeweb.api.ChatInfoApi; +import com.alttd.altitudeweb.model.PartyNameDto; import com.alttd.altitudeweb.model.PlayerNameDto; import com.alttd.altitudeweb.services.chat.ChatInfoService; import lombok.RequiredArgsConstructor; @@ -25,7 +26,7 @@ public class ChatInfoController implements ChatInfoApi { } @Override - public ResponseEntity getPartyName(String id) { + public ResponseEntity getPartyName(String id) { int partyId; try { partyId = Integer.parseInt(id); @@ -33,6 +34,11 @@ public class ChatInfoController implements ChatInfoApi { return ResponseEntity.badRequest().build(); } return chatInfoService.getPartyName(partyId) + .map(partyName -> { + PartyNameDto partyNameDto = new PartyNameDto(); + partyNameDto.setName(partyName); + return partyNameDto; + }) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } diff --git a/frontend/src/app/pages/altitude/chat/components/channel-list/channel-list.component.html b/frontend/src/app/pages/altitude/chat/components/channel-list/channel-list.component.html index 4ac82d3..793ef70 100644 --- a/frontend/src/app/pages/altitude/chat/components/channel-list/channel-list.component.html +++ b/frontend/src/app/pages/altitude/chat/components/channel-list/channel-list.component.html @@ -1,9 +1,16 @@

Channels

@for (channel of channels(); track channel.type + channel.name) { -
- {{ channel.name }} + @if (channel.type === 'PARTY') { + {{ chatService.partieMap().get(channel.name) ?? channel.name }} + } @else if (channel.type === 'DM') { + {{ chatService.userNameMap().get(channel.name) ?? channel.name }} + } @else { + {{ channel.name }} + } @if (channel.unreadMessages > 0) {
diff --git a/frontend/src/app/pages/altitude/chat/components/channel-list/channel-list.component.ts b/frontend/src/app/pages/altitude/chat/components/channel-list/channel-list.component.ts index 6fd291a..fb484bb 100644 --- a/frontend/src/app/pages/altitude/chat/components/channel-list/channel-list.component.ts +++ b/frontend/src/app/pages/altitude/chat/components/channel-list/channel-list.component.ts @@ -1,6 +1,7 @@ -import {Component, effect, input, output} from '@angular/core'; +import {Component, effect, inject, input, output} from '@angular/core'; import {ChatChannel} from '@pages/altitude/chat/objects/chat-channel.object'; import {CircleSvgComponent} from '@pages/altitude/chat/svg/circle.svg'; +import {ChatService} from '@pages/altitude/chat/service/chat.service'; @Component({ selector: 'app-channel-list', @@ -11,6 +12,7 @@ import {CircleSvgComponent} from '@pages/altitude/chat/svg/circle.svg'; styleUrl: './channel-list.component.scss' }) export class ChannelListComponent { + protected readonly chatService = inject(ChatService); public readonly channels = input.required(); public readonly selectedChannel = input.required(); public readonly selectedChannelChange = output(); 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 a216a5c..097ef9b 100644 --- a/frontend/src/app/pages/altitude/chat/service/chat.service.ts +++ b/frontend/src/app/pages/altitude/chat/service/chat.service.ts @@ -115,10 +115,10 @@ export class ChatService implements OnDestroy { return {name: 'Global Admin Chat', type: 'GAC'}; } if (message.type === 'PARTY') { - if (!message.channelName) { + if (!message.channel) { throw new Error('Party name is missing'); } - this.updatePartyMap(message.channelName) + this.updatePartyMap(message.channel) return {name: message.channel, type: 'PARTY'}; } if (message.type === 'MSG') { @@ -133,26 +133,26 @@ export class ChatService implements OnDestroy { return {name: message.server, type: 'SERVER'}; } - public updatePartyMap(partieId: string): void { - if (this.partieMap().has(partieId) || this.pendingPartyNameRequests.has(partieId)) { + public updatePartyMap(partyId: string): void { + if (this.partieMap().has(partyId) || this.pendingPartyNameRequests.has(partyId)) { return; } - this.pendingPartyNameRequests.add(partieId); + this.pendingPartyNameRequests.add(partyId); - this.chatInfoService.getPartyName(partieId).subscribe({ + this.chatInfoService.getPartyName(partyId).subscribe({ next: (partyName) => { this.partieMap.update((old) => { const newMap = new Map(old); - newMap.set(partieId, partyName); + newMap.set(partyId, partyName.name); return newMap; }); }, error: (error) => { - console.error(`Failed to load party name for ${partieId}:`, error); + console.error(`Failed to load party name for ${partyId}:`, error); }, complete: () => { - this.pendingPartyNameRequests.delete(partieId); + this.pendingPartyNameRequests.delete(partyId); } }); } diff --git a/frontend/src/app/services/auth.service.ts b/frontend/src/app/services/auth.service.ts index ac7cabf..7b88996 100644 --- a/frontend/src/app/services/auth.service.ts +++ b/frontend/src/app/services/auth.service.ts @@ -58,7 +58,6 @@ export class AuthService { } this.loginService.getUsername().subscribe({ next: (username) => { - console.log("Username retrieved: " + username.username); this._username.set(username.username); }, error: (error) => { diff --git a/open_api/src/main/resources/schemas/chat_info/chat_info.yml b/open_api/src/main/resources/schemas/chat_info/chat_info.yml index f272fe0..0589e6a 100644 --- a/open_api/src/main/resources/schemas/chat_info/chat_info.yml +++ b/open_api/src/main/resources/schemas/chat_info/chat_info.yml @@ -39,7 +39,7 @@ PartyName: content: application/json: schema: - type: string + $ref: "#/components/schemas/PartyName" "400": description: Invalid ID "404": @@ -55,3 +55,10 @@ components: type: string nickname: type: string + PartyName: + type: object + required: + - name + properties: + name: + type: string