Solian/lib/models/message.dart

122 lines
3.2 KiB
Dart
Raw Normal View History

2024-05-18 10:17:16 +00:00
import 'package:solian/models/account.dart';
import 'package:solian/models/channel.dart';
class Message {
int id;
2024-05-26 05:39:21 +00:00
String uuid;
2024-05-18 10:17:16 +00:00
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
2024-05-25 17:21:08 +00:00
Map<String, dynamic> content;
2024-05-18 10:17:16 +00:00
String type;
2024-05-26 05:39:21 +00:00
List<int>? attachments;
2024-05-18 10:17:16 +00:00
Channel? channel;
Sender sender;
int? replyId;
Message? replyTo;
int channelId;
int senderId;
bool isSending = false;
Message({
required this.id,
2024-05-26 05:39:21 +00:00
required this.uuid,
2024-05-18 10:17:16 +00:00
required this.createdAt,
required this.updatedAt,
this.deletedAt,
2024-05-25 17:21:08 +00:00
required this.content,
2024-05-18 10:17:16 +00:00
required this.type,
this.attachments,
this.channel,
required this.sender,
required this.replyId,
required this.replyTo,
required this.channelId,
required this.senderId,
});
factory Message.fromJson(Map<String, dynamic> json) => Message(
id: json['id'],
2024-05-26 05:39:21 +00:00
uuid: json['uuid'],
2024-05-18 10:17:16 +00:00
createdAt: DateTime.parse(json['created_at']),
updatedAt: DateTime.parse(json['updated_at']),
deletedAt: json['deleted_at'],
2024-05-25 17:21:08 +00:00
content: json['content'],
2024-05-18 10:17:16 +00:00
type: json['type'],
2024-05-26 05:39:21 +00:00
attachments: json["attachments"] != null
? List<int>.from(json["attachments"])
: null,
channel:
json['channel'] != null ? Channel.fromJson(json['channel']) : null,
2024-05-18 10:17:16 +00:00
sender: Sender.fromJson(json['sender']),
replyId: json['reply_id'],
2024-05-25 17:21:08 +00:00
replyTo: json['reply_to'] != null
? Message.fromJson(json['reply_to'])
: null,
2024-05-18 10:17:16 +00:00
channelId: json['channel_id'],
senderId: json['sender_id'],
);
Map<String, dynamic> toJson() => {
'id': id,
2024-05-26 05:39:21 +00:00
'uuid': uuid,
2024-05-18 10:17:16 +00:00
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt,
2024-05-25 17:21:08 +00:00
'content': content,
2024-05-18 10:17:16 +00:00
'type': type,
'attachments': attachments,
'channel': channel?.toJson(),
'sender': sender.toJson(),
'reply_id': replyId,
'reply_to': replyTo?.toJson(),
'channel_id': channelId,
'sender_id': senderId,
};
}
class Sender {
int id;
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
Account account;
int channelId;
int accountId;
int notify;
Sender({
required this.id,
required this.createdAt,
required this.updatedAt,
this.deletedAt,
required this.account,
required this.channelId,
required this.accountId,
required this.notify,
});
factory Sender.fromJson(Map<String, dynamic> json) => Sender(
id: json['id'],
createdAt: DateTime.parse(json['created_at']),
updatedAt: DateTime.parse(json['updated_at']),
deletedAt: json['deleted_at'],
account: Account.fromJson(json['account']),
channelId: json['channel_id'],
accountId: json['account_id'],
notify: json['notify'],
);
Map<String, dynamic> toJson() => {
'id': id,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt,
'account': account.toJson(),
'channel_id': channelId,
'account_id': accountId,
'notify': notify,
};
}