Show more data in webapp deliveries-table
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { UserPreview } from "./user.model";
|
||||
|
||||
export type ClientType = 'ANDROID' | 'IOS' | 'LINUX' | 'MACOS' | 'WINDOWS';
|
||||
|
||||
export interface Client {
|
||||
@@ -15,6 +17,19 @@ export interface ClientListResponse {
|
||||
clients: Client[];
|
||||
}
|
||||
|
||||
export interface ClientPreview {
|
||||
client_id: string;
|
||||
name: string | null;
|
||||
type: ClientType;
|
||||
agent_model: string;
|
||||
agent_version: string;
|
||||
}
|
||||
|
||||
export interface ClientPreviewResponse {
|
||||
user: UserPreview;
|
||||
client: ClientPreview;
|
||||
}
|
||||
|
||||
export function getClientTypeIcon(type: ClientType): string {
|
||||
switch (type) {
|
||||
case 'ANDROID':
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
UpdateKeyRequest,
|
||||
Client,
|
||||
ClientListResponse,
|
||||
ClientPreviewResponse,
|
||||
SenderNameStatistics,
|
||||
SenderNameListResponse,
|
||||
DeliveryListResponse,
|
||||
@@ -93,6 +94,10 @@ export class ApiService {
|
||||
return this.http.delete<Client>(`${this.baseUrl}/users/${userId}/clients/${clientId}`);
|
||||
}
|
||||
|
||||
getClientPreview(clientId: string): Observable<ClientPreviewResponse> {
|
||||
return this.http.get<ClientPreviewResponse>(`${this.baseUrl}/preview/clients/${clientId}`);
|
||||
}
|
||||
|
||||
// Channel endpoints
|
||||
getChannels(userId: string, selector?: ChannelSelector): Observable<ChannelListResponse> {
|
||||
let params = new HttpParams();
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable, of, catchError, map, shareReplay } from 'rxjs';
|
||||
import { ApiService } from './api.service';
|
||||
|
||||
export interface ResolvedClient {
|
||||
clientId: string;
|
||||
clientName: string | null;
|
||||
userId: string;
|
||||
userName: string | null;
|
||||
agentModel: string;
|
||||
agentVersion: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ClientCacheService {
|
||||
private apiService = inject(ApiService);
|
||||
|
||||
private cache = new Map<string, Observable<ResolvedClient | null>>();
|
||||
|
||||
resolveClient(clientId: string): Observable<ResolvedClient | null> {
|
||||
if (!this.cache.has(clientId)) {
|
||||
const request$ = this.apiService.getClientPreview(clientId).pipe(
|
||||
map(response => ({
|
||||
clientId: response.client.client_id,
|
||||
clientName: response.client.name,
|
||||
userId: response.user.user_id,
|
||||
userName: response.user.username,
|
||||
agentModel: response.client.agent_model,
|
||||
agentVersion: response.client.agent_version,
|
||||
})),
|
||||
catchError(() => of(null)),
|
||||
shareReplay(1)
|
||||
);
|
||||
this.cache.set(clientId, request$);
|
||||
}
|
||||
return this.cache.get(clientId)!;
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
this.cache.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user