LES MESSAGES MARCHENT
This commit is contained in:
@@ -6,6 +6,7 @@ import { MessagesSend } from "../messages-send/messages-send.component";
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { discussionsService, Message } from "../../../core/chat/discussion.service";
|
||||
import { AuthService } from "../../../core/auth/auth.service";
|
||||
import {ChatService} from "../../../core/chat/chat.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-messages-main',
|
||||
@@ -18,12 +19,13 @@ export class MessagesMain implements OnInit {
|
||||
private route = inject(ActivatedRoute);
|
||||
private discussionService = inject(discussionsService);
|
||||
private authService = inject(AuthService);
|
||||
private chatService = inject(ChatService);
|
||||
|
||||
currentDiscussionId!: string;
|
||||
currentUserId!: number;
|
||||
messages: Message[] = [];
|
||||
|
||||
ngOnInit() {
|
||||
async ngOnInit() {
|
||||
this.currentDiscussionId = this.route.snapshot.paramMap.get('discussionId')!;
|
||||
this.currentUserId = this.authService.getCurrentUserId();
|
||||
|
||||
@@ -31,9 +33,18 @@ export class MessagesMain implements OnInit {
|
||||
next: (messages) => this.messages = messages,
|
||||
error: (err) => console.error('Impossible de charger les messages', err)
|
||||
});
|
||||
|
||||
// réception temps réel
|
||||
this.chatService.onMessage((message: Message) => {
|
||||
this.messages = [...this.messages, message];
|
||||
});
|
||||
|
||||
// rejoindre la room pour ne recevoir que cette conversation
|
||||
await this.chatService.connect();
|
||||
await this.chatService.joinConversation(this.currentDiscussionId);
|
||||
}
|
||||
|
||||
isSent(message: Message): boolean {
|
||||
return message.authorId === this.currentUserId;
|
||||
return message.userId === this.currentUserId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user