-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Martin
-
That pizza place was amazing! We should go again sometime. 🍕
-
-
-
-
-
-
-
-
-
Charlie
-
Hey, do you have any recommendations for a good movie to watch?
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{{ conversation.nom }}
+
{{ conversation.messages[0].contenu || 'No message yet' }}
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+
diff --git a/src/app/components/tchat/tchat.component.ts b/src/app/components/tchat/tchat.component.ts
index 67b888a..8acbf4d 100644
--- a/src/app/components/tchat/tchat.component.ts
+++ b/src/app/components/tchat/tchat.component.ts
@@ -1,14 +1,31 @@
-import { Component } from '@angular/core';
-import { AuthService } from '@auth0/auth0-angular';
-import { Utilisateur } from 'src/app/interfaces/interfaces';
+import { Component, OnInit, Output, EventEmitter } from '@angular/core';
+import { UserService } from '../../services/user.service';
+import { Conversation } from '../../interfaces/interfaces';
@Component({
selector: 'app-tchat',
templateUrl: './tchat.component.html',
styleUrls: ['./tchat.component.scss']
})
-export class TchatComponent {
- user?: Utilisateur;
+export class TchatComponent implements OnInit {
+ conversations: Conversation[] = [];
+ menuVisible = true;
+ selectedConversation: Conversation | null = null;
- constructor(public auth: AuthService) {}
-}
+ constructor(private userService: UserService) {}
+
+ ngOnInit() {
+ this.userService.getConversations().subscribe(conversations => {
+ this.conversations = conversations;
+ console.log('🚀 ~ TchatComponent ~ this.userService.getConversations ~ this.conversations:', this.conversations);
+ });
+ }
+
+ toggleMenu() {
+ this.menuVisible = !this.menuVisible;
+ }
+
+ onSelectConversation(conversation: any) {
+ this.selectedConversation = conversation;
+ }
+}
\ No newline at end of file
diff --git a/src/app/interfaces/interfaces.ts b/src/app/interfaces/interfaces.ts
index e0f9009..d038ceb 100644
--- a/src/app/interfaces/interfaces.ts
+++ b/src/app/interfaces/interfaces.ts
@@ -54,16 +54,11 @@ export interface Video {
export interface Utilisateur {
id: number;
email: string;
- hash: string;
- adresse?: string;
- ville?: string;
- codePostal?: string;
- telephone?: string;
- nom?: string;
- prenom?: string;
+ userId: string;
+ img: string;
+ nom: string;
associationId?: number;
role: Role;
- password?: string;
favoris: Favori[];
association?: Association;
}
@@ -133,10 +128,18 @@ export interface PageEvent {
export interface Message {
- contenu: string
- conversationsId : number;
- createdAt: string
- id: number
- isAuthor: boolean
- utilisateursId: number
+ id: number;
+ contenu: string;
+ createdAt: Date;
+ utilisateursId: number;
+ associationsId: number;
+ isUserSender: boolean;
}
+
+export interface Conversation {
+ id: number;
+ nom: string;
+ img?: string;
+ messages: Message[];
+ photos?: Photo[];
+}
\ No newline at end of file
diff --git a/src/app/services/app.service.ts b/src/app/services/app.service.ts
index 6b6a03a..21903b5 100644
--- a/src/app/services/app.service.ts
+++ b/src/app/services/app.service.ts
@@ -148,31 +148,25 @@ export class AppService {
);
}
- sendMessage(conversationId: number, userId: number, content: string) {
- return this.http.post(`${this.api}/conversations/${conversationId}/messages`, {
+ sendMessage(userId: number, associationId: number, content: string, isUserSender: boolean) {
+ return this.http.post(`${this.api}/messages`, {
userId,
+ associationId,
content,
+ isUserSender,
}).pipe(
map((res: any) => res),
share(),
take(1)
);
}
-
- getMessages(conversationId: number) {
- return this.http.get(`${this.api}/conversations/${conversationId}/messages`).pipe(
+
+ getMessages(userId: number, associationId: number) {
+ return this.http.get(`${this.api}/messages/${associationId}/${userId}`).pipe(
map((res: any) => res),
share(),
take(1)
- );;
- }
-
- getConversations(userId: number) {
- return this.http.get(`${this.api}/conversations/user/${userId}`).pipe(
- map((res: any) => res),
- share(),
- take(1)
- );;
+ );
}
diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts
index 681562a..7dee400 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 { UserRole } from '../interfaces/interfaces';
+import { Conversation, UserRole } from '../interfaces/interfaces';
import { environment } from 'src/environments/environment';
@Injectable({
@@ -19,6 +19,7 @@ export class UserService {
private auth: AuthService
) {
this.auth.user$.subscribe((user) => {
+ console.log('🚀 ~ UserService ~ this.auth.user$.subscribe ~ user:', user);
if (user) {
const roles = user['roles'] || user['https://potits-chats.com/roles'];
this.isAdmin = this.isRole(roles, UserRole.Admin);
@@ -41,6 +42,22 @@ export class UserService {
);
}
+ getMeInfo(): Observable
{
+ return this.http.get(this.api + '/users/infos').pipe(
+ map((res: any) => res),
+ share(),
+ take(1)
+ );
+ }
+
+ getConversations(): Observable {
+ return this.http.get(`${this.api}/messages/conversations`).pipe(
+ map((res: any) => res),
+ share(),
+ take(1)
+ );
+ }
+
private isRole(roles: string[], role: UserRole): boolean {
return roles && roles.includes(role);
}
From e18eced2408f672efb06ac2885fe052846ff15ec Mon Sep 17 00:00:00 2001
From: FazCodeFR <30906528+FazCodeFR@users.noreply.github.com>
Date: Tue, 16 Jul 2024 21:00:46 +0200
Subject: [PATCH 3/4] update message
---
src/app/app-routing.module.ts | 5 +++
.../associations-details.component.html | 5 ++-
.../tchat-message.component.html | 43 +++++++++++--------
.../tchat-message/tchat-message.component.ts | 24 ++++++++---
src/app/interfaces/interfaces.ts | 1 +
src/app/services/user.service.ts | 7 ++-
6 files changed, 59 insertions(+), 26 deletions(-)
diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts
index c599cc9..b01099d 100644
--- a/src/app/app-routing.module.ts
+++ b/src/app/app-routing.module.ts
@@ -72,6 +72,11 @@ const routes: Routes = [
path: 'mentions-legales',
component: CguComponent,
},
+ {
+ path: 'tchat/:id',
+ component: TchatComponent,
+ canActivate: [AuthGuard],
+ },
{
path: 'tchat',
component: TchatComponent,
diff --git a/src/app/components/associations/associations-details/associations-details.component.html b/src/app/components/associations/associations-details/associations-details.component.html
index 7b7d386..e954df7 100644
--- a/src/app/components/associations/associations-details/associations-details.component.html
+++ b/src/app/components/associations/associations-details/associations-details.component.html
@@ -141,8 +141,9 @@
- Contacter {{asso.nom }}
+ class="flex mx-auto mt-16 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-none hover:bg-indigo-600 rounded text-lg"
+ [routerLink]="['/tchat', asso.id]">
+ Contacter {{asso.nom }}
\ No newline at end of file
diff --git a/src/app/components/tchat/tchat-message/tchat-message.component.html b/src/app/components/tchat/tchat-message/tchat-message.component.html
index 5fb5d3d..fee0f26 100644
--- a/src/app/components/tchat/tchat-message/tchat-message.component.html
+++ b/src/app/components/tchat/tchat-message/tchat-message.component.html
@@ -1,33 +1,40 @@
-