2024-06-15 15:56:50 +02:00
|
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
|
|
import 'package:simplecloudnotifier/state/interfaces.dart';
|
|
|
|
|
2024-06-15 21:29:51 +02:00
|
|
|
part 'scn_message.g.dart';
|
2024-06-15 15:56:50 +02:00
|
|
|
|
|
|
|
@HiveType(typeId: 105)
|
2024-06-15 21:29:51 +02:00
|
|
|
class SCNMessage extends HiveObject implements FieldDebuggable {
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(0)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String messageID;
|
2024-06-15 15:56:50 +02:00
|
|
|
|
|
|
|
@HiveField(10)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String senderUserID;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(11)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String channelInternalName;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(12)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String channelID;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(13)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String? senderName;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(14)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String senderIP;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(15)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String timestamp;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(16)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String title;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(17)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String? content;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(18)
|
2024-02-18 17:36:58 +01:00
|
|
|
final int priority;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(19)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String? userMessageID;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(20)
|
2024-02-18 17:36:58 +01:00
|
|
|
final String usedKeyID;
|
2024-06-15 15:56:50 +02:00
|
|
|
@HiveField(21)
|
2024-02-18 17:36:58 +01:00
|
|
|
final bool trimmed;
|
|
|
|
|
2024-06-15 21:29:51 +02:00
|
|
|
SCNMessage({
|
2024-02-18 17:36:58 +01:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
|
2024-06-15 21:29:51 +02:00
|
|
|
factory SCNMessage.fromJson(Map<String, dynamic> json) {
|
|
|
|
return SCNMessage(
|
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-06-15 21:29:51 +02:00
|
|
|
static (String, List<SCNMessage>) fromPaginatedJsonArray(Map<String, dynamic> data, String keyMessages, String keyToken) {
|
2024-05-25 18:09:39 +02:00
|
|
|
final npt = data[keyToken] as String;
|
|
|
|
|
2024-06-15 21:29:51 +02:00
|
|
|
final messages = (data[keyMessages] as List<dynamic>).map<SCNMessage>((e) => SCNMessage.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
|
|
|
}
|
2024-06-15 15:56:50 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return 'Message[${this.messageID}]';
|
|
|
|
}
|
|
|
|
|
|
|
|
List<(String, String)> debugFieldList() {
|
|
|
|
return [
|
|
|
|
('messageID', this.messageID),
|
|
|
|
('senderUserID', this.senderUserID),
|
|
|
|
('channelInternalName', this.channelInternalName),
|
|
|
|
('channelID', this.channelID),
|
|
|
|
('senderName', this.senderName ?? ''),
|
|
|
|
('senderIP', this.senderIP),
|
|
|
|
('timestamp', this.timestamp),
|
|
|
|
('title', this.title),
|
|
|
|
('content', this.content ?? ''),
|
|
|
|
('priority', '${this.priority}'),
|
|
|
|
('userMessageID', this.userMessageID ?? ''),
|
|
|
|
('usedKeyID', this.usedKeyID),
|
|
|
|
('trimmed', '${this.trimmed}'),
|
|
|
|
];
|
|
|
|
}
|
2024-02-18 17:36:58 +01:00
|
|
|
}
|