refactor: 重构 Agent 模块为 AgentScope,删除旧版 CrewAI/LiteLLM 实现
This commit is contained in:
@@ -8,8 +8,11 @@ import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/page_header.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../calendar/data/calendar_api.dart';
|
||||
import '../../../friends/data/friends_api.dart';
|
||||
import '../../data/inbox_api.dart';
|
||||
import '../../ui/widgets/calendar_message_card.dart';
|
||||
|
||||
class MessageWithFriend {
|
||||
final InboxMessageResponse message;
|
||||
@@ -29,6 +32,7 @@ class MessageInviteListScreen extends StatefulWidget {
|
||||
class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
late final InboxApi _inboxApi;
|
||||
late final FriendsApi _friendsApi;
|
||||
late final CalendarApi _calendarApi;
|
||||
|
||||
List<MessageWithFriend> _unreadMessages = [];
|
||||
List<MessageWithFriend> _readMessages = [];
|
||||
@@ -40,6 +44,7 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
super.initState();
|
||||
_inboxApi = sl<InboxApi>();
|
||||
_friendsApi = sl<FriendsApi>();
|
||||
_calendarApi = sl<CalendarApi>();
|
||||
_loadMessages();
|
||||
}
|
||||
|
||||
@@ -103,7 +108,23 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
final message = item.message;
|
||||
switch (message.messageType) {
|
||||
case InboxMessageType.calendar:
|
||||
context.push('/messages/invites/${message.id}');
|
||||
final content = _parseCalendarContent(message.content);
|
||||
if (content == null) return;
|
||||
|
||||
final type = content['type'] as String?;
|
||||
if (type == 'invite') {
|
||||
if (message.status.value == 'pending') {
|
||||
await _showCalendarInviteSheet(message);
|
||||
} else if (message.status.value == 'accepted') {
|
||||
if (message.scheduleItemId != null) {
|
||||
context.push('/calendar/${message.scheduleItemId}');
|
||||
}
|
||||
}
|
||||
} else if (type == 'update') {
|
||||
if (message.scheduleItemId != null) {
|
||||
context.push('/calendar/${message.scheduleItemId}');
|
||||
}
|
||||
}
|
||||
return;
|
||||
case InboxMessageType.friendRequest:
|
||||
if (item.friendRequest == null) {
|
||||
@@ -122,6 +143,91 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic>? _parseCalendarContent(String? content) {
|
||||
if (content == null) return null;
|
||||
try {
|
||||
return jsonDecode(content) as Map<String, dynamic>;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showCalendarInviteSheet(InboxMessageResponse message) async {
|
||||
final itemId = message.scheduleItemId;
|
||||
if (itemId == null) return;
|
||||
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (ctx) => Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(AppRadius.lg),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'日历邀请',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppButton(
|
||||
text: '拒绝',
|
||||
isOutlined: true,
|
||||
onPressed: () async {
|
||||
try {
|
||||
await _calendarApi.rejectSubscription(itemId);
|
||||
await _inboxApi.markAsRead(message.id);
|
||||
if (mounted) {
|
||||
Navigator.pop(ctx);
|
||||
Toast.show(context, '已拒绝', type: ToastType.success);
|
||||
_loadMessages();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '操作失败', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: AppButton(
|
||||
text: '接受',
|
||||
onPressed: () async {
|
||||
try {
|
||||
await _calendarApi.acceptSubscription(itemId);
|
||||
await _inboxApi.markAsRead(message.id);
|
||||
if (mounted) {
|
||||
Navigator.pop(ctx);
|
||||
Toast.show(context, '已接受', type: ToastType.success);
|
||||
_loadMessages();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '操作失败', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showFriendRequestReadOnlySheet(MessageWithFriend item) {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
@@ -465,7 +571,35 @@ class _MessageCard extends StatelessWidget {
|
||||
return '系统消息';
|
||||
}
|
||||
|
||||
String _content() => message.content ?? '点击查看详情';
|
||||
String _content() {
|
||||
if (message.messageType == InboxMessageType.calendar) {
|
||||
Map<String, dynamic>? data;
|
||||
if (message.content != null) {
|
||||
try {
|
||||
data = jsonDecode(message.content!) as Map<String, dynamic>;
|
||||
} catch (_) {
|
||||
data = null;
|
||||
}
|
||||
}
|
||||
if (data == null) return '点击查看详情';
|
||||
|
||||
final type = data['type'] as String?;
|
||||
if (type == 'invite') {
|
||||
final status = message.status.value;
|
||||
if (status == 'pending') {
|
||||
return '邀请您加入日历';
|
||||
} else if (status == 'accepted') {
|
||||
return '已接受日历邀请';
|
||||
} else if (status == 'rejected') {
|
||||
return '已拒绝日历邀请';
|
||||
}
|
||||
} else if (type == 'update') {
|
||||
return '更新了日历事件';
|
||||
}
|
||||
return '点击查看详情';
|
||||
}
|
||||
return message.content ?? '点击查看详情';
|
||||
}
|
||||
}
|
||||
|
||||
class _FriendRequestSheet extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user