Solian/lib/models/event.dart

147 lines
3.8 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 Event {
2024-05-18 10:17:16 +00:00
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;
Map<String, dynamic> body;
2024-05-18 10:17:16 +00:00
String type;
Channel? channel;
Sender sender;
int channelId;
int senderId;
2024-06-27 16:59:11 +00:00
bool isPending = false;
2024-05-18 10:17:16 +00:00
Event({
2024-05-18 10:17:16 +00:00
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,
required this.body,
2024-05-18 10:17:16 +00:00
required this.type,
this.channel,
required this.sender,
required this.channelId,
required this.senderId,
});
factory Event.fromJson(Map<String, dynamic> json) => Event(
2024-05-18 10:17:16 +00:00
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'],
body: json['body'],
2024-05-18 10:17:16 +00:00
type: json['type'],
channel:
json['channel'] != null ? Channel.fromJson(json['channel']) : null,
2024-05-18 10:17:16 +00:00
sender: Sender.fromJson(json['sender']),
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,
'body': body,
2024-05-18 10:17:16 +00:00
'type': type,
'channel': channel?.toJson(),
'sender': sender.toJson(),
'channel_id': channelId,
'sender_id': senderId,
};
}
class EventMessageBody {
String text;
String algorithm;
List<int>? attachments;
int? quoteEvent;
int? relatedEvent;
List<int>? relatedUsers;
EventMessageBody({
required this.text,
required this.algorithm,
required this.attachments,
required this.quoteEvent,
required this.relatedEvent,
required this.relatedUsers,
});
factory EventMessageBody.fromJson(Map<String, dynamic> json) =>
EventMessageBody(
2024-06-28 11:33:59 +00:00
text: json['text'] ?? '',
algorithm: json['algorithm'] ?? 'plain',
attachments: json['attachments'] != null
? List<int>.from(json['attachments'].map((x) => x))
: null,
quoteEvent: json['quote_event'],
relatedEvent: json['related_event'],
relatedUsers: json['related_users'] != null
? List<int>.from(json['related_users'].map((x) => x))
: null,
);
Map<String, dynamic> toJson() => {
'text': text,
'algorithm': algorithm,
'attachments': attachments?.cast<dynamic>(),
'quote_event': quoteEvent,
'related_event': relatedEvent,
'related_users': relatedUsers?.cast<dynamic>(),
};
}
2024-05-18 10:17:16 +00:00
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,
};
}