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';
|
2021-01-04 12:00:04 +01:00
|
|
|
import { ContactsPage } from './messages/contacts/contacts.page';
|
2021-01-07 09:39:36 +01:00
|
|
|
import { MessagesPage } from './messages/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 {
|
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-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";
|
2020-12-16 15:07:28 +01:00
|
|
|
this.doRefresh();
|
2021-01-04 12:00:04 +01:00
|
|
|
/* this.authService.getUserData(); */
|
2020-12-16 15:07:28 +01:00
|
|
|
|
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(){
|
2021-01-07 09:39:36 +01:00
|
|
|
/* this.getGroups(); */
|
2020-12-16 15:07:28 +01:00
|
|
|
this.getConnectedUsers();
|
2020-09-10 09:48:37 +01:00
|
|
|
}
|
2021-01-07 09:39:36 +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
|
|
|
});
|
2021-01-07 09:39:36 +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;
|
2021-01-07 09:39:36 +01:00
|
|
|
|
2020-11-03 11:52:21 +01:00
|
|
|
this.result = this.chatService.getAllConnectedUsers().subscribe((res:any)=>{
|
2021-01-07 09:39:36 +01:00
|
|
|
/* this.userConnectedList = res.users; */
|
|
|
|
|
/* console.log(res); */
|
|
|
|
|
|
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-12-21 16:37:44 +01:00
|
|
|
async selectContact(){
|
|
|
|
|
const modal = await this.modalController.create({
|
2021-01-04 12:00:04 +01:00
|
|
|
component: ContactsPage,
|
|
|
|
|
cssClass: 'contacts',
|
2020-12-21 16:37:44 +01:00
|
|
|
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-30 11:13:50 +01:00
|
|
|
async openMessages(){
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: MessagesPage,
|
|
|
|
|
cssClass: 'group-messages',
|
|
|
|
|
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
|
|
|
}
|