2021-03-17 11:13:09 +01:00
|
|
|
import { Component, OnChanges, OnInit, Input, SimpleChanges, Output, EventEmitter} from '@angular/core';
|
2021-03-18 09:25:59 +01:00
|
|
|
import { ActionSheetController, AnimationController, MenuController, ModalController, PopoverController } from '@ionic/angular';
|
2021-04-13 14:14:55 +01:00
|
|
|
import { AlertService } from 'src/app/services/alert.service';
|
2021-03-04 18:50:26 +01:00
|
|
|
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';
|
|
|
|
|
import { NewGroupPage } from '../new-group/new-group.page';
|
|
|
|
|
import { GroupContactsPage } from './group-contacts/group-contacts.page';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-group-messages',
|
|
|
|
|
templateUrl: './group-messages.page.html',
|
|
|
|
|
styleUrls: ['./group-messages.page.scss'],
|
|
|
|
|
})
|
2021-03-12 11:56:54 +01:00
|
|
|
export class GroupMessagesPage implements OnInit, OnChanges {
|
2021-03-04 18:50:26 +01:00
|
|
|
showLoader: boolean;
|
|
|
|
|
isGroupCreated:boolean;
|
|
|
|
|
loggedUser: any;
|
|
|
|
|
message:any;
|
2021-04-20 17:18:57 +01:00
|
|
|
leaveStatus:any;
|
2021-03-04 18:50:26 +01:00
|
|
|
messages:any;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
room:any;
|
2021-04-15 23:57:14 +01:00
|
|
|
roomName:any;
|
2021-03-04 18:50:26 +01:00
|
|
|
members:any;
|
2021-03-12 11:56:54 +01:00
|
|
|
|
|
|
|
|
@Input() roomId:string;
|
2021-04-15 23:57:14 +01:00
|
|
|
@Output() closeAllDesktopComponents:EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
@Output() showEmptyContainer:EventEmitter<any> = new EventEmitter<any>();
|
2021-03-17 11:13:09 +01:00
|
|
|
@Output() openGroupContacts:EventEmitter<any> = new EventEmitter<any>();
|
2021-04-16 11:25:10 +01:00
|
|
|
@Output() openEditGroupPage:EventEmitter<any> = new EventEmitter<any>();
|
2021-03-04 18:50:26 +01:00
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private menu: MenuController,
|
|
|
|
|
private modalController: ModalController,
|
|
|
|
|
private actionSheetController: ActionSheetController,
|
|
|
|
|
public popoverController: PopoverController,
|
|
|
|
|
private chatService: ChatService,
|
|
|
|
|
private authService: AuthService,
|
2021-03-18 09:25:59 +01:00
|
|
|
private animationController: AnimationController,
|
2021-04-13 14:14:55 +01:00
|
|
|
private alertService: AlertService,
|
2021-03-04 18:50:26 +01:00
|
|
|
) {
|
|
|
|
|
this.isGroupCreated = true;
|
2021-03-12 11:56:54 +01:00
|
|
|
}
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
|
this.getRoomInfo();
|
2021-03-04 18:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.authService.userData$.subscribe((res:any)=>{
|
|
|
|
|
this.loggedUser=res;
|
|
|
|
|
console.log(this.loggedUser);
|
|
|
|
|
});
|
2021-03-12 11:56:54 +01:00
|
|
|
this.getRoomInfo();
|
|
|
|
|
console.log(this.roomId);
|
2021-03-17 11:13:09 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-13 14:14:55 +01:00
|
|
|
notImplemented(){
|
|
|
|
|
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 11:13:09 +01:00
|
|
|
openGroupContactsPage(){
|
|
|
|
|
this.openGroupContacts.emit(this.roomId);
|
2021-03-04 18:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(){
|
|
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doRefresh(ev:any){
|
2021-03-12 11:56:54 +01:00
|
|
|
this.getRoomInfo();
|
2021-03-04 18:50:26 +01:00
|
|
|
ev.target.complete();
|
|
|
|
|
}
|
2021-03-12 11:56:54 +01:00
|
|
|
get watch(){
|
|
|
|
|
this.getRoomInfo();
|
|
|
|
|
console.log('here watching');
|
|
|
|
|
|
|
|
|
|
return this.roomId;
|
|
|
|
|
}
|
|
|
|
|
getRoomInfo(){
|
|
|
|
|
this.showLoader = true;
|
|
|
|
|
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
|
|
|
|
|
this.room = room['room'];
|
2021-04-15 23:57:14 +01:00
|
|
|
this.roomName = this.room.name.split('-').join(' ');
|
2021-03-12 11:56:54 +01:00
|
|
|
this.getGroupContacts(this.room);
|
|
|
|
|
this.loadGroupMessages(this.room);
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-04 18:50:26 +01:00
|
|
|
|
2021-03-12 11:56:54 +01:00
|
|
|
getGroupContacts(room:any){
|
2021-03-04 18:50:26 +01:00
|
|
|
this.showLoader = true;
|
|
|
|
|
//If group is private call getGroupMembers
|
2021-03-12 11:56:54 +01:00
|
|
|
if(room.t === 'p'){
|
|
|
|
|
this.chatService.getGroupMembers(this.roomId).subscribe(res=>{
|
2021-03-04 18:50:26 +01:00
|
|
|
console.log(res);
|
|
|
|
|
this.members = res['members'];
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//Otherwise call getChannelMembers for públic groups
|
|
|
|
|
else{
|
2021-03-12 11:56:54 +01:00
|
|
|
this.chatService.getChannelMembers(this.roomId).subscribe(res=>{
|
2021-03-04 18:50:26 +01:00
|
|
|
console.log(res);
|
|
|
|
|
this.members = res['members'];
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-12 11:56:54 +01:00
|
|
|
loadGroupMessages(room:any){
|
|
|
|
|
console.log('here'+room.t);
|
|
|
|
|
|
2021-03-04 18:50:26 +01:00
|
|
|
this.showLoader = true;
|
|
|
|
|
//If group is private call getGroupMembers
|
2021-03-12 11:56:54 +01:00
|
|
|
if(room.t === 'p'){
|
|
|
|
|
console.log('private');
|
|
|
|
|
|
|
|
|
|
this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res=>{
|
2021-03-04 18:50:26 +01:00
|
|
|
console.log(res);
|
|
|
|
|
let msgOnly = res['messages'].filter(data => data.t != 'au');
|
|
|
|
|
this.messages = msgOnly.reverse();
|
2021-03-12 11:56:54 +01:00
|
|
|
console.log(res);
|
|
|
|
|
|
2021-03-04 18:50:26 +01:00
|
|
|
this.showLoader = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//Otherwise call getChannelMembers for públic groups
|
|
|
|
|
else{
|
2021-03-12 11:56:54 +01:00
|
|
|
this.chatService.getPublicGroupMessages(this.roomId).subscribe(res=>{
|
2021-03-04 18:50:26 +01:00
|
|
|
console.log(res);
|
|
|
|
|
this.messages = res['messages'].reverse();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sendMessage(){
|
|
|
|
|
|
|
|
|
|
let body = {
|
|
|
|
|
"message":
|
|
|
|
|
{
|
2021-03-12 11:56:54 +01:00
|
|
|
"rid": this.roomId, "msg": this.message
|
2021-03-04 18:50:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.chatService.sendMessage(body).subscribe(res=> {
|
2021-03-12 11:56:54 +01:00
|
|
|
/* this.loadGroupMessages(); */
|
|
|
|
|
this.getRoomInfo();
|
2021-03-04 18:50:26 +01:00
|
|
|
});
|
|
|
|
|
this.message = "";
|
|
|
|
|
}
|
2021-03-18 09:25:59 +01:00
|
|
|
async openGroupMessagesOptions() {
|
|
|
|
|
|
|
|
|
|
const enterAnimation = (baseEl: any) => {
|
|
|
|
|
const backdropAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('ion-backdrop')!)
|
|
|
|
|
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
|
|
|
|
|
|
|
|
|
|
const wrapperAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('.modal-wrapper')!)
|
|
|
|
|
.keyframes([
|
|
|
|
|
{ offset: 0, opacity: '1', right: '-100%' },
|
|
|
|
|
{ offset: 1, opacity: '1', right: '0px' }
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return this.animationController.create()
|
|
|
|
|
.addElement(baseEl)
|
|
|
|
|
.easing('ease-out')
|
|
|
|
|
.duration(500)
|
|
|
|
|
.addAnimation([backdropAnimation, wrapperAnimation]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const leaveAnimation = (baseEl: any) => {
|
|
|
|
|
return enterAnimation(baseEl).direction('reverse');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* const popover = await this.popoverController.create({
|
|
|
|
|
component: MessagesOptionsPage,
|
|
|
|
|
componentProps: {
|
|
|
|
|
roomId: this.dm._id,
|
|
|
|
|
},
|
|
|
|
|
cssClass: 'messages-options',
|
|
|
|
|
event: ev,
|
|
|
|
|
translucent: true,
|
|
|
|
|
});
|
|
|
|
|
return await popover.present(); */
|
|
|
|
|
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
enterAnimation,
|
|
|
|
|
leaveAnimation,
|
|
|
|
|
component: ChatPopoverPage,
|
|
|
|
|
cssClass: 'model profile-modal search-submodal',
|
|
|
|
|
componentProps: {
|
|
|
|
|
roomId: this.roomId,
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-04-15 23:57:14 +01:00
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss().then(res=>{
|
|
|
|
|
console.log(res);
|
|
|
|
|
if(res.data == 'leave'){
|
2021-04-20 17:18:57 +01:00
|
|
|
this.leaveStatus = this.loggedUser.me.name + ' saiu do grupo';
|
2021-04-15 23:57:14 +01:00
|
|
|
}
|
|
|
|
|
else if(res.data == 'delete'){
|
|
|
|
|
this.closeAllDesktopComponents.emit();
|
|
|
|
|
this.showEmptyContainer.emit();
|
|
|
|
|
}
|
|
|
|
|
else if(res.data == 'cancel'){
|
|
|
|
|
console.log('CANCEL');
|
|
|
|
|
}
|
2021-04-16 09:57:08 +01:00
|
|
|
else if(res.data == 'edit'){
|
2021-04-16 11:25:10 +01:00
|
|
|
console.log(this.roomId);
|
|
|
|
|
//this.closeAllDesktopComponents.emit();
|
|
|
|
|
this.openEditGroupPage.emit(this.roomId);
|
2021-04-16 09:57:08 +01:00
|
|
|
}
|
2021-04-15 23:57:14 +01:00
|
|
|
else{
|
|
|
|
|
this.roomName = res.data.name.split('-').join(' ');
|
|
|
|
|
console.log(this.roomName);
|
|
|
|
|
|
|
|
|
|
this.getRoomInfo();
|
|
|
|
|
//this.modalController.dismiss();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|
2021-03-18 09:25:59 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
openSendGroupMessageOptions(ev: any){
|
|
|
|
|
if(window.innerWidth <= 1024){
|
|
|
|
|
console.log('mobile');
|
|
|
|
|
this.openChatOptions(ev);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
console.log('desktop');
|
|
|
|
|
this._openChatOptions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 18:50:26 +01:00
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
async openOptions(ev: any) {
|
2021-03-04 18:50:26 +01:00
|
|
|
const popover = await this.popoverController.create({
|
|
|
|
|
component: ChatPopoverPage,
|
|
|
|
|
cssClass: 'chat-popover',
|
|
|
|
|
event: ev,
|
|
|
|
|
componentProps: {
|
|
|
|
|
room: this.room,
|
|
|
|
|
},
|
|
|
|
|
translucent: true
|
|
|
|
|
});
|
|
|
|
|
await popover.present();
|
|
|
|
|
popover.onDidDismiss().then(res=>{
|
|
|
|
|
console.log(res);
|
|
|
|
|
if(res.data){
|
2021-03-18 16:30:03 +01:00
|
|
|
this.getRoomInfo();
|
2021-03-12 11:56:54 +01:00
|
|
|
//this.modalController.dismiss();
|
2021-03-04 18:50:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
async openChatOptions(ev: any) {
|
|
|
|
|
const popover = await this.popoverController.create({
|
|
|
|
|
component: ChatOptionsPopoverPage,
|
|
|
|
|
cssClass: 'chat-options-popover',
|
|
|
|
|
event: ev,
|
|
|
|
|
componentProps: {
|
|
|
|
|
room: this.room,
|
|
|
|
|
},
|
|
|
|
|
translucent: true
|
|
|
|
|
});
|
|
|
|
|
return await popover.present();
|
|
|
|
|
}
|
|
|
|
|
async addContacts(){
|
|
|
|
|
console.log(this.members);
|
|
|
|
|
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: GroupContactsPage,
|
|
|
|
|
componentProps: {
|
|
|
|
|
isCreated: this.isGroupCreated,
|
|
|
|
|
room: this.room,
|
|
|
|
|
members: this.members,
|
|
|
|
|
name: this.room.name,
|
|
|
|
|
},
|
|
|
|
|
cssClass: 'contacts',
|
|
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await modal.present();
|
|
|
|
|
|
|
|
|
|
modal.onDidDismiss().then(()=>{
|
2021-03-18 16:30:03 +01:00
|
|
|
this.getRoomInfo();
|
2021-03-04 18:50:26 +01:00
|
|
|
});
|
|
|
|
|
}
|
2021-03-18 16:30:03 +01:00
|
|
|
|
2021-03-04 18:50:26 +01:00
|
|
|
/* async actionSheet() {
|
|
|
|
|
const actionSheet = await this.actionSheetController.create({
|
|
|
|
|
cssClass: 'my-custom-class',
|
|
|
|
|
buttons: [{
|
|
|
|
|
text: 'Sair do grupo',
|
|
|
|
|
handler: () => {
|
|
|
|
|
console.log('Delete clicked');
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
text: 'Alterar nome do grupo1',
|
|
|
|
|
handler: () => {
|
|
|
|
|
console.log('Alterar nome do grupo');
|
|
|
|
|
this.openChangeGroupName()
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
text: 'Apagar o grupo',
|
|
|
|
|
handler: () => {
|
|
|
|
|
console.log('Play clicked');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
await actionSheet.present();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
async _openChatOptions() {
|
|
|
|
|
|
|
|
|
|
const enterAnimation = (baseEl: any) => {
|
|
|
|
|
const backdropAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('ion-backdrop')!)
|
|
|
|
|
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
|
|
|
|
|
|
|
|
|
|
const wrapperAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('.modal-wrapper')!)
|
|
|
|
|
.keyframes([
|
|
|
|
|
{ offset: 0, opacity: '1', right: '-100%' },
|
|
|
|
|
{ offset: 1, opacity: '1', right: '0px' }
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return this.animationController.create()
|
|
|
|
|
.addElement(baseEl)
|
|
|
|
|
.easing('ease-out')
|
|
|
|
|
.duration(500)
|
|
|
|
|
.addAnimation([backdropAnimation, wrapperAnimation]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const leaveAnimation = (baseEl: any) => {
|
|
|
|
|
return enterAnimation(baseEl).direction('reverse');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
enterAnimation,
|
|
|
|
|
leaveAnimation,
|
|
|
|
|
component: ChatOptionsPopoverPage,
|
|
|
|
|
cssClass: 'model profile-modal search-submodal',
|
|
|
|
|
componentProps: {
|
|
|
|
|
roomId: this.roomId,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return await modal.present();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 18:50:26 +01:00
|
|
|
}
|
2021-03-12 11:56:54 +01:00
|
|
|
|