Fix 7TV emotes not using custom names (#291)

* Fix 7TV emotes not using custom set names

* Show real name in emote details
This commit is contained in:
Tommy Chow
2023-11-01 17:55:49 -04:00
committed by GitHub
parent 62f66067fb
commit bc67aad670
4 changed files with 40 additions and 11 deletions

View File

@ -17,7 +17,7 @@ class SevenTVApi {
final response = await _client.get(url); final response = await _client.get(url);
if (response.statusCode == 200) { if (response.statusCode == 200) {
final decoded = jsonDecode(response.body)['emotes'] as List; 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 return emotes
.map((emote) => Emote.from7TV(emote, EmoteType.sevenTVGlobal)) .map((emote) => Emote.from7TV(emote, EmoteType.sevenTVGlobal))
@ -34,7 +34,7 @@ class SevenTVApi {
final response = await _client.get(url); final response = await _client.get(url);
if (response.statusCode == 200) { if (response.statusCode == 200) {
final decoded = jsonDecode(response.body)['emote_set']['emotes'] as List; 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 return emotes
.map((emote) => Emote.from7TV(emote, EmoteType.sevenTVChannel)) .map((emote) => Emote.from7TV(emote, EmoteType.sevenTVChannel))

View File

@ -107,20 +107,36 @@ class EmoteFFZ {
@JsonSerializable(createToJson: false, fieldRename: FieldRename.snake) @JsonSerializable(createToJson: false, fieldRename: FieldRename.snake)
class Emote7TV { class Emote7TV {
final String id;
final String name;
final Emote7TVData data;
const Emote7TV(
this.id,
this.name,
this.data,
);
factory Emote7TV.fromJson(Map<String, dynamic> json) =>
_$Emote7TVFromJson(json);
}
@JsonSerializable(createToJson: false, fieldRename: FieldRename.snake)
class Emote7TVData {
final String id; final String id;
final String name; final String name;
final List<String>? tags; final List<String>? tags;
final Emote7TVHost host; final Emote7TVHost host;
const Emote7TV( const Emote7TVData(
this.id, this.id,
this.name, this.name,
this.tags, this.tags,
this.host, this.host,
); );
factory Emote7TV.fromJson(Map<String, dynamic> json) => factory Emote7TVData.fromJson(Map<String, dynamic> json) =>
_$Emote7TVFromJson(json); _$Emote7TVDataFromJson(json);
} }
@JsonSerializable(createToJson: false, fieldRename: FieldRename.snake) @JsonSerializable(createToJson: false, fieldRename: FieldRename.snake)
@ -159,6 +175,7 @@ class Emote7TVFile {
@JsonSerializable() @JsonSerializable()
class Emote { class Emote {
final String name; final String name;
final String? realName;
final int? width; final int? width;
final int? height; final int? height;
final bool zeroWidth; final bool zeroWidth;
@ -168,6 +185,7 @@ class Emote {
const Emote({ const Emote({
required this.name, required this.name,
this.realName,
this.width, this.width,
this.height, this.height,
required this.zeroWidth, required this.zeroWidth,
@ -202,17 +220,18 @@ class Emote {
); );
factory Emote.from7TV(Emote7TV emote, EmoteType type) { factory Emote.from7TV(Emote7TV emote, EmoteType type) {
final url = emote.host.url; final url = emote.data.host.url;
// Flutter doesn't support AVIF yet. // 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'), (file) => file.format != 'AVIF' && file.name.contains('4x'),
); );
return Emote( return Emote(
name: emote.name, name: emote.name,
width: emote.host.files.first.width, realName: emote.name != emote.data.name ? emote.data.name : null,
height: emote.host.files.first.height, width: emote.data.host.files.first.width,
zeroWidth: emote.tags?.contains('zerowidth') ?? false, height: emote.data.host.files.first.height,
zeroWidth: emote.data.tags?.contains('zerowidth') ?? false,
url: 'https:$url/${file.name}', url: 'https:$url/${file.name}',
type: type, type: type,
); );

View File

@ -52,6 +52,12 @@ EmoteFFZ _$EmoteFFZFromJson(Map<String, dynamic> json) => EmoteFFZ(
); );
Emote7TV _$Emote7TVFromJson(Map<String, dynamic> json) => Emote7TV( Emote7TV _$Emote7TVFromJson(Map<String, dynamic> json) => Emote7TV(
json['id'] as String,
json['name'] as String,
Emote7TVData.fromJson(json['data'] as Map<String, dynamic>),
);
Emote7TVData _$Emote7TVDataFromJson(Map<String, dynamic> json) => Emote7TVData(
json['id'] as String, json['id'] as String,
json['name'] as String, json['name'] as String,
(json['tags'] as List<dynamic>?)?.map((e) => e as String).toList(), (json['tags'] as List<dynamic>?)?.map((e) => e as String).toList(),
@ -74,6 +80,7 @@ Emote7TVFile _$Emote7TVFileFromJson(Map<String, dynamic> json) => Emote7TVFile(
Emote _$EmoteFromJson(Map<String, dynamic> json) => Emote( Emote _$EmoteFromJson(Map<String, dynamic> json) => Emote(
name: json['name'] as String, name: json['name'] as String,
realName: json['realName'] as String?,
width: json['width'] as int?, width: json['width'] as int?,
height: json['height'] as int?, height: json['height'] as int?,
zeroWidth: json['zeroWidth'] as bool, zeroWidth: json['zeroWidth'] as bool,
@ -84,6 +91,7 @@ Emote _$EmoteFromJson(Map<String, dynamic> json) => Emote(
Map<String, dynamic> _$EmoteToJson(Emote instance) => <String, dynamic>{ Map<String, dynamic> _$EmoteToJson(Emote instance) => <String, dynamic>{
'name': instance.name, 'name': instance.name,
'realName': instance.realName,
'width': instance.width, 'width': instance.width,
'height': instance.height, 'height': instance.height,
'zeroWidth': instance.zeroWidth, 'zeroWidth': instance.zeroWidth,

View File

@ -648,7 +648,9 @@ class IRCMessage {
width: 56, width: 56,
), ),
url: emote.url, url: emote.url,
title: emote.name, title: emote.realName != null
? '${emote.name} (${emote.realName})'
: emote.name,
subtitle: Text(emote.type.toString()), subtitle: Text(emote.type.toString()),
launchExternal: launchExternal, launchExternal: launchExternal,
); );