Simple Managment webapp [LLM]
This commit is contained in:
@@ -135,10 +135,22 @@ export class ApiService {
|
||||
if (params) {
|
||||
if (params.after) httpParams = httpParams.set('after', params.after);
|
||||
if (params.before) httpParams = httpParams.set('before', params.before);
|
||||
if (params.channel) httpParams = httpParams.set('channel', params.channel);
|
||||
if (params.priority !== undefined) httpParams = httpParams.set('priority', params.priority);
|
||||
if (params.channel_id) {
|
||||
for (const c of params.channel_id) {
|
||||
httpParams = httpParams.append('channel_id', c);
|
||||
}
|
||||
}
|
||||
if (params.priority) {
|
||||
for (const p of params.priority) {
|
||||
httpParams = httpParams.append('priority', p);
|
||||
}
|
||||
}
|
||||
if (params.search) httpParams = httpParams.set('search', params.search);
|
||||
if (params.sender) httpParams = httpParams.set('sender', params.sender);
|
||||
if (params.sender) {
|
||||
for (const s of params.sender) {
|
||||
httpParams = httpParams.append('sender', s);
|
||||
}
|
||||
}
|
||||
if (params.subscription_status) httpParams = httpParams.set('subscription_status', params.subscription_status);
|
||||
if (params.trimmed !== undefined) httpParams = httpParams.set('trimmed', params.trimmed);
|
||||
if (params.page_size) httpParams = httpParams.set('page_size', params.page_size);
|
||||
|
||||
88
webapp/src/app/core/services/channel-cache.service.ts
Normal file
88
webapp/src/app/core/services/channel-cache.service.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable, of, map, shareReplay, catchError } from 'rxjs';
|
||||
import { ApiService } from './api.service';
|
||||
import { AuthService } from './auth.service';
|
||||
import { ChannelWithSubscription } from '../models';
|
||||
|
||||
export interface ResolvedChannel {
|
||||
channelId: string;
|
||||
displayName: string;
|
||||
internalName: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChannelCacheService {
|
||||
private apiService = inject(ApiService);
|
||||
private authService = inject(AuthService);
|
||||
|
||||
private channelsCache$: Observable<Map<string, ChannelWithSubscription>> | null = null;
|
||||
|
||||
getAllChannels(): Observable<ChannelWithSubscription[]> {
|
||||
const userId = this.authService.getUserId();
|
||||
if (!userId) {
|
||||
return of([]);
|
||||
}
|
||||
return this.apiService.getChannels(userId, 'owned').pipe(
|
||||
map(response => response.channels),
|
||||
catchError(() => of([]))
|
||||
);
|
||||
}
|
||||
|
||||
resolveChannel(channelId: string): Observable<ResolvedChannel> {
|
||||
return this.getChannelsMap().pipe(
|
||||
map(channelsMap => {
|
||||
const channel = channelsMap.get(channelId);
|
||||
return {
|
||||
channelId,
|
||||
displayName: channel?.display_name || channel?.internal_name || channelId,
|
||||
internalName: channel?.internal_name || channelId
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
resolveChannels(channelIds: string[]): Observable<Map<string, ResolvedChannel>> {
|
||||
return this.getChannelsMap().pipe(
|
||||
map(channelsMap => {
|
||||
const resolved = new Map<string, ResolvedChannel>();
|
||||
for (const channelId of channelIds) {
|
||||
const channel = channelsMap.get(channelId);
|
||||
resolved.set(channelId, {
|
||||
channelId,
|
||||
displayName: channel?.display_name || channel?.internal_name || channelId,
|
||||
internalName: channel?.internal_name || channelId
|
||||
});
|
||||
}
|
||||
return resolved;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private getChannelsMap(): Observable<Map<string, ChannelWithSubscription>> {
|
||||
const userId = this.authService.getUserId();
|
||||
if (!userId) {
|
||||
return of(new Map());
|
||||
}
|
||||
|
||||
if (!this.channelsCache$) {
|
||||
this.channelsCache$ = this.apiService.getChannels(userId, 'owned').pipe(
|
||||
map(response => {
|
||||
const map = new Map<string, ChannelWithSubscription>();
|
||||
for (const channel of response.channels) {
|
||||
map.set(channel.channel_id, channel);
|
||||
}
|
||||
return map;
|
||||
}),
|
||||
catchError(() => of(new Map())),
|
||||
shareReplay(1)
|
||||
);
|
||||
}
|
||||
return this.channelsCache$;
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
this.channelsCache$ = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user