mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
608eee8cc2
- add group in progress
217 lines
5.8 KiB
TypeScript
217 lines
5.8 KiB
TypeScript
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
import { ChatService } from 'src/app/services/chat.service';
|
|
import { ConversationPage } from './conversation/conversation.page';
|
|
import { GroupMessagesPage } from './group-messages/group-messages.page';
|
|
import { ContactsPage } from './messages/contacts/contacts.page';
|
|
import { MessagesPage } from './messages/messages.page';
|
|
import { NewGroupPage } from './new-group/new-group.page';
|
|
import { NewchatPage } from './newchat/newchat.page';
|
|
|
|
@Component({
|
|
selector: 'app-chat',
|
|
templateUrl: './chat.page.html',
|
|
styleUrls: ['./chat.page.scss'],
|
|
})
|
|
export class ChatPage implements OnInit {
|
|
|
|
headers: HttpHeaders;
|
|
options:any;
|
|
X_User_Id:any;
|
|
X_Auth_Token:any;
|
|
|
|
showLoader: boolean;
|
|
loggedUser: any;
|
|
/* Set segment variable */
|
|
segment:string;
|
|
allGroups: any[];
|
|
privateGroups: any[];
|
|
publicGroups: any[];
|
|
userConnectedList: any[];
|
|
userRooms: any[];
|
|
userChannels: any[];
|
|
userDirectMessages: any[];
|
|
result:any;
|
|
dmUsers:any;
|
|
|
|
constructor(
|
|
private http:HttpClient,
|
|
private chatService: ChatService,
|
|
private modalController: ModalController,
|
|
private authService: AuthService,
|
|
|
|
) {
|
|
this.headers = new HttpHeaders();
|
|
this.headers = this.headers.set('X-User-Id', 'GqjNWiLrGEHRna7Zn');
|
|
this.headers = this.headers.set('X-Auth-Token', 'SJwIgtlqfloPK696fpc2VBvyDluipuIHKB_0Q6-9ycJ');
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.segment = "Contactos";
|
|
this.authService.userData$.subscribe((res:any)=>{
|
|
this.loggedUser=res;
|
|
console.log(this.loggedUser);
|
|
|
|
});
|
|
this.doRefresh();
|
|
this.loadJoinedRooms();
|
|
}
|
|
loadJoinedRooms(){
|
|
this.chatService.loadJoinedRooms().subscribe(res => {
|
|
console.log(res);
|
|
});
|
|
}
|
|
onSegmentChange(){
|
|
this.doRefresh();
|
|
}
|
|
doRefresh(){
|
|
/* setInterval(()=>{ */
|
|
this.getDirectMessages();
|
|
this.getGroups();
|
|
this.customRoom();
|
|
/* }, 2000); */
|
|
}
|
|
customRoom(){
|
|
let params = new HttpParams();
|
|
params = params.set("types", "c");
|
|
this.chatService.customsRooms(params).subscribe(res=>{
|
|
console.log(res);
|
|
});
|
|
}
|
|
|
|
getDirectMessages(){
|
|
this.showLoader = true;
|
|
|
|
/* this.result = */
|
|
this.chatService.getAllDirectMessages().subscribe((res:any)=>{
|
|
console.log(res.ims);
|
|
|
|
this.userDirectMessages = res.ims.sort((a,b)=>{
|
|
var dateA = new Date(a.lastMessage._updatedAt).getTime();
|
|
var dateB = new Date(b.lastMessage._updatedAt).getTime();
|
|
return dateB - dateA;
|
|
});
|
|
console.log(this.userDirectMessages);
|
|
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
getChatMembers(){
|
|
this.chatService.getMembers(this.userDirectMessages[0]._id).subscribe(res=> {
|
|
this.dmUsers = res['members'].filter(data => data.username != this.loggedUser.me.username)
|
|
/* console.log(res);
|
|
console.log(this.dmUsers); */
|
|
});
|
|
}
|
|
getGroups(){
|
|
this.showLoader = true;
|
|
this.result = this.chatService.getAllPrivateGroups().subscribe((res:any)=>{
|
|
this.privateGroups = res.groups;
|
|
this.result = this.chatService.getAllUserChannels().subscribe((res:any)=>{
|
|
this.publicGroups = res.channels;
|
|
let all = this.privateGroups.concat(this.publicGroups);
|
|
this.allGroups = all.sort((a,b)=>{
|
|
var dateA = new Date(a._updatedAt).getTime();
|
|
var dateB = new Date(b._updatedAt).getTime();
|
|
return dateB - dateA;
|
|
});
|
|
console.log(this.allGroups);
|
|
|
|
this.showLoader = false;
|
|
});
|
|
});
|
|
}
|
|
/* getConnectedChannels(){
|
|
this.showLoader = true;
|
|
|
|
this.result = this.chatService.getAllUserChannels().subscribe((res:any)=>{
|
|
this.userChannels = res.channels;
|
|
console.log(res);
|
|
|
|
this.showLoader = false;
|
|
});
|
|
} */
|
|
|
|
/* getConnectedRooms(){
|
|
this.showLoader = true;
|
|
|
|
this.result = this.chatService.getAllRooms().subscribe((res:any)=>{
|
|
this.userRooms = res.update;
|
|
console.log(res.update);
|
|
|
|
this.showLoader = false;
|
|
});
|
|
} */
|
|
|
|
/* getConnectedUsers(){
|
|
this.showLoader = true;
|
|
|
|
this.result = this.chatService.getAllConnectedUsers().subscribe((res:any)=>{
|
|
this.userConnectedList = res.users;
|
|
|
|
this.showLoader = false;
|
|
});
|
|
} */
|
|
|
|
async startConversation(selectedUser) {
|
|
const modal = await this.modalController.create({
|
|
component: ConversationPage,
|
|
cssClass: 'conversation',
|
|
backdropDismiss: false,
|
|
componentProps: {
|
|
user: selectedUser,
|
|
}
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
async selectContact(){
|
|
const modal = await this.modalController.create({
|
|
component: ContactsPage,
|
|
cssClass: 'contacts',
|
|
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();
|
|
}
|
|
async openMessages(dm:any){
|
|
console.log(dm);
|
|
|
|
const modal = await this.modalController.create({
|
|
component: MessagesPage,
|
|
cssClass: 'group-messages',
|
|
backdropDismiss: false,
|
|
componentProps: {
|
|
dm: dm,
|
|
},
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
async openGroupMessages(room:any){
|
|
console.log(room);
|
|
|
|
const modal = await this.modalController.create({
|
|
component: GroupMessagesPage,
|
|
cssClass: 'group-messages',
|
|
backdropDismiss: false,
|
|
componentProps: {
|
|
room: room,
|
|
},
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
}
|