diff --git a/lib/apis/seventv_api.dart b/lib/apis/seventv_api.dart index b890445e..61a387c4 100644 --- a/lib/apis/seventv_api.dart +++ b/lib/apis/seventv_api.dart @@ -17,7 +17,7 @@ class SevenTVApi { final response = await _client.get(url); if (response.statusCode == 200) { final decoded = jsonDecode(response.body)['emotes'] as List; - final emotes = decoded.map((emote) => Emote7TV.fromJson(emote['data'])); + final emotes = decoded.map((emote) => Emote7TV.fromJson(emote)); return emotes .map((emote) => Emote.from7TV(emote, EmoteType.sevenTVGlobal)) @@ -34,7 +34,7 @@ class SevenTVApi { final response = await _client.get(url); if (response.statusCode == 200) { final decoded = jsonDecode(response.body)['emote_set']['emotes'] as List; - final emotes = decoded.map((emote) => Emote7TV.fromJson(emote['data'])); + final emotes = decoded.map((emote) => Emote7TV.fromJson(emote)); return emotes .map((emote) => Emote.from7TV(emote, EmoteType.sevenTVChannel)) diff --git a/lib/models/emotes.dart b/lib/models/emotes.dart index 15d11a0d..cbbdf870 100644 --- a/lib/models/emotes.dart +++ b/lib/models/emotes.dart @@ -107,20 +107,36 @@ class EmoteFFZ { @JsonSerializable(createToJson: false, fieldRename: FieldRename.snake) class Emote7TV { + final String id; + final String name; + final Emote7TVData data; + + const Emote7TV( + this.id, + this.name, + this.data, + ); + + factory Emote7TV.fromJson(Map json) => + _$Emote7TVFromJson(json); +} + +@JsonSerializable(createToJson: false, fieldRename: FieldRename.snake) +class Emote7TVData { final String id; final String name; final List? tags; final Emote7TVHost host; - const Emote7TV( + const Emote7TVData( this.id, this.name, this.tags, this.host, ); - factory Emote7TV.fromJson(Map json) => - _$Emote7TVFromJson(json); + factory Emote7TVData.fromJson(Map json) => + _$Emote7TVDataFromJson(json); } @JsonSerializable(createToJson: false, fieldRename: FieldRename.snake) @@ -159,6 +175,7 @@ class Emote7TVFile { @JsonSerializable() class Emote { final String name; + final String? realName; final int? width; final int? height; final bool zeroWidth; @@ -168,6 +185,7 @@ class Emote { const Emote({ required this.name, + this.realName, this.width, this.height, required this.zeroWidth, @@ -202,17 +220,18 @@ class Emote { ); factory Emote.from7TV(Emote7TV emote, EmoteType type) { - final url = emote.host.url; + final url = emote.data.host.url; // Flutter doesn't support AVIF yet. - final file = emote.host.files.reversed.firstWhere( + final file = emote.data.host.files.reversed.firstWhere( (file) => file.format != 'AVIF' && file.name.contains('4x'), ); return Emote( name: emote.name, - width: emote.host.files.first.width, - height: emote.host.files.first.height, - zeroWidth: emote.tags?.contains('zerowidth') ?? false, + realName: emote.name != emote.data.name ? emote.data.name : null, + width: emote.data.host.files.first.width, + height: emote.data.host.files.first.height, + zeroWidth: emote.data.tags?.contains('zerowidth') ?? false, url: 'https:$url/${file.name}', type: type, ); diff --git a/lib/models/emotes.g.dart b/lib/models/emotes.g.dart index 1d8fd99d..551262a9 100644 --- a/lib/models/emotes.g.dart +++ b/lib/models/emotes.g.dart @@ -52,6 +52,12 @@ EmoteFFZ _$EmoteFFZFromJson(Map json) => EmoteFFZ( ); Emote7TV _$Emote7TVFromJson(Map json) => Emote7TV( + json['id'] as String, + json['name'] as String, + Emote7TVData.fromJson(json['data'] as Map), + ); + +Emote7TVData _$Emote7TVDataFromJson(Map json) => Emote7TVData( json['id'] as String, json['name'] as String, (json['tags'] as List?)?.map((e) => e as String).toList(), @@ -74,6 +80,7 @@ Emote7TVFile _$Emote7TVFileFromJson(Map json) => Emote7TVFile( Emote _$EmoteFromJson(Map json) => Emote( name: json['name'] as String, + realName: json['realName'] as String?, width: json['width'] as int?, height: json['height'] as int?, zeroWidth: json['zeroWidth'] as bool, @@ -84,6 +91,7 @@ Emote _$EmoteFromJson(Map json) => Emote( Map _$EmoteToJson(Emote instance) => { 'name': instance.name, + 'realName': instance.realName, 'width': instance.width, 'height': instance.height, 'zeroWidth': instance.zeroWidth, diff --git a/lib/models/irc.dart b/lib/models/irc.dart index ada2095b..d9d90176 100644 --- a/lib/models/irc.dart +++ b/lib/models/irc.dart @@ -648,7 +648,9 @@ class IRCMessage { width: 56, ), url: emote.url, - title: emote.name, + title: emote.realName != null + ? '${emote.name} (${emote.realName})' + : emote.name, subtitle: Text(emote.type.toString()), launchExternal: launchExternal, );