Skip to content

Commit

Permalink
fix(chat): fix automigration icons (Issue #265) (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kezik authored Feb 14, 2024
1 parent bf250fd commit 08b6700
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions apps/chat/src/utils/app/data/storages/api-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
throwError,
} from 'rxjs';

import { regenerateConversationId } from '@/src/utils/app/conversation';
import { ApiEntityStorage } from '@/src/utils/app/data/storages/api/api-entity-storage';
import { constructPath } from '@/src/utils/app/file';
import { generateNextName } from '@/src/utils/app/folders';
import { addGeneratedPromptId } from '@/src/utils/app/prompts';

import { Conversation, ConversationInfo } from '@/src/types/chat';
import { Entity } from '@/src/types/common';
import { BackendResourceType, Entity } from '@/src/types/common';
import { FolderInterface, FoldersAndEntities } from '@/src/types/folder';
import { Prompt, PromptInfo } from '@/src/types/prompt';
import { DialStorage } from '@/src/types/storage';
Expand All @@ -35,12 +36,12 @@ export class ApiStorage implements DialStorage {
entity: T,
entities: T[],
apiStorage: ApiEntityStorage<T, T>,
entityType: BackendResourceType,
): Observable<void> {
let retries = 0;

const retry = (
entity: T,
entities: T[],
apiStorage: ApiEntityStorage<T, T>,
): Observable<void> =>
apiStorage.createEntity(entity).pipe(
Expand All @@ -49,7 +50,7 @@ export class ApiStorage implements DialStorage {
retries++;

const defaultName =
'messages' in entity
entityType === BackendResourceType.CONVERSATION
? DEFAULT_CONVERSATION_NAME
: DEFAULT_PROMPT_NAME;
const newName = generateNextName(
Expand All @@ -59,18 +60,22 @@ export class ApiStorage implements DialStorage {
);
const updatedEntity = {
...entity,
id: constructPath(entity.folderId, newName),
name: newName,
};

return retry(updatedEntity, entities, apiStorage);
const updatedEntityWithRegeneratedId =
entityType === BackendResourceType.CONVERSATION
? regenerateConversationId(updatedEntity as Conversation)
: addGeneratedPromptId(updatedEntity as Prompt);

return retry(updatedEntityWithRegeneratedId as T, apiStorage);
}

return throwError(() => err);
}),
);

return retry(entity, entities, apiStorage);
return retry(entity, apiStorage);
}

getConversationsFolders(path?: string): Observable<FolderInterface[]> {
Expand Down Expand Up @@ -127,6 +132,7 @@ export class ApiStorage implements DialStorage {
conv,
[...conversations, ...apiConversations],
this._conversationApiStorage,
BackendResourceType.CONVERSATION,
),
),
),
Expand Down Expand Up @@ -169,6 +175,7 @@ export class ApiStorage implements DialStorage {
prompt,
[...prompts, ...apiPrompts],
this._promptApiStorage,
BackendResourceType.PROMPT,
),
),
),
Expand Down

0 comments on commit 08b6700

Please sign in to comment.