mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
100 lines
2.7 KiB
TypeScript
100 lines
2.7 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
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';
|
|
|
|
@Component({
|
|
selector: 'app-set-room-owner',
|
|
templateUrl: './set-room-owner.page.html',
|
|
styleUrls: ['./set-room-owner.page.scss'],
|
|
})
|
|
export class SetRoomOwnerPage implements OnInit {
|
|
|
|
textSearch:string = "";
|
|
roomId:any;
|
|
members:any;
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private http: HttpClient,
|
|
private chatService: ChatService,
|
|
private authService: AuthService,
|
|
private navParams: NavParams,
|
|
public ThemeService: ThemeService,
|
|
private toastService: ToastService,
|
|
public wsChatMethodsService: WsChatMethodsService,
|
|
) {
|
|
this.roomId = this.navParams.get('roomId');
|
|
this.members = this.navParams.get('members');
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.chatService.refreshtoken();
|
|
}
|
|
|
|
async close(){
|
|
this.modalController.dismiss();
|
|
}
|
|
|
|
onChange(event){
|
|
this.textSearch = event.detail.value;
|
|
}
|
|
|
|
separateLetter(record, recordIndex, records){
|
|
if(recordIndex == 0){
|
|
return record.name[0];
|
|
}
|
|
|
|
let first_prev = records[recordIndex - 1].name[0];
|
|
let first_current = record.name[0];
|
|
|
|
if(first_prev != first_current){
|
|
return first_current;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
async setRoomOwner(user:any){
|
|
|
|
let res:any = await this.wsChatMethodsService.addRoomOwner(this.roomId, user._id);
|
|
|
|
|
|
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.roomId,
|
|
"userId": user._id
|
|
}
|
|
|
|
this.chatService.addGroupOwner(body).subscribe((res)=>{
|
|
console.log(res);
|
|
this.close();
|
|
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.');
|
|
}
|
|
}); */
|
|
|
|
}
|
|
|
|
}
|