chore: select source when user is not anon (#7921)

This commit is contained in:
Nathan.fooo 2025-05-13 11:10:32 +08:00 committed by GitHub
parent 636794b9ba
commit a359313974
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 90 additions and 4 deletions

View File

@ -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> {
@override
void 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();
}
@override
Widget 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),

View File

@ -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];
}

View File

@ -1,2 +1 @@
mod chat_message_test;
mod local_chat_test;