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 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: messageId > 0 ? messageId : -(DateTime.now().microsecondsSinceEpoch), 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 { 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 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) return null; return SendMessageResponse.fromJson(data); } }