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:
parent
8ecfb99b27
commit
8f9aea2e0f
|
|
@ -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<String> getPartyName(String id) {
|
||||
public ResponseEntity<PartyNameDto> 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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user