From 6ccb291ce2a153d975c3705d1b62d2958c685707 Mon Sep 17 00:00:00 2001 From: MizovOO Date: Sun, 21 May 2017 16:53:06 +0300 Subject: [PATCH 1/2] update sentAt property on sending instead of on creating --- src/app/chat-window/chat-window.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/chat-window/chat-window.component.ts b/src/app/chat-window/chat-window.component.ts index 8870689..a3384c9 100644 --- a/src/app/chat-window/chat-window.component.ts +++ b/src/app/chat-window/chat-window.component.ts @@ -65,6 +65,7 @@ export class ChatWindowComponent implements OnInit { m.author = this.currentUser; m.thread = this.currentThread; m.isRead = true; + m.sentAt = new Date(); this.messagesService.addMessage(m); this.draftMessage = new Message(); } From 6e1f7a1a9be85edacc92feea602f9f69f8f84f3b Mon Sep 17 00:00:00 2001 From: MizovOO Date: Sun, 21 May 2017 20:05:07 +0300 Subject: [PATCH 2/2] Fixed sending of empty message --- src/app/chat-window/chat-window.component.ts | 43 +++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/app/chat-window/chat-window.component.ts b/src/app/chat-window/chat-window.component.ts index a3384c9..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 { @@ -66,13 +67,15 @@ export class ChatWindowComponent implements OnInit { m.thread = this.currentThread; m.isRead = true; m.sentAt = new Date(); - this.messagesService.addMessage(m); - this.draftMessage = new Message(); + 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; } }