-
+
0; else noMessages">
+
+
+
+
+
+
+
+
{{ msg.contenu + ' (receveur)' }}
+
-
-
{{ msg.contenu + ' (receveur)' }}
-
-
-
-
-
-
{{ msg.contenu + ' (envoyeur)' }}
-
-
-
+
+
+
+
{{ msg.contenu + ' (envoyeur)' }}
+
+
+
+
+
+
+ Merci d'écrire votre message
+
diff --git a/src/app/components/tchat/tchat-message/tchat-message.component.ts b/src/app/components/tchat/tchat-message/tchat-message.component.ts
index 284ceae..56c6f5e 100644
--- a/src/app/components/tchat/tchat-message/tchat-message.component.ts
+++ b/src/app/components/tchat/tchat-message/tchat-message.component.ts
@@ -5,6 +5,7 @@ import { WebSocketService } from '../../../services/web-socket.service';
import { Message } from '../../../interfaces/interfaces';
import { Conversation } from '../../../interfaces/interfaces';
import { UserService } from '../../../services/user.service';
+import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-tchat-message',
@@ -15,6 +16,7 @@ export class TchatMessageComponent implements OnInit, OnChanges {
@Input() selectedConversation: Conversation | null = null;
associationId: number = 1; // Remplacez par l'ID de l'association appropriée
+ idFromUrl: number | null = null;
isAssociation = false;
utilisateurId: number = 1; // Remplacez par l'ID de l'utilisateur approprié
message = '';
@@ -23,23 +25,35 @@ export class TchatMessageComponent implements OnInit, OnChanges {
constructor(
public auth: AuthService,
private appService: AppService,
- private webSocketService: WebSocketService
+ private webSocketService: WebSocketService,
+ private route: ActivatedRoute
) {}
ngOnInit(): void {
- this.loadMessages();
+ this.route.params.subscribe(params => {
+ const idFromUrl = params['id'];
+ if (idFromUrl) {
+ this.idFromUrl = +idFromUrl;
+ this.associationId = this.idFromUrl;
+ this.loadMessages();
+ this.appService.getByIdAsso(this.idFromUrl).subscribe((association) => {
+ this.selectedConversation = association as unknown as Conversation;
+ });
+ }
+ });
}
ngOnChanges(changes: SimpleChanges): void {
if (changes['selectedConversation'] && this.selectedConversation) {
- console.log('🚀 ~ TchatMessageComponent ~ ngOnChanges ~ this.selectedConversation:', this.selectedConversation);
+ this.isAssociation = !!this.selectedConversation.img ? true : false;
+ console.log('🚀 ~ TchatMessageComponent ~ ngOnChanges ~ this.isAssociation:', this.isAssociation);
+ this.associationId = this.selectedConversation.id;
this.loadMessages();
}
}
loadMessages(): void {
- if (this.selectedConversation) {
- this.associationId = this.selectedConversation.id;
+ if (this.selectedConversation || this.idFromUrl) {
this.appService.getMessages(this.utilisateurId, this.associationId).subscribe((messages: Message[]) => {
this.messages = messages;
console.log('🚀 ~ TchatMessageComponent ~ this.appService.getMessages ~ this.messages:', this.messages);
diff --git a/src/app/interfaces/interfaces.ts b/src/app/interfaces/interfaces.ts
index d038ceb..7142711 100644
--- a/src/app/interfaces/interfaces.ts
+++ b/src/app/interfaces/interfaces.ts
@@ -142,4 +142,5 @@ export interface Conversation {
img?: string;
messages: Message[];
photos?: Photo[];
+ associationId?: number;
}
\ No newline at end of file
diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts
index 7dee400..ef3cfa9 100644
--- a/src/app/services/user.service.ts
+++ b/src/app/services/user.service.ts
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, map, share, take } from 'rxjs';
import { AuthService } from '@auth0/auth0-angular';
-import { Conversation, UserRole } from '../interfaces/interfaces';
+import { Conversation, UserRole, Utilisateur } from '../interfaces/interfaces';
import { environment } from 'src/environments/environment';
@Injectable({
@@ -13,6 +13,7 @@ export class UserService {
public isAsso = false;
public isUser = false;
api = environment.urlAPI;
+ public user: Utilisateur | null = null;
constructor(
private http: HttpClient,
@@ -30,6 +31,10 @@ export class UserService {
}
this.isAsso = this.isRole(roles, UserRole.Asso);
this.isUser = true;
+
+ this.getMeInfo().subscribe((res) => {
+ this.user = res;
+ });
}
});
}