SimpleCloudNotifier/flutter/lib/models/channel.dart

87 lines
2.6 KiB
Dart
Raw Normal View History

2024-02-18 17:36:58 +01:00
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) {
2024-05-25 18:09:39 +02:00
return Channel(
2024-05-25 21:36:05 +02:00
channelID: json['channel_id'] as String,
ownerUserID: json['owner_user_id'] as String,
internalName: json['internal_name'] as String,
displayName: json['display_name'] as String,
descriptionName: json['description_name'] as String?,
subscribeKey: json['subscribe_key'] as String?,
timestampCreated: json['timestamp_created'] as String,
timestampLastSent: json['timestamp_lastsent'] as String?,
messagesSent: json['messages_sent'] as int,
2024-05-25 18:09:39 +02:00
);
2024-02-18 17:36:58 +01:00
}
}
class ChannelWithSubscription {
final Channel channel;
2024-02-18 17:36:58 +01:00
final Subscription subscription;
ChannelWithSubscription({
required this.channel,
2024-02-18 17:36:58 +01:00
required this.subscription,
});
factory ChannelWithSubscription.fromJson(Map<String, dynamic> json) {
2024-05-25 18:09:39 +02:00
return ChannelWithSubscription(
channel: Channel.fromJson(json),
2024-05-25 21:36:05 +02:00
subscription: Subscription.fromJson(json['subscription'] as Map<String, dynamic>),
2024-05-25 18:09:39 +02:00
);
}
static List<ChannelWithSubscription> fromJsonArray(List<dynamic> jsonArr) {
2024-05-25 21:36:05 +02:00
return jsonArr.map<ChannelWithSubscription>((e) => ChannelWithSubscription.fromJson(e as Map<String, dynamic>)).toList();
2024-02-18 17:36:58 +01:00
}
}
2024-06-12 01:17:00 +02:00
class ChannelPreview {
final String channelID;
final String ownerUserID;
final String internalName;
final String displayName;
final String? descriptionName;
const ChannelPreview({
required this.channelID,
required this.ownerUserID,
required this.internalName,
required this.displayName,
required this.descriptionName,
});
factory ChannelPreview.fromJson(Map<String, dynamic> json) {
return ChannelPreview(
channelID: json['channel_id'] as String,
ownerUserID: json['owner_user_id'] as String,
internalName: json['internal_name'] as String,
displayName: json['display_name'] as String,
descriptionName: json['description_name'] as String?,
);
}
}