mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
continue working on exit from room
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { ModalController, NavParams } from '@ionic/angular';
|
||||
import { AuthService } from 'src/app/services/auth.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 { ToastService } from 'src/app/services/toast.service';
|
||||
|
||||
@@ -14,7 +15,7 @@ import { ToastService } from 'src/app/services/toast.service';
|
||||
export class SetRoomOwnerPage implements OnInit {
|
||||
|
||||
textSearch:string = "";
|
||||
room:any;
|
||||
roomId:any;
|
||||
members:any;
|
||||
|
||||
constructor(
|
||||
@@ -25,13 +26,14 @@ export class SetRoomOwnerPage implements OnInit {
|
||||
private navParams: NavParams,
|
||||
public ThemeService: ThemeService,
|
||||
private toastService: ToastService,
|
||||
public wsChatMethodsService: WsChatMethodsService,
|
||||
) {
|
||||
this.room = this.navParams.get('room');
|
||||
this.roomId = this.navParams.get('roomId');
|
||||
this.members = this.navParams.get('members');
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
console.log(this.room);
|
||||
console.log(this.members);
|
||||
|
||||
}
|
||||
|
||||
@@ -57,23 +59,43 @@ export class SetRoomOwnerPage implements OnInit {
|
||||
return null;
|
||||
}
|
||||
|
||||
setRoomOwner(user:any){
|
||||
async setRoomOwner(user:any){
|
||||
|
||||
console.log(user);
|
||||
console.log(this.room);
|
||||
let res:any = await this.wsChatMethodsService.addRoomOwner(this.roomId, user._id);
|
||||
|
||||
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 = {
|
||||
"roomId": this.room._id,
|
||||
"roomId": this.roomId,
|
||||
"userId": user._id
|
||||
}
|
||||
|
||||
this.chatService.addGroupOwner(body).subscribe((res)=>{
|
||||
alert('here');
|
||||
console.log(res);
|
||||
|
||||
this.close();
|
||||
}, (error) => {
|
||||
this.toastService._successMessage('Operação realizada com sucesso');
|
||||
}, (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.');
|
||||
});
|
||||
}
|
||||
}); */
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,10 @@ export class RoomService {
|
||||
this.WsChatService.send(this.id, msg)
|
||||
}
|
||||
|
||||
leave(rid?) {
|
||||
this.WsChatService.leaveRoom(this.id)
|
||||
}
|
||||
|
||||
getMsgFromDBMobile() {
|
||||
console.log('ALL MSG DBBB', this.id)
|
||||
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 {
|
||||
try {
|
||||
return this.dm[id]
|
||||
|
||||
@@ -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(){}
|
||||
deleteMessage() {}
|
||||
createRoom() {}
|
||||
|
||||
@@ -364,6 +364,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
});
|
||||
return await popover.present(); */
|
||||
|
||||
console.log(this.roomId);
|
||||
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
enterAnimation,
|
||||
leaveAnimation,
|
||||
@@ -379,6 +382,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
console.log(res);
|
||||
if (res.data == 'leave') {
|
||||
this.getRoomInfo();
|
||||
this.wsChatMethodsService.hidingRoom(this.roomId);
|
||||
this.closeAllDesktopComponents.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 { ThemeService } from 'src/app/services/theme.service'
|
||||
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({
|
||||
@@ -22,7 +23,8 @@ export class ChatPopoverPage implements OnInit {
|
||||
private navParams: NavParams,
|
||||
private chatService: ChatService,
|
||||
private toastService: ToastService,
|
||||
public ThemeService: ThemeService
|
||||
public ThemeService: ThemeService,
|
||||
public wsChatMethodsService: WsChatMethodsService,
|
||||
) {
|
||||
this.roomId = this.navParams.get('roomId');
|
||||
this.members = this.navParams.get('members');
|
||||
@@ -58,21 +60,45 @@ export class ChatPopoverPage implements OnInit {
|
||||
cssClass: classs,
|
||||
backdropDismiss: true,
|
||||
componentProps: {
|
||||
room: this.room,
|
||||
roomId: this.roomId,
|
||||
members: this.members,
|
||||
}
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then((res)=>{
|
||||
this.leaveGroup();
|
||||
});
|
||||
}
|
||||
|
||||
leaveGroup(){
|
||||
console.log('leave');
|
||||
async leaveGroup(){
|
||||
|
||||
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'];
|
||||
|
||||
if(this.room.t === 'p'){
|
||||
@@ -117,7 +143,7 @@ export class ChatPopoverPage implements OnInit {
|
||||
//loader.remove()
|
||||
});
|
||||
}
|
||||
});
|
||||
}); */
|
||||
}
|
||||
|
||||
//Delete
|
||||
|
||||
Reference in New Issue
Block a user