Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed for the issue (#91) #121

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Note

## v0.4.0

- Split the `PreviewCard` object into a `TrendsLink` object. Now `List<TrendsLink>` is returned from `InstanceV1Service.lookupTrendingLinks`. The fields are the same as in PreviewCard before the modification, so there is no effect if the type is not explicitly specified. If you have explicitly specified the `PreviewCard` as type, rewrite it to `TrendsLink` if necessary. ([#91](https://github.com/mastodon-dart/mastodon-api/issues/91))

## v0.3.3

- Supported `custom_emojis API methods`. ([#38](https://github.com/mastodon-dart/mastodon-api/issues/38))
Expand Down
1 change: 1 addition & 0 deletions lib/mastodon_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export 'package:mastodon_api/src/service/entities/tag.dart';
export 'package:mastodon_api/src/service/entities/thumbnail.dart';
export 'package:mastodon_api/src/service/entities/thumbnail_version.dart';
export 'package:mastodon_api/src/service/entities/token.dart';
export 'package:mastodon_api/src/service/entities/trends_link.dart';
export 'package:mastodon_api/src/service/entities/usage_statistics.dart';
export 'package:mastodon_api/src/service/mastodon_v1_service.dart';
export 'package:mastodon_api/src/service/mastodon_v2_service.dart';
Expand Down
4 changes: 0 additions & 4 deletions lib/src/service/entities/preview_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:freezed_annotation/freezed_annotation.dart';

// 🌎 Project imports:
import 'preview_card_type.dart';
import 'usage_statistics.dart';

part 'preview_card.freezed.dart';
part 'preview_card.g.dart';
Expand Down Expand Up @@ -59,9 +58,6 @@ class PreviewCard with _$PreviewCard {
/// A hash computed by the BlurHash algorithm, for generating colorful
/// preview thumbnails when media has not been downloaded yet.
@JsonKey(name: 'blurhash') String? blurHash,

/// Usage statistics for given days (typically the past week).
@JsonKey(name: 'history') required List<UsageStatistics> usageHistory,
}) = _PreviewCard;

factory PreviewCard.fromJson(Map<String, Object?> json) =>
Expand Down
63 changes: 9 additions & 54 deletions lib/src/service/entities/preview_card.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ mixin _$PreviewCard {
@JsonKey(name: 'blurhash')
String? get blurHash => throw _privateConstructorUsedError;

/// Usage statistics for given days (typically the past week).
@JsonKey(name: 'history')
List<UsageStatistics> get usageHistory => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$PreviewCardCopyWith<PreviewCard> get copyWith =>
Expand All @@ -95,8 +91,7 @@ abstract class $PreviewCardCopyWith<$Res> {
int height,
@JsonKey(name: 'image') String? imageUrl,
String embedUrl,
@JsonKey(name: 'blurhash') String? blurHash,
@JsonKey(name: 'history') List<UsageStatistics> usageHistory});
@JsonKey(name: 'blurhash') String? blurHash});
}

/// @nodoc
Expand Down Expand Up @@ -126,7 +121,6 @@ class _$PreviewCardCopyWithImpl<$Res, $Val extends PreviewCard>
Object? imageUrl = freezed,
Object? embedUrl = null,
Object? blurHash = freezed,
Object? usageHistory = null,
}) {
return _then(_value.copyWith(
url: null == url
Expand Down Expand Up @@ -185,10 +179,6 @@ class _$PreviewCardCopyWithImpl<$Res, $Val extends PreviewCard>
? _value.blurHash
: blurHash // ignore: cast_nullable_to_non_nullable
as String?,
usageHistory: null == usageHistory
? _value.usageHistory
: usageHistory // ignore: cast_nullable_to_non_nullable
as List<UsageStatistics>,
) as $Val);
}
}
Expand All @@ -215,8 +205,7 @@ abstract class _$$_PreviewCardCopyWith<$Res>
int height,
@JsonKey(name: 'image') String? imageUrl,
String embedUrl,
@JsonKey(name: 'blurhash') String? blurHash,
@JsonKey(name: 'history') List<UsageStatistics> usageHistory});
@JsonKey(name: 'blurhash') String? blurHash});
}

/// @nodoc
Expand Down Expand Up @@ -244,7 +233,6 @@ class __$$_PreviewCardCopyWithImpl<$Res>
Object? imageUrl = freezed,
Object? embedUrl = null,
Object? blurHash = freezed,
Object? usageHistory = null,
}) {
return _then(_$_PreviewCard(
url: null == url
Expand Down Expand Up @@ -303,10 +291,6 @@ class __$$_PreviewCardCopyWithImpl<$Res>
? _value.blurHash
: blurHash // ignore: cast_nullable_to_non_nullable
as String?,
usageHistory: null == usageHistory
? _value._usageHistory
: usageHistory // ignore: cast_nullable_to_non_nullable
as List<UsageStatistics>,
));
}
}
Expand All @@ -326,14 +310,9 @@ class _$_PreviewCard implements _PreviewCard {
required this.html,
required this.width,
required this.height,
@JsonKey(name: 'image')
this.imageUrl,
@JsonKey(name: 'image') this.imageUrl,
required this.embedUrl,
@JsonKey(name: 'blurhash')
this.blurHash,
@JsonKey(name: 'history')
required final List<UsageStatistics> usageHistory})
: _usageHistory = usageHistory;
@JsonKey(name: 'blurhash') this.blurHash});

factory _$_PreviewCard.fromJson(Map<String, dynamic> json) =>
_$$_PreviewCardFromJson(json);
Expand Down Expand Up @@ -397,21 +376,9 @@ class _$_PreviewCard implements _PreviewCard {
@JsonKey(name: 'blurhash')
final String? blurHash;

/// Usage statistics for given days (typically the past week).
final List<UsageStatistics> _usageHistory;

/// Usage statistics for given days (typically the past week).
@override
@JsonKey(name: 'history')
List<UsageStatistics> get usageHistory {
if (_usageHistory is EqualUnmodifiableListView) return _usageHistory;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_usageHistory);
}

@override
String toString() {
return 'PreviewCard(url: $url, title: $title, description: $description, type: $type, authorName: $authorName, authorUrl: $authorUrl, providerName: $providerName, providerUrl: $providerUrl, html: $html, width: $width, height: $height, imageUrl: $imageUrl, embedUrl: $embedUrl, blurHash: $blurHash, usageHistory: $usageHistory)';
return 'PreviewCard(url: $url, title: $title, description: $description, type: $type, authorName: $authorName, authorUrl: $authorUrl, providerName: $providerName, providerUrl: $providerUrl, html: $html, width: $width, height: $height, imageUrl: $imageUrl, embedUrl: $embedUrl, blurHash: $blurHash)';
}

@override
Expand Down Expand Up @@ -440,9 +407,7 @@ class _$_PreviewCard implements _PreviewCard {
(identical(other.embedUrl, embedUrl) ||
other.embedUrl == embedUrl) &&
(identical(other.blurHash, blurHash) ||
other.blurHash == blurHash) &&
const DeepCollectionEquality()
.equals(other._usageHistory, _usageHistory));
other.blurHash == blurHash));
}

@JsonKey(ignore: true)
Expand All @@ -462,8 +427,7 @@ class _$_PreviewCard implements _PreviewCard {
height,
imageUrl,
embedUrl,
blurHash,
const DeepCollectionEquality().hash(_usageHistory));
blurHash);

@JsonKey(ignore: true)
@override
Expand Down Expand Up @@ -492,13 +456,9 @@ abstract class _PreviewCard implements PreviewCard {
required final String html,
required final int width,
required final int height,
@JsonKey(name: 'image')
final String? imageUrl,
@JsonKey(name: 'image') final String? imageUrl,
required final String embedUrl,
@JsonKey(name: 'blurhash')
final String? blurHash,
@JsonKey(name: 'history')
required final List<UsageStatistics> usageHistory}) = _$_PreviewCard;
@JsonKey(name: 'blurhash') final String? blurHash}) = _$_PreviewCard;

factory _PreviewCard.fromJson(Map<String, dynamic> json) =
_$_PreviewCard.fromJson;
Expand Down Expand Up @@ -563,11 +523,6 @@ abstract class _PreviewCard implements PreviewCard {
@JsonKey(name: 'blurhash')
String? get blurHash;
@override

/// Usage statistics for given days (typically the past week).
@JsonKey(name: 'history')
List<UsageStatistics> get usageHistory;
@override
@JsonKey(ignore: true)
_$$_PreviewCardCopyWith<_$_PreviewCard> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
10 changes: 1 addition & 9 deletions lib/src/service/entities/preview_card.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions lib/src/service/entities/trends_link.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2023 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

// ignore_for_file: invalid_annotation_target

// 📦 Package imports:
import 'package:freezed_annotation/freezed_annotation.dart';

// 🌎 Project imports:
import 'preview_card_type.dart';
import 'usage_statistics.dart';

part 'trends_link.freezed.dart';
part 'trends_link.g.dart';

@freezed
class TrendsLink with _$TrendsLink {
const factory TrendsLink({
/// Location of linked resource.
required String url,

/// Title of linked resource.
required String title,

/// Description of preview.
required String description,

/// The type of the preview card.
required PreviewCardType type,

/// The author of the original resource.
required String authorName,

/// A link to the author of the original resource.
required String authorUrl,

/// The provider of the original resource.
required String providerName,

/// A link to the provider of the original resource.
required String providerUrl,

/// HTML to be used for generating the preview card.
required String html,

/// Width of preview, in pixels.
required int width,

/// Height of preview, in pixels.
required int height,

/// Preview thumbnail.
@JsonKey(name: 'image') String? imageUrl,

/// Used for photo embeds, instead of custom html.
required String embedUrl,

/// A hash computed by the BlurHash algorithm, for generating colorful
/// preview thumbnails when media has not been downloaded yet.
@JsonKey(name: 'blurhash') String? blurHash,

/// Usage statistics for given days (typically the past week).
@JsonKey(name: 'history') required List<UsageStatistics> usageHistory,
}) = _TrendsLink;

factory TrendsLink.fromJson(Map<String, Object?> json) =>
_$TrendsLinkFromJson(json);
}
Loading