55 lines
1.9 KiB
Dart
55 lines
1.9 KiB
Dart
|
|
// 功能描述:解析消息中心真实业务消息及分类计数;版本:1.0.0。
|
|||
|
|
class UserMessage {
|
|||
|
|
const UserMessage({
|
|||
|
|
required this.key,
|
|||
|
|
required this.category,
|
|||
|
|
required this.title,
|
|||
|
|
required this.summary,
|
|||
|
|
required this.statusText,
|
|||
|
|
required this.target,
|
|||
|
|
required this.targetIdentity,
|
|||
|
|
required this.occurredAt,
|
|||
|
|
required this.read,
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
factory UserMessage.fromJson(Map<String, dynamic> json) => UserMessage(
|
|||
|
|
key: json['key']?.toString() ?? '',
|
|||
|
|
category: json['category']?.toString() ?? '',
|
|||
|
|
title: json['title']?.toString() ?? '',
|
|||
|
|
summary: json['summary']?.toString() ?? '',
|
|||
|
|
statusText: json['status_text']?.toString() ?? '',
|
|||
|
|
target: json['target']?.toString() ?? '',
|
|||
|
|
targetIdentity: json['target_identity']?.toString() ?? '',
|
|||
|
|
occurredAt:
|
|||
|
|
DateTime.tryParse(json['occurred_at']?.toString() ?? '') ??
|
|||
|
|
DateTime.fromMillisecondsSinceEpoch(0),
|
|||
|
|
read: json['read'] == true,
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
final String key, category, title, summary, statusText, target, targetIdentity;
|
|||
|
|
final DateTime occurredAt;
|
|||
|
|
final bool read;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
class MessageCenterData {
|
|||
|
|
const MessageCenterData({required this.items, required this.counts});
|
|||
|
|
factory MessageCenterData.fromJson(Map<String, dynamic> json) {
|
|||
|
|
final rawItems = json['items'] is List ? json['items'] as List<dynamic> : const <dynamic>[];
|
|||
|
|
final rawCounts = json['counts'] is Map
|
|||
|
|
? Map<String, dynamic>.from(json['counts'] as Map<dynamic, dynamic>)
|
|||
|
|
: const <String, dynamic>{};
|
|||
|
|
return MessageCenterData(
|
|||
|
|
items: List.unmodifiable(
|
|||
|
|
rawItems.whereType<Map<dynamic, dynamic>>().map(
|
|||
|
|
(item) => UserMessage.fromJson(Map<String, dynamic>.from(item)),
|
|||
|
|
),
|
|||
|
|
),
|
|||
|
|
counts: Map.unmodifiable(
|
|||
|
|
rawCounts.map((key, value) => MapEntry(key, value is num ? value.toInt() : 0)),
|
|||
|
|
),
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
final List<UserMessage> items;
|
|||
|
|
final Map<String, int> counts;
|
|||
|
|
}
|