This commit is contained in:
Peter Maquiran
2021-08-19 11:32:08 +01:00
30 changed files with 162 additions and 145 deletions
+41 -55
View File
@@ -11,6 +11,7 @@ import { ProfileComponent } from '../../headers/header-no-search/profile/profile
import { ContactsPage } from '../new-group/contacts/contacts.page';
import { Router } from '@angular/router';
import { connection } from 'src/app/services/socket/synchro.service';
import { ChatOptionsFeaturesPage } from 'src/app/modals/chat-options-features/chat-options-features.page';
@Component({
selector: 'app-messages',
@@ -50,20 +51,7 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
) {
this.loggedUser = authService.ValidatedUserChat['data'];
this.connection.callback = function() {
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
if (res == 502) {
} else if (res != 200) {
this.messages = res['messages'].reverse();
console.log(this.messages);
}
});
}
this.connection.callback = this.load
/* this.dm = this.navParams.get('dm'); */
}
@@ -71,6 +59,17 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
this.load();
//throw new Error('Method not implemented.');
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
if (res == 502) {
} else if (res != 200) {
this.messages = res['messages'].reverse();
console.log(this.messages);
}
});
}
ngOnInit() {
@@ -98,7 +97,7 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
}
load(){
load = ()=>{
this.checktimeOut = true;
this.serverLongPull();
this.getChatMembers();
@@ -191,7 +190,7 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
}
openSendMessageOptions(ev?:any){
if(window.innerWidth <= 1024){
if(window.innerWidth < 701){
console.log('mobile');
this.openChatOptions(ev);
}
@@ -289,22 +288,10 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
return enterAnimation(baseEl).direction('reverse');
}
/* const popover = await this.popoverController.create({
component: MessagesOptionsPage,
componentProps: {
roomId: this.dm._id,
},
cssClass: 'messages-options',
event: ev,
translucent: true,
});
return await popover.present(); */
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
component: ChatOptionsPopoverPage,
component: ChatOptionsFeaturesPage,
cssClass: 'model profile-modal search-submodal',
componentProps: {
roomId: this.roomId,
@@ -314,36 +301,35 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
}
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")
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 {
await new Promise(resolve => setTimeout(resolve, 1000));
await this.serverLongPull();
console.log('Timer message running')
// Got message
//let message = await response.text();
//this.loadMessages()
//await this.serverLongPull();
}
} else {
// Got message
//let message = await response.text();
//this.loadMessages()
await this.serverLongPull();
}
});
});
}
}