Skip to content

Commit

Permalink
fix(chat): fix unicode splitting and not delete if create fails (Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaBondar authored Mar 11, 2024
1 parent 0671397 commit 647729d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
49 changes: 26 additions & 23 deletions apps/chat/src/store/conversations/conversations.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2200,32 +2200,35 @@ const recreateConversationEpic: AppEpic = (action$) =>
action$.pipe(
filter(ConversationsActions.recreateConversation.match),
mergeMap(({ payload }) => {
return zip(
ConversationService.createConversation(payload.new),
ConversationService.deleteConversation(
getConversationInfoFromId(payload.old.id),
),
).pipe(
switchMap(() => EMPTY),
catchError((err) => {
console.error(err);
return concat(
of(
ConversationsActions.recreateConversationFail({
newId: payload.new.id,
oldConversation: payload.old,
}),
return ConversationService.createConversation(payload.new)
.pipe(
switchMap(() =>
ConversationService.deleteConversation(
getConversationInfoFromId(payload.old.id),
),
of(
UIActions.showErrorToast(
translate(
'An error occurred while saving the conversation. Please refresh the page.',
),
)
.pipe(
switchMap(() => EMPTY),
catchError((err) => {
console.error(err);
return concat(
of(
ConversationsActions.recreateConversationFail({
newId: payload.new.id,
oldConversation: payload.old,
}),
),
of(
UIActions.showErrorToast(
translate(
'An error occurred while saving the conversation. Please refresh the page.',
),
),
),
),
);
}),
);
);
}),
);
}),
);

Expand Down
3 changes: 2 additions & 1 deletion apps/chat/src/utils/app/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MAX_ENTITY_LENGTH } from '@/src/constants/default-ui-settings';

import trimEnd from 'lodash-es/trimEnd';
import uniq from 'lodash-es/uniq';
import { substring } from 'stringz';

/**
* Combine entities. If there are the same ids then will be used entity from entities1 i.e. first in array
Expand Down Expand Up @@ -99,7 +100,7 @@ export const prepareEntityName = (name: string, forRenaming = false) => {
.filter(Boolean)[0] ?? '';

if (clearName.length > MAX_ENTITY_LENGTH) {
return trimEndDots(clearName.substring(0, MAX_ENTITY_LENGTH));
return trimEndDots(substring(clearName, 0, MAX_ENTITY_LENGTH));
}

return trimEndDots(clearName);
Expand Down
10 changes: 9 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"rehype-sanitize": "^5.0.1",
"remark-gfm": "^3.0.1",
"rxjs": "^7.8.1",
"stringz": "^2.1.0",
"svgo": "^3.0.2",
"tslib": "^2.6.0"
},
Expand Down

0 comments on commit 647729d

Please sign in to comment.