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.

This commit is contained in:
2026-08-01 20:47:34 +02:00
parent 8ecfb99b27
commit 8f9aea2e0f
6 changed files with 36 additions and 15 deletions
@@ -1,9 +1,16 @@
<div class="channel-list">
<p>Channels</p>
@for (channel of channels(); track channel.type + channel.name) {
<div class="channel" [class.selected]="selectedChannel()?.name === channel.name && selectedChannel()?.type === channel.type"
<div class="channel"
[class.selected]="selectedChannel()?.name === channel.name && selectedChannel()?.type === channel.type"
(click)="selectedChannelChange.emit(channel)">
<span class="channel-name">{{ channel.name }}</span>
@if (channel.type === 'PARTY') {
<span class="channel-name">{{ chatService.partieMap().get(channel.name) ?? channel.name }}</span>
} @else if (channel.type === 'DM') {
<span class="channel-name">{{ chatService.userNameMap().get(channel.name) ?? channel.name }}</span>
} @else {
<span class="channel-name">{{ channel.name }}</span>
}
@if (channel.unreadMessages > 0) {
<div class="notification">
<svg-circle></svg-circle>
@@ -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<ChatChannel[]>();
public readonly selectedChannel = input.required<ChatChannel | null>();
public readonly selectedChannelChange = output<ChatChannel>();
@@ -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);
}
});
}
@@ -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) => {