diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 16c295461..4e266526d 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -115,7 +115,7 @@ export class ChatPage implements OnInit { private authService: AuthService, private storage:Storage, private resolver: ComponentFactoryResolver, - private router: Router, + private route: Router, ){ this.loggedUserChat = authService.ValidatedUserChat['data']; this.headers = new HttpHeaders(); @@ -355,20 +355,34 @@ hideRefreshButton(){ }); } - getDirectMessages(){ - this.showLoader = true; + async getDirectMessages(){ - this.chatService.getAllDirectMessages().subscribe((res:any)=>{ - console.log(res.ims); + this.chatService.getAllDirectMessages().subscribe(async (res:any)=>{ - this.userDirectMessages = res.ims.sort((a,b)=>{ - var dateA = new Date(a._updatedAt).getTime(); - var dateB = new Date(b._updatedAt).getTime(); - return dateB - dateA; - }); - console.log(this.userDirectMessages); - this.showLoader = false; + if(res.ims != 200){ + console.log(res.ims); + this.userDirectMessages = res.ims.sort((a,b)=>{ + var dateA = new Date(a._updatedAt).getTime(); + var dateB = new Date(b._updatedAt).getTime(); + return dateB - dateA; + }); + console.log(this.userDirectMessages); + if(this.route.url != "/home/chat"){ + console.log("Timer message stop") + } + else { + //Check if modal is opened + if(this.segment == "Contactos"){ + await new Promise(resolve => setTimeout(resolve, 5000)); + await this.getDirectMessages(); + console.log('Timer contactos list running') + } + } + } + else{ + await this.getDirectMessages(); + } }); } @@ -418,9 +432,12 @@ hideRefreshButton(){ console.log(this.dmUsers); }); } - getGroups(){ - this.showLoader = true; - this.result = this.chatService.getAllPrivateGroups().subscribe((res:any)=>{ + + async getGroups(){ + this.result = this.chatService.getAllPrivateGroups().subscribe(async (res:any)=>{ + + if(res.groups != 200){ + this.privateGroups = res.groups; /* this.result = this.chatService.getAllUserChannels().subscribe((res:any)=>{ this.publicGroups = res.channels; */ @@ -431,8 +448,24 @@ hideRefreshButton(){ return dateB - dateA; }); console.log(this.allGroups); - this.showLoader = false; /* }); */ + if(this.route.url != "/home/chat"){ + console.log("Timer message stop") + } + else { + //Check if modal is opened + if(this.segment == "Grupos"){ + await new Promise(resolve => setTimeout(resolve, 5000)); + await this.getGroups(); + console.log('Timer groups list running') + } + } + + } + else{ + await this.getGroups(); + } + }); }