mirror of
https://github.com/tommyxchow/frosty.git
synced 2025-05-21 08:26:31 +08:00
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:
@ -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))
|
||||
|
@ -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<String, dynamic> json) =>
|
||||
_$Emote7TVFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(createToJson: false, fieldRename: FieldRename.snake)
|
||||
class Emote7TVData {
|
||||
final String id;
|
||||
final String name;
|
||||
final List<String>? tags;
|
||||
final Emote7TVHost host;
|
||||
|
||||
const Emote7TV(
|
||||
const Emote7TVData(
|
||||
this.id,
|
||||
this.name,
|
||||
this.tags,
|
||||
this.host,
|
||||
);
|
||||
|
||||
factory Emote7TV.fromJson(Map<String, dynamic> json) =>
|
||||
_$Emote7TVFromJson(json);
|
||||
factory Emote7TVData.fromJson(Map<String, dynamic> 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,
|
||||
);
|
||||
|
@ -52,6 +52,12 @@ EmoteFFZ _$EmoteFFZFromJson(Map<String, dynamic> json) => EmoteFFZ(
|
||||
);
|
||||
|
||||
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['name'] as String,
|
||||
(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(
|
||||
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<String, dynamic> json) => Emote(
|
||||
|
||||
Map<String, dynamic> _$EmoteToJson(Emote instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'realName': instance.realName,
|
||||
'width': instance.width,
|
||||
'height': instance.height,
|
||||
'zeroWidth': instance.zeroWidth,
|
||||
|
@ -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,
|
||||
);
|
||||
|
Reference in New Issue
Block a user