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
chore: select source when user is not anon (#7921)
Nathan.foooa3593139747f
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dartindex 938aef6f00..495f770c31 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart@@ -1,5 +1,6 @@import 'package:appflowy/ai/ai.dart';import 'package:appflowy/plugins/ai_chat/application/chat_input_control_cubit.dart';+import 'package:appflowy/plugins/ai_chat/application/chat_user_cubit.dart';import 'package:appflowy/plugins/ai_chat/presentation/layout_define.dart';import 'package:appflowy/startup/startup.dart';import 'package:appflowy/util/theme_extension.dart';@@ -48,6 +49,7 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {final layerLink = LayerLink();final overlayController = OverlayPortalController();final inputControlCubit = ChatInputControlCubit();+ final chatUserCubit = ChatUserCubit();final focusNode = FocusNode();late SendButtonState sendButtonState;@@ -56,6 +58,7 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {@overridevoid initState() {super.initState();+ chatUserCubit.fetchUserProfile();widget.textController.addListener(handleTextControllerChanged);focusNode@@ -90,13 +93,17 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {focusNode.dispose();widget.textController.removeListener(handleTextControllerChanged);inputControlCubit.close();+ chatUserCubit.close();super.dispose();}@overrideWidget build(BuildContext context) {- return BlocProvider.value(- value: inputControlCubit,+ return MultiBlocProvider(+ providers: [+ BlocProvider.value(value: inputControlCubit),+ BlocProvider.value(value: chatUserCubit),+ ],child: BlocListener<ChatInputControlCubit, ChatInputControlState>(listener: (context, state) {state.maybeWhen(@@ -656,7 +663,9 @@ class _PromptBottomActions extends StatelessWidget {const Spacer(),- _selectSourcesButton(),+ if (context.read<ChatUserCubit>().supportSelectSource())+ _selectSourcesButton(),+if (extraBottomActionButton != null) extraBottomActionButton!,// _mentionButton(context),if (state.supportChatWithFile) _attachmentButton(context),diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_user_cubit.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_user_cubit.dartnew file mode 100644index 0000000000..da21875078--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_user_cubit.dart@@ -0,0 +1,78 @@+import 'package:appflowy/startup/startup.dart';+import 'package:appflowy/user/application/auth/auth_service.dart';+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';+import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart';+import 'package:equatable/equatable.dart';+import 'package:flutter_bloc/flutter_bloc.dart';++/// ChatUserCubit is responsible for fetching and storing the user profile+class ChatUserCubit extends Cubit<ChatUserState> {+ ChatUserCubit() : super(ChatUserLoadingState()) {+ fetchUserProfile();+ }++ /// Fetches the user profile from the AuthService+ Future<void> fetchUserProfile() async {+ emit(ChatUserLoadingState());+ final userOrFailure = await getIt<AuthService>().getUser();++ userOrFailure.fold(+ (userProfile) => emit(ChatUserSuccessState(userProfile)),+ (error) => emit(ChatUserFailureState(error)),+ );+ }++ bool supportSelectSource() {+ if (state is ChatUserSuccessState) {+ final userProfile = (state as ChatUserSuccessState).userProfile;+ if (userProfile.userAuthType == AuthTypePB.Server) {+ return true;+ }+ }+ return false;+ }++ bool isValueWorkspace() {+ if (state is ChatUserSuccessState) {+ final userProfile = (state as ChatUserSuccessState).userProfile;+ return userProfile.workspaceType == WorkspaceTypePB.LocalW &&+ userProfile.userAuthType != AuthTypePB.Local;+ }+ return false;+ }++ /// Refreshes the user profile data+ Future<void> refresh() async {+ await fetchUserProfile();+ }+}++/// Base state class for ChatUserCubit+abstract class ChatUserState extends Equatable {+ const ChatUserState();++ @override+ List<Object?> get props => [];+}++/// Loading state when fetching user profile+class ChatUserLoadingState extends ChatUserState {}++/// Success state when user profile is fetched successfully+class ChatUserSuccessState extends ChatUserState {+ const ChatUserSuccessState(this.userProfile);+ final UserProfilePB userProfile;++ @override+ List<Object?> get props => [userProfile];+}++/// Failure state when fetching user profile fails+class ChatUserFailureState extends ChatUserState {+ const ChatUserFailureState(this.error);+ final FlowyError error;++ @override+ List<Object?> get props => [error];+}diff --git a/frontend/rust-lib/event-integration-test/tests/chat/mod.rs b/frontend/rust-lib/event-integration-test/tests/chat/mod.rsindex 7203432c70..773bdab81f 100644--- a/frontend/rust-lib/event-integration-test/tests/chat/mod.rs+++ b/frontend/rust-lib/event-integration-test/tests/chat/mod.rs@@ -1,2 +1 @@mod chat_message_test;-mod local_chat_test;