Files
doneit-web/src/app/pages/chat/chat.page.ts
T

68 lines
1.7 KiB
TypeScript
Raw Normal View History

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';
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 {
showLoader: boolean;
loggedUser: any;
/* Set segment variable */
segment:string;
groupList: any[];
2020-11-03 11:52:21 +01:00
userConnectedList: any[];
result:any;
2020-09-10 09:48:37 +01:00
constructor(
private chatService: ChatService,
2020-11-03 11:52:21 +01:00
private modalController: ModalController,
private authService: AuthService) { }
2020-09-10 09:48:37 +01:00
ngOnInit() {
this.segment = "Contactos";
this.doRefresh();
2020-09-10 09:48:37 +01:00
}
onSegmentChange(){
this.doRefresh();
}
doRefresh(){
this.getGroups();
this.getConnectedUsers();
2020-09-10 09:48:37 +01:00
}
2020-11-03 11:52:21 +01:00
getGroups(){
this.showLoader = true;
2020-11-03 11:52:21 +01:00
this.result = this.chatService.getAllPrivateGroups().subscribe((res:any)=>{
this.groupList = res.groups;
this.showLoader = false;
2020-11-03 11:52:21 +01:00
});
}
2020-11-03 11:52:21 +01:00
getConnectedUsers(){
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);
this.showLoader = false;
2020-11-03 11:52:21 +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-11-03 11:52:21 +01:00
await modal.present();
modal.onDidDismiss();
}
2020-09-10 09:48:37 +01:00
}