user without permission cant delete or edit group name

This commit is contained in:
Eudes Inácio
2022-06-13 12:11:35 +01:00
parent 3c716ee3ea
commit 9a1d0c67d2
3 changed files with 16 additions and 8 deletions
@@ -75,6 +75,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
scrollToBottomBtn = false; scrollToBottomBtn = false;
roomCountDownDate: string; roomCountDownDate: string;
roomCountDownTime: string; roomCountDownTime: string;
isAdmin = false;
@Input() roomId: string; @Input() roomId: string;
@Output() closeAllDesktopComponents: EventEmitter<any> = new EventEmitter<any>(); @Output() closeAllDesktopComponents: EventEmitter<any> = new EventEmitter<any>();
@@ -101,7 +102,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null
sessionStore = SessionStore sessionStore = SessionStore
groupAdminId = "";
constructor( constructor(
public wsChatMethodsService: WsChatMethodsService, public wsChatMethodsService: WsChatMethodsService,
@@ -404,11 +404,17 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
let room = await this.chatService.getRoomInfo(this.roomId).toPromise(); let room = await this.chatService.getRoomInfo(this.roomId).toPromise();
console.log('ROOM',room) console.log('ROOM',room)
this.room = room['room']; this.room = room['room'];
this.groupAdminId = this.room.u._id;
if (this.room.name) { if (this.room.name) {
this.roomName = this.room.name.split('-').join(' '); this.roomName = this.room.name.split('-').join(' ');
} }
if(SessionStore.user.ChatData.data.userId == this.room.u._id){
this.isAdmin = true
} else {
this.isAdmin = false
}
if (this.room.customFields.countDownDate) { if (this.room.customFields.countDownDate) {
this.roomCountDownDate = this.room.customFields.countDownDate; this.roomCountDownDate = this.room.customFields.countDownDate;
} }
@@ -506,8 +512,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
async openGroupMessagesOptions() { async openGroupMessagesOptions() {
alert(this.groupAdminId)
if(SessionStore.user.ChatData.data.userId == this.groupAdminId) {
const enterAnimation = (baseEl: any) => { const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create() const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!) .addElement(baseEl.querySelector('ion-backdrop')!)
@@ -554,6 +558,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
componentProps: { componentProps: {
roomId: this.roomId, roomId: this.roomId,
members: this.members, members: this.members,
isAdmin: this.isAdmin
} }
}); });
await modal.present(); await modal.present();
@@ -583,7 +588,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}; };
}); });
}
} }
@@ -7,9 +7,9 @@
</div> </div>
<div class="buttons"> <div class="buttons">
<button (click)="leaveGroup()" class="btn-cancel" shape="round" >Sair do Grupo</button> <button (click)="leaveGroup()" class="btn-cancel" shape="round" >Sair do Grupo</button>
<button (click)="openChangeGroupName()" class="btn-cancel" shape="round" >Alterar nome do grupo</button> <button *ngIf="isAdmin" (click)="openChangeGroupName()" class="btn-cancel" shape="round" >Alterar nome do grupo</button>
<div class="solid"></div> <div class="solid"></div>
<button (click)="close('cancel')" full class="btn-cancel mobile-only" shape="round" >Cancelar</button> <button (click)="close('cancel')" full class="btn-cancel mobile-only" shape="round" >Cancelar</button>
<button (click)="deleteGroup()" class="btn-delete" shape="round">Apagar grupo</button> <button *ngIf="isAdmin" (click)="deleteGroup()" class="btn-delete" shape="round">Apagar grupo</button>
</div> </div>
</ion-content> </ion-content>
@@ -6,6 +6,7 @@ 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'; import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { SessionStore } from 'src/app/store/session.service';
@Component({ @Component({
@@ -17,6 +18,7 @@ export class ChatPopoverPage implements OnInit {
roomId:string; roomId:string;
room: any; room: any;
members:any; members:any;
isAdmin = false;
constructor( constructor(
private popoverController: PopoverController, private popoverController: PopoverController,
@@ -29,6 +31,7 @@ export class ChatPopoverPage implements OnInit {
) { ) {
this.roomId = this.navParams.get('roomId'); this.roomId = this.navParams.get('roomId');
this.members = this.navParams.get('members'); this.members = this.navParams.get('members');
this.isAdmin = this.navParams.get('isAdmin');
} }
ngOnInit() { ngOnInit() {
@@ -63,6 +66,7 @@ export class ChatPopoverPage implements OnInit {
componentProps: { componentProps: {
roomId: this.roomId, roomId: this.roomId,
members: this.members, members: this.members,
isAdmin: this.isAdmin
} }
}); });
await modal.present(); await modal.present();