continue working on exit from room

This commit is contained in:
tiago.kayaya
2022-01-26 09:19:54 +01:00
parent c6ec2abc1f
commit 58a32f45d4
7 changed files with 161 additions and 19 deletions
@@ -9,7 +9,7 @@
</button> </button>
</div> </div>
<div class="div-title"> <div class="div-title">
<ion-label class="title">Promover para Administrador</ion-label> <ion-label class="title">Nomear novo administrador</ion-label>
</div> </div>
</div> </div>
</div> </div>
@@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular'; import { ModalController, NavParams } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service'; import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service'; import { ChatService } from 'src/app/services/chat.service';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { ToastService } from 'src/app/services/toast.service'; import { ToastService } from 'src/app/services/toast.service';
@@ -14,7 +15,7 @@ import { ToastService } from 'src/app/services/toast.service';
export class SetRoomOwnerPage implements OnInit { export class SetRoomOwnerPage implements OnInit {
textSearch:string = ""; textSearch:string = "";
room:any; roomId:any;
members:any; members:any;
constructor( constructor(
@@ -25,13 +26,14 @@ export class SetRoomOwnerPage implements OnInit {
private navParams: NavParams, private navParams: NavParams,
public ThemeService: ThemeService, public ThemeService: ThemeService,
private toastService: ToastService, private toastService: ToastService,
public wsChatMethodsService: WsChatMethodsService,
) { ) {
this.room = this.navParams.get('room'); this.roomId = this.navParams.get('roomId');
this.members = this.navParams.get('members'); this.members = this.navParams.get('members');
} }
ngOnInit() { ngOnInit() {
console.log(this.room); console.log(this.members);
} }
@@ -57,23 +59,43 @@ export class SetRoomOwnerPage implements OnInit {
return null; return null;
} }
setRoomOwner(user:any){ async setRoomOwner(user:any){
console.log(user); let res:any = await this.wsChatMethodsService.addRoomOwner(this.roomId, user._id);
console.log(this.room);
console.log(res);
if(res.error){
if(res.error.error == 'error-user-already-owner'){
this.toastService._badRequest('Este utilizador já é administrador');
}
else{
this.toastService._badRequest('Não foi possível completar a ação, por favor tente novamente.');
}
}
else{
this.modalController.dismiss('success');
}
/*
let body = { let body = {
"roomId": this.room._id, "roomId": this.roomId,
"userId": user._id "userId": user._id
} }
this.chatService.addGroupOwner(body).subscribe((res)=>{ this.chatService.addGroupOwner(body).subscribe((res)=>{
alert('here');
console.log(res); console.log(res);
this.close(); this.close();
}, (error) => { this.toastService._successMessage('Operação realizada com sucesso');
this.toastService._badRequest('Não foi possível completar a ação, por favor tente novamente.'); }, (e) => {
}); if(e.error.errorType == 'error-user-already-owner'){
this.toastService._badRequest('Este utilizador já é administrador');
}
else{
this.toastService._badRequest('Não foi possível completar a ação, por favor tente novamente.');
}
}); */
} }
+4
View File
@@ -89,6 +89,10 @@ export class RoomService {
this.WsChatService.send(this.id, msg) this.WsChatService.send(this.id, msg)
} }
leave(rid?) {
this.WsChatService.leaveRoom(this.id)
}
getMsgFromDBMobile() { getMsgFromDBMobile() {
console.log('ALL MSG DBBB', this.id) console.log('ALL MSG DBBB', this.id)
this.sqlservice.getAllChatMSG(this.id).then((msg: any = []) => { this.sqlservice.getAllChatMSG(this.id).then((msg: any = []) => {
@@ -99,6 +99,18 @@ export class WsChatMethodsService {
})) }))
} }
leaveRoom(id?) {
return this.WsChatService.leaveRoom(id);
}
hidingRoom(id?) {
return this.WsChatService.hidingRoom(id);
}
addRoomOwner(roomid, userId){
return this.WsChatService.addRoomOwner(roomid, userId);
}
getDmRoom(id): RoomService { getDmRoom(id): RoomService {
try { try {
return this.dm[id] return this.dm[id]
+74
View File
@@ -153,6 +153,80 @@ export class WsChatService {
}); });
} }
leaveRoom(roomId) {
const requestId = uuidv4()
var message = {
msg: "method",
method: "leaveRoom",
id: requestId,
params: [
roomId,
]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
addRoomOwner(roomId, userId) {
const requestId = uuidv4()
var message = {
msg: "method",
method: "addRoomOwner",
id: requestId,
params: [
roomId,
userId
]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
hidingRoom(roomId){
const requestId = uuidv4()
var message = {
msg: "method",
method: "hideRoom",
id: requestId,
params: [roomId]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
joinRoom(){} joinRoom(){}
deleteMessage() {} deleteMessage() {}
createRoom() {} createRoom() {}
@@ -364,6 +364,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}); });
return await popover.present(); */ return await popover.present(); */
console.log(this.roomId);
const modal = await this.modalController.create({ const modal = await this.modalController.create({
enterAnimation, enterAnimation,
leaveAnimation, leaveAnimation,
@@ -379,6 +382,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
console.log(res); console.log(res);
if (res.data == 'leave') { if (res.data == 'leave') {
this.getRoomInfo(); this.getRoomInfo();
this.wsChatMethodsService.hidingRoom(this.roomId);
this.closeAllDesktopComponents.emit(); this.closeAllDesktopComponents.emit();
this.showEmptyContainer.emit(); this.showEmptyContainer.emit();
} }
@@ -4,6 +4,7 @@ import { ChatService } from 'src/app/services/chat.service';
import { ToastService } from 'src/app/services/toast.service'; import { ToastService } from 'src/app/services/toast.service';
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { SetRoomOwnerPage } from 'src/app/modals/set-room-owner/set-room-owner.page'; import { SetRoomOwnerPage } from 'src/app/modals/set-room-owner/set-room-owner.page';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
@Component({ @Component({
@@ -22,7 +23,8 @@ export class ChatPopoverPage implements OnInit {
private navParams: NavParams, private navParams: NavParams,
private chatService: ChatService, private chatService: ChatService,
private toastService: ToastService, private toastService: ToastService,
public ThemeService: ThemeService public ThemeService: ThemeService,
public wsChatMethodsService: WsChatMethodsService,
) { ) {
this.roomId = this.navParams.get('roomId'); this.roomId = this.navParams.get('roomId');
this.members = this.navParams.get('members'); this.members = this.navParams.get('members');
@@ -58,21 +60,45 @@ export class ChatPopoverPage implements OnInit {
cssClass: classs, cssClass: classs,
backdropDismiss: true, backdropDismiss: true,
componentProps: { componentProps: {
room: this.room, roomId: this.roomId,
members: this.members, members: this.members,
} }
}); });
await modal.present(); await modal.present();
modal.onDidDismiss().then((res)=>{ modal.onDidDismiss().then((res)=>{
this.leaveGroup();
}); });
} }
leaveGroup(){ async leaveGroup(){
console.log('leave');
let body = { "roomId":this.roomId, } let body = { "roomId":this.roomId, }
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{ let res:any = await this.wsChatMethodsService.leaveRoom(this.roomId);
console.log(res.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.close('leave');
}
this.close('leave');
/* this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
this.room = room['room']; this.room = room['room'];
if(this.room.t === 'p'){ if(this.room.t === 'p'){
@@ -117,7 +143,7 @@ export class ChatPopoverPage implements OnInit {
//loader.remove() //loader.remove()
}); });
} }
}); }); */
} }
//Delete //Delete