change room name

This commit is contained in:
Peter Maquiran
2024-06-12 09:44:28 +01:00
parent 703c3aaed6
commit 751ebb7731
7 changed files with 108 additions and 62 deletions
@@ -16,6 +16,7 @@
</div>
</div>
</ion-toolbar>
<ion-progress-bar type="indeterminate" *ngIf="showLoader"></ion-progress-bar>
</ion-header>
<ion-content class="width-100">
@@ -41,4 +42,3 @@
</div>
</ion-content>
@@ -4,7 +4,11 @@ import { ModalController, PickerController } from '@ionic/angular';
import { ChatService } from 'src/app/services/chat.service';
import { ThemeService } from 'src/app/services/theme.service'
import { SessionStore } from 'src/app/store/session.service';
import { RoomRepositoryService } from 'src/app/services/Repositorys/chat/repository/room-repository.service'
import { HttpResponse } from '@microsoft/signalr';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { ToastService } from 'src/app/services/toast.service';
import { ZodError } from 'zod';
@Component({
selector: 'app-edit-group',
templateUrl: './edit-group.page.html',
@@ -23,11 +27,15 @@ export class EditGroupPage implements OnInit {
@Output() openGroupMessage:EventEmitter<any> = new EventEmitter<any>();
@Output() closeAllDesktopComponents:EventEmitter<any> = new EventEmitter<any>();
constructor(
private modalController: ModalController,
private pickerController: PickerController,
private chatService: ChatService,
public ThemeService: ThemeService
public ThemeService: ThemeService,
private RoomRepositoryService: RoomRepositoryService,
private httpErrorHandle: HttpErrorHandle,
private toastService: ToastService,
) {
this.loggedUser = SessionStore.user.ChatData['data'];
}
@@ -56,24 +64,32 @@ export class EditGroupPage implements OnInit {
this.openGroupMessage.emit(this.roomId);
}
changeGroupName() {
if(this.groupName.trim().length > 1) {
let name = this.groupName.split(' ').join('-');
let body = {
"roomId": this.room._id,
"name": name,
}
this.chatService.renameGroup(body).subscribe(res=>{
this.modalController.dismiss(res['group']);
});
}
else{
async changeGroupName() {
this.showLoader = true
const result = await this.RoomRepositoryService.updateRoomBy({
roomId: this.roomId,
roomName: this.groupName,
roomType: 0
})
if(result.isOk()) {
this.openGroupMessage.emit(this.roomId);
} else if (result.error instanceof HttpResponse) {
this.httpErrorHandle.httpStatusHandle(result.error)
} else if (result.error instanceof ZodError) {
this.toastService._badRequest("Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico.")
console.log(result.error.errors)
} else {
this.toastService._badRequest("Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico.")
console.log(result.error)
}
this.updateGroup();
this.showLoader = false
}
updateGroup(){
updateGroup() {
this.showLoader = true;
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
this.room = room['room'];