diff --git a/src/app/chat-window/chat-window.component.ts b/src/app/chat-window/chat-window.component.ts index 8870689..4411dcc 100644 --- a/src/app/chat-window/chat-window.component.ts +++ b/src/app/chat-window/chat-window.component.ts @@ -1,8 +1,8 @@ import { - Component, - Inject, - ElementRef, - OnInit + Component, + Inject, + ElementRef, + OnInit } from '@angular/core'; import { Observable } from 'rxjs'; @@ -13,6 +13,7 @@ import { ThreadsService } from '../thread/threads.service'; import { Message } from '../message/message.model'; import { MessagesService } from '../message/messages.service'; + @Component({ selector: 'chat-window', templateUrl: './chat-window.component.html', @@ -36,23 +37,23 @@ export class ChatWindowComponent implements OnInit { this.draftMessage = new Message(); this.threadsService.currentThread.subscribe( - (thread: Thread) => { - this.currentThread = thread; - }); + (thread: Thread) => { + this.currentThread = thread; + }); this.UsersService.currentUser - .subscribe( - (user: User) => { - this.currentUser = user; - }); + .subscribe( + (user: User) => { + this.currentUser = user; + }); this.messages - .subscribe( - (messages: Array) => { - setTimeout(() => { - this.scrollToBottom(); - }); - }); + .subscribe( + (messages: Array) => { + setTimeout(() => { + this.scrollToBottom(); + }); + }); } onEnter(event: any): void { @@ -65,13 +66,16 @@ export class ChatWindowComponent implements OnInit { m.author = this.currentUser; m.thread = this.currentThread; m.isRead = true; - this.messagesService.addMessage(m); - this.draftMessage = new Message(); + m.sentAt = new Date(); + if(m.text && m.text !== null){ + this.messagesService.addMessage(m); + this.draftMessage = new Message(); + } } scrollToBottom(): void { const scrollPane: any = this.el - .nativeElement.querySelector('.msg-container-base'); + .nativeElement.querySelector('.msg-container-base'); scrollPane.scrollTop = scrollPane.scrollHeight; } }