implemented

- get groups contacts
-get messages contacts
-order group conversation list to most recent
-send message in group.
This commit is contained in:
tiago.kayaya
2021-01-19 16:10:40 +01:00
parent b90247b566
commit 3043d519e5
8 changed files with 163 additions and 38 deletions
@@ -1,5 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { ActionSheetController, MenuController, ModalController, PopoverController } from '@ionic/angular';
import { ActionSheetController, MenuController, ModalController, NavParams, PopoverController } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service';
import { ChatOptionsPopoverPage } from 'src/app/shared/popover/chat-options-popover/chat-options-popover.page';
import { ChatPopoverPage } from 'src/app/shared/popover/chat-popover/chat-popover.page';
import { ContactsPage } from '../new-group/contacts/contacts.page';
@@ -11,8 +13,11 @@ import { NewGroupPage } from '../new-group/new-group.page';
styleUrls: ['./group-messages.page.scss'],
})
export class GroupMessagesPage implements OnInit {
loggedUser: any;
message:any;
messages:any;
room:any;
members:any;
contacts: string[] = [" Ana M.", "Andre F.", "Bruno G.", "Catarina T", "Tiago"];
constructor(
@@ -20,9 +25,67 @@ export class GroupMessagesPage implements OnInit {
private modalController: ModalController,
private actionSheetController: ActionSheetController,
public popoverController: PopoverController,
) { }
private chatService: ChatService,
private navParams: NavParams,
private authService: AuthService,
) {
this.room = this.navParams.get('room');
}
ngOnInit() {
this.authService.userData$.subscribe((res:any)=>{
this.loggedUser=res;
console.log(this.loggedUser);
});
this.getGroupContacts();
this.loadGroupMessages()
}
getGroupContacts(){
//If group is private call getGroupMembers
if(this.room.t === 'p'){
this.chatService.getGroupMembers(this.room._id).subscribe(res=>{
console.log(res);
this.members = res['members'];
});
}
//Otherwise call getChannelMembers for públic groups
else{
this.chatService.getChannelMembers(this.room._id).subscribe(res=>{
console.log(res);
this.members = res['members'];
});
}
}
loadGroupMessages(){
//If group is private call getGroupMembers
if(this.room.t === 'p'){
this.chatService.getPrivateGroupMessages(this.room._id).subscribe(res=>{
console.log(res);
this.messages = res['messages'].reverse();
});
}
//Otherwise call getChannelMembers for públic groups
else{
this.chatService.getPublicGroupMessages(this.room._id).subscribe(res=>{
console.log(res);
this.messages = res['messages'].reverse();
});
}
}
sendMessage(){
let body = {
"message":
{
"rid": this.room._id, "msg": this.message
}
}
this.chatService.sendMessage(body).subscribe(res=> {
this.loadGroupMessages();
});
this.message = "";
}
async actionSheet() {