SimpleCloudNotifier/flutter/lib/models/message.dart

58 lines
1.8 KiB
Dart
Raw Normal View History

2024-02-18 17:36:58 +01:00
class Message {
final String messageID;
final String senderUserID;
final String channelInternalName;
final String channelID;
final String? senderName;
final String senderIP;
final String timestamp;
final String title;
final String? content;
final int priority;
final String? userMessageID;
final String usedKeyID;
final bool trimmed;
const Message({
required this.messageID,
required this.senderUserID,
required this.channelInternalName,
required this.channelID,
required this.senderName,
required this.senderIP,
required this.timestamp,
required this.title,
required this.content,
required this.priority,
required this.userMessageID,
required this.usedKeyID,
required this.trimmed,
});
factory Message.fromJson(Map<String, dynamic> json) {
2024-05-25 18:09:39 +02:00
return Message(
2024-05-25 21:36:05 +02:00
messageID: json['message_id'] as String,
senderUserID: json['sender_user_id'] as String,
channelInternalName: json['channel_internal_name'] as String,
channelID: json['channel_id'] as String,
2024-05-26 00:20:25 +02:00
senderName: json['sender_name'] as String?,
2024-05-25 21:36:05 +02:00
senderIP: json['sender_ip'] as String,
timestamp: json['timestamp'] as String,
title: json['title'] as String,
2024-05-26 00:20:25 +02:00
content: json['content'] as String?,
2024-05-25 21:36:05 +02:00
priority: json['priority'] as int,
2024-05-26 00:20:25 +02:00
userMessageID: json['usr_message_id'] as String?,
2024-05-25 21:36:05 +02:00
usedKeyID: json['used_key_id'] as String,
trimmed: json['trimmed'] as bool,
2024-05-25 18:09:39 +02:00
);
}
2024-05-25 21:36:05 +02:00
static (String, List<Message>) fromPaginatedJsonArray(Map<String, dynamic> data, String keyMessages, String keyToken) {
2024-05-25 18:09:39 +02:00
final npt = data[keyToken] as String;
2024-05-25 21:36:05 +02:00
final messages = (data[keyMessages] as List<dynamic>).map<Message>((e) => Message.fromJson(e as Map<String, dynamic>)).toList();
2024-05-25 18:09:39 +02:00
return (npt, messages);
2024-02-18 17:36:58 +01:00
}
}