mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
141 lines
3.7 KiB
TypeScript
141 lines
3.7 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { ModalController, NavParams, PopoverController } from '@ionic/angular';
|
|
import { ChatService } from 'src/app/services/chat.service';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { SetRoomOwnerPage } from 'src/app/modals/set-room-owner/set-room-owner.page';
|
|
import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { GroupContactsPage } from '../../chat/group-messages/group-contacts/group-contacts.page';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-chat-popover',
|
|
templateUrl: './chat-popover.page.html',
|
|
styleUrls: ['./chat-popover.page.scss'],
|
|
})
|
|
export class ChatPopoverPage implements OnInit {
|
|
roomId:string;
|
|
room: any;
|
|
members:any;
|
|
isAdmin = false;
|
|
isGroupCreated: boolean;
|
|
|
|
constructor(
|
|
private popoverController: PopoverController,
|
|
private modalController: ModalController,
|
|
private navParams: NavParams,
|
|
private chatService: ChatService,
|
|
private toastService: ToastService,
|
|
public ThemeService: ThemeService,
|
|
public ChatSystemService: ChatSystemService,
|
|
) {
|
|
this.roomId = this.navParams.get('roomId');
|
|
this.members = this.navParams.get('members');
|
|
this.isAdmin = this.navParams.get('isAdmin');
|
|
}
|
|
|
|
ngOnInit() {
|
|
// this.chatService.refreshtoken();
|
|
}
|
|
|
|
close(action:any){
|
|
if( window.innerWidth < 701){
|
|
this.popoverController.dismiss(action);
|
|
}
|
|
else{
|
|
this.modalController.dismiss(action)
|
|
}
|
|
}
|
|
|
|
//Top menu options
|
|
//Close
|
|
|
|
async setRoomOwner(){
|
|
let classs;
|
|
if (window.innerWidth < 701) {
|
|
classs = 'modal modal-desktop'
|
|
} else {
|
|
classs = 'centered-rounded-modal'
|
|
}
|
|
const modal = await this.modalController.create({
|
|
component: SetRoomOwnerPage,
|
|
cssClass: classs,
|
|
backdropDismiss: true,
|
|
componentProps: {
|
|
roomId: this.roomId,
|
|
members: this.members,
|
|
isAdmin: this.isAdmin
|
|
}
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then((res)=>{
|
|
if(res.data == 'success'){
|
|
this.leaveGroup();
|
|
//this.ChatSystemService.hidingRoom(this.roomId);
|
|
}
|
|
});
|
|
}
|
|
|
|
async leaveGroup(){
|
|
|
|
let body = { "roomId":this.roomId, }
|
|
|
|
let res:any;
|
|
try {
|
|
res = await this.ChatSystemService.leaveRoom(this.roomId);
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
if(res.error){
|
|
if(res.error.error = "error-you-are-last-owner"){
|
|
this.toastService._badRequest("Você é o último administrador do grupo. Por favor, defina o novo administrador antes de sair da grupo.");
|
|
|
|
this.setRoomOwner();
|
|
}
|
|
else if(res.error.error == 'error-user-not-in-room'){
|
|
this.toastService._badRequest("Você já não esta nesta conversa");
|
|
}
|
|
else{
|
|
this.toastService._badRequest("Não foi possível sair do grupo");
|
|
}
|
|
}
|
|
else {
|
|
this.ChatSystemService.deleteRoom(this.roomId)
|
|
this.close('leave');
|
|
}
|
|
|
|
}
|
|
|
|
//Delete
|
|
deleteGroup() {
|
|
let body = { "roomId":this.roomId }
|
|
this.chatService.getRoomInfo(this.roomId).subscribe(room => {
|
|
this.room = room['room'];
|
|
|
|
if(this.room.t === 'p') {
|
|
this.chatService.deleteGroup(body).subscribe(res=>{
|
|
this.ChatSystemService.deleteRoom(this.roomId)
|
|
});
|
|
}
|
|
else {
|
|
this.chatService.deleteChannel(body).subscribe(res=>{
|
|
this.ChatSystemService.deleteRoom(this.roomId)
|
|
});
|
|
}
|
|
});
|
|
this.close('delete');
|
|
}
|
|
|
|
async openChangeGroupName(){
|
|
this.close('edit');
|
|
}
|
|
|
|
|
|
async addUser() {
|
|
this.close('addUser');
|
|
}
|
|
|
|
}
|