Skip to content

Instantly share code, notes, and snippets.

@Jimmy-Prime
Created April 13, 2021 09:29
Show Gist options
  • Save Jimmy-Prime/12f7d2c81a8d65e09119095b692243c5 to your computer and use it in GitHub Desktop.
Save Jimmy-Prime/12f7d2c81a8d65e09119095b692243c5 to your computer and use it in GitHub Desktop.
class Channel {
final int id;
bool isStarred;
bool isJoined;
bool isEncrypted;
Channel.fromJson(Map<String, dynamic> json)
: id = json['channel_id'],
isStarred = json['is_star'],
isJoined = json['is_joined'],
isEncrypted = json['encrypted'];
}
class Conversation extends Channel {
List<int> members;
Conversation.fromJson(Map<String, dynamic> json)
: members = json['members'].cast<int>(),
super.fromJson(json);
}
class NamedChannel extends Channel {
String name;
String purpose;
NamedChannel.fromJson(Map<String, dynamic> json)
: name = json['name'],
purpose = json['purpose'],
super.fromJson(json);
}
class PublicChannel extends NamedChannel {
PublicChannel.fromJson(Map<String, dynamic> json) : super.fromJson(json);
}
class PrivateChannel extends NamedChannel {
PrivateChannel.fromJson(Map<String, dynamic> json) : super.fromJson(json);
}
class ChatBotChannel extends NamedChannel {
ChatBotChannel.fromJson(Map<String, dynamic> json) : super.fromJson(json);
}
// make a factory class?
Channel createChannelFromJSONObject(dynamic json) {
switch (json['type']) {
case 'public':
return PublicChannel.fromJson(json);
case 'private':
return PublicChannel.fromJson(json);
case 'anonymous':
return Conversation.fromJson(json);
case 'chatbot':
return ChatBotChannel.fromJson(json);
default:
return Channel.fromJson(json);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment