feat: Allow admin to create new text channels

This commit is contained in:
2026-03-30 01:25:56 +02:00
parent 109402cdd6
commit 83694570e3
24 changed files with 563 additions and 64 deletions

View File

@@ -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;
}