Longpull added to mobile

This commit is contained in:
Eudes Inácio
2021-07-26 19:31:19 +01:00
parent 491424768e
commit 0201e0b571
5 changed files with 129 additions and 4 deletions
+35 -1
View File
@@ -1,4 +1,5 @@
import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import {Router} from '@angular/router'
import { ModalController, NavParams, PopoverController } from '@ionic/angular';
import { Status } from 'src/app/models/chat/status.model';
import { ContactsPage } from 'src/app/pages/chat/messages/contacts/contacts.page';
@@ -37,6 +38,7 @@ export class MessagesPage implements OnInit, AfterViewChecked {
private authService: AuthService,
private alertService: AlertService,
private toastService: ToastService,
private route: Router
) {
this.loggedUser = authService.ValidatedUserChat['data'];
this.roomId = this.navParams.get('roomId');
@@ -63,7 +65,7 @@ export class MessagesPage implements OnInit, AfterViewChecked {
}
load(){
this.loadMessages();
this.serverLongPull();
this.getChatMembers();
}
@@ -150,4 +152,36 @@ async openChatOptions(ev?: any) {
return await popover.present();
}
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();
} else if (res != 200) {
// Show Error
//showMessage(response.statusText);
//this.loadMessages()
this.messages = res['messages'].reverse();
console.log(this.messages);
// Reconnect in one second
if(this.route.url != "/home/chat"){
console.log("Timer message stop")
} else {
await new Promise(resolve => setTimeout(resolve, 1000));
await this.serverLongPull();
console.log('Timer message running')
}
} else {
// Got message
//let message = await response.text();
//this.loadMessages()
await this.serverLongPull();
}
});
}
}