diff --git a/lib/models/activity.dart b/lib/models/activity.dart index 273b40a..c4f1d0e 100644 --- a/lib/models/activity.dart +++ b/lib/models/activity.dart @@ -10,13 +10,10 @@ sealed class SnActivity with _$SnActivity { required String id, required String type, required String resourceIdentifier, - required int visibility, - required String accountId, - required SnAccount account, required dynamic data, required DateTime createdAt, required DateTime updatedAt, - required dynamic deletedAt, + required DateTime? deletedAt, }) = _SnActivity; factory SnActivity.fromJson(Map json) => diff --git a/lib/models/activity.freezed.dart b/lib/models/activity.freezed.dart index 05400e0..3a40705 100644 --- a/lib/models/activity.freezed.dart +++ b/lib/models/activity.freezed.dart @@ -16,7 +16,7 @@ T _$identity(T value) => value; /// @nodoc mixin _$SnActivity { - String get id; String get type; String get resourceIdentifier; int get visibility; String get accountId; SnAccount get account; dynamic get data; DateTime get createdAt; DateTime get updatedAt; dynamic get deletedAt; + String get id; String get type; String get resourceIdentifier; dynamic get data; DateTime get createdAt; DateTime get updatedAt; DateTime? get deletedAt; /// Create a copy of SnActivity /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -29,16 +29,16 @@ $SnActivityCopyWith get copyWith => _$SnActivityCopyWithImpl Object.hash(runtimeType,id,type,resourceIdentifier,visibility,accountId,account,const DeepCollectionEquality().hash(data),createdAt,updatedAt,const DeepCollectionEquality().hash(deletedAt)); +int get hashCode => Object.hash(runtimeType,id,type,resourceIdentifier,const DeepCollectionEquality().hash(data),createdAt,updatedAt,deletedAt); @override String toString() { - return 'SnActivity(id: $id, type: $type, resourceIdentifier: $resourceIdentifier, visibility: $visibility, accountId: $accountId, account: $account, data: $data, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)'; + return 'SnActivity(id: $id, type: $type, resourceIdentifier: $resourceIdentifier, data: $data, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)'; } @@ -49,11 +49,11 @@ abstract mixin class $SnActivityCopyWith<$Res> { factory $SnActivityCopyWith(SnActivity value, $Res Function(SnActivity) _then) = _$SnActivityCopyWithImpl; @useResult $Res call({ - String id, String type, String resourceIdentifier, int visibility, String accountId, SnAccount account, dynamic data, DateTime createdAt, DateTime updatedAt, dynamic deletedAt + String id, String type, String resourceIdentifier, dynamic data, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt }); -$SnAccountCopyWith<$Res> get account; + } /// @nodoc @@ -66,31 +66,19 @@ class _$SnActivityCopyWithImpl<$Res> /// Create a copy of SnActivity /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? type = null,Object? resourceIdentifier = null,Object? visibility = null,Object? accountId = null,Object? account = null,Object? data = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? type = null,Object? resourceIdentifier = null,Object? data = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { return _then(_self.copyWith( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable as String,resourceIdentifier: null == resourceIdentifier ? _self.resourceIdentifier : resourceIdentifier // ignore: cast_nullable_to_non_nullable -as String,visibility: null == visibility ? _self.visibility : visibility // ignore: cast_nullable_to_non_nullable -as int,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable -as String,account: null == account ? _self.account : account // ignore: cast_nullable_to_non_nullable -as SnAccount,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable +as String,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable as dynamic,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable as DateTime,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable -as dynamic, +as DateTime?, )); } -/// Create a copy of SnActivity -/// with the given fields replaced by the non-null parameter values. -@override -@pragma('vm:prefer-inline') -$SnAccountCopyWith<$Res> get account { - - return $SnAccountCopyWith<$Res>(_self.account, (value) { - return _then(_self.copyWith(account: value)); - }); -} + } @@ -98,19 +86,16 @@ $SnAccountCopyWith<$Res> get account { @JsonSerializable() class _SnActivity implements SnActivity { - const _SnActivity({required this.id, required this.type, required this.resourceIdentifier, required this.visibility, required this.accountId, required this.account, required this.data, required this.createdAt, required this.updatedAt, required this.deletedAt}); + const _SnActivity({required this.id, required this.type, required this.resourceIdentifier, required this.data, required this.createdAt, required this.updatedAt, required this.deletedAt}); factory _SnActivity.fromJson(Map json) => _$SnActivityFromJson(json); @override final String id; @override final String type; @override final String resourceIdentifier; -@override final int visibility; -@override final String accountId; -@override final SnAccount account; @override final dynamic data; @override final DateTime createdAt; @override final DateTime updatedAt; -@override final dynamic deletedAt; +@override final DateTime? deletedAt; /// Create a copy of SnActivity /// with the given fields replaced by the non-null parameter values. @@ -125,16 +110,16 @@ Map toJson() { @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnActivity&&(identical(other.id, id) || other.id == id)&&(identical(other.type, type) || other.type == type)&&(identical(other.resourceIdentifier, resourceIdentifier) || other.resourceIdentifier == resourceIdentifier)&&(identical(other.visibility, visibility) || other.visibility == visibility)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.account, account) || other.account == account)&&const DeepCollectionEquality().equals(other.data, data)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&const DeepCollectionEquality().equals(other.deletedAt, deletedAt)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnActivity&&(identical(other.id, id) || other.id == id)&&(identical(other.type, type) || other.type == type)&&(identical(other.resourceIdentifier, resourceIdentifier) || other.resourceIdentifier == resourceIdentifier)&&const DeepCollectionEquality().equals(other.data, data)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,id,type,resourceIdentifier,visibility,accountId,account,const DeepCollectionEquality().hash(data),createdAt,updatedAt,const DeepCollectionEquality().hash(deletedAt)); +int get hashCode => Object.hash(runtimeType,id,type,resourceIdentifier,const DeepCollectionEquality().hash(data),createdAt,updatedAt,deletedAt); @override String toString() { - return 'SnActivity(id: $id, type: $type, resourceIdentifier: $resourceIdentifier, visibility: $visibility, accountId: $accountId, account: $account, data: $data, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)'; + return 'SnActivity(id: $id, type: $type, resourceIdentifier: $resourceIdentifier, data: $data, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)'; } @@ -145,11 +130,11 @@ abstract mixin class _$SnActivityCopyWith<$Res> implements $SnActivityCopyWith<$ factory _$SnActivityCopyWith(_SnActivity value, $Res Function(_SnActivity) _then) = __$SnActivityCopyWithImpl; @override @useResult $Res call({ - String id, String type, String resourceIdentifier, int visibility, String accountId, SnAccount account, dynamic data, DateTime createdAt, DateTime updatedAt, dynamic deletedAt + String id, String type, String resourceIdentifier, dynamic data, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt }); -@override $SnAccountCopyWith<$Res> get account; + } /// @nodoc @@ -162,32 +147,20 @@ class __$SnActivityCopyWithImpl<$Res> /// Create a copy of SnActivity /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? type = null,Object? resourceIdentifier = null,Object? visibility = null,Object? accountId = null,Object? account = null,Object? data = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? type = null,Object? resourceIdentifier = null,Object? data = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { return _then(_SnActivity( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable as String,resourceIdentifier: null == resourceIdentifier ? _self.resourceIdentifier : resourceIdentifier // ignore: cast_nullable_to_non_nullable -as String,visibility: null == visibility ? _self.visibility : visibility // ignore: cast_nullable_to_non_nullable -as int,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable -as String,account: null == account ? _self.account : account // ignore: cast_nullable_to_non_nullable -as SnAccount,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable +as String,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable as dynamic,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable as DateTime,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable -as dynamic, +as DateTime?, )); } -/// Create a copy of SnActivity -/// with the given fields replaced by the non-null parameter values. -@override -@pragma('vm:prefer-inline') -$SnAccountCopyWith<$Res> get account { - - return $SnAccountCopyWith<$Res>(_self.account, (value) { - return _then(_self.copyWith(account: value)); - }); -} + } diff --git a/lib/models/activity.g.dart b/lib/models/activity.g.dart index ebb056d..2373de1 100644 --- a/lib/models/activity.g.dart +++ b/lib/models/activity.g.dart @@ -10,13 +10,13 @@ _SnActivity _$SnActivityFromJson(Map json) => _SnActivity( id: json['id'] as String, type: json['type'] as String, resourceIdentifier: json['resource_identifier'] as String, - visibility: (json['visibility'] as num).toInt(), - accountId: json['account_id'] as String, - account: SnAccount.fromJson(json['account'] as Map), data: json['data'], createdAt: DateTime.parse(json['created_at'] as String), updatedAt: DateTime.parse(json['updated_at'] as String), - deletedAt: json['deleted_at'], + deletedAt: + json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), ); Map _$SnActivityToJson(_SnActivity instance) => @@ -24,13 +24,10 @@ Map _$SnActivityToJson(_SnActivity instance) => 'id': instance.id, 'type': instance.type, 'resource_identifier': instance.resourceIdentifier, - 'visibility': instance.visibility, - 'account_id': instance.accountId, - 'account': instance.account.toJson(), 'data': instance.data, 'created_at': instance.createdAt.toIso8601String(), 'updated_at': instance.updatedAt.toIso8601String(), - 'deleted_at': instance.deletedAt, + 'deleted_at': instance.deletedAt?.toIso8601String(), }; _SnCheckInResult _$SnCheckInResultFromJson(Map json) => diff --git a/lib/screens/chat/room_detail.g.dart b/lib/screens/chat/room_detail.g.dart index 0250fb7..e336fd8 100644 --- a/lib/screens/chat/room_detail.g.dart +++ b/lib/screens/chat/room_detail.g.dart @@ -7,7 +7,7 @@ part of 'room_detail.dart'; // ************************************************************************** String _$chatMemberListNotifierHash() => - r'f14dbb3c6ccfef26a49d8bf5dd53b05f7c63eb6c'; + r'f2191a631ba00ae3de39ccac10e4cdd065ffee17'; /// Copied from Dart SDK class _SystemHash { diff --git a/lib/screens/explore.dart b/lib/screens/explore.dart index e4ff972..1a80dbe 100644 --- a/lib/screens/explore.dart +++ b/lib/screens/explore.dart @@ -168,12 +168,6 @@ class _ActivityListView extends HookConsumerWidget { ); } break; - case 'accounts.check-in': - itemWidget = CheckInActivityWidget(item: item); - break; - case 'accounts.status': - itemWidget = StatusActivityWidget(item: item); - break; default: itemWidget = const Placeholder(); } @@ -196,12 +190,14 @@ class ActivityListNotifier extends _$ActivityListNotifier @override Future> fetch({required String? cursor}) async { final client = ref.read(apiClientProvider); - final offset = cursor == null ? 0 : int.parse(cursor); final take = 20; final response = await client.get( '/activities', - queryParameters: {'offset': offset, 'take': take}, + queryParameters: { + if (cursor != null) 'reading_cursor': cursor, + 'take': take, + }, ); final List items = @@ -209,9 +205,9 @@ class ActivityListNotifier extends _$ActivityListNotifier .map((e) => SnActivity.fromJson(e as Map)) .toList(); - final total = int.tryParse(response.headers['x-total']?.first ?? '') ?? 0; - final hasMore = offset + items.length < total; - final nextCursor = hasMore ? (offset + items.length).toString() : null; + final hasMore = (items.firstOrNull?.type ?? 'empty') != 'empty'; + final nextCursor = + items.map((x) => x.createdAt).lastOrNull?.toIso8601String().toString(); return CursorPagingData( items: items, diff --git a/lib/screens/explore.g.dart b/lib/screens/explore.g.dart index 2f4d224..11b31ec 100644 --- a/lib/screens/explore.g.dart +++ b/lib/screens/explore.g.dart @@ -7,7 +7,7 @@ part of 'explore.dart'; // ************************************************************************** String _$activityListNotifierHash() => - r'8a67d302e828408c7c4cf724d84c2c5958f2dc7e'; + r'1baf0bb961bc02bfc8a5b5f515981072c6ce1750'; /// See also [ActivityListNotifier]. @ProviderFor(ActivityListNotifier) diff --git a/lib/widgets/account/status.dart b/lib/widgets/account/status.dart index 8f30757..4a95c4a 100644 --- a/lib/widgets/account/status.dart +++ b/lib/widgets/account/status.dart @@ -133,54 +133,3 @@ class AccountStatusWidget extends HookConsumerWidget { ).opacity((userStatus.value?.isCustomized ?? false) ? 1 : 0.85); } } - -class StatusActivityWidget extends StatelessWidget { - final SnActivity item; - const StatusActivityWidget({super.key, required this.item}); - - @override - Widget build(BuildContext context) { - final result = SnAccountStatus.fromJson(item.data); - return Row( - spacing: 12, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ProfilePictureWidget( - fileId: item.account.profile.picture?.id, - radius: 12, - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Icon(Symbols.circle, size: 12).padding(top: 1, left: 2), - const Gap(4), - Text('status').fontSize(11).tr(), - ], - ).opacity(0.85), - Text( - result.clearedAt == null - ? 'statusActivityTitle' - : 'statusActivityEndedTitle', - ) - .tr( - args: [ - item.account.nick, - result.label, - RelativeTime(context).format(result.createdAt), - if (result.clearedAt != null) - RelativeTime(context).format(result.clearedAt!), - ], - ) - .fontSize(13) - .padding(left: 2), - ], - ), - ), - ], - ).padding(horizontal: 16, vertical: 12); - } -} diff --git a/lib/widgets/response.dart b/lib/widgets/response.dart index 2c86afa..a49963e 100644 --- a/lib/widgets/response.dart +++ b/lib/widgets/response.dart @@ -9,7 +9,11 @@ class ResponseErrorWidget extends StatelessWidget { final dynamic error; final VoidCallback onRetry; - const ResponseErrorWidget({super.key, required this.error, required this.onRetry}); + const ResponseErrorWidget({ + super.key, + required this.error, + required this.onRetry, + }); @override Widget build(BuildContext context) { @@ -36,6 +40,15 @@ class ResponseErrorWidget extends StatelessWidget { ], ), ).center() + else if (error is DioException && error.response != null) + ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 320), + child: Text( + error.response.toString(), + textAlign: TextAlign.center, + style: const TextStyle(color: Color(0xFF757575)), + ), + ).center() else ConstrainedBox( constraints: const BoxConstraints(maxWidth: 320),