1- import { AfterViewChecked , Component , ElementRef , HostListener , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
1+ import {
2+ AfterViewChecked ,
3+ Component ,
4+ ElementRef ,
5+ HostListener ,
6+ QueryList ,
7+ ViewChild ,
8+ ViewChildren
9+ } from '@angular/core' ;
210import { TranslocoService } from '@ngneat/transloco' ;
311import { takeUntil } from 'rxjs' ;
412import { DestroyService } from '../../services/destroy.service' ;
513import { Sound , SoundService } from '../../services/sound.service' ;
614import { MessageHistory } from './message-history' ;
7- import { ChatMessage , ChatService , MessageTypes } from 'src/app/services/chat.service' ;
15+ import {
16+ ChatMessage ,
17+ ChatService ,
18+ MessageTypes
19+ } from 'src/app/services/chat.service' ;
820import { ClientService } from 'src/app/services/client.service' ;
921
1022interface ChatComponentMessage extends ChatMessage {
1123 date : number ;
1224 typeClass : string ;
1325}
1426
15-
1627function messageTypeToClassName ( type : MessageTypes ) : string {
1728 switch ( type ) {
1829 case MessageTypes . SYSTEM_MESSAGE :
19- return " system" ;
20-
30+ return ' system' ;
31+
2132 case MessageTypes . PLAYER_DIALOGUE :
22- return " dialogue" ;
23-
33+ return ' dialogue' ;
34+
2435 case MessageTypes . PARTY_CHAT :
25- return " party" ;
26-
36+ return ' party' ;
37+
2738 case MessageTypes . LOCAL_CHAT :
28- return " local" ;
39+ return ' local' ;
2940
3041 default :
31- return " global" ;
42+ return ' global' ;
3243 }
3344}
3445
3546@Component ( {
3647 selector : 'app-chat' ,
3748 templateUrl : './chat.component.html' ,
3849 styleUrls : [ './chat.component.scss' ] ,
39- providers : [ DestroyService ] ,
50+ providers : [ DestroyService ]
4051} )
4152export class ChatComponent implements AfterViewChecked {
42-
4353 public padding = 0 ;
4454
4555 public message = '' ;
@@ -51,14 +61,15 @@ export class ChatComponent implements AfterViewChecked {
5161
5262 private scrollBack = 0 ;
5363
54- private history = new MessageHistory ( { maxHistoryLength : 50 } ) ;
64+ private history = new MessageHistory ( { maxHistoryLength : 50 } ) ;
5565
5666 private get maxScroll ( ) : number {
57- return this . logRef . nativeElement . scrollHeight - this . logRef . nativeElement . clientHeight ;
67+ return (
68+ this . logRef . nativeElement . scrollHeight -
69+ this . logRef . nativeElement . clientHeight
70+ ) ;
5871 }
5972
60-
61-
6273 @ViewChild ( 'input' ) private inputRef ! : ElementRef ;
6374 @ViewChildren ( 'entry' ) private entryRefQuery ! : QueryList < ElementRef > ;
6475 @ViewChild ( 'log' ) private logRef ! : ElementRef ;
@@ -68,8 +79,7 @@ export class ChatComponent implements AfterViewChecked {
6879 private readonly clientService : ClientService ,
6980 private readonly chatService : ChatService ,
7081 private readonly sound : SoundService ,
71- private readonly translocoService : TranslocoService ,
72-
82+ private readonly translocoService : TranslocoService
7383 ) {
7484 chatService . messageList
7585 . pipe ( takeUntil ( this . destroy$ ) )
@@ -95,7 +105,7 @@ export class ChatComponent implements AfterViewChecked {
95105 this . sound . play ( Sound . Message ) ;
96106 } ) ;
97107
98- clientService . activationStateChange
108+ clientService . activationStateChange
99109 . pipe ( takeUntil ( this . destroy$ ) )
100110 . subscribe ( state => {
101111 if ( ! state && this . inputRef ) {
@@ -128,7 +138,7 @@ export class ChatComponent implements AfterViewChecked {
128138 if ( this . message ) {
129139 this . chatService . sendMessage ( MessageTypes . GLOBAL_CHAT , this . message ) ;
130140 this . sound . play ( Sound . Focus ) ;
131- this . history . push ( this . message )
141+ this . history . push ( this . message ) ;
132142 this . message = '' ;
133143 }
134144
@@ -160,15 +170,14 @@ export class ChatComponent implements AfterViewChecked {
160170 event . preventDefault ( ) ;
161171 event . stopPropagation ( ) ;
162172
163- this . message = this . history . prev ( this . message )
173+ this . message = this . history . prev ( this . message ) ;
164174 }
165175
166176 @HostListener ( 'keydown.ArrowDown' , [ '$event' ] )
167177 private onArrowDown ( event : KeyboardEvent ) {
168178 event . preventDefault ( ) ;
169179 event . stopPropagation ( ) ;
170180
171- this . message = this . history . next ( )
181+ this . message = this . history . next ( ) ;
172182 }
173-
174183}
0 commit comments