diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index bb63de878..7fe657a88 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -58,7 +58,7 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges { this.load(); /* }, 9000); */ console.log(this.roomId); - + } @@ -68,7 +68,7 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges { } load(){ - this.loadMessages(); + this.serverLongPull(); this.getChatMembers(); } @@ -100,7 +100,6 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges { } this.chatService.sendMessage(body).subscribe(res=> { - this.loadMessages(); }); this.message = ""; } @@ -111,7 +110,7 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges { console.log(res); this.messages = res['messages'].reverse(); console.log(this.messages); - this.serverLongPull(res) + //this.serverLongPull(res) /* this.chatService.subscribe(this.roomId).then(res => { console.log("Real fake msg", res) }); */ @@ -280,27 +279,31 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges { return await modal.present(); } - async serverLongPull(res){ + async serverLongPull(){ + this.chatService.getRoomMessages(this.roomId).subscribe(async res => { + if (res == 502) { // Connection timeout // happens when the connection was pending for too long // let's reconnect - await this.serverLongPull(res); + await this.serverLongPull(); } else if (res != 200) { // Show Error //showMessage(response.statusText); - this.loadMessages() + //this.loadMessages() + this.messages = res['messages'].reverse(); + console.log(this.messages); // Reconnect in one second await new Promise(resolve => setTimeout(resolve, 1000)); - await this.serverLongPull(res); + await this.serverLongPull(); } else { // Got message //let message = await response.text(); - this.loadMessages() - await this.serverLongPull(res); + //this.loadMessages() + await this.serverLongPull(); } + }); } - }