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;
|
package com.alttd.altitudeweb.controllers.chat;
|
||||||
|
|
||||||
import com.alttd.altitudeweb.api.ChatInfoApi;
|
import com.alttd.altitudeweb.api.ChatInfoApi;
|
||||||
|
import com.alttd.altitudeweb.model.PartyNameDto;
|
||||||
import com.alttd.altitudeweb.model.PlayerNameDto;
|
import com.alttd.altitudeweb.model.PlayerNameDto;
|
||||||
import com.alttd.altitudeweb.services.chat.ChatInfoService;
|
import com.alttd.altitudeweb.services.chat.ChatInfoService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
@ -25,7 +26,7 @@ public class ChatInfoController implements ChatInfoApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<String> getPartyName(String id) {
|
public ResponseEntity<PartyNameDto> getPartyName(String id) {
|
||||||
int partyId;
|
int partyId;
|
||||||
try {
|
try {
|
||||||
partyId = Integer.parseInt(id);
|
partyId = Integer.parseInt(id);
|
||||||
|
|
@ -33,6 +34,11 @@ public class ChatInfoController implements ChatInfoApi {
|
||||||
return ResponseEntity.badRequest().build();
|
return ResponseEntity.badRequest().build();
|
||||||
}
|
}
|
||||||
return chatInfoService.getPartyName(partyId)
|
return chatInfoService.getPartyName(partyId)
|
||||||
|
.map(partyName -> {
|
||||||
|
PartyNameDto partyNameDto = new PartyNameDto();
|
||||||
|
partyNameDto.setName(partyName);
|
||||||
|
return partyNameDto;
|
||||||
|
})
|
||||||
.map(ResponseEntity::ok)
|
.map(ResponseEntity::ok)
|
||||||
.orElse(ResponseEntity.notFound().build());
|
.orElse(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,16 @@
|
||||||
<div class="channel-list">
|
<div class="channel-list">
|
||||||
<p>Channels</p>
|
<p>Channels</p>
|
||||||
@for (channel of channels(); track channel.type + channel.name) {
|
@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)">
|
(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) {
|
@if (channel.unreadMessages > 0) {
|
||||||
<div class="notification">
|
<div class="notification">
|
||||||
<svg-circle></svg-circle>
|
<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 {ChatChannel} from '@pages/altitude/chat/objects/chat-channel.object';
|
||||||
import {CircleSvgComponent} from '@pages/altitude/chat/svg/circle.svg';
|
import {CircleSvgComponent} from '@pages/altitude/chat/svg/circle.svg';
|
||||||
|
import {ChatService} from '@pages/altitude/chat/service/chat.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-channel-list',
|
selector: 'app-channel-list',
|
||||||
|
|
@ -11,6 +12,7 @@ import {CircleSvgComponent} from '@pages/altitude/chat/svg/circle.svg';
|
||||||
styleUrl: './channel-list.component.scss'
|
styleUrl: './channel-list.component.scss'
|
||||||
})
|
})
|
||||||
export class ChannelListComponent {
|
export class ChannelListComponent {
|
||||||
|
protected readonly chatService = inject(ChatService);
|
||||||
public readonly channels = input.required<ChatChannel[]>();
|
public readonly channels = input.required<ChatChannel[]>();
|
||||||
public readonly selectedChannel = input.required<ChatChannel | null>();
|
public readonly selectedChannel = input.required<ChatChannel | null>();
|
||||||
public readonly selectedChannelChange = output<ChatChannel>();
|
public readonly selectedChannelChange = output<ChatChannel>();
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,10 @@ export class ChatService implements OnDestroy {
|
||||||
return {name: 'Global Admin Chat', type: 'GAC'};
|
return {name: 'Global Admin Chat', type: 'GAC'};
|
||||||
}
|
}
|
||||||
if (message.type === 'PARTY') {
|
if (message.type === 'PARTY') {
|
||||||
if (!message.channelName) {
|
if (!message.channel) {
|
||||||
throw new Error('Party name is missing');
|
throw new Error('Party name is missing');
|
||||||
}
|
}
|
||||||
this.updatePartyMap(message.channelName)
|
this.updatePartyMap(message.channel)
|
||||||
return {name: message.channel, type: 'PARTY'};
|
return {name: message.channel, type: 'PARTY'};
|
||||||
}
|
}
|
||||||
if (message.type === 'MSG') {
|
if (message.type === 'MSG') {
|
||||||
|
|
@ -133,26 +133,26 @@ export class ChatService implements OnDestroy {
|
||||||
return {name: message.server, type: 'SERVER'};
|
return {name: message.server, type: 'SERVER'};
|
||||||
}
|
}
|
||||||
|
|
||||||
public updatePartyMap(partieId: string): void {
|
public updatePartyMap(partyId: string): void {
|
||||||
if (this.partieMap().has(partieId) || this.pendingPartyNameRequests.has(partieId)) {
|
if (this.partieMap().has(partyId) || this.pendingPartyNameRequests.has(partyId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pendingPartyNameRequests.add(partieId);
|
this.pendingPartyNameRequests.add(partyId);
|
||||||
|
|
||||||
this.chatInfoService.getPartyName(partieId).subscribe({
|
this.chatInfoService.getPartyName(partyId).subscribe({
|
||||||
next: (partyName) => {
|
next: (partyName) => {
|
||||||
this.partieMap.update((old) => {
|
this.partieMap.update((old) => {
|
||||||
const newMap = new Map(old);
|
const newMap = new Map(old);
|
||||||
newMap.set(partieId, partyName);
|
newMap.set(partyId, partyName.name);
|
||||||
return newMap;
|
return newMap;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error(`Failed to load party name for ${partieId}:`, error);
|
console.error(`Failed to load party name for ${partyId}:`, error);
|
||||||
},
|
},
|
||||||
complete: () => {
|
complete: () => {
|
||||||
this.pendingPartyNameRequests.delete(partieId);
|
this.pendingPartyNameRequests.delete(partyId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ export class AuthService {
|
||||||
}
|
}
|
||||||
this.loginService.getUsername().subscribe({
|
this.loginService.getUsername().subscribe({
|
||||||
next: (username) => {
|
next: (username) => {
|
||||||
console.log("Username retrieved: " + username.username);
|
|
||||||
this._username.set(username.username);
|
this._username.set(username.username);
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ PartyName:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
$ref: "#/components/schemas/PartyName"
|
||||||
"400":
|
"400":
|
||||||
description: Invalid ID
|
description: Invalid ID
|
||||||
"404":
|
"404":
|
||||||
|
|
@ -55,3 +55,10 @@ components:
|
||||||
type: string
|
type: string
|
||||||
nickname:
|
nickname:
|
||||||
type: string
|
type: string
|
||||||
|
PartyName:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user