feat: Allow admin to create new text channels
This commit is contained in:
@@ -8,7 +8,10 @@ import {
|
||||
throwError
|
||||
} from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { User } from '../../../shared-kernel';
|
||||
import {
|
||||
type Channel,
|
||||
User
|
||||
} from '../../../shared-kernel';
|
||||
import { ServerEndpointStateService } from '../application/server-endpoint-state.service';
|
||||
import type {
|
||||
BanServerMemberRequest,
|
||||
@@ -382,6 +385,7 @@ export class ServerDirectoryApiService {
|
||||
hasPassword: this.getBooleanValue(candidate['hasPassword']),
|
||||
isPrivate: this.getBooleanValue(candidate['isPrivate']),
|
||||
tags: Array.isArray(candidate['tags']) ? candidate['tags'] as string[] : [],
|
||||
channels: this.getChannelsValue(candidate['channels']),
|
||||
createdAt: this.getNumberValue(candidate['createdAt'], Date.now()),
|
||||
sourceId: this.getStringValue(candidate['sourceId']) ?? source?.id,
|
||||
sourceName: sourceName ?? source?.name,
|
||||
@@ -399,6 +403,37 @@ export class ServerDirectoryApiService {
|
||||
return typeof value === 'number' ? value : fallback;
|
||||
}
|
||||
|
||||
private getChannelsValue(value: unknown): Channel[] | undefined {
|
||||
if (!Array.isArray(value)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return value
|
||||
.filter((channel): channel is Record<string, unknown> => !!channel && typeof channel === 'object')
|
||||
.map((channel, index) => {
|
||||
const id = this.getStringValue(channel['id']);
|
||||
const name = this.getStringValue(channel['name']);
|
||||
const type = this.getChannelTypeValue(channel['type']);
|
||||
const position = this.getNumberValue(channel['position'], index);
|
||||
|
||||
if (!id || !name || !type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
position
|
||||
} satisfies Channel;
|
||||
})
|
||||
.filter((channel): channel is Channel => !!channel);
|
||||
}
|
||||
|
||||
private getChannelTypeValue(value: unknown): Channel['type'] | undefined {
|
||||
return value === 'text' || value === 'voice' ? value : undefined;
|
||||
}
|
||||
|
||||
private getStringValue(value: unknown): string | undefined {
|
||||
return typeof value === 'string' ? value : undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user