WebApp: Fix channel-detail page for non-owned channels
This commit is contained in:
@@ -12,7 +12,7 @@ import { ApiService } from '../../../core/services/api.service';
|
||||
import { AuthService } from '../../../core/services/auth.service';
|
||||
import { NotificationService } from '../../../core/services/notification.service';
|
||||
import { SettingsService } from '../../../core/services/settings.service';
|
||||
import { Client, ClientType, getClientTypeIcon } from '../../../core/models';
|
||||
import { Client, ClientPreview, ClientType, getClientTypeIcon } from '../../../core/models';
|
||||
import { RelativeTimePipe } from '../../../shared/pipes/relative-time.pipe';
|
||||
import { MetadataGridComponent, MetadataValueComponent } from '../../../shared/components/metadata-grid';
|
||||
|
||||
@@ -45,6 +45,7 @@ export class ClientDetailComponent implements OnInit {
|
||||
private settingsService = inject(SettingsService);
|
||||
|
||||
client = signal<Client | null>(null);
|
||||
clientPreview = signal<ClientPreview | null>(null);
|
||||
loading = signal(true);
|
||||
expertMode = this.settingsService.expertMode;
|
||||
|
||||
@@ -60,10 +61,22 @@ export class ClientDetailComponent implements OnInit {
|
||||
if (!userId) return;
|
||||
|
||||
this.loading.set(true);
|
||||
this.apiService.getClient(userId, clientId).subscribe({
|
||||
next: (client) => {
|
||||
this.client.set(client);
|
||||
this.loading.set(false);
|
||||
this.apiService.getClientPreview(clientId).subscribe({
|
||||
next: (response) => {
|
||||
this.clientPreview.set(response.client);
|
||||
if (response.client.user_id === userId) {
|
||||
this.apiService.getClient(userId, clientId).subscribe({
|
||||
next: (client) => {
|
||||
this.client.set(client);
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: () => {
|
||||
this.loading.set(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.loading.set(false);
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
this.loading.set(false);
|
||||
@@ -71,6 +84,19 @@ export class ClientDetailComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
clientData() {
|
||||
return this.client() ?? this.clientPreview();
|
||||
}
|
||||
|
||||
isOwner(): boolean {
|
||||
const userId = this.authService.getUserId();
|
||||
const client = this.client();
|
||||
if (client) return client.user_id === userId;
|
||||
const preview = this.clientPreview();
|
||||
if (preview) return preview.user_id === userId;
|
||||
return false;
|
||||
}
|
||||
|
||||
goBack(): void {
|
||||
this.router.navigate(['/clients']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user