100 lines
2.9 KiB
TypeScript
100 lines
2.9 KiB
TypeScript
/* eslint-disable @typescript-eslint/member-ordering */
|
|
import {
|
|
Component,
|
|
inject,
|
|
input,
|
|
signal
|
|
} from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { NgIcon, provideIcons } from '@ng-icons/core';
|
|
import { Store } from '@ngrx/store';
|
|
import { lucideCheck } from '@ng-icons/lucide';
|
|
|
|
import { Room } from '../../../../core/models/index';
|
|
import { RoomsActions } from '../../../../store/rooms/rooms.actions';
|
|
|
|
@Component({
|
|
selector: 'app-permissions-settings',
|
|
standalone: true,
|
|
imports: [
|
|
CommonModule,
|
|
FormsModule,
|
|
NgIcon
|
|
],
|
|
viewProviders: [
|
|
provideIcons({
|
|
lucideCheck
|
|
})
|
|
],
|
|
templateUrl: './permissions-settings.component.html'
|
|
})
|
|
export class PermissionsSettingsComponent {
|
|
private store = inject(Store);
|
|
|
|
/** The currently selected server, passed from the parent. */
|
|
server = input<Room | null>(null);
|
|
/** Whether the current user is admin of this server. */
|
|
isAdmin = input(false);
|
|
|
|
allowVoice = true;
|
|
allowScreenShare = true;
|
|
allowFileUploads = true;
|
|
slowModeInterval = '0';
|
|
adminsManageRooms = false;
|
|
moderatorsManageRooms = false;
|
|
adminsManageIcon = false;
|
|
moderatorsManageIcon = false;
|
|
|
|
saveSuccess = signal<string | null>(null);
|
|
private saveTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
|
|
/** Load permissions from the server input. Called by parent via effect or on init. */
|
|
loadPermissions(room: Room): void {
|
|
const perms = room.permissions || {};
|
|
|
|
this.allowVoice = perms.allowVoice !== false;
|
|
this.allowScreenShare = perms.allowScreenShare !== false;
|
|
this.allowFileUploads = perms.allowFileUploads !== false;
|
|
this.slowModeInterval = String(perms.slowModeInterval ?? 0);
|
|
this.adminsManageRooms = !!perms.adminsManageRooms;
|
|
this.moderatorsManageRooms = !!perms.moderatorsManageRooms;
|
|
this.adminsManageIcon = !!perms.adminsManageIcon;
|
|
this.moderatorsManageIcon = !!perms.moderatorsManageIcon;
|
|
}
|
|
|
|
savePermissions(): void {
|
|
const room = this.server();
|
|
|
|
if (!room)
|
|
return;
|
|
|
|
this.store.dispatch(
|
|
RoomsActions.updateRoomPermissions({
|
|
roomId: room.id,
|
|
permissions: {
|
|
allowVoice: this.allowVoice,
|
|
allowScreenShare: this.allowScreenShare,
|
|
allowFileUploads: this.allowFileUploads,
|
|
slowModeInterval: parseInt(this.slowModeInterval, 10),
|
|
adminsManageRooms: this.adminsManageRooms,
|
|
moderatorsManageRooms: this.moderatorsManageRooms,
|
|
adminsManageIcon: this.adminsManageIcon,
|
|
moderatorsManageIcon: this.moderatorsManageIcon
|
|
}
|
|
})
|
|
);
|
|
|
|
this.showSaveSuccess('permissions');
|
|
}
|
|
|
|
private showSaveSuccess(key: string): void {
|
|
this.saveSuccess.set(key);
|
|
|
|
if (this.saveTimeout)
|
|
clearTimeout(this.saveTimeout);
|
|
|
|
this.saveTimeout = setTimeout(() => this.saveSuccess.set(null), 2000);
|
|
}
|
|
}
|