mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 13:55:51 +00:00
296 lines
6.6 KiB
TypeScript
296 lines
6.6 KiB
TypeScript
import { HttpHeaders } from '@angular/common/http';
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
import { ModalController } from '@ionic/angular';
|
|
import * as _ from 'lodash';
|
|
import { ChatService } from 'src/app/services/chat.service';
|
|
import { NewGroupPage } from '../../new-group/new-group.page';
|
|
import { GroupMessagesPage } from '../group-messages.page';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
|
|
|
|
@Component({
|
|
selector: 'app-group-contacts',
|
|
templateUrl: './group-contacts.page.html',
|
|
styleUrls: ['./group-contacts.page.scss'],
|
|
})
|
|
export class GroupContactsPage implements OnInit {
|
|
showLoader: boolean;
|
|
loggedUser: any;
|
|
users = [];
|
|
|
|
contact: string[] = [" Ana M.", "Andre F.", "Bruno G.", "Catarina T", "Tiago"];
|
|
|
|
options:any;
|
|
listContacts: any[];
|
|
contacts: any;
|
|
textSearch:string;
|
|
room:any;
|
|
members:any;
|
|
dm:any;
|
|
isGroupCreated:boolean;
|
|
groupName:string;
|
|
selectedUserList:any;
|
|
sessionStore = SessionStore
|
|
|
|
@Input() roomId:string;
|
|
@Output() openGroupMessage:EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private chatService: ChatService,
|
|
public ThemeService: ThemeService,
|
|
public ChatSystemService: ChatSystemService
|
|
)
|
|
{
|
|
this.loggedUser = SessionStore.user.ChatData['data'];
|
|
this.textSearch="";
|
|
this.dm=null;
|
|
this.room=null;
|
|
}
|
|
|
|
ngOnInit() {
|
|
// this.chatService.refreshtoken();
|
|
//this.getRoomInfo();
|
|
this.loadUsers();
|
|
|
|
this.getChatInfo();
|
|
//
|
|
}
|
|
|
|
getChatInfo(){
|
|
|
|
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
|
|
|
|
|
|
this.getGroupContacts(room['room']);
|
|
});
|
|
}
|
|
deleteMember(data:any){
|
|
|
|
|
|
let body = {
|
|
"roomId": this.roomId,
|
|
"userId": data._id,
|
|
}
|
|
|
|
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
|
|
if(room['room'].t == "p"){
|
|
this.chatService.removeGroupMember(body).subscribe(res=>{
|
|
|
|
this.getMembers();
|
|
this.getChatInfo();
|
|
});
|
|
}
|
|
else if(room['room'].t == "c"){
|
|
this.chatService.removeChannelMember(body).subscribe(res=>{
|
|
|
|
this.getMembers();
|
|
this.getChatInfo();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
getMembers(){
|
|
this.chatService.getRoomInfo(this.roomId).subscribe(res=>{
|
|
|
|
let room = res['room'];
|
|
|
|
if(room.t == "p"){
|
|
this.chatService.getGroupMembers(this.roomId).subscribe(res=>{
|
|
this.members = res['members'];
|
|
});
|
|
}
|
|
else if(room.t == "c"){
|
|
this.chatService.getChannelMembers(this.roomId).subscribe(res=>{
|
|
this.members = res['members'];
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
getGroupContacts(room:any){
|
|
this.showLoader = true;
|
|
if(room.t === 'p'){
|
|
this.chatService.getGroupMembers(this.roomId).subscribe(res=>{
|
|
this.members = res['members'];
|
|
this.loadUsers1(this.members);
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
else{
|
|
this.chatService.getChannelMembers(this.roomId).subscribe(res=>{
|
|
this.members = res['members'];
|
|
this.loadUsers1(this.members);
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
updateGroup(){
|
|
this.showLoader = true;
|
|
this.addContacts(this.roomId);
|
|
this.openGroupMessage.emit(this.roomId);
|
|
this.showLoader = false;
|
|
}
|
|
openGroupMessagesPage(){
|
|
this.showLoader = true;
|
|
this.openGroupMessage.emit(this.roomId)
|
|
this.showLoader = false;
|
|
}
|
|
|
|
loadUsers1(members:any) {
|
|
|
|
this.chatService.getAllUsers().subscribe((res:any)=>{
|
|
|
|
|
|
|
|
if(members){
|
|
this.contacts = res.users.filter(f => !this.members.some(item => item._id === f._id));
|
|
}
|
|
else{
|
|
this.contacts = res.users.filter(data => data.username != this.sessionStore.user.UserName);
|
|
}
|
|
|
|
this.users = this.contacts.sort((a,b) => {
|
|
if(a.name < b.name){
|
|
return -1;
|
|
}
|
|
if(a.name > b.name){
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
|
|
loadUsers(){
|
|
|
|
this.chatService.getAllUsers().subscribe((res:any)=>{
|
|
|
|
|
|
|
|
if(this.members){
|
|
this.contacts = res.users.filter(f => !this.members.some(item => item._id === f._id));
|
|
}
|
|
else{
|
|
this.contacts = res.users.filter(data => data.username != this.sessionStore.user.UserName);
|
|
}
|
|
|
|
this.users = this.contacts.sort((a,b) => {
|
|
if(a.name < b.name){
|
|
return -1;
|
|
}
|
|
if(a.name > b.name){
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
|
|
separateLetter(record, recordIndex, records){
|
|
if(recordIndex == 0){
|
|
return record.name[0];
|
|
}
|
|
|
|
let first_prev = records[recordIndex - 1].name[0];
|
|
let first_current = record.name[0];
|
|
|
|
if(first_prev != first_current){
|
|
return first_current;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
doRefresh(ev){
|
|
ev.target.complete();
|
|
}
|
|
|
|
async close(){
|
|
this.modalController.dismiss();
|
|
if(this.isGroupCreated){
|
|
|
|
}
|
|
else{
|
|
this.modalController.dismiss();
|
|
|
|
const modal = await this.modalController.create({
|
|
component: NewGroupPage,
|
|
componentProps: {
|
|
name:this.groupName,
|
|
duration:'',
|
|
},
|
|
cssClass: 'new-group modal-desktop',
|
|
backdropDismiss: false,
|
|
});
|
|
await modal.present();
|
|
}
|
|
}
|
|
|
|
onChange(event){
|
|
this.textSearch = event.detail.value;
|
|
}
|
|
|
|
clicked(){
|
|
|
|
}
|
|
|
|
selectedContact(user:any){
|
|
/* this.groupName = this.room.name; */
|
|
user.isChecked = !user.isChecked;
|
|
}
|
|
|
|
addContacts(roomId:any){
|
|
|
|
this.selectedUserList = this.users.filter(function(contact) {
|
|
return contact.isChecked == true;
|
|
});
|
|
|
|
this.selectedUserList.forEach(user=>{
|
|
let body ={
|
|
"roomId":roomId,
|
|
"userId":user._id,
|
|
}
|
|
this.chatService.addUserToGroup(body).subscribe(res=>{
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
async newGroup(){
|
|
this.close();
|
|
const modal = await this.modalController.create({
|
|
component: NewGroupPage,
|
|
cssClass: 'new-group modal-desktop',
|
|
backdropDismiss: false,
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
|
|
async openGroupMessages(room:any){
|
|
this.close();
|
|
const modal = await this.modalController.create({
|
|
component: GroupMessagesPage,
|
|
componentProps: {
|
|
room: room,
|
|
},
|
|
cssClass: 'group-messages',
|
|
backdropDismiss: false
|
|
});
|
|
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
|
|
}
|