2024-05-18 10:17:16 +00:00
|
|
|
import 'package:solian/models/account.dart';
|
2024-05-25 17:21:08 +00:00
|
|
|
import 'package:solian/models/realm.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
class Channel {
|
|
|
|
int id;
|
|
|
|
DateTime createdAt;
|
|
|
|
DateTime updatedAt;
|
|
|
|
DateTime? deletedAt;
|
|
|
|
String alias;
|
|
|
|
String name;
|
|
|
|
String description;
|
|
|
|
int type;
|
2024-05-28 16:14:41 +00:00
|
|
|
List<ChannelMember>? members;
|
2024-05-18 10:17:16 +00:00
|
|
|
Account account;
|
|
|
|
int accountId;
|
2024-05-25 17:21:08 +00:00
|
|
|
Realm? realm;
|
2024-05-18 10:17:16 +00:00
|
|
|
int? realmId;
|
|
|
|
bool isEncrypted;
|
|
|
|
|
|
|
|
bool isAvailable = false;
|
|
|
|
|
|
|
|
Channel({
|
|
|
|
required this.id,
|
|
|
|
required this.createdAt,
|
|
|
|
required this.updatedAt,
|
2024-05-28 16:14:41 +00:00
|
|
|
required this.deletedAt,
|
2024-05-18 10:17:16 +00:00
|
|
|
required this.alias,
|
|
|
|
required this.name,
|
|
|
|
required this.description,
|
|
|
|
required this.type,
|
2024-05-28 16:14:41 +00:00
|
|
|
required this.members,
|
2024-05-18 10:17:16 +00:00
|
|
|
required this.account,
|
|
|
|
required this.accountId,
|
|
|
|
required this.isEncrypted,
|
2024-05-28 16:14:41 +00:00
|
|
|
required this.realm,
|
|
|
|
required this.realmId,
|
2024-05-18 10:17:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
factory Channel.fromJson(Map<String, dynamic> json) => Channel(
|
|
|
|
id: json['id'],
|
|
|
|
createdAt: DateTime.parse(json['created_at']),
|
|
|
|
updatedAt: DateTime.parse(json['updated_at']),
|
|
|
|
deletedAt: json['deleted_at'],
|
|
|
|
alias: json['alias'],
|
|
|
|
name: json['name'],
|
|
|
|
description: json['description'],
|
|
|
|
type: json['type'],
|
2024-05-28 16:14:41 +00:00
|
|
|
members: json['members']
|
|
|
|
?.map((e) => ChannelMember.fromJson(e))
|
|
|
|
.toList()
|
|
|
|
.cast<ChannelMember>(),
|
2024-05-18 10:17:16 +00:00
|
|
|
account: Account.fromJson(json['account']),
|
|
|
|
accountId: json['account_id'],
|
2024-05-25 17:21:08 +00:00
|
|
|
realm: json['realm'] != null ? Realm.fromJson(json['realm']) : null,
|
2024-05-18 10:17:16 +00:00
|
|
|
realmId: json['realm_id'],
|
|
|
|
isEncrypted: json['is_encrypted'],
|
|
|
|
);
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
'id': id,
|
|
|
|
'created_at': createdAt.toIso8601String(),
|
|
|
|
'updated_at': updatedAt.toIso8601String(),
|
|
|
|
'deleted_at': deletedAt,
|
|
|
|
'alias': alias,
|
|
|
|
'name': name,
|
|
|
|
'description': description,
|
|
|
|
'type': type,
|
2024-05-28 16:14:41 +00:00
|
|
|
'members': members?.map((e) => e.toJson()).toList(),
|
2024-05-25 17:21:08 +00:00
|
|
|
'account': account.toJson(),
|
2024-05-18 10:17:16 +00:00
|
|
|
'account_id': accountId,
|
2024-05-25 17:21:08 +00:00
|
|
|
'realm': realm?.toJson(),
|
2024-05-18 10:17:16 +00:00
|
|
|
'realm_id': realmId,
|
|
|
|
'is_encrypted': isEncrypted,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChannelMember {
|
|
|
|
int id;
|
|
|
|
DateTime createdAt;
|
|
|
|
DateTime updatedAt;
|
|
|
|
DateTime? deletedAt;
|
|
|
|
int channelId;
|
|
|
|
int accountId;
|
|
|
|
Account account;
|
|
|
|
int notify;
|
|
|
|
|
|
|
|
ChannelMember({
|
|
|
|
required this.id,
|
|
|
|
required this.createdAt,
|
|
|
|
required this.updatedAt,
|
|
|
|
this.deletedAt,
|
|
|
|
required this.channelId,
|
|
|
|
required this.accountId,
|
|
|
|
required this.account,
|
|
|
|
required this.notify,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory ChannelMember.fromJson(Map<String, dynamic> json) => ChannelMember(
|
|
|
|
id: json['id'],
|
|
|
|
createdAt: DateTime.parse(json['created_at']),
|
|
|
|
updatedAt: DateTime.parse(json['updated_at']),
|
|
|
|
deletedAt: json['deleted_at'],
|
|
|
|
channelId: json['channel_id'],
|
|
|
|
accountId: json['account_id'],
|
|
|
|
account: Account.fromJson(json['account']),
|
|
|
|
notify: json['notify'],
|
|
|
|
);
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
'id': id,
|
|
|
|
'created_at': createdAt.toIso8601String(),
|
|
|
|
'updated_at': updatedAt.toIso8601String(),
|
|
|
|
'deleted_at': deletedAt,
|
|
|
|
'channel_id': channelId,
|
|
|
|
'account_id': accountId,
|
|
|
|
'account': account.toJson(),
|
|
|
|
'notify': notify,
|
|
|
|
};
|
|
|
|
}
|