:refactor: Central post fetching logic

This commit is contained in:
2024-11-26 00:00:09 +08:00
parent 41e2b08bcc
commit 356d3d4d3e
10 changed files with 206 additions and 140 deletions

View File

@ -53,6 +53,7 @@ class SnPost with _$SnPost {
@freezed
class SnPostPreload with _$SnPostPreload {
const factory SnPostPreload({
required SnAttachment? thumbnail,
required List<SnAttachment?>? attachments,
}) = _SnPostPreload;

View File

@ -953,6 +953,7 @@ SnPostPreload _$SnPostPreloadFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$SnPostPreload {
SnAttachment? get thumbnail => throw _privateConstructorUsedError;
List<SnAttachment?>? get attachments => throw _privateConstructorUsedError;
/// Serializes this SnPostPreload to a JSON map.
@ -971,7 +972,9 @@ abstract class $SnPostPreloadCopyWith<$Res> {
SnPostPreload value, $Res Function(SnPostPreload) then) =
_$SnPostPreloadCopyWithImpl<$Res, SnPostPreload>;
@useResult
$Res call({List<SnAttachment?>? attachments});
$Res call({SnAttachment? thumbnail, List<SnAttachment?>? attachments});
$SnAttachmentCopyWith<$Res>? get thumbnail;
}
/// @nodoc
@ -989,15 +992,34 @@ class _$SnPostPreloadCopyWithImpl<$Res, $Val extends SnPostPreload>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? thumbnail = freezed,
Object? attachments = freezed,
}) {
return _then(_value.copyWith(
thumbnail: freezed == thumbnail
? _value.thumbnail
: thumbnail // ignore: cast_nullable_to_non_nullable
as SnAttachment?,
attachments: freezed == attachments
? _value.attachments
: attachments // ignore: cast_nullable_to_non_nullable
as List<SnAttachment?>?,
) as $Val);
}
/// Create a copy of SnPostPreload
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$SnAttachmentCopyWith<$Res>? get thumbnail {
if (_value.thumbnail == null) {
return null;
}
return $SnAttachmentCopyWith<$Res>(_value.thumbnail!, (value) {
return _then(_value.copyWith(thumbnail: value) as $Val);
});
}
}
/// @nodoc
@ -1008,7 +1030,10 @@ abstract class _$$SnPostPreloadImplCopyWith<$Res>
__$$SnPostPreloadImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({List<SnAttachment?>? attachments});
$Res call({SnAttachment? thumbnail, List<SnAttachment?>? attachments});
@override
$SnAttachmentCopyWith<$Res>? get thumbnail;
}
/// @nodoc
@ -1024,9 +1049,14 @@ class __$$SnPostPreloadImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? thumbnail = freezed,
Object? attachments = freezed,
}) {
return _then(_$SnPostPreloadImpl(
thumbnail: freezed == thumbnail
? _value.thumbnail
: thumbnail // ignore: cast_nullable_to_non_nullable
as SnAttachment?,
attachments: freezed == attachments
? _value._attachments
: attachments // ignore: cast_nullable_to_non_nullable
@ -1038,12 +1068,16 @@ class __$$SnPostPreloadImplCopyWithImpl<$Res>
/// @nodoc
@JsonSerializable()
class _$SnPostPreloadImpl implements _SnPostPreload {
const _$SnPostPreloadImpl({required final List<SnAttachment?>? attachments})
const _$SnPostPreloadImpl(
{required this.thumbnail,
required final List<SnAttachment?>? attachments})
: _attachments = attachments;
factory _$SnPostPreloadImpl.fromJson(Map<String, dynamic> json) =>
_$$SnPostPreloadImplFromJson(json);
@override
final SnAttachment? thumbnail;
final List<SnAttachment?>? _attachments;
@override
List<SnAttachment?>? get attachments {
@ -1056,7 +1090,7 @@ class _$SnPostPreloadImpl implements _SnPostPreload {
@override
String toString() {
return 'SnPostPreload(attachments: $attachments)';
return 'SnPostPreload(thumbnail: $thumbnail, attachments: $attachments)';
}
@override
@ -1064,14 +1098,16 @@ class _$SnPostPreloadImpl implements _SnPostPreload {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SnPostPreloadImpl &&
(identical(other.thumbnail, thumbnail) ||
other.thumbnail == thumbnail) &&
const DeepCollectionEquality()
.equals(other._attachments, _attachments));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_attachments));
int get hashCode => Object.hash(runtimeType, thumbnail,
const DeepCollectionEquality().hash(_attachments));
/// Create a copy of SnPostPreload
/// with the given fields replaced by the non-null parameter values.
@ -1091,11 +1127,14 @@ class _$SnPostPreloadImpl implements _SnPostPreload {
abstract class _SnPostPreload implements SnPostPreload {
const factory _SnPostPreload(
{required final List<SnAttachment?>? attachments}) = _$SnPostPreloadImpl;
{required final SnAttachment? thumbnail,
required final List<SnAttachment?>? attachments}) = _$SnPostPreloadImpl;
factory _SnPostPreload.fromJson(Map<String, dynamic> json) =
_$SnPostPreloadImpl.fromJson;
@override
SnAttachment? get thumbnail;
@override
List<SnAttachment?>? get attachments;

View File

@ -102,6 +102,9 @@ Map<String, dynamic> _$$SnPostImplToJson(_$SnPostImpl instance) =>
_$SnPostPreloadImpl _$$SnPostPreloadImplFromJson(Map<String, dynamic> json) =>
_$SnPostPreloadImpl(
thumbnail: json['thumbnail'] == null
? null
: SnAttachment.fromJson(json['thumbnail'] as Map<String, dynamic>),
attachments: (json['attachments'] as List<dynamic>?)
?.map((e) => e == null
? null
@ -111,6 +114,7 @@ _$SnPostPreloadImpl _$$SnPostPreloadImplFromJson(Map<String, dynamic> json) =>
Map<String, dynamic> _$$SnPostPreloadImplToJson(_$SnPostPreloadImpl instance) =>
<String, dynamic>{
'thumbnail': instance.thumbnail?.toJson(),
'attachments': instance.attachments?.map((e) => e?.toJson()).toList(),
};