Add twitchSub & twitchUnlocked enum emote type

This commit is contained in:
tommyxchow 2021-12-22 17:50:42 -05:00
parent 8b9a85c204
commit 9f7529d2cc
3 changed files with 20 additions and 4 deletions

View file

@ -50,8 +50,17 @@ class Twitch {
if (response.statusCode == 200) {
final decoded = jsonDecode(response.body)['data'] as List;
final emotes = decoded.map((emote) => EmoteTwitch.fromJson(emote)).toList();
return emotes.map((emote) => Emote.fromTwitch(emote, EmoteType.twitchSub)).toList();
return emotes.map((emote) {
switch (emote.emoteType) {
case 'globals':
case 'smilies':
return Emote.fromTwitch(emote, EmoteType.twitchGlobal);
case 'subscriptions':
return Emote.fromTwitch(emote, EmoteType.twitchSub);
default:
return Emote.fromTwitch(emote, EmoteType.twitchUnlocked);
}
}).toList();
} else {
debugPrint('Failed to get Twitch emotes for set id: $setId. Error code: ${response.statusCode}');
return [];
@ -266,8 +275,10 @@ class Twitch {
}
/// Returns a user's info given their login name.
static Future<UserTwitch?> getUser({required String userLogin, required Map<String, String>? headers}) async {
final response = await http.get(Uri.parse('https://api.twitch.tv/helix/users?login=$userLogin'), headers: headers);
static Future<UserTwitch?> getUser({String? userLogin, String? id, required Map<String, String>? headers}) async {
final uri = id != null ? Uri.parse('https://api.twitch.tv/helix/users?id=$id') : Uri.parse('https://api.twitch.tv/helix/users?login=$userLogin');
final response = await http.get(uri, headers: headers);
if (response.statusCode == 200) {
final userData = jsonDecode(response.body)['data'] as List;

View file

@ -30,6 +30,7 @@ class EmoteTwitch {
final String? tier;
final String? emoteType;
final String? emoteSetId;
final String? ownerId;
final List<String> format;
final List<String> scale;
final List<String> themeMode;
@ -41,6 +42,7 @@ class EmoteTwitch {
this.tier,
this.emoteType,
this.emoteSetId,
this.ownerId,
this.format,
this.scale,
this.themeMode,
@ -288,7 +290,9 @@ class Emote {
}
enum EmoteType {
twitchSub,
twitchGlobal,
twitchUnlocked,
twitchChannel,
ffzGlobal,
ffzChannel,

View file

@ -19,6 +19,7 @@ EmoteTwitch _$EmoteTwitchFromJson(Map<String, dynamic> json) => EmoteTwitch(
json['tier'] as String?,
json['emote_type'] as String?,
json['emote_set_id'] as String?,
json['owner_id'] as String?,
(json['format'] as List<dynamic>).map((e) => e as String).toList(),
(json['scale'] as List<dynamic>).map((e) => e as String).toList(),
(json['theme_mode'] as List<dynamic>).map((e) => e as String).toList(),