refactor: 重构聊天数据层至core并简化首页UI
This commit is contained in:
@@ -2,16 +2,15 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:social_app/core/chat/chat_api.dart';
|
||||
import 'package:social_app/core/chat/agent_stage.dart';
|
||||
import 'package:social_app/core/chat/ag_ui_event.dart';
|
||||
import 'package:social_app/core/chat/ag_ui_service.dart';
|
||||
import 'package:social_app/core/chat/chat_list_item.dart';
|
||||
import 'package:social_app/core/chat/chat_orchestrator.dart';
|
||||
import 'package:social_app/data/network/i_api_client.dart';
|
||||
import 'package:social_app/core/chat/chat_history_repository.dart';
|
||||
import 'package:social_app/core/l10n/l10n.dart';
|
||||
|
||||
import '../../data/models/ag_ui_event.dart';
|
||||
import '../../data/repositories/chat_history_repository.dart';
|
||||
import '../../data/services/ag_ui_service.dart';
|
||||
|
||||
class ChatState implements ChatOrchestratorState {
|
||||
@override
|
||||
final List<ChatListItem> items;
|
||||
@@ -98,14 +97,11 @@ class ChatState implements ChatOrchestratorState {
|
||||
class ChatBloc extends Cubit<ChatState> implements ChatOrchestrator {
|
||||
ChatBloc({
|
||||
AgUiService? service,
|
||||
required IApiClient apiClient,
|
||||
required ChatApi chatApi,
|
||||
ChatHistoryRepository? historyRepository,
|
||||
}) : _service =
|
||||
service ??
|
||||
AgUiService(
|
||||
apiClient: apiClient,
|
||||
historyRepository: historyRepository,
|
||||
),
|
||||
AgUiService(chatApi: chatApi, historyRepository: historyRepository),
|
||||
super(const ChatState()) {
|
||||
_service.onEvent = _handleEvent;
|
||||
}
|
||||
@@ -434,7 +430,20 @@ class ChatBloc extends Cubit<ChatState> implements ChatOrchestrator {
|
||||
),
|
||||
);
|
||||
try {
|
||||
final sendResult = await _service.sendMessage(content, images: images);
|
||||
final uploadInputs = await Future.wait(
|
||||
(images ?? const <XFile>[]).map(
|
||||
(image) async => AttachmentUploadInput(
|
||||
name: image.name,
|
||||
mimeType: image.mimeType ?? 'image/jpeg',
|
||||
bytes: await image.readAsBytes(),
|
||||
localPath: image.path,
|
||||
),
|
||||
),
|
||||
);
|
||||
final sendResult = await _service.sendMessage(
|
||||
content,
|
||||
attachments: uploadInputs,
|
||||
);
|
||||
_syncUploadedAttachments(
|
||||
messageId: messageId,
|
||||
uploadedAttachments: sendResult.uploadedAttachments,
|
||||
|
||||
Reference in New Issue
Block a user