-add start direct message method from mobile App

- more improvements
This commit is contained in:
tiago.kayaya
2021-01-14 16:51:16 +01:00
parent 859bccc076
commit 48dbaa7744
7 changed files with 105 additions and 29 deletions
@@ -20,6 +20,8 @@ export class ContactsPage implements OnInit {
options:any;
contacts:any;
textSearch:string;
room:any;
dm:any;
constructor(
private modalController: ModalController,
@@ -32,6 +34,8 @@ export class ContactsPage implements OnInit {
this.loggedUser=res;
});
this.textSearch="";
this.dm=null;
this.room=null;
}
ngOnInit() {
@@ -46,10 +50,8 @@ export class ContactsPage implements OnInit {
this.options = {
headers: this.headers,
};
this.chatService.getAllUsers().subscribe((res:any)=>{
console.log(res.users);
this.contacts = res.users.filter(data => data.username != this.loggedUser.me.username);
this.users = this.contacts.sort((a,b) => {
if(a.name < b.name){
@@ -60,11 +62,8 @@ export class ContactsPage implements OnInit {
}
return 0;
});
this.showLoader = false;
});
}
separateLetter(record, recordIndex, records){
@@ -90,17 +89,65 @@ export class ContactsPage implements OnInit {
clicked(){
console.log('clicked');
}
async openMessages(){
createRoom(username:string){
let body = {
username: username,
}
this.chatService.createRoom(body).subscribe(res => {
console.log(res);
this.room = res['room'];
this.getDirectMessage(this.room._id);
});
}
getDirectMessage(roomId:any){
console.log(roomId);
this.chatService.getAllDirectMessages().subscribe(res=>{
let result = res['ims'].filter(data => data._id == roomId);
this.dm = result[0];
console.log(this.dm);
this.openModal(this.dm);
});
}
async openModal(dm:any){
this.close();
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 openMessages(username:string){
/* this.close(); */
let dm:any;
//Create new room
this.createRoom(username);
//Get direct messages (dm)
/* this.getDirectMessage(this.room._id); */
console.log(this.dm);
/* const modal = await this.modalController.create({
component: MessagesPage,
cssClass: 'group-messages',
backdropDismiss: false,
componentProps: {
dm: dm,
},
});
await modal.present();
modal.onDidDismiss(); */
}
}