This commit is contained in:
tiago.kayaya
2021-07-26 15:56:57 +01:00
parent 5f8e932fed
commit 491424768e
+14 -11
View File
@@ -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();
}
});
}
}