Files
customer-im-client-dev/apps/im_app/lib/data/remote/send_message_request.dart
pp-bot e715a0673b feat(chat): 发收消息全量实现 (#25~#28)
- 移除 @riverpod/@freezed 注解依赖,全部改为手写 Provider(无需 build_runner)
  · LoginState 改为纯 Dart,LoginViewModel/ThemeViewModel/ChatViewModel 改为 Notifier
  · UserNotifier 改为 FamilyAsyncNotifier<User?,int>,mini_app_provider 改为手写 Provider
  · 15 个 StreamProvider/StreamProvider.family 从 @riverpod 迁移至手写

- 发送消息(#25)
  · SendMessageRequest/SendMessageResponse DTO
  · SendMessageUseCase:乐观写入 DB → HTTP POST → 更新 Chat 摘要

- 接收消息 WS(#26)
  · WsMessageService:监听 mode2 WS 帧 → HTTP 补拉 → DB 写入 → Chat 更新
  · FetchHistoryRequest/FetchHistoryResponse DTO(GET /app/api/chat/history)
  · FetchHistoryUseCase:拉取 → insertOrReplaceAll

- DI 装配(chat_service_providers.dart)
  · wsMessageServiceProvider、sendMessageUseCaseProvider、fetchHistoryUseCaseProvider

- 聊天列表页(#27)
  · ChatListViewModel(Notifier<void>)+ chat_page.dart 真实会话列表 UI
  · ListTile:头像首字母、最新消息摘要、未读角标、时间格式化

- 聊天详情页(#28)
  · ChatDetailViewModel(FamilyNotifier<ChatDetailState,int>)+ chat_detail_page.dart
  · 消息气泡(自己/他人分左右)、底部输入框、发送状态与错误提示

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:16:44 +09:00

89 lines
2.5 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:networks_sdk/networks_sdk.dart';
import 'package:im_app/core/foundation/api_paths.dart';
import 'package:im_app/domain/entities/message.dart';
// ── 发送消息响应 ───────────────────────────────────────────────────────────────
/// 发送消息接口响应
class SendMessageResponse {
final int messageId;
final int chatIdx;
final int sendTime;
const SendMessageResponse({
required this.messageId,
required this.chatIdx,
required this.sendTime,
});
factory SendMessageResponse.fromJson(Map<String, dynamic> json) =>
SendMessageResponse(
messageId:
(json['message_id'] ?? json['messageId'] ?? json['id'] ?? 0)
as int,
chatIdx:
(json['chat_idx'] ?? json['chatIdx'] ?? 0) as int,
sendTime:
(json['send_time'] ?? json['sendTime'] ?? 0) as int,
);
Message toEntity({
required int chatId,
required int sendId,
required String content,
required int typ,
}) =>
Message(
id: 0,
messageId: messageId,
chatId: chatId,
chatIdx: chatIdx,
sendId: sendId,
content: content,
typ: typ,
sendTime: sendTime,
);
}
// ── 发送消息请求 ───────────────────────────────────────────────────────────────
/// POST /app/api/chat/send-message — 发送文本消息
///
/// [typ] 消息类型1 = 文本,详见服务端 MessageType 枚举。
/// [sendTime] Unix 时间戳(秒),由客户端生成,用于服务端去重。
class SendMessageRequest extends ApiRequestable<SendMessageResponse> {
final int chatId;
final String content;
final int typ;
final int sendTime;
const SendMessageRequest({
required this.chatId,
required this.content,
required this.typ,
required this.sendTime,
});
@override
String get path => ApiPaths.chatSendMessage;
@override
HttpMethod get method => HttpMethod.post;
@override
Map<String, dynamic> get parameters => {
'chat_id': chatId,
'content': content,
'typ': typ,
'send_time': sendTime,
};
@override
SendMessageResponse? decodeResponse(dynamic response) {
final data = (response as dynamic).data;
if (data is! Map<String, dynamic>) return null;
return SendMessageResponse.fromJson(data);
}
}