channel and message lists
This commit is contained in:
100
flutter/lib/models/channel.dart
Normal file
100
flutter/lib/models/channel.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
import 'package:simplecloudnotifier/models/subscription.dart';
|
||||
|
||||
class Channel {
|
||||
final String channelID;
|
||||
final String ownerUserID;
|
||||
final String internalName;
|
||||
final String displayName;
|
||||
final String? descriptionName;
|
||||
final String? subscribeKey;
|
||||
final String timestampCreated;
|
||||
final String? timestampLastSent;
|
||||
final int messagesSent;
|
||||
|
||||
const Channel({
|
||||
required this.channelID,
|
||||
required this.ownerUserID,
|
||||
required this.internalName,
|
||||
required this.displayName,
|
||||
required this.descriptionName,
|
||||
required this.subscribeKey,
|
||||
required this.timestampCreated,
|
||||
required this.timestampLastSent,
|
||||
required this.messagesSent,
|
||||
});
|
||||
|
||||
factory Channel.fromJson(Map<String, dynamic> json) {
|
||||
return switch (json) {
|
||||
{
|
||||
'channel_id': String channelID,
|
||||
'owner_user_id': String ownerUserID,
|
||||
'internal_name': String internalName,
|
||||
'display_name': String displayName,
|
||||
'description_name': String? descriptionName,
|
||||
'subscribe_key': String? subscribeKey,
|
||||
'timestamp_created': String timestampCreated,
|
||||
'timestamp_lastsent': String? timestampLastSent,
|
||||
'messages_sent': int messagesSent,
|
||||
} =>
|
||||
Channel(
|
||||
channelID: channelID,
|
||||
ownerUserID: ownerUserID,
|
||||
internalName: internalName,
|
||||
displayName: displayName,
|
||||
descriptionName: descriptionName,
|
||||
subscribeKey: subscribeKey,
|
||||
timestampCreated: timestampCreated,
|
||||
timestampLastSent: timestampLastSent,
|
||||
messagesSent: messagesSent,
|
||||
),
|
||||
_ => throw const FormatException('Failed to decode Channel.'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class ChannelWithSubscription extends Channel {
|
||||
final Subscription subscription;
|
||||
|
||||
ChannelWithSubscription({
|
||||
required super.channelID,
|
||||
required super.ownerUserID,
|
||||
required super.internalName,
|
||||
required super.displayName,
|
||||
required super.descriptionName,
|
||||
required super.subscribeKey,
|
||||
required super.timestampCreated,
|
||||
required super.timestampLastSent,
|
||||
required super.messagesSent,
|
||||
required this.subscription,
|
||||
});
|
||||
|
||||
factory ChannelWithSubscription.fromJson(Map<String, dynamic> json) {
|
||||
return switch (json) {
|
||||
{
|
||||
'channel_id': String channelID,
|
||||
'owner_user_id': String ownerUserID,
|
||||
'internal_name': String internalName,
|
||||
'display_name': String displayName,
|
||||
'description_name': String? descriptionName,
|
||||
'subscribe_key': String? subscribeKey,
|
||||
'timestamp_created': String timestampCreated,
|
||||
'timestamp_lastsent': String? timestampLastSent,
|
||||
'messages_sent': int messagesSent,
|
||||
'subscription': dynamic subscription,
|
||||
} =>
|
||||
ChannelWithSubscription(
|
||||
channelID: channelID,
|
||||
ownerUserID: ownerUserID,
|
||||
internalName: internalName,
|
||||
displayName: displayName,
|
||||
descriptionName: descriptionName,
|
||||
subscribeKey: subscribeKey,
|
||||
timestampCreated: timestampCreated,
|
||||
timestampLastSent: timestampLastSent,
|
||||
messagesSent: messagesSent,
|
||||
subscription: Subscription.fromJson(subscription),
|
||||
),
|
||||
_ => throw const FormatException('Failed to decode Channel.'),
|
||||
};
|
||||
}
|
||||
}
|
||||
67
flutter/lib/models/message.dart
Normal file
67
flutter/lib/models/message.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
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) {
|
||||
return switch (json) {
|
||||
{
|
||||
'message_id': String messageID,
|
||||
'sender_user_id': String senderUserID,
|
||||
'channel_internal_name': String channelInternalName,
|
||||
'channel_id': String channelID,
|
||||
'sender_name': String? senderName,
|
||||
'sender_ip': String senderIP,
|
||||
'timestamp': String timestamp,
|
||||
'title': String title,
|
||||
'content': String? content,
|
||||
'priority': int priority,
|
||||
'usr_message_id': String? userMessageID,
|
||||
'used_key_id': String usedKeyID,
|
||||
'trimmed': bool trimmed,
|
||||
} =>
|
||||
Message(
|
||||
messageID: messageID,
|
||||
senderUserID: senderUserID,
|
||||
channelInternalName: channelInternalName,
|
||||
channelID: channelID,
|
||||
senderName: senderName,
|
||||
senderIP: senderIP,
|
||||
timestamp: timestamp,
|
||||
title: title,
|
||||
content: content,
|
||||
priority: priority,
|
||||
userMessageID: userMessageID,
|
||||
usedKeyID: usedKeyID,
|
||||
trimmed: trimmed,
|
||||
),
|
||||
_ => throw const FormatException('Failed to decode Message.'),
|
||||
};
|
||||
}
|
||||
}
|
||||
43
flutter/lib/models/subscription.dart
Normal file
43
flutter/lib/models/subscription.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
class Subscription {
|
||||
final String subscriptionID;
|
||||
final String subscriberUserID;
|
||||
final String channelOwnerUserID;
|
||||
final String channelID;
|
||||
final String channelInternalName;
|
||||
final String timestampCreated;
|
||||
final bool confirmed;
|
||||
|
||||
const Subscription({
|
||||
required this.subscriptionID,
|
||||
required this.subscriberUserID,
|
||||
required this.channelOwnerUserID,
|
||||
required this.channelID,
|
||||
required this.channelInternalName,
|
||||
required this.timestampCreated,
|
||||
required this.confirmed,
|
||||
});
|
||||
|
||||
factory Subscription.fromJson(Map<String, dynamic> json) {
|
||||
return switch (json) {
|
||||
{
|
||||
'subscription_id': String subscriptionID,
|
||||
'subscriber_user_id': String subscriberUserID,
|
||||
'channel_owner_user_id': String channelOwnerUserID,
|
||||
'channel_id': String channelID,
|
||||
'channel_internal_name': String channelInternalName,
|
||||
'timestamp_created': String timestampCreated,
|
||||
'confirmed': bool confirmed,
|
||||
} =>
|
||||
Subscription(
|
||||
subscriptionID: subscriptionID,
|
||||
subscriberUserID: subscriberUserID,
|
||||
channelOwnerUserID: channelOwnerUserID,
|
||||
channelID: channelID,
|
||||
channelInternalName: channelInternalName,
|
||||
timestampCreated: timestampCreated,
|
||||
confirmed: confirmed,
|
||||
),
|
||||
_ => throw const FormatException('Failed to decode Subscription.'),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user