feat:增加消息记录功能
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:sweet_chat_app/models/user.dart';
|
||||
|
||||
part 'auth.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class Auth {
|
||||
final int userId;
|
||||
final User user;
|
||||
|
||||
Auth({required this.userId});
|
||||
Auth({required this.user});
|
||||
|
||||
factory Auth.fromJson(Map<String, dynamic> json) => _$AuthFromJson(json);
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ part of 'auth.dart';
|
||||
// **************************************************************************
|
||||
|
||||
Auth _$AuthFromJson(Map<String, dynamic> json) =>
|
||||
Auth(userId: (json['userId'] as num).toInt());
|
||||
Auth(user: User.fromJson(json['user'] as Map<String, dynamic>));
|
||||
|
||||
Map<String, dynamic> _$AuthToJson(Auth instance) => <String, dynamic>{
|
||||
'userId': instance.userId,
|
||||
'user': instance.user,
|
||||
};
|
||||
|
||||
26
lib/models/chat_message.dart
Normal file
26
lib/models/chat_message.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'chat_message.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ChatMessage {
|
||||
final int msgId;
|
||||
final int senderId;
|
||||
final String content;
|
||||
/// 消息类型(1文本 2图片 3语音)
|
||||
final int msgType;
|
||||
final DateTime createTime;
|
||||
|
||||
ChatMessage({
|
||||
required this.msgId,
|
||||
required this.senderId,
|
||||
required this.content,
|
||||
required this.msgType,
|
||||
required this.createTime,
|
||||
});
|
||||
|
||||
factory ChatMessage.fromJson(Map<String, dynamic> json) =>
|
||||
_$ChatMessageFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ChatMessageToJson(this);
|
||||
}
|
||||
24
lib/models/chat_message.g.dart
Normal file
24
lib/models/chat_message.g.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'chat_message.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ChatMessage _$ChatMessageFromJson(Map<String, dynamic> json) => ChatMessage(
|
||||
msgId: (json['msgId'] as num).toInt(),
|
||||
senderId: (json['senderId'] as num).toInt(),
|
||||
content: json['content'] as String,
|
||||
msgType: (json['msgType'] as num).toInt(),
|
||||
createTime: DateTime.parse(json['createTime'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ChatMessageToJson(ChatMessage instance) =>
|
||||
<String, dynamic>{
|
||||
'msgId': instance.msgId,
|
||||
'senderId': instance.senderId,
|
||||
'content': instance.content,
|
||||
'msgType': instance.msgType,
|
||||
'createTime': instance.createTime.toIso8601String(),
|
||||
};
|
||||
30
lib/models/chat_session.dart
Normal file
30
lib/models/chat_session.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'chat_session.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ChatSession {
|
||||
final int conversationId;
|
||||
final int targetUserId;
|
||||
final String title;
|
||||
final String avatarUrl;
|
||||
final int msgType;
|
||||
final String lastMessageContent;
|
||||
final DateTime lastMessageTime;
|
||||
final int unreadCount;
|
||||
|
||||
ChatSession({
|
||||
required this.conversationId,
|
||||
required this.targetUserId,
|
||||
required this.title,
|
||||
required this.avatarUrl,
|
||||
required this.msgType,
|
||||
required this.lastMessageContent,
|
||||
required this.lastMessageTime,
|
||||
required this.unreadCount,
|
||||
});
|
||||
|
||||
factory ChatSession.fromJson(Map<String, dynamic> json) => _$ChatSessionFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ChatSessionToJson(this);
|
||||
}
|
||||
30
lib/models/chat_session.g.dart
Normal file
30
lib/models/chat_session.g.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'chat_session.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ChatSession _$ChatSessionFromJson(Map<String, dynamic> json) => ChatSession(
|
||||
conversationId: (json['conversationId'] as num).toInt(),
|
||||
targetUserId: (json['targetUserId'] as num).toInt(),
|
||||
title: json['title'] as String,
|
||||
avatarUrl: json['avatarUrl'] as String,
|
||||
msgType: (json['msgType'] as num).toInt(),
|
||||
lastMessageContent: json['lastMessageContent'] as String,
|
||||
lastMessageTime: DateTime.parse(json['lastMessageTime'] as String),
|
||||
unreadCount: (json['unreadCount'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ChatSessionToJson(ChatSession instance) =>
|
||||
<String, dynamic>{
|
||||
'conversationId': instance.conversationId,
|
||||
'targetUserId': instance.targetUserId,
|
||||
'title': instance.title,
|
||||
'avatarUrl': instance.avatarUrl,
|
||||
'msgType': instance.msgType,
|
||||
'lastMessageContent': instance.lastMessageContent,
|
||||
'lastMessageTime': instance.lastMessageTime.toIso8601String(),
|
||||
'unreadCount': instance.unreadCount,
|
||||
};
|
||||
20
lib/models/contact_info.dart
Normal file
20
lib/models/contact_info.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:azlistview/azlistview.dart';
|
||||
|
||||
class ContactInfo extends ISuspensionBean {
|
||||
final int id;
|
||||
final String name;
|
||||
final String avatar;
|
||||
String? tagIndex;
|
||||
String? namePinyin;
|
||||
|
||||
ContactInfo({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.avatar,
|
||||
this.tagIndex,
|
||||
this.namePinyin,
|
||||
});
|
||||
|
||||
@override
|
||||
String getSuspensionTag() => tagIndex ?? '#';
|
||||
}
|
||||
@@ -1,7 +1,20 @@
|
||||
import 'dart:convert';
|
||||
|
||||
enum ImMessageType {
|
||||
chatPrivate('CHAT_PRIVATE'),
|
||||
chatGroup('CHAT_GROUP'),
|
||||
online('ONLINE'),
|
||||
heartbeat('HEARTBEAT'),
|
||||
system('SYSTEM'),
|
||||
notice('NOTICE');
|
||||
|
||||
final String value;
|
||||
|
||||
const ImMessageType(this.value);
|
||||
}
|
||||
|
||||
class ImMessage {
|
||||
final String type;
|
||||
final ImMessageType type;
|
||||
final String from;
|
||||
final String to;
|
||||
final String content;
|
||||
@@ -19,7 +32,7 @@ class ImMessage {
|
||||
|
||||
factory ImMessage.fromJson(Map<String, dynamic> json) {
|
||||
return ImMessage(
|
||||
type: json['type'],
|
||||
type: ImMessageType.values.firstWhere((e) => e.value == json['type']),
|
||||
from: json['from'],
|
||||
to: json['to'],
|
||||
content: json['content'],
|
||||
@@ -27,7 +40,7 @@ class ImMessage {
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'type': type,
|
||||
'type': type.value,
|
||||
'from': from,
|
||||
'to': to,
|
||||
'content': content,
|
||||
@@ -36,4 +49,13 @@ class ImMessage {
|
||||
String toJsonString() {
|
||||
return jsonEncode(toJson());
|
||||
}
|
||||
}
|
||||
|
||||
static ImMessage online(int userId) {
|
||||
return ImMessage(
|
||||
type: ImMessageType.online,
|
||||
from: userId.toString(),
|
||||
to: 'SYSTEM',
|
||||
content: '',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user