diff --git a/lib/screens/album.dart b/lib/screens/album.dart index eeaf766..585fe43 100644 --- a/lib/screens/album.dart +++ b/lib/screens/album.dart @@ -8,7 +8,6 @@ import 'package:material_symbols_icons/symbols.dart'; import 'package:provider/provider.dart'; import 'package:styled_widget/styled_widget.dart'; import 'package:surface/providers/sn_network.dart'; -import 'package:surface/providers/user_directory.dart'; import 'package:surface/types/attachment.dart'; import 'package:surface/widgets/attachment/attachment_zoom.dart'; import 'package:surface/widgets/attachment/attachment_item.dart'; @@ -53,7 +52,6 @@ class _AlbumScreenState extends State { try { final sn = context.read(); - final ud = context.read(); final resp = await sn.client.get('/cgi/uc/attachments', queryParameters: { 'take': 10, 'offset': _attachments.length, @@ -64,8 +62,6 @@ class _AlbumScreenState extends State { _attachments.addAll(attachments); _heroTags.addAll(_attachments.map((_) => uuid.v4())); - await ud.listAccount(attachments.map((e) => e.accountId).toSet()); - _totalCount = resp.data['count'] as int?; } catch (err) { if (!mounted) return; diff --git a/lib/types/attachment.dart b/lib/types/attachment.dart index 8e0a30b..9ad6942 100644 --- a/lib/types/attachment.dart +++ b/lib/types/attachment.dart @@ -1,4 +1,5 @@ import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:surface/types/account.dart'; part 'attachment.freezed.dart'; @@ -39,6 +40,7 @@ abstract class SnAttachment with _$SnAttachment { required int? refId, required SnAttachmentPool? pool, required int? poolId, + required SnAccount? account, required int accountId, int? thumbnailId, SnAttachment? thumbnail, @@ -49,7 +51,8 @@ abstract class SnAttachment with _$SnAttachment { @Default({}) Map metadata, }) = _SnAttachment; - factory SnAttachment.fromJson(Map json) => _$SnAttachmentFromJson(json); + factory SnAttachment.fromJson(Map json) => + _$SnAttachmentFromJson(json); Map get data => { ...metadata, @@ -85,7 +88,8 @@ abstract class SnAttachmentFragment with _$SnAttachmentFragment { @Default([]) List fileChunksMissing, }) = _SnAttachmentFragment; - factory SnAttachmentFragment.fromJson(Map json) => _$SnAttachmentFragmentFromJson(json); + factory SnAttachmentFragment.fromJson(Map json) => + _$SnAttachmentFragmentFromJson(json); SnMediaType get mediaType => switch (mimetype.split('/').firstOrNull) { 'image' => SnMediaType.image, @@ -109,7 +113,8 @@ abstract class SnAttachmentPool with _$SnAttachmentPool { required int? accountId, }) = _SnAttachmentPool; - factory SnAttachmentPool.fromJson(Map json) => _$SnAttachmentPoolFromJson(json); + factory SnAttachmentPool.fromJson(Map json) => + _$SnAttachmentPoolFromJson(json); } @freezed @@ -122,7 +127,8 @@ abstract class SnAttachmentDestination with _$SnAttachmentDestination { required bool isBoost, }) = _SnAttachmentDestination; - factory SnAttachmentDestination.fromJson(Map json) => _$SnAttachmentDestinationFromJson(json); + factory SnAttachmentDestination.fromJson(Map json) => + _$SnAttachmentDestinationFromJson(json); } @freezed @@ -139,7 +145,8 @@ abstract class SnAttachmentBoost with _$SnAttachmentBoost { required int account, }) = _SnAttachmentBoost; - factory SnAttachmentBoost.fromJson(Map json) => _$SnAttachmentBoostFromJson(json); + factory SnAttachmentBoost.fromJson(Map json) => + _$SnAttachmentBoostFromJson(json); } @freezed @@ -158,7 +165,8 @@ abstract class SnSticker with _$SnSticker { required int accountId, }) = _SnSticker; - factory SnSticker.fromJson(Map json) => _$SnStickerFromJson(json); + factory SnSticker.fromJson(Map json) => + _$SnStickerFromJson(json); } @freezed @@ -175,7 +183,8 @@ abstract class SnStickerPack with _$SnStickerPack { required int accountId, }) = _SnStickerPack; - factory SnStickerPack.fromJson(Map json) => _$SnStickerPackFromJson(json); + factory SnStickerPack.fromJson(Map json) => + _$SnStickerPackFromJson(json); } @freezed @@ -186,5 +195,6 @@ abstract class SnAttachmentBilling with _$SnAttachmentBilling { required double includedRatio, }) = _SnAttachmentBilling; - factory SnAttachmentBilling.fromJson(Map json) => _$SnAttachmentBillingFromJson(json); + factory SnAttachmentBilling.fromJson(Map json) => + _$SnAttachmentBillingFromJson(json); } diff --git a/lib/types/attachment.freezed.dart b/lib/types/attachment.freezed.dart index 1460a14..f4536fb 100644 --- a/lib/types/attachment.freezed.dart +++ b/lib/types/attachment.freezed.dart @@ -38,6 +38,7 @@ mixin _$SnAttachment { int? get refId; SnAttachmentPool? get pool; int? get poolId; + SnAccount? get account; int get accountId; int? get thumbnailId; SnAttachment? get thumbnail; @@ -98,6 +99,7 @@ mixin _$SnAttachment { (identical(other.refId, refId) || other.refId == refId) && (identical(other.pool, pool) || other.pool == pool) && (identical(other.poolId, poolId) || other.poolId == poolId) && + (identical(other.account, account) || other.account == account) && (identical(other.accountId, accountId) || other.accountId == accountId) && (identical(other.thumbnailId, thumbnailId) || @@ -140,6 +142,7 @@ mixin _$SnAttachment { refId, pool, poolId, + account, accountId, thumbnailId, thumbnail, @@ -152,7 +155,7 @@ mixin _$SnAttachment { @override String toString() { - return 'SnAttachment(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, rid: $rid, uuid: $uuid, size: $size, name: $name, alt: $alt, mimetype: $mimetype, hash: $hash, destination: $destination, refCount: $refCount, contentRating: $contentRating, qualityRating: $qualityRating, cleanedAt: $cleanedAt, isAnalyzed: $isAnalyzed, isSelfRef: $isSelfRef, isIndexable: $isIndexable, ref: $ref, refId: $refId, pool: $pool, poolId: $poolId, accountId: $accountId, thumbnailId: $thumbnailId, thumbnail: $thumbnail, compressedId: $compressedId, compressed: $compressed, boosts: $boosts, usermeta: $usermeta, metadata: $metadata)'; + return 'SnAttachment(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, rid: $rid, uuid: $uuid, size: $size, name: $name, alt: $alt, mimetype: $mimetype, hash: $hash, destination: $destination, refCount: $refCount, contentRating: $contentRating, qualityRating: $qualityRating, cleanedAt: $cleanedAt, isAnalyzed: $isAnalyzed, isSelfRef: $isSelfRef, isIndexable: $isIndexable, ref: $ref, refId: $refId, pool: $pool, poolId: $poolId, account: $account, accountId: $accountId, thumbnailId: $thumbnailId, thumbnail: $thumbnail, compressedId: $compressedId, compressed: $compressed, boosts: $boosts, usermeta: $usermeta, metadata: $metadata)'; } } @@ -186,6 +189,7 @@ abstract mixin class $SnAttachmentCopyWith<$Res> { int? refId, SnAttachmentPool? pool, int? poolId, + SnAccount? account, int accountId, int? thumbnailId, SnAttachment? thumbnail, @@ -197,6 +201,7 @@ abstract mixin class $SnAttachmentCopyWith<$Res> { $SnAttachmentCopyWith<$Res>? get ref; $SnAttachmentPoolCopyWith<$Res>? get pool; + $SnAccountCopyWith<$Res>? get account; $SnAttachmentCopyWith<$Res>? get thumbnail; $SnAttachmentCopyWith<$Res>? get compressed; } @@ -236,6 +241,7 @@ class _$SnAttachmentCopyWithImpl<$Res> implements $SnAttachmentCopyWith<$Res> { Object? refId = freezed, Object? pool = freezed, Object? poolId = freezed, + Object? account = freezed, Object? accountId = null, Object? thumbnailId = freezed, Object? thumbnail = freezed, @@ -338,6 +344,10 @@ class _$SnAttachmentCopyWithImpl<$Res> implements $SnAttachmentCopyWith<$Res> { ? _self.poolId : poolId // ignore: cast_nullable_to_non_nullable as int?, + account: freezed == account + ? _self.account + : account // ignore: cast_nullable_to_non_nullable + as SnAccount?, accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable @@ -401,6 +411,20 @@ class _$SnAttachmentCopyWithImpl<$Res> implements $SnAttachmentCopyWith<$Res> { }); } + /// Create a copy of SnAttachment + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $SnAccountCopyWith<$Res>? get account { + if (_self.account == null) { + return null; + } + + return $SnAccountCopyWith<$Res>(_self.account!, (value) { + return _then(_self.copyWith(account: value)); + }); + } + /// Create a copy of SnAttachment /// with the given fields replaced by the non-null parameter values. @override @@ -457,6 +481,7 @@ class _SnAttachment extends SnAttachment { required this.refId, required this.pool, required this.poolId, + required this.account, required this.accountId, this.thumbnailId, this.thumbnail, @@ -521,6 +546,8 @@ class _SnAttachment extends SnAttachment { @override final int? poolId; @override + final SnAccount? account; + @override final int accountId; @override final int? thumbnailId; @@ -612,6 +639,7 @@ class _SnAttachment extends SnAttachment { (identical(other.refId, refId) || other.refId == refId) && (identical(other.pool, pool) || other.pool == pool) && (identical(other.poolId, poolId) || other.poolId == poolId) && + (identical(other.account, account) || other.account == account) && (identical(other.accountId, accountId) || other.accountId == accountId) && (identical(other.thumbnailId, thumbnailId) || @@ -654,6 +682,7 @@ class _SnAttachment extends SnAttachment { refId, pool, poolId, + account, accountId, thumbnailId, thumbnail, @@ -666,7 +695,7 @@ class _SnAttachment extends SnAttachment { @override String toString() { - return 'SnAttachment(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, rid: $rid, uuid: $uuid, size: $size, name: $name, alt: $alt, mimetype: $mimetype, hash: $hash, destination: $destination, refCount: $refCount, contentRating: $contentRating, qualityRating: $qualityRating, cleanedAt: $cleanedAt, isAnalyzed: $isAnalyzed, isSelfRef: $isSelfRef, isIndexable: $isIndexable, ref: $ref, refId: $refId, pool: $pool, poolId: $poolId, accountId: $accountId, thumbnailId: $thumbnailId, thumbnail: $thumbnail, compressedId: $compressedId, compressed: $compressed, boosts: $boosts, usermeta: $usermeta, metadata: $metadata)'; + return 'SnAttachment(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, rid: $rid, uuid: $uuid, size: $size, name: $name, alt: $alt, mimetype: $mimetype, hash: $hash, destination: $destination, refCount: $refCount, contentRating: $contentRating, qualityRating: $qualityRating, cleanedAt: $cleanedAt, isAnalyzed: $isAnalyzed, isSelfRef: $isSelfRef, isIndexable: $isIndexable, ref: $ref, refId: $refId, pool: $pool, poolId: $poolId, account: $account, accountId: $accountId, thumbnailId: $thumbnailId, thumbnail: $thumbnail, compressedId: $compressedId, compressed: $compressed, boosts: $boosts, usermeta: $usermeta, metadata: $metadata)'; } } @@ -702,6 +731,7 @@ abstract mixin class _$SnAttachmentCopyWith<$Res> int? refId, SnAttachmentPool? pool, int? poolId, + SnAccount? account, int accountId, int? thumbnailId, SnAttachment? thumbnail, @@ -716,6 +746,8 @@ abstract mixin class _$SnAttachmentCopyWith<$Res> @override $SnAttachmentPoolCopyWith<$Res>? get pool; @override + $SnAccountCopyWith<$Res>? get account; + @override $SnAttachmentCopyWith<$Res>? get thumbnail; @override $SnAttachmentCopyWith<$Res>? get compressed; @@ -757,6 +789,7 @@ class __$SnAttachmentCopyWithImpl<$Res> Object? refId = freezed, Object? pool = freezed, Object? poolId = freezed, + Object? account = freezed, Object? accountId = null, Object? thumbnailId = freezed, Object? thumbnail = freezed, @@ -859,6 +892,10 @@ class __$SnAttachmentCopyWithImpl<$Res> ? _self.poolId : poolId // ignore: cast_nullable_to_non_nullable as int?, + account: freezed == account + ? _self.account + : account // ignore: cast_nullable_to_non_nullable + as SnAccount?, accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable @@ -922,6 +959,20 @@ class __$SnAttachmentCopyWithImpl<$Res> }); } + /// Create a copy of SnAttachment + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $SnAccountCopyWith<$Res>? get account { + if (_self.account == null) { + return null; + } + + return $SnAccountCopyWith<$Res>(_self.account!, (value) { + return _then(_self.copyWith(account: value)); + }); + } + /// Create a copy of SnAttachment /// with the given fields replaced by the non-null parameter values. @override diff --git a/lib/types/attachment.g.dart b/lib/types/attachment.g.dart index 984a128..c5ffed2 100644 --- a/lib/types/attachment.g.dart +++ b/lib/types/attachment.g.dart @@ -39,6 +39,9 @@ _SnAttachment _$SnAttachmentFromJson(Map json) => ? null : SnAttachmentPool.fromJson(json['pool'] as Map), poolId: (json['pool_id'] as num?)?.toInt(), + account: json['account'] == null + ? null + : SnAccount.fromJson(json['account'] as Map), accountId: (json['account_id'] as num).toInt(), thumbnailId: (json['thumbnail_id'] as num?)?.toInt(), thumbnail: json['thumbnail'] == null @@ -82,6 +85,7 @@ Map _$SnAttachmentToJson(_SnAttachment instance) => 'ref_id': instance.refId, 'pool': instance.pool?.toJson(), 'pool_id': instance.poolId, + 'account': instance.account?.toJson(), 'account_id': instance.accountId, 'thumbnail_id': instance.thumbnailId, 'thumbnail': instance.thumbnail?.toJson(), diff --git a/lib/types/reaction.dart b/lib/types/reaction.dart index ad9a92b..efd6158 100644 --- a/lib/types/reaction.dart +++ b/lib/types/reaction.dart @@ -17,4 +17,5 @@ const Map kTemplateReactions = { 'party': ReactInfo(icon: '🎉', attitude: 1), 'joy': ReactInfo(icon: '🤣', attitude: 1), 'pray': ReactInfo(icon: '🙏', attitude: 1), + 'heart': ReactInfo(icon: '❤️', attitude: 1), }; diff --git a/lib/widgets/attachment/attachment_zoom.dart b/lib/widgets/attachment/attachment_zoom.dart index 4d76eae..5f2cbb2 100644 --- a/lib/widgets/attachment/attachment_zoom.dart +++ b/lib/widgets/attachment/attachment_zoom.dart @@ -16,7 +16,6 @@ import 'package:photo_view/photo_view_gallery.dart'; import 'package:provider/provider.dart'; import 'package:styled_widget/styled_widget.dart'; import 'package:surface/providers/sn_network.dart'; -import 'package:surface/providers/user_directory.dart'; import 'package:surface/types/attachment.dart'; import 'package:surface/widgets/account/account_image.dart'; import 'package:surface/widgets/dialog.dart'; @@ -418,8 +417,7 @@ class _AttachmentZoomDetailPopup extends StatelessWidget { @override Widget build(BuildContext context) { - final ud = context.read(); - final account = ud.getFromCache(data.accountId); + final account = data.account!; const tableGap = TableRow( children: [ @@ -461,12 +459,12 @@ class _AttachmentZoomDetailPopup extends StatelessWidget { children: [ if (data.accountId > 0) AccountImage( - content: account?.avatar, + content: account.avatar, radius: 8, ), const Gap(8), Text(data.accountId > 0 - ? account?.nick ?? 'unknown'.tr() + ? account.nick : 'unknown'.tr()), const Gap(8), Text('#${data.accountId}', diff --git a/lib/widgets/post/post_comment_list.dart b/lib/widgets/post/post_comment_list.dart index c7a981d..e35ff1f 100644 --- a/lib/widgets/post/post_comment_list.dart +++ b/lib/widgets/post/post_comment_list.dart @@ -179,57 +179,54 @@ class _PostCommentListPopupState extends State { final ua = context.watch(); final devicePixelRatio = MediaQuery.of(context).devicePixelRatio; - return SizedBox( - height: MediaQuery.of(context).size.height * 0.85, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const Icon(Symbols.comment, size: 24), - const Gap(16), - Text('postCommentsDetailed') - .plural(widget.commentCount) - .textStyle(Theme.of(context).textTheme.titleLarge!), - ], - ).padding(horizontal: 20, top: 16, bottom: 12), - Expanded( - child: CustomScrollView( - slivers: [ - if (ua.isAuthorized) - SliverToBoxAdapter( - child: Container( - margin: const EdgeInsets.only(bottom: 8), - height: 240, - decoration: BoxDecoration( - border: Border.symmetric( - horizontal: BorderSide( - color: Theme.of(context).dividerColor, - width: 1 / devicePixelRatio, - ), + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Icon(Symbols.comment, size: 24), + const Gap(16), + Text('postCommentsDetailed') + .plural(widget.commentCount) + .textStyle(Theme.of(context).textTheme.titleLarge!), + ], + ).padding(horizontal: 20, top: 16, bottom: 12), + Expanded( + child: CustomScrollView( + slivers: [ + if (ua.isAuthorized) + SliverToBoxAdapter( + child: Container( + margin: const EdgeInsets.only(bottom: 8), + height: 240, + decoration: BoxDecoration( + border: Border.symmetric( + horizontal: BorderSide( + color: Theme.of(context).dividerColor, + width: 1 / devicePixelRatio, ), ), - child: PostMiniEditor( - postReplyId: widget.post.id, - onPost: () { - _childListKey.currentState!.refresh(); - }, - onExpand: () { - Navigator.pop(context); - }, - ), + ), + child: PostMiniEditor( + postReplyId: widget.post.id, + onPost: () { + _childListKey.currentState!.refresh(); + }, + onExpand: () { + Navigator.pop(context); + }, ), ), - PostCommentSliverList( - parentPost: widget.post, - key: _childListKey, ), - ], - ), + PostCommentSliverList( + parentPost: widget.post, + key: _childListKey, + ), + ], ), - ], - ), + ), + ], ); } } diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 387fda4..7bb6046 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -2056,8 +2056,6 @@ class _PostFeaturedCommentState extends State<_PostFeaturedComment> { onTap: () { showModalBottomSheet( context: context, - useRootNavigator: true, - isScrollControlled: true, builder: (context) => PostCommentListPopup( post: widget.data, commentCount: widget.data.metric.replyCount,