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: try to fix message regeneration being appended instead of replaced (#7084)
Richard Shiue06d5bc734b69
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 58146c42f1..c18389e262 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@@ -272,15 +272,19 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {// 3 mean message response from AIif (pb.authorType == 3 && answerStreamMessageId.isNotEmpty) {- temporaryMessageIDMap[pb.messageId.toString()] =- answerStreamMessageId;+ temporaryMessageIDMap.putIfAbsent(+ pb.messageId.toString(),+ () => answerStreamMessageId,+ );answerStreamMessageId = '';}// 1 mean message response from Userif (pb.authorType == 1 && questionStreamMessageId.isNotEmpty) {- temporaryMessageIDMap[pb.messageId.toString()] =- questionStreamMessageId;+ temporaryMessageIDMap.putIfAbsent(+ pb.messageId.toString(),+ () => questionStreamMessageId,+ );questionStreamMessageId = '';}@@ -422,8 +426,9 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {(question) {if (!isClosed) {final streamAnswer = _createAnswerStreamMessage(- answerStream!,- question.messageId,+ stream: answerStream!,+ questionMessageId: question.messageId,+ fakeQuestionMessageId: questionStreamMessage.id,);lastSentMessage = question;@@ -479,8 +484,8 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {(success) {if (!isClosed) {final streamAnswer = _createAnswerStreamMessage(- answerStream!,- answerMessageId - 1,+ stream: answerStream!,+ questionMessageId: answerMessageId - 1,).copyWith(id: answerMessageIdString);add(ChatEvent.receiveMessage(streamAnswer));@@ -491,11 +496,14 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {);}- Message _createAnswerStreamMessage(- AnswerStream stream,- Int64 questionMessageId,- ) {- answerStreamMessageId = (questionMessageId + 1).toString();+ Message _createAnswerStreamMessage({+ required AnswerStream stream,+ required Int64 questionMessageId,+ String? fakeQuestionMessageId,+ }) {+ answerStreamMessageId = fakeQuestionMessageId == null+ ? (questionMessageId + 1).toString()+ : "${fakeQuestionMessageId}_ans";return TextMessage(id: answerStreamMessageId,