|
@@ -1,33 +1,57 @@
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
+import { Router } from '@angular/router';
|
|
|
|
|
+import { FormsModule, NgForm } from '@angular/forms';
|
|
|
import { timer } from 'rxjs';
|
|
import { timer } from 'rxjs';
|
|
|
|
|
|
|
|
import { MenuComponent } from '../menu/menu.component';
|
|
import { MenuComponent } from '../menu/menu.component';
|
|
|
import { MessageShort } from '../../interfaces/chat';
|
|
import { MessageShort } from '../../interfaces/chat';
|
|
|
|
|
+import { PseudonymeList } from '../../interfaces/participant';
|
|
|
import { ChatService } from '../../services/chat.service';
|
|
import { ChatService } from '../../services/chat.service';
|
|
|
|
|
+import { AccountService } from '../../services/account.service'
|
|
|
|
|
|
|
|
-@Component({ selector: 'app-chat', imports: [MenuComponent], templateUrl: './chat.component.html', styleUrl: './chat.component.css' })
|
|
|
|
|
|
|
+@Component({ selector: 'app-chat', imports: [FormsModule, MenuComponent], templateUrl: './chat.component.html', styleUrl: './chat.component.css' })
|
|
|
|
|
|
|
|
export class ChatComponent implements OnInit
|
|
export class ChatComponent implements OnInit
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
|
|
+ logged: boolean = false;
|
|
|
|
|
+ disabled: boolean = false;
|
|
|
|
|
+
|
|
|
dernierNumero: number = 0;
|
|
dernierNumero: number = 0;
|
|
|
|
|
|
|
|
lignes: MessageShort[] = [];
|
|
lignes: MessageShort[] = [];
|
|
|
|
|
|
|
|
ajoute: MessageShort = new MessageShort();
|
|
ajoute: MessageShort = new MessageShort();
|
|
|
|
|
|
|
|
- constructor(private chatService: ChatService) { }
|
|
|
|
|
|
|
+ pseudonymes: PseudonymeList[] = [];
|
|
|
|
|
+
|
|
|
|
|
+ constructor(private chatService: ChatService, private accountService: AccountService, private router: Router) { }
|
|
|
|
|
|
|
|
ngOnInit()
|
|
ngOnInit()
|
|
|
{
|
|
{
|
|
|
- this.recupererToutesLignes();
|
|
|
|
|
|
|
+ this.logged = this.accountService.isLogged();
|
|
|
|
|
+
|
|
|
|
|
+ if (this.logged)
|
|
|
|
|
+ {
|
|
|
|
|
+ this.ajoute.pseudonyme = this.accountService.getUsername();
|
|
|
|
|
|
|
|
- timer(0, 7000).subscribe(() => { this.recupererDernieresLignes(); });
|
|
|
|
|
|
|
+ this.retreivePseudonymes();
|
|
|
|
|
+
|
|
|
|
|
+ timer(0, 7000).subscribe(() => { this.recupererDernieresLignes(); });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- recupererToutesLignes() { this.chatService.getList().subscribe(data => { this.lignes = data; }); this.setDernierNumero(); }
|
|
|
|
|
|
|
+ recupererDernieresLignes()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ((this.router.url !== '/chat')) { return; }
|
|
|
|
|
+
|
|
|
|
|
+ this.logged = this.accountService.isLogged();
|
|
|
|
|
|
|
|
- recupererDernieresLignes() { this.chatService.getNew(this.dernierNumero).subscribe(data => { this.lignes = [...this.lignes, ...data]; }); this.setDernierNumero(); }
|
|
|
|
|
|
|
+ if ((this.logged) && (this.disabled == false))
|
|
|
|
|
+ {
|
|
|
|
|
+ this.chatService.getNew(this.dernierNumero).subscribe(data => { if (data) { this.lignes = [...data, ...this.lignes]; } this.setDernierNumero(); });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
private setDernierNumero()
|
|
private setDernierNumero()
|
|
|
{
|
|
{
|
|
@@ -44,7 +68,19 @@ export class ChatComponent implements OnInit
|
|
|
|
|
|
|
|
envoiNouvelleLigne()
|
|
envoiNouvelleLigne()
|
|
|
{
|
|
{
|
|
|
- this.chatService.addNew(this.dernierNumero, this.ajoute).subscribe(data => { this.lignes = [...this.lignes, ...data]; }); this.setDernierNumero();
|
|
|
|
|
|
|
+ if (this.logged)
|
|
|
|
|
+ {
|
|
|
|
|
+ this.disabled = true;
|
|
|
|
|
+ this.chatService.addNew(this.dernierNumero, this.ajoute).subscribe(data => {
|
|
|
|
|
+ this.lignes = [...data, ...this.lignes];
|
|
|
|
|
+ this.ajoute = new MessageShort();
|
|
|
|
|
+ this.ajoute.pseudonyme = this.accountService.getUsername();
|
|
|
|
|
+ this.setDernierNumero();
|
|
|
|
|
+ this.disabled = false;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private retreivePseudonymes() { this.chatService.getOptionListPseudonyme().subscribe(data => { this.pseudonymes = data; }); }
|
|
|
|
|
+
|
|
|
}
|
|
}
|