mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
Implement add contacts to group-chat
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<div class="div-title">
|
||||
<ion-label class="title">Contactos</ion-label>
|
||||
</div>
|
||||
<app-btn-seguinte *ngIf="groupName" (click)="createGroup()"></app-btn-seguinte>
|
||||
<app-btn-seguinte (click)="createGroup()"></app-btn-seguinte>
|
||||
</div>
|
||||
</div>
|
||||
</ion-toolbar>
|
||||
|
||||
@@ -20,13 +20,14 @@ export class GroupContactsPage implements OnInit {
|
||||
|
||||
headers: HttpHeaders;
|
||||
options:any;
|
||||
|
||||
listContacts: any[];
|
||||
contacts: any;
|
||||
textSearch:string;
|
||||
room:any;
|
||||
dm:any;
|
||||
isGroupCreated:boolean;
|
||||
groupName:string;
|
||||
selectedUserList:any;
|
||||
|
||||
constructor(
|
||||
private modalController: ModalController,
|
||||
@@ -59,7 +60,20 @@ export class GroupContactsPage implements OnInit {
|
||||
};
|
||||
this.chatService.getAllUsers().subscribe((res:any)=>{
|
||||
console.log(res.users);
|
||||
this.contacts = res.users.filter(data => data.username != this.loggedUser.me.username);
|
||||
res.users.forEach(user =>{
|
||||
let usr = {
|
||||
"_id": user._id,
|
||||
"username": user.username,
|
||||
"name":user.name,
|
||||
"isChecked": false,
|
||||
}
|
||||
if(this.listContacts == null){
|
||||
this.listContacts = new Array();
|
||||
}
|
||||
this.listContacts.push(usr);
|
||||
});
|
||||
|
||||
this.contacts = this.listContacts.filter(data => data.username != this.loggedUser.me.username);
|
||||
this.users = this.contacts.sort((a,b) => {
|
||||
if(a.name < b.name){
|
||||
return -1;
|
||||
@@ -69,6 +83,8 @@ export class GroupContactsPage implements OnInit {
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
console.log(this.users);
|
||||
|
||||
this.showLoader = false;
|
||||
});
|
||||
}
|
||||
@@ -121,22 +137,54 @@ export class GroupContactsPage implements OnInit {
|
||||
|
||||
}
|
||||
selectedContact(user:any){
|
||||
this.groupName = this.room.name;
|
||||
console.log(user);
|
||||
|
||||
/* this.groupName = this.room.name; */
|
||||
user.isChecked = !user.isChecked;
|
||||
|
||||
|
||||
}
|
||||
addContacts(room:any){
|
||||
console.log(room);
|
||||
this.selectedUserList = this.users.filter(function(contact) {
|
||||
return contact.isChecked == true;
|
||||
});
|
||||
console.log( this.selectedUserList);
|
||||
this.selectedUserList.forEach(user=>{
|
||||
let body ={
|
||||
"roomId":room._id,
|
||||
"userId":user._id,
|
||||
|
||||
}
|
||||
this.chatService.addUserToGroup(body).subscribe(res=>{
|
||||
console.log(res['success']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
createGroup(){
|
||||
if(!this.isGroupCreated){
|
||||
let body = { "name":this.groupName, }
|
||||
this.chatService.addGroup(body).subscribe(res=>{
|
||||
console.log('group created');
|
||||
console.log(res['group']);
|
||||
this.addContacts(res['group']);
|
||||
this.openGroupMessages(res['group']);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
this.addContacts(this.room);
|
||||
this.openGroupMessages(this.room);
|
||||
/* this.chatService.getGroupInfo(this.room._id).subscribe(res=>{
|
||||
console.log(res);
|
||||
|
||||
this.addContacts(res['group']);
|
||||
this.openGroupMessages(res['group']);
|
||||
}) */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async newGroup(){
|
||||
this.close();
|
||||
const modal = await this.modalController.create({
|
||||
@@ -149,9 +197,6 @@ export class GroupContactsPage implements OnInit {
|
||||
}
|
||||
|
||||
async openGroupMessages(room:any){
|
||||
console.log(room);
|
||||
this.createGroup();
|
||||
this.isGroupCreated=true;
|
||||
this.close();
|
||||
const modal = await this.modalController.create({
|
||||
component: GroupMessagesPage,
|
||||
|
||||
Reference in New Issue
Block a user