Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: initial ai chat load (#6920)
Richard Shiue92945cafdf02
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_bloc.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_bloc.dartindex 5c0cdabe67..09d7ed2417 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_bloc.dart@@ -59,6 +59,16 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {AnswerStream? answerStream;int numSendMessage = 0;+ /// a counter used to determine whether the initial loading state should be+ /// set to finish. It should hit two before we emit: one for the local fetch+ /// and another for the server fetch.+ ///+ /// This is to work around a bug where if an ai chat that is not yet on the+ /// user local storage is opened but has messages in the server, it will+ /// remain stuck on the welcome screen until the user switches to another page+ /// then come back.+ int initialFetchCounter = 0;+@overrideFuture<void> close() async {await answerStream?.dispose();@@ -76,7 +86,11 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {await chatController.insert(message, index: 0);}- if (state.loadingState.isLoading) {+ if (initialFetchCounter < 2) {+ initialFetchCounter++;+ }++ if (state.loadingState.isLoading && initialFetchCounter >= 2) {emit(state.copyWith(loadingState: const ChatLoadingState.finish()),);