Skip to content

Commit

Permalink
Fixes the double creation of a new chat when clicking 'Create new cha…
Browse files Browse the repository at this point in the history
…t,' changing the selected tab, and clicking 'Create new chat' again.
  • Loading branch information
boyan-tonchev authored and svilenvelikov committed Oct 7, 2024
1 parent 405ec8e commit 603bc75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/js/angular/models/ttyg/chats.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ export class ChatsListModel {
return this._chats.find((c) => c.id === id);
}

getNonPersistedChat() {
return this._chats.find((chat) => !chat.id);
}

renameChat(renamedChat) {
const chat = this._chats.find((c) => c.id === renamedChat.id);
if (chat) {
Expand Down
6 changes: 5 additions & 1 deletion src/js/angular/ttyg/directives/chat-list.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ function ChatListComponent(TTYGContextService, ModalService, $translate, $filter
};

const onNewChat = () => {
if ($scope.selectedChat && !$scope.selectedChat.id) {
const newChat = $scope.chatList.getNonPersistedChat();
if (newChat) {
if ($scope.selectedChat.id !== newChat.id) {
TTYGContextService.selectChat(newChat);
}
return;
}
const data = {
Expand Down

0 comments on commit 603bc75

Please sign in to comment.