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

100 lines
2.6 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';
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-12-28 10:11:00 +01:00
import { GroupMessagesPage } from './group-messages/group-messages.page';
2020-12-21 16:37:44 +01:00
import { NewGroupPage } from './new-group/new-group.page';
import { NewchatPage } from './newchat/newchat.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;
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-12-29 12:40:19 +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";
this.doRefresh();
2020-12-21 16:37:44 +01:00
this.authService.getUserData();
2020-09-10 09:48:37 +01:00
}
2020-10-30 15:22:35 +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
});
}
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-12-21 16:37:44 +01:00
async selectContact(){
const modal = await this.modalController.create({
component: NewchatPage,
cssClass: 'newchat',
backdropDismiss: false,
});
await modal.present();
modal.onDidDismiss();
}
async newGroup(){
const modal = await this.modalController.create({
component: NewGroupPage,
cssClass: 'new-group',
backdropDismiss: false,
});
await modal.present();
modal.onDidDismiss();
}
2020-12-28 10:11:00 +01:00
async openGroupMessages(){
const modal = await this.modalController.create({
component: GroupMessagesPage,
cssClass: 'group-messages',
backdropDismiss: false,
});
await modal.present();
modal.onDidDismiss();
}
2020-09-10 09:48:37 +01:00
}