2020-09-10 09:48:37 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2020-11-03 11:52:21 +01:00
|
|
|
import { ModalController } from '@ionic/angular';
|
2020-10-30 15:22:35 +01:00
|
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
|
|
|
import { ChatService } from 'src/app/services/chat.service';
|
2020-11-03 11:52:21 +01:00
|
|
|
import { ConversationPage } from './conversation/conversation.page';
|
2020-09-10 09:48:37 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-chat',
|
|
|
|
|
templateUrl: './chat.page.html',
|
|
|
|
|
styleUrls: ['./chat.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class ChatPage implements OnInit {
|
2020-12-16 15:07:28 +01:00
|
|
|
showLoader: boolean;
|
2020-10-30 15:22:35 +01:00
|
|
|
loggedUser: any;
|
|
|
|
|
/* Set segment variable */
|
|
|
|
|
segment:string;
|
|
|
|
|
groupList: any[];
|
2020-11-03 11:52:21 +01:00
|
|
|
userConnectedList: any[];
|
2020-10-30 15:22:35 +01:00
|
|
|
result:any;
|
2020-09-10 09:48:37 +01:00
|
|
|
|
2020-10-30 15:22:35 +01:00
|
|
|
constructor(
|
|
|
|
|
private chatService: ChatService,
|
2020-11-03 11:52:21 +01:00
|
|
|
private modalController: ModalController,
|
2020-10-30 15:22:35 +01:00
|
|
|
private authService: AuthService) { }
|
2020-09-10 09:48:37 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-10-30 15:22:35 +01:00
|
|
|
this.segment = "Contactos";
|
2020-12-16 15:07:28 +01:00
|
|
|
this.doRefresh();
|
|
|
|
|
|
2020-09-10 09:48:37 +01:00
|
|
|
}
|
2020-10-30 15:22:35 +01:00
|
|
|
onSegmentChange(){
|
2020-12-16 15:07:28 +01:00
|
|
|
this.doRefresh();
|
|
|
|
|
}
|
|
|
|
|
doRefresh(){
|
|
|
|
|
this.getGroups();
|
|
|
|
|
this.getConnectedUsers();
|
2020-09-10 09:48:37 +01:00
|
|
|
}
|
2020-11-03 11:52:21 +01:00
|
|
|
getGroups(){
|
2020-12-16 15:07:28 +01:00
|
|
|
this.showLoader = true;
|
2020-11-03 11:52:21 +01:00
|
|
|
this.result = this.chatService.getAllPrivateGroups().subscribe((res:any)=>{
|
|
|
|
|
this.groupList = res.groups;
|
2020-12-16 15:07:28 +01:00
|
|
|
this.showLoader = false;
|
2020-11-03 11:52:21 +01:00
|
|
|
});
|
|
|
|
|
}
|
2020-12-16 15:07:28 +01:00
|
|
|
|
2020-11-03 11:52:21 +01:00
|
|
|
getConnectedUsers(){
|
2020-12-16 15:07:28 +01:00
|
|
|
this.showLoader = true;
|
2020-11-03 11:52:21 +01:00
|
|
|
this.result = this.chatService.getAllConnectedUsers().subscribe((res:any)=>{
|
|
|
|
|
this.userConnectedList = res.users;
|
|
|
|
|
console.log(this.userConnectedList);
|
2020-12-16 15:07:28 +01:00
|
|
|
this.showLoader = false;
|
2020-11-03 11:52:21 +01:00
|
|
|
});
|
|
|
|
|
}
|
2020-12-16 15:07:28 +01:00
|
|
|
|
2020-12-16 16:06:14 +01:00
|
|
|
async startConversation(selectedUser) {
|
2020-11-03 11:52:21 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: ConversationPage,
|
|
|
|
|
cssClass: 'conversation',
|
|
|
|
|
backdropDismiss: false,
|
|
|
|
|
componentProps: {
|
|
|
|
|
user: selectedUser,
|
|
|
|
|
}
|
2020-10-30 15:22:35 +01:00
|
|
|
});
|
2020-11-03 11:52:21 +01:00
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss();
|
|
|
|
|
}
|
2020-09-10 09:48:37 +01:00
|
|
|
}
|