From 4983e3ae63c19c59ce233edb797b186da744d1dd Mon Sep 17 00:00:00 2001 From: andannn Date: Sun, 29 Oct 2023 21:16:33 +0900 Subject: [PATCH 01/10] add notification data source --- lib/core/data/model/notification_type.dart | 35 ++ .../api/notification_query_graphql.dart | 244 ++++++++++++ lib/core/network/auth_data_source.dart | 41 ++- .../model/activity_like_notification_dto.dart | 24 ++ ...ctivity_like_notification_dto.freezed.dart | 309 ++++++++++++++++ .../activity_like_notification_dto.g.dart | 48 +++ .../activity_message_notification_dto.dart | 25 ++ ...vity_message_notification_dto.freezed.dart | 335 +++++++++++++++++ .../activity_message_notification_dto.g.dart | 50 +++ .../activity_reply_like_notification_dto.dart | 27 ++ ...y_reply_like_notification_dto.freezed.dart | 337 +++++++++++++++++ ...ctivity_reply_like_notification_dto.g.dart | 50 +++ .../activity_reply_notification_dto.dart | 25 ++ ...tivity_reply_notification_dto.freezed.dart | 333 +++++++++++++++++ .../activity_reply_notification_dto.g.dart | 50 +++ ...y_reply_subscription_notification_dto.dart | 26 ++ ...subscription_notification_dto.freezed.dart | 340 +++++++++++++++++ ...reply_subscription_notification_dto.g.dart | 51 +++ .../model/airing_notification_dto.dart | 25 ++ .../airing_notification_dto.freezed.dart | 326 +++++++++++++++++ .../model/airing_notification_dto.g.dart | 50 +++ .../model/following_notification_dto.dart | 24 ++ .../following_notification_dto.freezed.dart | 305 +++++++++++++++ .../model/following_notification_dto.g.dart | 48 +++ .../media_data_change_notification_dto.dart | 25 ++ ..._data_change_notification_dto.freezed.dart | 334 +++++++++++++++++ .../media_data_change_notification_dto.g.dart | 50 +++ .../media_deletion_notification_dto.dart | 24 ++ ...dia_deletion_notification_dto.freezed.dart | 293 +++++++++++++++ .../media_deletion_notification_dto.g.dart | 46 +++ .../model/media_merge_notification_dto.dart | 26 ++ .../media_merge_notification_dto.freezed.dart | 346 ++++++++++++++++++ .../model/media_merge_notification_dto.g.dart | 52 +++ lib/core/network/model/notification.dart | 42 +++ ...lated_media_addition_notification_dto.dart | 25 ++ ...dia_addition_notification_dto.freezed.dart | 315 ++++++++++++++++ ...ted_media_addition_notification_dto.g.dart | 49 +++ .../media_list_repository_test.dart | 4 +- test/core/network/auth_data_source_test.dart | 14 + .../model/airing_notification_dto_test.dart | 40 ++ 40 files changed, 4810 insertions(+), 3 deletions(-) create mode 100644 lib/core/data/model/notification_type.dart create mode 100644 lib/core/network/api/notification_query_graphql.dart create mode 100644 lib/core/network/model/activity_like_notification_dto.dart create mode 100644 lib/core/network/model/activity_like_notification_dto.freezed.dart create mode 100644 lib/core/network/model/activity_like_notification_dto.g.dart create mode 100644 lib/core/network/model/activity_message_notification_dto.dart create mode 100644 lib/core/network/model/activity_message_notification_dto.freezed.dart create mode 100644 lib/core/network/model/activity_message_notification_dto.g.dart create mode 100644 lib/core/network/model/activity_reply_like_notification_dto.dart create mode 100644 lib/core/network/model/activity_reply_like_notification_dto.freezed.dart create mode 100644 lib/core/network/model/activity_reply_like_notification_dto.g.dart create mode 100644 lib/core/network/model/activity_reply_notification_dto.dart create mode 100644 lib/core/network/model/activity_reply_notification_dto.freezed.dart create mode 100644 lib/core/network/model/activity_reply_notification_dto.g.dart create mode 100644 lib/core/network/model/activity_reply_subscription_notification_dto.dart create mode 100644 lib/core/network/model/activity_reply_subscription_notification_dto.freezed.dart create mode 100644 lib/core/network/model/activity_reply_subscription_notification_dto.g.dart create mode 100644 lib/core/network/model/airing_notification_dto.dart create mode 100644 lib/core/network/model/airing_notification_dto.freezed.dart create mode 100644 lib/core/network/model/airing_notification_dto.g.dart create mode 100644 lib/core/network/model/following_notification_dto.dart create mode 100644 lib/core/network/model/following_notification_dto.freezed.dart create mode 100644 lib/core/network/model/following_notification_dto.g.dart create mode 100644 lib/core/network/model/media_data_change_notification_dto.dart create mode 100644 lib/core/network/model/media_data_change_notification_dto.freezed.dart create mode 100644 lib/core/network/model/media_data_change_notification_dto.g.dart create mode 100644 lib/core/network/model/media_deletion_notification_dto.dart create mode 100644 lib/core/network/model/media_deletion_notification_dto.freezed.dart create mode 100644 lib/core/network/model/media_deletion_notification_dto.g.dart create mode 100644 lib/core/network/model/media_merge_notification_dto.dart create mode 100644 lib/core/network/model/media_merge_notification_dto.freezed.dart create mode 100644 lib/core/network/model/media_merge_notification_dto.g.dart create mode 100644 lib/core/network/model/notification.dart create mode 100644 lib/core/network/model/related_media_addition_notification_dto.dart create mode 100644 lib/core/network/model/related_media_addition_notification_dto.freezed.dart create mode 100644 lib/core/network/model/related_media_addition_notification_dto.g.dart create mode 100644 test/core/network/model/airing_notification_dto_test.dart diff --git a/lib/core/data/model/notification_type.dart b/lib/core/data/model/notification_type.dart new file mode 100644 index 00000000..1b6ba38a --- /dev/null +++ b/lib/core/data/model/notification_type.dart @@ -0,0 +1,35 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +@JsonEnum() +enum NotificationType { + @JsonValue('AIRING') + airing('AIRING'), + @JsonValue('ACTIVITY_LIKE') + activityLike('ACTIVITY_LIKE'), + @JsonValue('ACTIVITY_REPLY') + activityReply('ACTIVITY_REPLY'), + @JsonValue('ACTIVITY_MENTION') + activityMention('ACTIVITY_MENTION'), + @JsonValue('ACTIVITY_REPLY_LIKE') + activityReplyLike('ACTIVITY_REPLY_LIKE'), + @JsonValue('ACTIVITY_MESSAGE') + activityMessage('ACTIVITY_MESSAGE'), + @JsonValue('FOLLOWING') + following('FOLLOWING'), + @JsonValue('MEDIA_DATA_CHANGE') + mediaDataChange('MEDIA_DATA_CHANGE'), + @JsonValue('RELATED_MEDIA_ADDITION') + relatedMediaAddition('RELATED_MEDIA_ADDITION'), + @JsonValue('MEDIA_DELETION') + mediaDeletion('MEDIA_DELETION'), + @JsonValue('MEDIA_MERGE') + mediaMerge('MEDIA_MERGE'); + + final String typeName; + + const NotificationType(this.typeName); + + static NotificationType resolveType(String name) { + return NotificationType.values.firstWhere((e) => e.name == name); + } +} diff --git a/lib/core/network/api/notification_query_graphql.dart b/lib/core/network/api/notification_query_graphql.dart new file mode 100644 index 00000000..d5d8d96b --- /dev/null +++ b/lib/core/network/api/notification_query_graphql.dart @@ -0,0 +1,244 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; + +class NotificationQueryParam { + final int page; + final int? perPage; + final List type; + + NotificationQueryParam( + {required this.page, + this.perPage, + this.type = const []}); +} + + +String get notificationQueryGraphql => ''' +query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { + Page(page: \$page, perPage: \$perPage) { + notifications(type_in: \$type_in) { + __typename + ... on AiringNotification { + id + type + animeId + episode + contexts + createdAt + media { + id + type + coverImage { + extraLarge + large + medium + color + } + title { + romaji + english + native + } + } + } + ... on ActivityLikeNotification { + id + userId + type + context + activityId + createdAt + user { + id + name + avatar { + large + medium + } + bannerImage + } + } + ... on ActivityMentionNotification { + id + userId + type + activityId + context + createdAt + user { + id + name + avatar { + large + medium + } + bannerImage + } + } + ... on ActivityMessageNotification { + id + userId + type + activityId + context + createdAt + message { + id + } + user { + id + name + avatar { + large + medium + } + bannerImage + } + } + ... on ActivityReplySubscribedNotification { + id + userId + type + activityId + context + createdAt + user { + id + name + avatar { + large + medium + } + bannerImage + } + } + ... on ActivityReplyLikeNotification { + id + userId + type + activityId + context + createdAt + user { + id + name + avatar { + large + medium + } + bannerImage + } + } + ... on ActivityReplyNotification { + id + userId + type + activityId + context + createdAt + user { + id + name + avatar { + large + medium + } + bannerImage + } + } + ... on FollowingNotification { + id + userId + type + context + createdAt + user { + id + name + avatar { + large + medium + } + bannerImage + } + } + ... on MediaMergeNotification { + id + type + mediaId + deletedMediaTitles + context + reason + createdAt + media { + id + type + coverImage { + extraLarge + large + medium + color + } + title { + romaji + english + native + } + } + } + ... on MediaDataChangeNotification { + id + type + mediaId + context + reason + createdAt + media { + id + type + coverImage { + extraLarge + large + medium + color + } + title { + romaji + english + native + } + } + } + ... on MediaDeletionNotification { + id + type + deletedMediaTitle + context + reason + createdAt + } + ... on RelatedMediaAdditionNotification { + id + type + mediaId + context + createdAt + media { + id + type + coverImage { + extraLarge + large + medium + color + } + title { + romaji + english + native + } + } + } + } + } +} +'''; diff --git a/lib/core/network/auth_data_source.dart b/lib/core/network/auth_data_source.dart index 4f73e8a9..54b0eccc 100644 --- a/lib/core/network/auth_data_source.dart +++ b/lib/core/network/auth_data_source.dart @@ -4,10 +4,11 @@ import 'package:aniflow/core/common/util/global_static_constants.dart'; import 'package:aniflow/core/common/util/logger.dart'; import 'package:aniflow/core/network/api/ani_auth_mution_graphql.dart'; import 'package:aniflow/core/network/api/ani_save_media_list_mution_graphql.dart'; +import 'package:aniflow/core/network/api/notification_query_graphql.dart'; import 'package:aniflow/core/network/client/ani_list_dio.dart'; import 'package:aniflow/core/network/model/media_list_dto.dart'; -import 'package:aniflow/core/network/model/user_data_dto.dart' - show UserDataDto; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:aniflow/core/network/model/user_data_dto.dart'; import 'package:aniflow/core/network/util/auth_request_util.dart'; import 'package:aniflow/core/network/util/http_status_util.dart'; import 'package:aniflow/core/shared_preference/aniflow_preferences.dart'; @@ -92,4 +93,40 @@ class AuthDataSource { throw e.covertToNetWorkException(); } } + + Future> getNotifications( + NotificationQueryParam param) async { + final variablesMap = { + 'page': param.page, + 'perPage': param.perPage, + 'type_in': param.type.map((e) => e.typeName).toList(), + }; + + try { + final response = await AniListDio().dio.post( + AniListDio.aniListUrl, + queryParameters: { + 'query': notificationQueryGraphql, + 'variables': variablesMap, + }, + options: _createQueryOptions(), + ); + List resultJson = response.data['data']['Page']['notifications']; + return resultJson + .map((e) => AniNotification.mapToAniNotification(e)) + .toList(); + } on DioException catch (e) { + throw e.covertToNetWorkException(); + } + } + + Options _createQueryOptions() { + return Options( + headers: { + 'Authorization': 'Bearer $_token', + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }, + ); + } } diff --git a/lib/core/network/model/activity_like_notification_dto.dart b/lib/core/network/model/activity_like_notification_dto.dart new file mode 100644 index 00000000..b5b04323 --- /dev/null +++ b/lib/core/network/model/activity_like_notification_dto.dart @@ -0,0 +1,24 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:aniflow/core/network/model/user_data_dto.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'activity_like_notification_dto.freezed.dart'; + +part 'activity_like_notification_dto.g.dart'; + +@freezed +class ActivityLikeNotificationDto extends AniNotification + with _$ActivityLikeNotificationDto { + factory ActivityLikeNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user, + }) = _ActivityLikeNotificationDto; + + factory ActivityLikeNotificationDto.fromJson(Map json) => + _$$_ActivityLikeNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/activity_like_notification_dto.freezed.dart b/lib/core/network/model/activity_like_notification_dto.freezed.dart new file mode 100644 index 00000000..c0755536 --- /dev/null +++ b/lib/core/network/model/activity_like_notification_dto.freezed.dart @@ -0,0 +1,309 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'activity_like_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +ActivityLikeNotificationDto _$ActivityLikeNotificationDtoFromJson( + Map json) { + return _ActivityLikeNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$ActivityLikeNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'userId') + int? get userId => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'user') + UserDataDto? get user => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ActivityLikeNotificationDtoCopyWith + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ActivityLikeNotificationDtoCopyWith<$Res> { + factory $ActivityLikeNotificationDtoCopyWith( + ActivityLikeNotificationDto value, + $Res Function(ActivityLikeNotificationDto) then) = + _$ActivityLikeNotificationDtoCopyWithImpl<$Res, + ActivityLikeNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class _$ActivityLikeNotificationDtoCopyWithImpl<$Res, + $Val extends ActivityLikeNotificationDto> + implements $ActivityLikeNotificationDtoCopyWith<$Res> { + _$ActivityLikeNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $UserDataDtoCopyWith<$Res>? get user { + if (_value.user == null) { + return null; + } + + return $UserDataDtoCopyWith<$Res>(_value.user!, (value) { + return _then(_value.copyWith(user: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_ActivityLikeNotificationDtoCopyWith<$Res> + implements $ActivityLikeNotificationDtoCopyWith<$Res> { + factory _$$_ActivityLikeNotificationDtoCopyWith( + _$_ActivityLikeNotificationDto value, + $Res Function(_$_ActivityLikeNotificationDto) then) = + __$$_ActivityLikeNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + @override + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class __$$_ActivityLikeNotificationDtoCopyWithImpl<$Res> + extends _$ActivityLikeNotificationDtoCopyWithImpl<$Res, + _$_ActivityLikeNotificationDto> + implements _$$_ActivityLikeNotificationDtoCopyWith<$Res> { + __$$_ActivityLikeNotificationDtoCopyWithImpl( + _$_ActivityLikeNotificationDto _value, + $Res Function(_$_ActivityLikeNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_$_ActivityLikeNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_ActivityLikeNotificationDto implements _ActivityLikeNotificationDto { + _$_ActivityLikeNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'userId') this.userId, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'user') this.user}) + : _contexts = contexts; + + factory _$_ActivityLikeNotificationDto.fromJson(Map json) => + _$$_ActivityLikeNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'userId') + final int? userId; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'user') + final UserDataDto? user; + + @override + String toString() { + return 'ActivityLikeNotificationDto(id: $id, type: $type, userId: $userId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_ActivityLikeNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.userId, userId) || other.userId == userId) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.user, user) || other.user == user)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, userId, + const DeepCollectionEquality().hash(_contexts), createdAt, user); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_ActivityLikeNotificationDtoCopyWith<_$_ActivityLikeNotificationDto> + get copyWith => __$$_ActivityLikeNotificationDtoCopyWithImpl< + _$_ActivityLikeNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_ActivityLikeNotificationDtoToJson( + this, + ); + } +} + +abstract class _ActivityLikeNotificationDto + implements ActivityLikeNotificationDto { + factory _ActivityLikeNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user}) = + _$_ActivityLikeNotificationDto; + + factory _ActivityLikeNotificationDto.fromJson(Map json) = + _$_ActivityLikeNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'userId') + int? get userId; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'user') + UserDataDto? get user; + @override + @JsonKey(ignore: true) + _$$_ActivityLikeNotificationDtoCopyWith<_$_ActivityLikeNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/activity_like_notification_dto.g.dart b/lib/core/network/model/activity_like_notification_dto.g.dart new file mode 100644 index 00000000..60a3fdf0 --- /dev/null +++ b/lib/core/network/model/activity_like_notification_dto.g.dart @@ -0,0 +1,48 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'activity_like_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_ActivityLikeNotificationDto _$$_ActivityLikeNotificationDtoFromJson( + Map json) => + _$_ActivityLikeNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + userId: json['userId'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + user: json['user'] == null + ? null + : UserDataDto.fromJson(json['user'] as Map), + ); + +Map _$$_ActivityLikeNotificationDtoToJson( + _$_ActivityLikeNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'userId': instance.userId, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'user': instance.user, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/activity_message_notification_dto.dart b/lib/core/network/model/activity_message_notification_dto.dart new file mode 100644 index 00000000..b137f427 --- /dev/null +++ b/lib/core/network/model/activity_message_notification_dto.dart @@ -0,0 +1,25 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:aniflow/core/network/model/user_data_dto.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'activity_message_notification_dto.freezed.dart'; + +part 'activity_message_notification_dto.g.dart'; + +@freezed +class ActivityMessageNotificationDto extends AniNotification + with _$ActivityMessageNotificationDto { + factory ActivityMessageNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user, + }) = _ActivityMessageNotificationDto; + + factory ActivityMessageNotificationDto.fromJson(Map json) => + _$$_ActivityMessageNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/activity_message_notification_dto.freezed.dart b/lib/core/network/model/activity_message_notification_dto.freezed.dart new file mode 100644 index 00000000..6e8b2a1e --- /dev/null +++ b/lib/core/network/model/activity_message_notification_dto.freezed.dart @@ -0,0 +1,335 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'activity_message_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +ActivityMessageNotificationDto _$ActivityMessageNotificationDtoFromJson( + Map json) { + return _ActivityMessageNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$ActivityMessageNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'userId') + int? get userId => throw _privateConstructorUsedError; + @JsonKey(name: 'activityId') + int? get activityId => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'user') + UserDataDto? get user => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ActivityMessageNotificationDtoCopyWith + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ActivityMessageNotificationDtoCopyWith<$Res> { + factory $ActivityMessageNotificationDtoCopyWith( + ActivityMessageNotificationDto value, + $Res Function(ActivityMessageNotificationDto) then) = + _$ActivityMessageNotificationDtoCopyWithImpl<$Res, + ActivityMessageNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class _$ActivityMessageNotificationDtoCopyWithImpl<$Res, + $Val extends ActivityMessageNotificationDto> + implements $ActivityMessageNotificationDtoCopyWith<$Res> { + _$ActivityMessageNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? activityId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + activityId: freezed == activityId + ? _value.activityId + : activityId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $UserDataDtoCopyWith<$Res>? get user { + if (_value.user == null) { + return null; + } + + return $UserDataDtoCopyWith<$Res>(_value.user!, (value) { + return _then(_value.copyWith(user: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_ActivityMessageNotificationDtoCopyWith<$Res> + implements $ActivityMessageNotificationDtoCopyWith<$Res> { + factory _$$_ActivityMessageNotificationDtoCopyWith( + _$_ActivityMessageNotificationDto value, + $Res Function(_$_ActivityMessageNotificationDto) then) = + __$$_ActivityMessageNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + @override + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class __$$_ActivityMessageNotificationDtoCopyWithImpl<$Res> + extends _$ActivityMessageNotificationDtoCopyWithImpl<$Res, + _$_ActivityMessageNotificationDto> + implements _$$_ActivityMessageNotificationDtoCopyWith<$Res> { + __$$_ActivityMessageNotificationDtoCopyWithImpl( + _$_ActivityMessageNotificationDto _value, + $Res Function(_$_ActivityMessageNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? activityId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_$_ActivityMessageNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + activityId: freezed == activityId + ? _value.activityId + : activityId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_ActivityMessageNotificationDto + implements _ActivityMessageNotificationDto { + _$_ActivityMessageNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'userId') this.userId, + @JsonKey(name: 'activityId') this.activityId, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'user') this.user}) + : _contexts = contexts; + + factory _$_ActivityMessageNotificationDto.fromJson( + Map json) => + _$$_ActivityMessageNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'userId') + final int? userId; + @override + @JsonKey(name: 'activityId') + final int? activityId; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'user') + final UserDataDto? user; + + @override + String toString() { + return 'ActivityMessageNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_ActivityMessageNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.userId, userId) || other.userId == userId) && + (identical(other.activityId, activityId) || + other.activityId == activityId) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.user, user) || other.user == user)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, userId, activityId, + const DeepCollectionEquality().hash(_contexts), createdAt, user); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_ActivityMessageNotificationDtoCopyWith<_$_ActivityMessageNotificationDto> + get copyWith => __$$_ActivityMessageNotificationDtoCopyWithImpl< + _$_ActivityMessageNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_ActivityMessageNotificationDtoToJson( + this, + ); + } +} + +abstract class _ActivityMessageNotificationDto + implements ActivityMessageNotificationDto { + factory _ActivityMessageNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'activityId') final int? activityId, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user}) = + _$_ActivityMessageNotificationDto; + + factory _ActivityMessageNotificationDto.fromJson(Map json) = + _$_ActivityMessageNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'userId') + int? get userId; + @override + @JsonKey(name: 'activityId') + int? get activityId; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'user') + UserDataDto? get user; + @override + @JsonKey(ignore: true) + _$$_ActivityMessageNotificationDtoCopyWith<_$_ActivityMessageNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/activity_message_notification_dto.g.dart b/lib/core/network/model/activity_message_notification_dto.g.dart new file mode 100644 index 00000000..e7fec1c9 --- /dev/null +++ b/lib/core/network/model/activity_message_notification_dto.g.dart @@ -0,0 +1,50 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'activity_message_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_ActivityMessageNotificationDto _$$_ActivityMessageNotificationDtoFromJson( + Map json) => + _$_ActivityMessageNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + userId: json['userId'] as int?, + activityId: json['activityId'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + user: json['user'] == null + ? null + : UserDataDto.fromJson(json['user'] as Map), + ); + +Map _$$_ActivityMessageNotificationDtoToJson( + _$_ActivityMessageNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'userId': instance.userId, + 'activityId': instance.activityId, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'user': instance.user, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/activity_reply_like_notification_dto.dart b/lib/core/network/model/activity_reply_like_notification_dto.dart new file mode 100644 index 00000000..ca910afc --- /dev/null +++ b/lib/core/network/model/activity_reply_like_notification_dto.dart @@ -0,0 +1,27 @@ +// ignore_for_file: lines_longer_than_80_chars + +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:aniflow/core/network/model/user_data_dto.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'activity_reply_like_notification_dto.freezed.dart'; + +part 'activity_reply_like_notification_dto.g.dart'; + +@freezed +class ActivityReplyLikeNotificationDto extends AniNotification + with _$ActivityReplyLikeNotificationDto { + factory ActivityReplyLikeNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user, + }) = _ActivityReplyLikeNotificationDto; + + factory ActivityReplyLikeNotificationDto.fromJson(Map json) => + _$$_ActivityReplyLikeNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/activity_reply_like_notification_dto.freezed.dart b/lib/core/network/model/activity_reply_like_notification_dto.freezed.dart new file mode 100644 index 00000000..6d1e3490 --- /dev/null +++ b/lib/core/network/model/activity_reply_like_notification_dto.freezed.dart @@ -0,0 +1,337 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'activity_reply_like_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +ActivityReplyLikeNotificationDto _$ActivityReplyLikeNotificationDtoFromJson( + Map json) { + return _ActivityReplyLikeNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$ActivityReplyLikeNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'userId') + int? get userId => throw _privateConstructorUsedError; + @JsonKey(name: 'activityId') + int? get activityId => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'user') + UserDataDto? get user => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ActivityReplyLikeNotificationDtoCopyWith + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ActivityReplyLikeNotificationDtoCopyWith<$Res> { + factory $ActivityReplyLikeNotificationDtoCopyWith( + ActivityReplyLikeNotificationDto value, + $Res Function(ActivityReplyLikeNotificationDto) then) = + _$ActivityReplyLikeNotificationDtoCopyWithImpl<$Res, + ActivityReplyLikeNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class _$ActivityReplyLikeNotificationDtoCopyWithImpl<$Res, + $Val extends ActivityReplyLikeNotificationDto> + implements $ActivityReplyLikeNotificationDtoCopyWith<$Res> { + _$ActivityReplyLikeNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? activityId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + activityId: freezed == activityId + ? _value.activityId + : activityId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $UserDataDtoCopyWith<$Res>? get user { + if (_value.user == null) { + return null; + } + + return $UserDataDtoCopyWith<$Res>(_value.user!, (value) { + return _then(_value.copyWith(user: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_ActivityReplyLikeNotificationDtoCopyWith<$Res> + implements $ActivityReplyLikeNotificationDtoCopyWith<$Res> { + factory _$$_ActivityReplyLikeNotificationDtoCopyWith( + _$_ActivityReplyLikeNotificationDto value, + $Res Function(_$_ActivityReplyLikeNotificationDto) then) = + __$$_ActivityReplyLikeNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + @override + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class __$$_ActivityReplyLikeNotificationDtoCopyWithImpl<$Res> + extends _$ActivityReplyLikeNotificationDtoCopyWithImpl<$Res, + _$_ActivityReplyLikeNotificationDto> + implements _$$_ActivityReplyLikeNotificationDtoCopyWith<$Res> { + __$$_ActivityReplyLikeNotificationDtoCopyWithImpl( + _$_ActivityReplyLikeNotificationDto _value, + $Res Function(_$_ActivityReplyLikeNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? activityId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_$_ActivityReplyLikeNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + activityId: freezed == activityId + ? _value.activityId + : activityId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_ActivityReplyLikeNotificationDto + implements _ActivityReplyLikeNotificationDto { + _$_ActivityReplyLikeNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'userId') this.userId, + @JsonKey(name: 'activityId') this.activityId, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'user') this.user}) + : _contexts = contexts; + + factory _$_ActivityReplyLikeNotificationDto.fromJson( + Map json) => + _$$_ActivityReplyLikeNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'userId') + final int? userId; + @override + @JsonKey(name: 'activityId') + final int? activityId; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'user') + final UserDataDto? user; + + @override + String toString() { + return 'ActivityReplyLikeNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_ActivityReplyLikeNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.userId, userId) || other.userId == userId) && + (identical(other.activityId, activityId) || + other.activityId == activityId) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.user, user) || other.user == user)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, userId, activityId, + const DeepCollectionEquality().hash(_contexts), createdAt, user); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_ActivityReplyLikeNotificationDtoCopyWith< + _$_ActivityReplyLikeNotificationDto> + get copyWith => __$$_ActivityReplyLikeNotificationDtoCopyWithImpl< + _$_ActivityReplyLikeNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_ActivityReplyLikeNotificationDtoToJson( + this, + ); + } +} + +abstract class _ActivityReplyLikeNotificationDto + implements ActivityReplyLikeNotificationDto { + factory _ActivityReplyLikeNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'activityId') final int? activityId, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user}) = + _$_ActivityReplyLikeNotificationDto; + + factory _ActivityReplyLikeNotificationDto.fromJson( + Map json) = _$_ActivityReplyLikeNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'userId') + int? get userId; + @override + @JsonKey(name: 'activityId') + int? get activityId; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'user') + UserDataDto? get user; + @override + @JsonKey(ignore: true) + _$$_ActivityReplyLikeNotificationDtoCopyWith< + _$_ActivityReplyLikeNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/activity_reply_like_notification_dto.g.dart b/lib/core/network/model/activity_reply_like_notification_dto.g.dart new file mode 100644 index 00000000..ddc3828d --- /dev/null +++ b/lib/core/network/model/activity_reply_like_notification_dto.g.dart @@ -0,0 +1,50 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'activity_reply_like_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_ActivityReplyLikeNotificationDto + _$$_ActivityReplyLikeNotificationDtoFromJson(Map json) => + _$_ActivityReplyLikeNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + userId: json['userId'] as int?, + activityId: json['activityId'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + user: json['user'] == null + ? null + : UserDataDto.fromJson(json['user'] as Map), + ); + +Map _$$_ActivityReplyLikeNotificationDtoToJson( + _$_ActivityReplyLikeNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'userId': instance.userId, + 'activityId': instance.activityId, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'user': instance.user, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/activity_reply_notification_dto.dart b/lib/core/network/model/activity_reply_notification_dto.dart new file mode 100644 index 00000000..cad5a9d3 --- /dev/null +++ b/lib/core/network/model/activity_reply_notification_dto.dart @@ -0,0 +1,25 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:aniflow/core/network/model/user_data_dto.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'activity_reply_notification_dto.freezed.dart'; + +part 'activity_reply_notification_dto.g.dart'; + +@freezed +class ActivityReplyNotificationDto extends AniNotification + with _$ActivityReplyNotificationDto { + factory ActivityReplyNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user, + }) = _ActivityReplyNotificationDto; + + factory ActivityReplyNotificationDto.fromJson(Map json) => + _$$_ActivityReplyNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/activity_reply_notification_dto.freezed.dart b/lib/core/network/model/activity_reply_notification_dto.freezed.dart new file mode 100644 index 00000000..4d6a31a2 --- /dev/null +++ b/lib/core/network/model/activity_reply_notification_dto.freezed.dart @@ -0,0 +1,333 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'activity_reply_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +ActivityReplyNotificationDto _$ActivityReplyNotificationDtoFromJson( + Map json) { + return _ActivityReplyNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$ActivityReplyNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'userId') + int? get userId => throw _privateConstructorUsedError; + @JsonKey(name: 'activityId') + int? get activityId => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'user') + UserDataDto? get user => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ActivityReplyNotificationDtoCopyWith + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ActivityReplyNotificationDtoCopyWith<$Res> { + factory $ActivityReplyNotificationDtoCopyWith( + ActivityReplyNotificationDto value, + $Res Function(ActivityReplyNotificationDto) then) = + _$ActivityReplyNotificationDtoCopyWithImpl<$Res, + ActivityReplyNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class _$ActivityReplyNotificationDtoCopyWithImpl<$Res, + $Val extends ActivityReplyNotificationDto> + implements $ActivityReplyNotificationDtoCopyWith<$Res> { + _$ActivityReplyNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? activityId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + activityId: freezed == activityId + ? _value.activityId + : activityId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $UserDataDtoCopyWith<$Res>? get user { + if (_value.user == null) { + return null; + } + + return $UserDataDtoCopyWith<$Res>(_value.user!, (value) { + return _then(_value.copyWith(user: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_ActivityReplyNotificationDtoCopyWith<$Res> + implements $ActivityReplyNotificationDtoCopyWith<$Res> { + factory _$$_ActivityReplyNotificationDtoCopyWith( + _$_ActivityReplyNotificationDto value, + $Res Function(_$_ActivityReplyNotificationDto) then) = + __$$_ActivityReplyNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + @override + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class __$$_ActivityReplyNotificationDtoCopyWithImpl<$Res> + extends _$ActivityReplyNotificationDtoCopyWithImpl<$Res, + _$_ActivityReplyNotificationDto> + implements _$$_ActivityReplyNotificationDtoCopyWith<$Res> { + __$$_ActivityReplyNotificationDtoCopyWithImpl( + _$_ActivityReplyNotificationDto _value, + $Res Function(_$_ActivityReplyNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? activityId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_$_ActivityReplyNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + activityId: freezed == activityId + ? _value.activityId + : activityId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_ActivityReplyNotificationDto implements _ActivityReplyNotificationDto { + _$_ActivityReplyNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'userId') this.userId, + @JsonKey(name: 'activityId') this.activityId, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'user') this.user}) + : _contexts = contexts; + + factory _$_ActivityReplyNotificationDto.fromJson(Map json) => + _$$_ActivityReplyNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'userId') + final int? userId; + @override + @JsonKey(name: 'activityId') + final int? activityId; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'user') + final UserDataDto? user; + + @override + String toString() { + return 'ActivityReplyNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_ActivityReplyNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.userId, userId) || other.userId == userId) && + (identical(other.activityId, activityId) || + other.activityId == activityId) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.user, user) || other.user == user)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, userId, activityId, + const DeepCollectionEquality().hash(_contexts), createdAt, user); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_ActivityReplyNotificationDtoCopyWith<_$_ActivityReplyNotificationDto> + get copyWith => __$$_ActivityReplyNotificationDtoCopyWithImpl< + _$_ActivityReplyNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_ActivityReplyNotificationDtoToJson( + this, + ); + } +} + +abstract class _ActivityReplyNotificationDto + implements ActivityReplyNotificationDto { + factory _ActivityReplyNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'activityId') final int? activityId, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user}) = + _$_ActivityReplyNotificationDto; + + factory _ActivityReplyNotificationDto.fromJson(Map json) = + _$_ActivityReplyNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'userId') + int? get userId; + @override + @JsonKey(name: 'activityId') + int? get activityId; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'user') + UserDataDto? get user; + @override + @JsonKey(ignore: true) + _$$_ActivityReplyNotificationDtoCopyWith<_$_ActivityReplyNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/activity_reply_notification_dto.g.dart b/lib/core/network/model/activity_reply_notification_dto.g.dart new file mode 100644 index 00000000..e98f6df2 --- /dev/null +++ b/lib/core/network/model/activity_reply_notification_dto.g.dart @@ -0,0 +1,50 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'activity_reply_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_ActivityReplyNotificationDto _$$_ActivityReplyNotificationDtoFromJson( + Map json) => + _$_ActivityReplyNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + userId: json['userId'] as int?, + activityId: json['activityId'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + user: json['user'] == null + ? null + : UserDataDto.fromJson(json['user'] as Map), + ); + +Map _$$_ActivityReplyNotificationDtoToJson( + _$_ActivityReplyNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'userId': instance.userId, + 'activityId': instance.activityId, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'user': instance.user, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/activity_reply_subscription_notification_dto.dart b/lib/core/network/model/activity_reply_subscription_notification_dto.dart new file mode 100644 index 00000000..1c237a77 --- /dev/null +++ b/lib/core/network/model/activity_reply_subscription_notification_dto.dart @@ -0,0 +1,26 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:aniflow/core/network/model/user_data_dto.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'activity_reply_subscription_notification_dto.freezed.dart'; + +part 'activity_reply_subscription_notification_dto.g.dart'; + +@freezed +class ActivityReplySubscribedNotificationDto extends AniNotification + with _$ActivityReplySubscribedNotificationDto { + factory ActivityReplySubscribedNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user, + }) = _ActivityReplySubscribedNotificationDto; + + factory ActivityReplySubscribedNotificationDto.fromJson( + Map json) => + _$$_ActivityReplySubscribedNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/activity_reply_subscription_notification_dto.freezed.dart b/lib/core/network/model/activity_reply_subscription_notification_dto.freezed.dart new file mode 100644 index 00000000..3f0f1767 --- /dev/null +++ b/lib/core/network/model/activity_reply_subscription_notification_dto.freezed.dart @@ -0,0 +1,340 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'activity_reply_subscription_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +ActivityReplySubscribedNotificationDto + _$ActivityReplySubscribedNotificationDtoFromJson( + Map json) { + return _ActivityReplySubscribedNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$ActivityReplySubscribedNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'userId') + int? get userId => throw _privateConstructorUsedError; + @JsonKey(name: 'activityId') + int? get activityId => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'user') + UserDataDto? get user => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ActivityReplySubscribedNotificationDtoCopyWith< + ActivityReplySubscribedNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ActivityReplySubscribedNotificationDtoCopyWith<$Res> { + factory $ActivityReplySubscribedNotificationDtoCopyWith( + ActivityReplySubscribedNotificationDto value, + $Res Function(ActivityReplySubscribedNotificationDto) then) = + _$ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res, + ActivityReplySubscribedNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class _$ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res, + $Val extends ActivityReplySubscribedNotificationDto> + implements $ActivityReplySubscribedNotificationDtoCopyWith<$Res> { + _$ActivityReplySubscribedNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? activityId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + activityId: freezed == activityId + ? _value.activityId + : activityId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $UserDataDtoCopyWith<$Res>? get user { + if (_value.user == null) { + return null; + } + + return $UserDataDtoCopyWith<$Res>(_value.user!, (value) { + return _then(_value.copyWith(user: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_ActivityReplySubscribedNotificationDtoCopyWith<$Res> + implements $ActivityReplySubscribedNotificationDtoCopyWith<$Res> { + factory _$$_ActivityReplySubscribedNotificationDtoCopyWith( + _$_ActivityReplySubscribedNotificationDto value, + $Res Function(_$_ActivityReplySubscribedNotificationDto) then) = + __$$_ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'activityId') int? activityId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + @override + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class __$$_ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res> + extends _$ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res, + _$_ActivityReplySubscribedNotificationDto> + implements _$$_ActivityReplySubscribedNotificationDtoCopyWith<$Res> { + __$$_ActivityReplySubscribedNotificationDtoCopyWithImpl( + _$_ActivityReplySubscribedNotificationDto _value, + $Res Function(_$_ActivityReplySubscribedNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? activityId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_$_ActivityReplySubscribedNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + activityId: freezed == activityId + ? _value.activityId + : activityId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_ActivityReplySubscribedNotificationDto + implements _ActivityReplySubscribedNotificationDto { + _$_ActivityReplySubscribedNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'userId') this.userId, + @JsonKey(name: 'activityId') this.activityId, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'user') this.user}) + : _contexts = contexts; + + factory _$_ActivityReplySubscribedNotificationDto.fromJson( + Map json) => + _$$_ActivityReplySubscribedNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'userId') + final int? userId; + @override + @JsonKey(name: 'activityId') + final int? activityId; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'user') + final UserDataDto? user; + + @override + String toString() { + return 'ActivityReplySubscribedNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_ActivityReplySubscribedNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.userId, userId) || other.userId == userId) && + (identical(other.activityId, activityId) || + other.activityId == activityId) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.user, user) || other.user == user)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, userId, activityId, + const DeepCollectionEquality().hash(_contexts), createdAt, user); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_ActivityReplySubscribedNotificationDtoCopyWith< + _$_ActivityReplySubscribedNotificationDto> + get copyWith => __$$_ActivityReplySubscribedNotificationDtoCopyWithImpl< + _$_ActivityReplySubscribedNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_ActivityReplySubscribedNotificationDtoToJson( + this, + ); + } +} + +abstract class _ActivityReplySubscribedNotificationDto + implements ActivityReplySubscribedNotificationDto { + factory _ActivityReplySubscribedNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'activityId') final int? activityId, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user}) = + _$_ActivityReplySubscribedNotificationDto; + + factory _ActivityReplySubscribedNotificationDto.fromJson( + Map json) = + _$_ActivityReplySubscribedNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'userId') + int? get userId; + @override + @JsonKey(name: 'activityId') + int? get activityId; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'user') + UserDataDto? get user; + @override + @JsonKey(ignore: true) + _$$_ActivityReplySubscribedNotificationDtoCopyWith< + _$_ActivityReplySubscribedNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/activity_reply_subscription_notification_dto.g.dart b/lib/core/network/model/activity_reply_subscription_notification_dto.g.dart new file mode 100644 index 00000000..b4d2e7e9 --- /dev/null +++ b/lib/core/network/model/activity_reply_subscription_notification_dto.g.dart @@ -0,0 +1,51 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'activity_reply_subscription_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_ActivityReplySubscribedNotificationDto + _$$_ActivityReplySubscribedNotificationDtoFromJson( + Map json) => + _$_ActivityReplySubscribedNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + userId: json['userId'] as int?, + activityId: json['activityId'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + user: json['user'] == null + ? null + : UserDataDto.fromJson(json['user'] as Map), + ); + +Map _$$_ActivityReplySubscribedNotificationDtoToJson( + _$_ActivityReplySubscribedNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'userId': instance.userId, + 'activityId': instance.activityId, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'user': instance.user, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/airing_notification_dto.dart b/lib/core/network/model/airing_notification_dto.dart new file mode 100644 index 00000000..c91a64b3 --- /dev/null +++ b/lib/core/network/model/airing_notification_dto.dart @@ -0,0 +1,25 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/media_dto.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'airing_notification_dto.freezed.dart'; + +part 'airing_notification_dto.g.dart'; + +@freezed +class AiringNotificationDto extends AniNotification + with _$AiringNotificationDto { + factory AiringNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'animeId') int? animeId, + @JsonKey(name: 'episode') int? episode, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'media') MediaDto? media, + }) = _AiringNotificationDto; + + factory AiringNotificationDto.fromJson(Map json) => + _$$_AiringNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/airing_notification_dto.freezed.dart b/lib/core/network/model/airing_notification_dto.freezed.dart new file mode 100644 index 00000000..27a85a0a --- /dev/null +++ b/lib/core/network/model/airing_notification_dto.freezed.dart @@ -0,0 +1,326 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'airing_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +AiringNotificationDto _$AiringNotificationDtoFromJson( + Map json) { + return _AiringNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$AiringNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'animeId') + int? get animeId => throw _privateConstructorUsedError; + @JsonKey(name: 'episode') + int? get episode => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'media') + MediaDto? get media => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $AiringNotificationDtoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AiringNotificationDtoCopyWith<$Res> { + factory $AiringNotificationDtoCopyWith(AiringNotificationDto value, + $Res Function(AiringNotificationDto) then) = + _$AiringNotificationDtoCopyWithImpl<$Res, AiringNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'animeId') int? animeId, + @JsonKey(name: 'episode') int? episode, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'media') MediaDto? media}); + + $MediaDtoCopyWith<$Res>? get media; +} + +/// @nodoc +class _$AiringNotificationDtoCopyWithImpl<$Res, + $Val extends AiringNotificationDto> + implements $AiringNotificationDtoCopyWith<$Res> { + _$AiringNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? animeId = freezed, + Object? episode = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? media = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + animeId: freezed == animeId + ? _value.animeId + : animeId // ignore: cast_nullable_to_non_nullable + as int?, + episode: freezed == episode + ? _value.episode + : episode // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + media: freezed == media + ? _value.media + : media // ignore: cast_nullable_to_non_nullable + as MediaDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $MediaDtoCopyWith<$Res>? get media { + if (_value.media == null) { + return null; + } + + return $MediaDtoCopyWith<$Res>(_value.media!, (value) { + return _then(_value.copyWith(media: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_AiringNotificationDtoCopyWith<$Res> + implements $AiringNotificationDtoCopyWith<$Res> { + factory _$$_AiringNotificationDtoCopyWith(_$_AiringNotificationDto value, + $Res Function(_$_AiringNotificationDto) then) = + __$$_AiringNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'animeId') int? animeId, + @JsonKey(name: 'episode') int? episode, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'media') MediaDto? media}); + + @override + $MediaDtoCopyWith<$Res>? get media; +} + +/// @nodoc +class __$$_AiringNotificationDtoCopyWithImpl<$Res> + extends _$AiringNotificationDtoCopyWithImpl<$Res, _$_AiringNotificationDto> + implements _$$_AiringNotificationDtoCopyWith<$Res> { + __$$_AiringNotificationDtoCopyWithImpl(_$_AiringNotificationDto _value, + $Res Function(_$_AiringNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? animeId = freezed, + Object? episode = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? media = freezed, + }) { + return _then(_$_AiringNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + animeId: freezed == animeId + ? _value.animeId + : animeId // ignore: cast_nullable_to_non_nullable + as int?, + episode: freezed == episode + ? _value.episode + : episode // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + media: freezed == media + ? _value.media + : media // ignore: cast_nullable_to_non_nullable + as MediaDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_AiringNotificationDto implements _AiringNotificationDto { + _$_AiringNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'animeId') this.animeId, + @JsonKey(name: 'episode') this.episode, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'media') this.media}) + : _contexts = contexts; + + factory _$_AiringNotificationDto.fromJson(Map json) => + _$$_AiringNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'animeId') + final int? animeId; + @override + @JsonKey(name: 'episode') + final int? episode; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'media') + final MediaDto? media; + + @override + String toString() { + return 'AiringNotificationDto(id: $id, type: $type, animeId: $animeId, episode: $episode, contexts: $contexts, createdAt: $createdAt, media: $media)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_AiringNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.animeId, animeId) || other.animeId == animeId) && + (identical(other.episode, episode) || other.episode == episode) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.media, media) || other.media == media)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, animeId, episode, + const DeepCollectionEquality().hash(_contexts), createdAt, media); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_AiringNotificationDtoCopyWith<_$_AiringNotificationDto> get copyWith => + __$$_AiringNotificationDtoCopyWithImpl<_$_AiringNotificationDto>( + this, _$identity); + + @override + Map toJson() { + return _$$_AiringNotificationDtoToJson( + this, + ); + } +} + +abstract class _AiringNotificationDto implements AiringNotificationDto { + factory _AiringNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'animeId') final int? animeId, + @JsonKey(name: 'episode') final int? episode, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'media') final MediaDto? media}) = + _$_AiringNotificationDto; + + factory _AiringNotificationDto.fromJson(Map json) = + _$_AiringNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'animeId') + int? get animeId; + @override + @JsonKey(name: 'episode') + int? get episode; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'media') + MediaDto? get media; + @override + @JsonKey(ignore: true) + _$$_AiringNotificationDtoCopyWith<_$_AiringNotificationDto> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/airing_notification_dto.g.dart b/lib/core/network/model/airing_notification_dto.g.dart new file mode 100644 index 00000000..d41ad42e --- /dev/null +++ b/lib/core/network/model/airing_notification_dto.g.dart @@ -0,0 +1,50 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'airing_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_AiringNotificationDto _$$_AiringNotificationDtoFromJson( + Map json) => + _$_AiringNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + animeId: json['animeId'] as int?, + episode: json['episode'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + media: json['media'] == null + ? null + : MediaDto.fromJson(json['media'] as Map), + ); + +Map _$$_AiringNotificationDtoToJson( + _$_AiringNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'animeId': instance.animeId, + 'episode': instance.episode, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'media': instance.media, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/following_notification_dto.dart b/lib/core/network/model/following_notification_dto.dart new file mode 100644 index 00000000..613417f7 --- /dev/null +++ b/lib/core/network/model/following_notification_dto.dart @@ -0,0 +1,24 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:aniflow/core/network/model/user_data_dto.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'following_notification_dto.freezed.dart'; + +part 'following_notification_dto.g.dart'; + +@freezed +class FollowingNotificationDto extends AniNotification + with _$FollowingNotificationDto { + factory FollowingNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user, + }) = _FollowingNotificationDto; + + factory FollowingNotificationDto.fromJson(Map json) => + _$$_FollowingNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/following_notification_dto.freezed.dart b/lib/core/network/model/following_notification_dto.freezed.dart new file mode 100644 index 00000000..30ade0fe --- /dev/null +++ b/lib/core/network/model/following_notification_dto.freezed.dart @@ -0,0 +1,305 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'following_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +FollowingNotificationDto _$FollowingNotificationDtoFromJson( + Map json) { + return _FollowingNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$FollowingNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'userId') + int? get userId => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'user') + UserDataDto? get user => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $FollowingNotificationDtoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $FollowingNotificationDtoCopyWith<$Res> { + factory $FollowingNotificationDtoCopyWith(FollowingNotificationDto value, + $Res Function(FollowingNotificationDto) then) = + _$FollowingNotificationDtoCopyWithImpl<$Res, FollowingNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class _$FollowingNotificationDtoCopyWithImpl<$Res, + $Val extends FollowingNotificationDto> + implements $FollowingNotificationDtoCopyWith<$Res> { + _$FollowingNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $UserDataDtoCopyWith<$Res>? get user { + if (_value.user == null) { + return null; + } + + return $UserDataDtoCopyWith<$Res>(_value.user!, (value) { + return _then(_value.copyWith(user: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_FollowingNotificationDtoCopyWith<$Res> + implements $FollowingNotificationDtoCopyWith<$Res> { + factory _$$_FollowingNotificationDtoCopyWith( + _$_FollowingNotificationDto value, + $Res Function(_$_FollowingNotificationDto) then) = + __$$_FollowingNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'userId') int? userId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'user') UserDataDto? user}); + + @override + $UserDataDtoCopyWith<$Res>? get user; +} + +/// @nodoc +class __$$_FollowingNotificationDtoCopyWithImpl<$Res> + extends _$FollowingNotificationDtoCopyWithImpl<$Res, + _$_FollowingNotificationDto> + implements _$$_FollowingNotificationDtoCopyWith<$Res> { + __$$_FollowingNotificationDtoCopyWithImpl(_$_FollowingNotificationDto _value, + $Res Function(_$_FollowingNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? userId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? user = freezed, + }) { + return _then(_$_FollowingNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + userId: freezed == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + user: freezed == user + ? _value.user + : user // ignore: cast_nullable_to_non_nullable + as UserDataDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_FollowingNotificationDto implements _FollowingNotificationDto { + _$_FollowingNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'userId') this.userId, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'user') this.user}) + : _contexts = contexts; + + factory _$_FollowingNotificationDto.fromJson(Map json) => + _$$_FollowingNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'userId') + final int? userId; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'user') + final UserDataDto? user; + + @override + String toString() { + return 'FollowingNotificationDto(id: $id, type: $type, userId: $userId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_FollowingNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.userId, userId) || other.userId == userId) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.user, user) || other.user == user)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, userId, + const DeepCollectionEquality().hash(_contexts), createdAt, user); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_FollowingNotificationDtoCopyWith<_$_FollowingNotificationDto> + get copyWith => __$$_FollowingNotificationDtoCopyWithImpl< + _$_FollowingNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_FollowingNotificationDtoToJson( + this, + ); + } +} + +abstract class _FollowingNotificationDto implements FollowingNotificationDto { + factory _FollowingNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user}) = + _$_FollowingNotificationDto; + + factory _FollowingNotificationDto.fromJson(Map json) = + _$_FollowingNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'userId') + int? get userId; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'user') + UserDataDto? get user; + @override + @JsonKey(ignore: true) + _$$_FollowingNotificationDtoCopyWith<_$_FollowingNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/following_notification_dto.g.dart b/lib/core/network/model/following_notification_dto.g.dart new file mode 100644 index 00000000..cce3e193 --- /dev/null +++ b/lib/core/network/model/following_notification_dto.g.dart @@ -0,0 +1,48 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'following_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_FollowingNotificationDto _$$_FollowingNotificationDtoFromJson( + Map json) => + _$_FollowingNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + userId: json['userId'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + user: json['user'] == null + ? null + : UserDataDto.fromJson(json['user'] as Map), + ); + +Map _$$_FollowingNotificationDtoToJson( + _$_FollowingNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'userId': instance.userId, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'user': instance.user, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/media_data_change_notification_dto.dart b/lib/core/network/model/media_data_change_notification_dto.dart new file mode 100644 index 00000000..c458a7a4 --- /dev/null +++ b/lib/core/network/model/media_data_change_notification_dto.dart @@ -0,0 +1,25 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/media_dto.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'media_data_change_notification_dto.freezed.dart'; + +part 'media_data_change_notification_dto.g.dart'; + +@freezed +class MediaDataChangeNotificationDto extends AniNotification + with _$MediaDataChangeNotificationDto { + factory MediaDataChangeNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') int? mediaId, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'reason') String? reason, + @JsonKey(name: 'media') MediaDto? media, + }) = _MediaDataChangeNotificationDto; + + factory MediaDataChangeNotificationDto.fromJson(Map json) => + _$$_MediaDataChangeNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/media_data_change_notification_dto.freezed.dart b/lib/core/network/model/media_data_change_notification_dto.freezed.dart new file mode 100644 index 00000000..0b68e2b3 --- /dev/null +++ b/lib/core/network/model/media_data_change_notification_dto.freezed.dart @@ -0,0 +1,334 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'media_data_change_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +MediaDataChangeNotificationDto _$MediaDataChangeNotificationDtoFromJson( + Map json) { + return _MediaDataChangeNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$MediaDataChangeNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'mediaId') + int? get mediaId => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'reason') + String? get reason => throw _privateConstructorUsedError; + @JsonKey(name: 'media') + MediaDto? get media => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $MediaDataChangeNotificationDtoCopyWith + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MediaDataChangeNotificationDtoCopyWith<$Res> { + factory $MediaDataChangeNotificationDtoCopyWith( + MediaDataChangeNotificationDto value, + $Res Function(MediaDataChangeNotificationDto) then) = + _$MediaDataChangeNotificationDtoCopyWithImpl<$Res, + MediaDataChangeNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') int? mediaId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'reason') String? reason, + @JsonKey(name: 'media') MediaDto? media}); + + $MediaDtoCopyWith<$Res>? get media; +} + +/// @nodoc +class _$MediaDataChangeNotificationDtoCopyWithImpl<$Res, + $Val extends MediaDataChangeNotificationDto> + implements $MediaDataChangeNotificationDtoCopyWith<$Res> { + _$MediaDataChangeNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? mediaId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? reason = freezed, + Object? media = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + mediaId: freezed == mediaId + ? _value.mediaId + : mediaId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + reason: freezed == reason + ? _value.reason + : reason // ignore: cast_nullable_to_non_nullable + as String?, + media: freezed == media + ? _value.media + : media // ignore: cast_nullable_to_non_nullable + as MediaDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $MediaDtoCopyWith<$Res>? get media { + if (_value.media == null) { + return null; + } + + return $MediaDtoCopyWith<$Res>(_value.media!, (value) { + return _then(_value.copyWith(media: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_MediaDataChangeNotificationDtoCopyWith<$Res> + implements $MediaDataChangeNotificationDtoCopyWith<$Res> { + factory _$$_MediaDataChangeNotificationDtoCopyWith( + _$_MediaDataChangeNotificationDto value, + $Res Function(_$_MediaDataChangeNotificationDto) then) = + __$$_MediaDataChangeNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') int? mediaId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'reason') String? reason, + @JsonKey(name: 'media') MediaDto? media}); + + @override + $MediaDtoCopyWith<$Res>? get media; +} + +/// @nodoc +class __$$_MediaDataChangeNotificationDtoCopyWithImpl<$Res> + extends _$MediaDataChangeNotificationDtoCopyWithImpl<$Res, + _$_MediaDataChangeNotificationDto> + implements _$$_MediaDataChangeNotificationDtoCopyWith<$Res> { + __$$_MediaDataChangeNotificationDtoCopyWithImpl( + _$_MediaDataChangeNotificationDto _value, + $Res Function(_$_MediaDataChangeNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? mediaId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? reason = freezed, + Object? media = freezed, + }) { + return _then(_$_MediaDataChangeNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + mediaId: freezed == mediaId + ? _value.mediaId + : mediaId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + reason: freezed == reason + ? _value.reason + : reason // ignore: cast_nullable_to_non_nullable + as String?, + media: freezed == media + ? _value.media + : media // ignore: cast_nullable_to_non_nullable + as MediaDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_MediaDataChangeNotificationDto + implements _MediaDataChangeNotificationDto { + _$_MediaDataChangeNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'mediaId') this.mediaId, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'reason') this.reason, + @JsonKey(name: 'media') this.media}) + : _contexts = contexts; + + factory _$_MediaDataChangeNotificationDto.fromJson( + Map json) => + _$$_MediaDataChangeNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'mediaId') + final int? mediaId; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'reason') + final String? reason; + @override + @JsonKey(name: 'media') + final MediaDto? media; + + @override + String toString() { + return 'MediaDataChangeNotificationDto(id: $id, type: $type, mediaId: $mediaId, contexts: $contexts, createdAt: $createdAt, reason: $reason, media: $media)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_MediaDataChangeNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.mediaId, mediaId) || other.mediaId == mediaId) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.reason, reason) || other.reason == reason) && + (identical(other.media, media) || other.media == media)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, mediaId, + const DeepCollectionEquality().hash(_contexts), createdAt, reason, media); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_MediaDataChangeNotificationDtoCopyWith<_$_MediaDataChangeNotificationDto> + get copyWith => __$$_MediaDataChangeNotificationDtoCopyWithImpl< + _$_MediaDataChangeNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_MediaDataChangeNotificationDtoToJson( + this, + ); + } +} + +abstract class _MediaDataChangeNotificationDto + implements MediaDataChangeNotificationDto { + factory _MediaDataChangeNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'mediaId') final int? mediaId, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'reason') final String? reason, + @JsonKey(name: 'media') final MediaDto? media}) = + _$_MediaDataChangeNotificationDto; + + factory _MediaDataChangeNotificationDto.fromJson(Map json) = + _$_MediaDataChangeNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'mediaId') + int? get mediaId; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'reason') + String? get reason; + @override + @JsonKey(name: 'media') + MediaDto? get media; + @override + @JsonKey(ignore: true) + _$$_MediaDataChangeNotificationDtoCopyWith<_$_MediaDataChangeNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/media_data_change_notification_dto.g.dart b/lib/core/network/model/media_data_change_notification_dto.g.dart new file mode 100644 index 00000000..f485f900 --- /dev/null +++ b/lib/core/network/model/media_data_change_notification_dto.g.dart @@ -0,0 +1,50 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'media_data_change_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_MediaDataChangeNotificationDto _$$_MediaDataChangeNotificationDtoFromJson( + Map json) => + _$_MediaDataChangeNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + mediaId: json['mediaId'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + reason: json['reason'] as String?, + media: json['media'] == null + ? null + : MediaDto.fromJson(json['media'] as Map), + ); + +Map _$$_MediaDataChangeNotificationDtoToJson( + _$_MediaDataChangeNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'mediaId': instance.mediaId, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'reason': instance.reason, + 'media': instance.media, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/media_deletion_notification_dto.dart b/lib/core/network/model/media_deletion_notification_dto.dart new file mode 100644 index 00000000..9fa3c01b --- /dev/null +++ b/lib/core/network/model/media_deletion_notification_dto.dart @@ -0,0 +1,24 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'media_deletion_notification_dto.freezed.dart'; + +part 'media_deletion_notification_dto.g.dart'; + +@freezed +class MediaDeletionNotificationDto extends AniNotification + with _$MediaDeletionNotificationDto { + factory MediaDeletionNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'deletedMediaTitle') String? deletedMediaTitle, + @JsonKey(name: 'reason') String? reason, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + }) = _MediaDeletionNotificationDto; + + factory MediaDeletionNotificationDto.fromJson( + Map json) => + _$$_MediaDeletionNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/media_deletion_notification_dto.freezed.dart b/lib/core/network/model/media_deletion_notification_dto.freezed.dart new file mode 100644 index 00000000..54a928ef --- /dev/null +++ b/lib/core/network/model/media_deletion_notification_dto.freezed.dart @@ -0,0 +1,293 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'media_deletion_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +MediaDeletionNotificationDto _$MediaDeletionNotificationDtoFromJson( + Map json) { + return _MediaDeletionNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$MediaDeletionNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'deletedMediaTitle') + String? get deletedMediaTitle => throw _privateConstructorUsedError; + @JsonKey(name: 'reason') + String? get reason => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $MediaDeletionNotificationDtoCopyWith + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MediaDeletionNotificationDtoCopyWith<$Res> { + factory $MediaDeletionNotificationDtoCopyWith( + MediaDeletionNotificationDto value, + $Res Function(MediaDeletionNotificationDto) then) = + _$MediaDeletionNotificationDtoCopyWithImpl<$Res, + MediaDeletionNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'deletedMediaTitle') String? deletedMediaTitle, + @JsonKey(name: 'reason') String? reason, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt}); +} + +/// @nodoc +class _$MediaDeletionNotificationDtoCopyWithImpl<$Res, + $Val extends MediaDeletionNotificationDto> + implements $MediaDeletionNotificationDtoCopyWith<$Res> { + _$MediaDeletionNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? deletedMediaTitle = freezed, + Object? reason = freezed, + Object? contexts = null, + Object? createdAt = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + deletedMediaTitle: freezed == deletedMediaTitle + ? _value.deletedMediaTitle + : deletedMediaTitle // ignore: cast_nullable_to_non_nullable + as String?, + reason: freezed == reason + ? _value.reason + : reason // ignore: cast_nullable_to_non_nullable + as String?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_MediaDeletionNotificationDtoCopyWith<$Res> + implements $MediaDeletionNotificationDtoCopyWith<$Res> { + factory _$$_MediaDeletionNotificationDtoCopyWith( + _$_MediaDeletionNotificationDto value, + $Res Function(_$_MediaDeletionNotificationDto) then) = + __$$_MediaDeletionNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'deletedMediaTitle') String? deletedMediaTitle, + @JsonKey(name: 'reason') String? reason, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt}); +} + +/// @nodoc +class __$$_MediaDeletionNotificationDtoCopyWithImpl<$Res> + extends _$MediaDeletionNotificationDtoCopyWithImpl<$Res, + _$_MediaDeletionNotificationDto> + implements _$$_MediaDeletionNotificationDtoCopyWith<$Res> { + __$$_MediaDeletionNotificationDtoCopyWithImpl( + _$_MediaDeletionNotificationDto _value, + $Res Function(_$_MediaDeletionNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? deletedMediaTitle = freezed, + Object? reason = freezed, + Object? contexts = null, + Object? createdAt = freezed, + }) { + return _then(_$_MediaDeletionNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + deletedMediaTitle: freezed == deletedMediaTitle + ? _value.deletedMediaTitle + : deletedMediaTitle // ignore: cast_nullable_to_non_nullable + as String?, + reason: freezed == reason + ? _value.reason + : reason // ignore: cast_nullable_to_non_nullable + as String?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_MediaDeletionNotificationDto implements _MediaDeletionNotificationDto { + _$_MediaDeletionNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'deletedMediaTitle') this.deletedMediaTitle, + @JsonKey(name: 'reason') this.reason, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt}) + : _contexts = contexts; + + factory _$_MediaDeletionNotificationDto.fromJson(Map json) => + _$$_MediaDeletionNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'deletedMediaTitle') + final String? deletedMediaTitle; + @override + @JsonKey(name: 'reason') + final String? reason; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + + @override + String toString() { + return 'MediaDeletionNotificationDto(id: $id, type: $type, deletedMediaTitle: $deletedMediaTitle, reason: $reason, contexts: $contexts, createdAt: $createdAt)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_MediaDeletionNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.deletedMediaTitle, deletedMediaTitle) || + other.deletedMediaTitle == deletedMediaTitle) && + (identical(other.reason, reason) || other.reason == reason) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, deletedMediaTitle, + reason, const DeepCollectionEquality().hash(_contexts), createdAt); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_MediaDeletionNotificationDtoCopyWith<_$_MediaDeletionNotificationDto> + get copyWith => __$$_MediaDeletionNotificationDtoCopyWithImpl< + _$_MediaDeletionNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_MediaDeletionNotificationDtoToJson( + this, + ); + } +} + +abstract class _MediaDeletionNotificationDto + implements MediaDeletionNotificationDto { + factory _MediaDeletionNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'deletedMediaTitle') final String? deletedMediaTitle, + @JsonKey(name: 'reason') final String? reason, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt}) = + _$_MediaDeletionNotificationDto; + + factory _MediaDeletionNotificationDto.fromJson(Map json) = + _$_MediaDeletionNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'deletedMediaTitle') + String? get deletedMediaTitle; + @override + @JsonKey(name: 'reason') + String? get reason; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(ignore: true) + _$$_MediaDeletionNotificationDtoCopyWith<_$_MediaDeletionNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/media_deletion_notification_dto.g.dart b/lib/core/network/model/media_deletion_notification_dto.g.dart new file mode 100644 index 00000000..196fedca --- /dev/null +++ b/lib/core/network/model/media_deletion_notification_dto.g.dart @@ -0,0 +1,46 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'media_deletion_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_MediaDeletionNotificationDto _$$_MediaDeletionNotificationDtoFromJson( + Map json) => + _$_MediaDeletionNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + deletedMediaTitle: json['deletedMediaTitle'] as String?, + reason: json['reason'] as String?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + ); + +Map _$$_MediaDeletionNotificationDtoToJson( + _$_MediaDeletionNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'deletedMediaTitle': instance.deletedMediaTitle, + 'reason': instance.reason, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/media_merge_notification_dto.dart b/lib/core/network/model/media_merge_notification_dto.dart new file mode 100644 index 00000000..65eafc8a --- /dev/null +++ b/lib/core/network/model/media_merge_notification_dto.dart @@ -0,0 +1,26 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/media_dto.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'media_merge_notification_dto.freezed.dart'; + +part 'media_merge_notification_dto.g.dart'; + +@freezed +class MediaMergeNotificationDto extends AniNotification + with _$MediaMergeNotificationDto { + factory MediaMergeNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') String? mediaId, + @JsonKey(name: 'deletedMediaTitle') List? deletedMediaTitle, + @JsonKey(name: 'reason') String? reason, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'media') MediaDto? media, + }) = _MediaMergeNotificationDto; + + factory MediaMergeNotificationDto.fromJson( + Map json) => + _$$_MediaMergeNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/media_merge_notification_dto.freezed.dart b/lib/core/network/model/media_merge_notification_dto.freezed.dart new file mode 100644 index 00000000..24eca7f3 --- /dev/null +++ b/lib/core/network/model/media_merge_notification_dto.freezed.dart @@ -0,0 +1,346 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'media_merge_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +MediaMergeNotificationDto _$MediaMergeNotificationDtoFromJson( + Map json) { + return _MediaMergeNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$MediaMergeNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'mediaId') + String? get mediaId => throw _privateConstructorUsedError; + @JsonKey(name: 'deletedMediaTitle') + List? get deletedMediaTitle => throw _privateConstructorUsedError; + @JsonKey(name: 'reason') + String? get reason => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'media') + MediaDto? get media => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $MediaMergeNotificationDtoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MediaMergeNotificationDtoCopyWith<$Res> { + factory $MediaMergeNotificationDtoCopyWith(MediaMergeNotificationDto value, + $Res Function(MediaMergeNotificationDto) then) = + _$MediaMergeNotificationDtoCopyWithImpl<$Res, MediaMergeNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') String? mediaId, + @JsonKey(name: 'deletedMediaTitle') List? deletedMediaTitle, + @JsonKey(name: 'reason') String? reason, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'media') MediaDto? media}); + + $MediaDtoCopyWith<$Res>? get media; +} + +/// @nodoc +class _$MediaMergeNotificationDtoCopyWithImpl<$Res, + $Val extends MediaMergeNotificationDto> + implements $MediaMergeNotificationDtoCopyWith<$Res> { + _$MediaMergeNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? mediaId = freezed, + Object? deletedMediaTitle = freezed, + Object? reason = freezed, + Object? contexts = null, + Object? media = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + mediaId: freezed == mediaId + ? _value.mediaId + : mediaId // ignore: cast_nullable_to_non_nullable + as String?, + deletedMediaTitle: freezed == deletedMediaTitle + ? _value.deletedMediaTitle + : deletedMediaTitle // ignore: cast_nullable_to_non_nullable + as List?, + reason: freezed == reason + ? _value.reason + : reason // ignore: cast_nullable_to_non_nullable + as String?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + media: freezed == media + ? _value.media + : media // ignore: cast_nullable_to_non_nullable + as MediaDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $MediaDtoCopyWith<$Res>? get media { + if (_value.media == null) { + return null; + } + + return $MediaDtoCopyWith<$Res>(_value.media!, (value) { + return _then(_value.copyWith(media: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_MediaMergeNotificationDtoCopyWith<$Res> + implements $MediaMergeNotificationDtoCopyWith<$Res> { + factory _$$_MediaMergeNotificationDtoCopyWith( + _$_MediaMergeNotificationDto value, + $Res Function(_$_MediaMergeNotificationDto) then) = + __$$_MediaMergeNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') String? mediaId, + @JsonKey(name: 'deletedMediaTitle') List? deletedMediaTitle, + @JsonKey(name: 'reason') String? reason, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'media') MediaDto? media}); + + @override + $MediaDtoCopyWith<$Res>? get media; +} + +/// @nodoc +class __$$_MediaMergeNotificationDtoCopyWithImpl<$Res> + extends _$MediaMergeNotificationDtoCopyWithImpl<$Res, + _$_MediaMergeNotificationDto> + implements _$$_MediaMergeNotificationDtoCopyWith<$Res> { + __$$_MediaMergeNotificationDtoCopyWithImpl( + _$_MediaMergeNotificationDto _value, + $Res Function(_$_MediaMergeNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? mediaId = freezed, + Object? deletedMediaTitle = freezed, + Object? reason = freezed, + Object? contexts = null, + Object? media = freezed, + }) { + return _then(_$_MediaMergeNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + mediaId: freezed == mediaId + ? _value.mediaId + : mediaId // ignore: cast_nullable_to_non_nullable + as String?, + deletedMediaTitle: freezed == deletedMediaTitle + ? _value._deletedMediaTitle + : deletedMediaTitle // ignore: cast_nullable_to_non_nullable + as List?, + reason: freezed == reason + ? _value.reason + : reason // ignore: cast_nullable_to_non_nullable + as String?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + media: freezed == media + ? _value.media + : media // ignore: cast_nullable_to_non_nullable + as MediaDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_MediaMergeNotificationDto implements _MediaMergeNotificationDto { + _$_MediaMergeNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'mediaId') this.mediaId, + @JsonKey(name: 'deletedMediaTitle') final List? deletedMediaTitle, + @JsonKey(name: 'reason') this.reason, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'media') this.media}) + : _deletedMediaTitle = deletedMediaTitle, + _contexts = contexts; + + factory _$_MediaMergeNotificationDto.fromJson(Map json) => + _$$_MediaMergeNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'mediaId') + final String? mediaId; + final List? _deletedMediaTitle; + @override + @JsonKey(name: 'deletedMediaTitle') + List? get deletedMediaTitle { + final value = _deletedMediaTitle; + if (value == null) return null; + if (_deletedMediaTitle is EqualUnmodifiableListView) + return _deletedMediaTitle; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + @override + @JsonKey(name: 'reason') + final String? reason; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'media') + final MediaDto? media; + + @override + String toString() { + return 'MediaMergeNotificationDto(id: $id, type: $type, mediaId: $mediaId, deletedMediaTitle: $deletedMediaTitle, reason: $reason, contexts: $contexts, media: $media)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_MediaMergeNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.mediaId, mediaId) || other.mediaId == mediaId) && + const DeepCollectionEquality() + .equals(other._deletedMediaTitle, _deletedMediaTitle) && + (identical(other.reason, reason) || other.reason == reason) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.media, media) || other.media == media)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, + id, + type, + mediaId, + const DeepCollectionEquality().hash(_deletedMediaTitle), + reason, + const DeepCollectionEquality().hash(_contexts), + media); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_MediaMergeNotificationDtoCopyWith<_$_MediaMergeNotificationDto> + get copyWith => __$$_MediaMergeNotificationDtoCopyWithImpl< + _$_MediaMergeNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_MediaMergeNotificationDtoToJson( + this, + ); + } +} + +abstract class _MediaMergeNotificationDto implements MediaMergeNotificationDto { + factory _MediaMergeNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'mediaId') final String? mediaId, + @JsonKey(name: 'deletedMediaTitle') final List? deletedMediaTitle, + @JsonKey(name: 'reason') final String? reason, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'media') + final MediaDto? media}) = _$_MediaMergeNotificationDto; + + factory _MediaMergeNotificationDto.fromJson(Map json) = + _$_MediaMergeNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'mediaId') + String? get mediaId; + @override + @JsonKey(name: 'deletedMediaTitle') + List? get deletedMediaTitle; + @override + @JsonKey(name: 'reason') + String? get reason; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'media') + MediaDto? get media; + @override + @JsonKey(ignore: true) + _$$_MediaMergeNotificationDtoCopyWith<_$_MediaMergeNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/media_merge_notification_dto.g.dart b/lib/core/network/model/media_merge_notification_dto.g.dart new file mode 100644 index 00000000..2d691e01 --- /dev/null +++ b/lib/core/network/model/media_merge_notification_dto.g.dart @@ -0,0 +1,52 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'media_merge_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_MediaMergeNotificationDto _$$_MediaMergeNotificationDtoFromJson( + Map json) => + _$_MediaMergeNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + mediaId: json['mediaId'] as String?, + deletedMediaTitle: (json['deletedMediaTitle'] as List?) + ?.map((e) => e as String) + .toList(), + reason: json['reason'] as String?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + media: json['media'] == null + ? null + : MediaDto.fromJson(json['media'] as Map), + ); + +Map _$$_MediaMergeNotificationDtoToJson( + _$_MediaMergeNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'mediaId': instance.mediaId, + 'deletedMediaTitle': instance.deletedMediaTitle, + 'reason': instance.reason, + 'contexts': instance.contexts, + 'media': instance.media, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/lib/core/network/model/notification.dart b/lib/core/network/model/notification.dart new file mode 100644 index 00000000..154ab35d --- /dev/null +++ b/lib/core/network/model/notification.dart @@ -0,0 +1,42 @@ +import 'package:aniflow/core/network/model/activity_like_notification_dto.dart'; +import 'package:aniflow/core/network/model/activity_message_notification_dto.dart'; +import 'package:aniflow/core/network/model/activity_reply_like_notification_dto.dart'; +import 'package:aniflow/core/network/model/activity_reply_notification_dto.dart'; +import 'package:aniflow/core/network/model/activity_reply_subscription_notification_dto.dart'; +import 'package:aniflow/core/network/model/airing_notification_dto.dart'; +import 'package:aniflow/core/network/model/following_notification_dto.dart'; +import 'package:aniflow/core/network/model/media_data_change_notification_dto.dart'; +import 'package:aniflow/core/network/model/media_deletion_notification_dto.dart'; +import 'package:aniflow/core/network/model/media_merge_notification_dto.dart'; +import 'package:aniflow/core/network/model/related_media_addition_notification_dto.dart'; + +abstract class AniNotification { + static AniNotification mapToAniNotification(Map jsonMap) { + switch (jsonMap['__typename']) { + case 'ActivityLikeNotification': + return ActivityLikeNotificationDto.fromJson(jsonMap); + case 'AiringNotification': + return AiringNotificationDto.fromJson(jsonMap); + case 'FollowingNotification': + return FollowingNotificationDto.fromJson(jsonMap); + case 'MediaDataChangeNotification': + return MediaDataChangeNotificationDto.fromJson(jsonMap); + case 'RelatedMediaAdditionNotification': + return RelatedMediaAdditionNotificationDto.fromJson(jsonMap); + case 'MediaDeletionNotification': + return MediaDeletionNotificationDto.fromJson(jsonMap); + case 'MediaMergeNotification': + return MediaMergeNotificationDto.fromJson(jsonMap); + case 'ActivityReplyNotification': + return ActivityReplyNotificationDto.fromJson(jsonMap); + case 'ActivityReplyLikeNotification': + return ActivityReplyLikeNotificationDto.fromJson(jsonMap); + case 'ActivityReplySubscribedNotification': + return ActivityReplySubscribedNotificationDto.fromJson(jsonMap); + case 'ActivityMessageNotification': + return ActivityMessageNotificationDto.fromJson(jsonMap); + } + + throw Exception('InvalidType'); + } +} diff --git a/lib/core/network/model/related_media_addition_notification_dto.dart b/lib/core/network/model/related_media_addition_notification_dto.dart new file mode 100644 index 00000000..9e3c6d0e --- /dev/null +++ b/lib/core/network/model/related_media_addition_notification_dto.dart @@ -0,0 +1,25 @@ +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/media_dto.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'related_media_addition_notification_dto.freezed.dart'; + +part 'related_media_addition_notification_dto.g.dart'; + +@freezed +class RelatedMediaAdditionNotificationDto extends AniNotification + with _$RelatedMediaAdditionNotificationDto { + factory RelatedMediaAdditionNotificationDto({ + @Default(-1) @JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') int? mediaId, + @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'media') MediaDto? media, + }) = _RelatedMediaAdditionNotificationDto; + + factory RelatedMediaAdditionNotificationDto.fromJson( + Map json) => + _$$_RelatedMediaAdditionNotificationDtoFromJson(json); +} diff --git a/lib/core/network/model/related_media_addition_notification_dto.freezed.dart b/lib/core/network/model/related_media_addition_notification_dto.freezed.dart new file mode 100644 index 00000000..f7f82844 --- /dev/null +++ b/lib/core/network/model/related_media_addition_notification_dto.freezed.dart @@ -0,0 +1,315 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'related_media_addition_notification_dto.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +RelatedMediaAdditionNotificationDto + _$RelatedMediaAdditionNotificationDtoFromJson(Map json) { + return _RelatedMediaAdditionNotificationDto.fromJson(json); +} + +/// @nodoc +mixin _$RelatedMediaAdditionNotificationDto { + @JsonKey(name: 'id') + int get id => throw _privateConstructorUsedError; + @JsonKey(name: 'type') + NotificationType? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'mediaId') + int? get mediaId => throw _privateConstructorUsedError; + @JsonKey(name: 'contexts') + List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: 'media') + MediaDto? get media => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $RelatedMediaAdditionNotificationDtoCopyWith< + RelatedMediaAdditionNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RelatedMediaAdditionNotificationDtoCopyWith<$Res> { + factory $RelatedMediaAdditionNotificationDtoCopyWith( + RelatedMediaAdditionNotificationDto value, + $Res Function(RelatedMediaAdditionNotificationDto) then) = + _$RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res, + RelatedMediaAdditionNotificationDto>; + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') int? mediaId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'media') MediaDto? media}); + + $MediaDtoCopyWith<$Res>? get media; +} + +/// @nodoc +class _$RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res, + $Val extends RelatedMediaAdditionNotificationDto> + implements $RelatedMediaAdditionNotificationDtoCopyWith<$Res> { + _$RelatedMediaAdditionNotificationDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? mediaId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? media = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + mediaId: freezed == mediaId + ? _value.mediaId + : mediaId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value.contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + media: freezed == media + ? _value.media + : media // ignore: cast_nullable_to_non_nullable + as MediaDto?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $MediaDtoCopyWith<$Res>? get media { + if (_value.media == null) { + return null; + } + + return $MediaDtoCopyWith<$Res>(_value.media!, (value) { + return _then(_value.copyWith(media: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_RelatedMediaAdditionNotificationDtoCopyWith<$Res> + implements $RelatedMediaAdditionNotificationDtoCopyWith<$Res> { + factory _$$_RelatedMediaAdditionNotificationDtoCopyWith( + _$_RelatedMediaAdditionNotificationDto value, + $Res Function(_$_RelatedMediaAdditionNotificationDto) then) = + __$$_RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'id') int id, + @JsonKey(name: 'type') NotificationType? type, + @JsonKey(name: 'mediaId') int? mediaId, + @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'createdAt') int? createdAt, + @JsonKey(name: 'media') MediaDto? media}); + + @override + $MediaDtoCopyWith<$Res>? get media; +} + +/// @nodoc +class __$$_RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res> + extends _$RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res, + _$_RelatedMediaAdditionNotificationDto> + implements _$$_RelatedMediaAdditionNotificationDtoCopyWith<$Res> { + __$$_RelatedMediaAdditionNotificationDtoCopyWithImpl( + _$_RelatedMediaAdditionNotificationDto _value, + $Res Function(_$_RelatedMediaAdditionNotificationDto) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? type = freezed, + Object? mediaId = freezed, + Object? contexts = null, + Object? createdAt = freezed, + Object? media = freezed, + }) { + return _then(_$_RelatedMediaAdditionNotificationDto( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as NotificationType?, + mediaId: freezed == mediaId + ? _value.mediaId + : mediaId // ignore: cast_nullable_to_non_nullable + as int?, + contexts: null == contexts + ? _value._contexts + : contexts // ignore: cast_nullable_to_non_nullable + as List, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, + media: freezed == media + ? _value.media + : media // ignore: cast_nullable_to_non_nullable + as MediaDto?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_RelatedMediaAdditionNotificationDto + implements _RelatedMediaAdditionNotificationDto { + _$_RelatedMediaAdditionNotificationDto( + {@JsonKey(name: 'id') this.id = -1, + @JsonKey(name: 'type') this.type, + @JsonKey(name: 'mediaId') this.mediaId, + @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'createdAt') this.createdAt, + @JsonKey(name: 'media') this.media}) + : _contexts = contexts; + + factory _$_RelatedMediaAdditionNotificationDto.fromJson( + Map json) => + _$$_RelatedMediaAdditionNotificationDtoFromJson(json); + + @override + @JsonKey(name: 'id') + final int id; + @override + @JsonKey(name: 'type') + final NotificationType? type; + @override + @JsonKey(name: 'mediaId') + final int? mediaId; + final List _contexts; + @override + @JsonKey(name: 'contexts') + List get contexts { + if (_contexts is EqualUnmodifiableListView) return _contexts; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_contexts); + } + + @override + @JsonKey(name: 'createdAt') + final int? createdAt; + @override + @JsonKey(name: 'media') + final MediaDto? media; + + @override + String toString() { + return 'RelatedMediaAdditionNotificationDto(id: $id, type: $type, mediaId: $mediaId, contexts: $contexts, createdAt: $createdAt, media: $media)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_RelatedMediaAdditionNotificationDto && + (identical(other.id, id) || other.id == id) && + (identical(other.type, type) || other.type == type) && + (identical(other.mediaId, mediaId) || other.mediaId == mediaId) && + const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.media, media) || other.media == media)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, type, mediaId, + const DeepCollectionEquality().hash(_contexts), createdAt, media); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_RelatedMediaAdditionNotificationDtoCopyWith< + _$_RelatedMediaAdditionNotificationDto> + get copyWith => __$$_RelatedMediaAdditionNotificationDtoCopyWithImpl< + _$_RelatedMediaAdditionNotificationDto>(this, _$identity); + + @override + Map toJson() { + return _$$_RelatedMediaAdditionNotificationDtoToJson( + this, + ); + } +} + +abstract class _RelatedMediaAdditionNotificationDto + implements RelatedMediaAdditionNotificationDto { + factory _RelatedMediaAdditionNotificationDto( + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'mediaId') final int? mediaId, + @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'media') final MediaDto? media}) = + _$_RelatedMediaAdditionNotificationDto; + + factory _RelatedMediaAdditionNotificationDto.fromJson( + Map json) = + _$_RelatedMediaAdditionNotificationDto.fromJson; + + @override + @JsonKey(name: 'id') + int get id; + @override + @JsonKey(name: 'type') + NotificationType? get type; + @override + @JsonKey(name: 'mediaId') + int? get mediaId; + @override + @JsonKey(name: 'contexts') + List get contexts; + @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override + @JsonKey(name: 'media') + MediaDto? get media; + @override + @JsonKey(ignore: true) + _$$_RelatedMediaAdditionNotificationDtoCopyWith< + _$_RelatedMediaAdditionNotificationDto> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/core/network/model/related_media_addition_notification_dto.g.dart b/lib/core/network/model/related_media_addition_notification_dto.g.dart new file mode 100644 index 00000000..f8c349e7 --- /dev/null +++ b/lib/core/network/model/related_media_addition_notification_dto.g.dart @@ -0,0 +1,49 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'related_media_addition_notification_dto.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_RelatedMediaAdditionNotificationDto + _$$_RelatedMediaAdditionNotificationDtoFromJson( + Map json) => + _$_RelatedMediaAdditionNotificationDto( + id: json['id'] as int? ?? -1, + type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), + mediaId: json['mediaId'] as int?, + contexts: (json['contexts'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + createdAt: json['createdAt'] as int?, + media: json['media'] == null + ? null + : MediaDto.fromJson(json['media'] as Map), + ); + +Map _$$_RelatedMediaAdditionNotificationDtoToJson( + _$_RelatedMediaAdditionNotificationDto instance) => + { + 'id': instance.id, + 'type': _$NotificationTypeEnumMap[instance.type], + 'mediaId': instance.mediaId, + 'contexts': instance.contexts, + 'createdAt': instance.createdAt, + 'media': instance.media, + }; + +const _$NotificationTypeEnumMap = { + NotificationType.airing: 'AIRING', + NotificationType.activityLike: 'ACTIVITY_LIKE', + NotificationType.activityReply: 'ACTIVITY_REPLY', + NotificationType.activityMention: 'ACTIVITY_MENTION', + NotificationType.activityReplyLike: 'ACTIVITY_REPLY_LIKE', + NotificationType.activityMessage: 'ACTIVITY_MESSAGE', + NotificationType.following: 'FOLLOWING', + NotificationType.mediaDataChange: 'MEDIA_DATA_CHANGE', + NotificationType.relatedMediaAddition: 'RELATED_MEDIA_ADDITION', + NotificationType.mediaDeletion: 'MEDIA_DELETION', + NotificationType.mediaMerge: 'MEDIA_MERGE', +}; diff --git a/test/core/data/repository/media_list_repository_test.dart b/test/core/data/repository/media_list_repository_test.dart index 3a9e1f3c..9ac6a771 100644 --- a/test/core/data/repository/media_list_repository_test.dart +++ b/test/core/data/repository/media_list_repository_test.dart @@ -28,7 +28,9 @@ void main() { repository = MediaListRepositoryImpl(); isUnitTest = true; - }); + testToken = + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2In0.eyJhdWQiOiIxNDQwOSIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2IiwiaWF0IjoxNjk4NTY2MzU0LCJuYmYiOjE2OTg1NjYzNTQsImV4cCI6MTczMDE4ODc1NCwic3ViIjoiNjM3ODM5MyIsInNjb3BlcyI6W119.cjnTU0bSGzQnjxbAy-wkzRqiI5r2zAI_XmOX8teX0MZuceDj7qiBQQ6An-p6Ue30LYSI7V5Tw4ocChZn1bRsg6sRFCPAmE8eBbV4XBGjOhlAb9ciqMgTmVeND6bz0uWO1lr3D0fLfmQKPchrZAwb1-aVDhMkI3Ba4bC1VzxfbGPpw3IzbXjbAg1kFStENCvn3fTXTX53ndNGuPlbS6l8tfOlgYSK7dm0le4JrJAEIlm_Om4WYb6ij42sI0WK1pJY5Lzpar-K0KxaubN9poNKXa81PX65DABzywHXrEi8_D7_O_DkIVsKPjU5dAhXUEhmukFkkLDbRgn7np0i8A-wAfTrVq3tLPvUkDoqdyH105mmwXR_nwO3ZqKJtCnolUok289my02qP1yA0uSmq0nJ51ikI3CEnk_H-jCz5OcVAUhN2qNRb3fhx0fNekBBfaUuJqbHr7usgaNAWRu_vQX0LGs7daClKl1k5FBtdrsJGwSkbY13ghKH42pmBVlY-I9oS8ocznuMsVtyo7QfY6oaMv9kZBuelMto7pM28z61S__qo2jsKzr_2I5uAH3avjUY28G8M3r0r3nkkXqMu_BPn3T95LOLTCghtwx2cE4LARBpZ_1t9rYFUzDb05HeARrqWzbhOwbm9c0N5RM8guq6O1q8kAVZFNLTLjK25ycBuiw'; + }); tearDown(() async { await animeDatabase.aniflowDB.delete(Tables.mediaTable); diff --git a/test/core/network/auth_data_source_test.dart b/test/core/network/auth_data_source_test.dart index d86ca0d8..c60333ea 100644 --- a/test/core/network/auth_data_source_test.dart +++ b/test/core/network/auth_data_source_test.dart @@ -1,6 +1,10 @@ +// ignore_for_file: lines_longer_than_80_chars + import 'package:aniflow/core/common/util/global_static_constants.dart'; import 'package:aniflow/core/data/media_list_repository.dart'; +import 'package:aniflow/core/data/model/notification_type.dart'; import 'package:aniflow/core/network/api/ani_save_media_list_mution_graphql.dart'; +import 'package:aniflow/core/network/api/notification_query_graphql.dart'; import 'package:aniflow/core/network/auth_data_source.dart'; import 'package:aniflow/core/network/util/http_status_util.dart'; import 'package:aniflow/core/shared_preference/aniflow_preferences.dart'; @@ -8,6 +12,11 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; void main() { + setUp(() async { + isUnitTest = true; + testToken = + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2In0.eyJhdWQiOiIxNDQwOSIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2IiwiaWF0IjoxNjk4NTY2MzU0LCJuYmYiOjE2OTg1NjYzNTQsImV4cCI6MTczMDE4ODc1NCwic3ViIjoiNjM3ODM5MyIsInNjb3BlcyI6W119.cjnTU0bSGzQnjxbAy-wkzRqiI5r2zAI_XmOX8teX0MZuceDj7qiBQQ6An-p6Ue30LYSI7V5Tw4ocChZn1bRsg6sRFCPAmE8eBbV4XBGjOhlAb9ciqMgTmVeND6bz0uWO1lr3D0fLfmQKPchrZAwb1-aVDhMkI3Ba4bC1VzxfbGPpw3IzbXjbAg1kFStENCvn3fTXTX53ndNGuPlbS6l8tfOlgYSK7dm0le4JrJAEIlm_Om4WYb6ij42sI0WK1pJY5Lzpar-K0KxaubN9poNKXa81PX65DABzywHXrEi8_D7_O_DkIVsKPjU5dAhXUEhmukFkkLDbRgn7np0i8A-wAfTrVq3tLPvUkDoqdyH105mmwXR_nwO3ZqKJtCnolUok289my02qP1yA0uSmq0nJ51ikI3CEnk_H-jCz5OcVAUhN2qNRb3fhx0fNekBBfaUuJqbHr7usgaNAWRu_vQX0LGs7daClKl1k5FBtdrsJGwSkbY13ghKH42pmBVlY-I9oS8ocznuMsVtyo7QfY6oaMv9kZBuelMto7pM28z61S__qo2jsKzr_2I5uAH3avjUY28G8M3r0r3nkkXqMu_BPn3T95LOLTCghtwx2cE4LARBpZ_1t9rYFUzDb05HeARrqWzbhOwbm9c0N5RM8guq6O1q8kAVZFNLTLjK25ycBuiw'; + }); group('auth_data_source_test', () { late AuthDataSource authDataSource; setUp(() async { @@ -30,5 +39,10 @@ void main() { // catch. } }); + + test('notification_query', () async { + await authDataSource.getNotifications(NotificationQueryParam( + page: 1, perPage: 2, type: [NotificationType.activityMessage])); + }); }); } diff --git a/test/core/network/model/airing_notification_dto_test.dart b/test/core/network/model/airing_notification_dto_test.dart new file mode 100644 index 00000000..7fe22e5e --- /dev/null +++ b/test/core/network/model/airing_notification_dto_test.dart @@ -0,0 +1,40 @@ +// ignore_for_file: lines_longer_than_80_chars + +import 'package:aniflow/core/network/model/activity_like_notification_dto.dart'; +import 'package:aniflow/core/network/model/airing_notification_dto.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('notification_test', () { + final airingNotification = { + "__typename": "AiringNotification", + "id": 464758426, + "type": "AIRING", + "animeId": 151970, + "episode": 5, + "contexts": ["Episode ", " of ", " aired."], + "createdAt": 1698566410, + "media": {"id": 151970} + }; + + final likeNotification = { + "__typename": "ActivityLikeNotification", + "id": 457867547, + "userId": 5338139, + "type": "ACTIVITY_LIKE", + "context": " liked your activity.", + "createdAt": 1696629541, + "user": {"id": 5338139} + }; + test('airing_notification', () async { + AiringNotificationDto.fromJson(airingNotification); + }); + test('like_notification', () async { + ActivityLikeNotificationDto.fromJson(likeNotification); + }); + test('resolve_type', () async { + AniNotification.mapToAniNotification(likeNotification); + }); + }); +} From abc155af7388595154cf44971a1a898af105d53c Mon Sep 17 00:00:00 2001 From: andannn Date: Mon, 6 Nov 2023 22:43:33 +0900 Subject: [PATCH 02/10] add cancel status --- lib/app/local/util/string_resource_util.dart | 4 ++++ lib/core/common/model/media_status.dart | 22 ++++++++++++++----- .../media_list_item_model_extension.dart | 2 ++ lib/core/database/model/media_entity.g.dart | 4 +++- lib/core/network/model/media_dto.g.dart | 4 +++- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/app/local/util/string_resource_util.dart b/lib/app/local/util/string_resource_util.dart index 4e445825..379984c5 100644 --- a/lib/app/local/util/string_resource_util.dart +++ b/lib/app/local/util/string_resource_util.dart @@ -51,6 +51,10 @@ extension AnimeStatusEx on MediaStatus { return AFLocalizations.of(context).animeFinished; case MediaStatus.notYetReleased: return AFLocalizations.of(context).animeNotYetReleased; + case MediaStatus.cancelled: + return 'Canceled'; + case MediaStatus.hiatus: + return 'Hiatus'; } } } diff --git a/lib/core/common/model/media_status.dart b/lib/core/common/model/media_status.dart index 95625075..222e2092 100644 --- a/lib/core/common/model/media_status.dart +++ b/lib/core/common/model/media_status.dart @@ -1,17 +1,29 @@ - import 'package:freezed_annotation/freezed_annotation.dart'; @JsonEnum() enum MediaStatus { - @JsonValue('RELEASING') - releasing('RELEASING'), + /// Has completed and is no longer being released @JsonValue('FINISHED') finished('FINISHED'), + + /// Currently releasing + @JsonValue('RELEASING') + releasing('RELEASING'), + + /// To be released at a later date @JsonValue('NOT_YET_RELEASED') - notYetReleased('NOT_YET_RELEASED'); + notYetReleased('NOT_YET_RELEASED'), + + /// Ended before the work could be finished + @JsonValue('CANCELLED') + cancelled('CANCELLED'), + + // ignore: lines_longer_than_80_chars + /// Version 2 only. Is currently paused from releasing and will resume at a later date. + @JsonValue('HIATUS') + hiatus('HIATUS'); final String sqlTypeString; const MediaStatus(this.sqlTypeString); } - diff --git a/lib/core/data/model/extension/media_list_item_model_extension.dart b/lib/core/data/model/extension/media_list_item_model_extension.dart index 5696a989..23020c5e 100644 --- a/lib/core/data/model/extension/media_list_item_model_extension.dart +++ b/lib/core/data/model/extension/media_list_item_model_extension.dart @@ -13,6 +13,8 @@ extension MediaListItemModelEx on MediaListItemModel { final status = animeModel!.status; switch (status) { + case MediaStatus.cancelled: + case MediaStatus.hiatus: case MediaStatus.releasing: final nextAiringEpisode = animeModel!.nextAiringEpisode; if (nextAiringEpisode == null) { diff --git a/lib/core/database/model/media_entity.g.dart b/lib/core/database/model/media_entity.g.dart index a49f99e8..07f18f57 100644 --- a/lib/core/database/model/media_entity.g.dart +++ b/lib/core/database/model/media_entity.g.dart @@ -83,7 +83,9 @@ const _$AnimeSeasonEnumMap = { }; const _$MediaStatusEnumMap = { - MediaStatus.releasing: 'RELEASING', MediaStatus.finished: 'FINISHED', + MediaStatus.releasing: 'RELEASING', MediaStatus.notYetReleased: 'NOT_YET_RELEASED', + MediaStatus.cancelled: 'CANCELLED', + MediaStatus.hiatus: 'HIATUS', }; diff --git a/lib/core/network/model/media_dto.g.dart b/lib/core/network/model/media_dto.g.dart index d3be3a62..0a78f691 100644 --- a/lib/core/network/model/media_dto.g.dart +++ b/lib/core/network/model/media_dto.g.dart @@ -86,9 +86,11 @@ Map _$$_MediaDtoToJson(_$_MediaDto instance) => }; const _$MediaStatusEnumMap = { - MediaStatus.releasing: 'RELEASING', MediaStatus.finished: 'FINISHED', + MediaStatus.releasing: 'RELEASING', MediaStatus.notYetReleased: 'NOT_YET_RELEASED', + MediaStatus.cancelled: 'CANCELLED', + MediaStatus.hiatus: 'HIATUS', }; const _$AnimeSourceEnumMap = { From 357c446b97cba84dfc5664d653ff90e6d3114429 Mon Sep 17 00:00:00 2001 From: andannn Date: Mon, 6 Nov 2023 23:03:34 +0900 Subject: [PATCH 03/10] only show home and track page when user logout --- lib/app/app.dart | 78 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/lib/app/app.dart b/lib/app/app.dart index e065723c..bbc2083f 100644 --- a/lib/app/app.dart +++ b/lib/app/app.dart @@ -108,12 +108,28 @@ class _AnimeTrackerAppScaffoldState extends State { var currentNavigation = TopLevelNavigation.discover; var needHideNavigationBar = false; var showFloatingButton = true; - late SettingsRepository userDataRepository = SettingsRepositoryImpl(); + final userDataRepository = SettingsRepositoryImpl(); + final authRepository = AuthRepositoryImpl(); late StreamSubscription _mediaTypeSub; + late StreamSubscription _authSub; + MediaType _mediaType = MediaType.anime; + bool? _isLogIn; bool get isAnime => _mediaType == MediaType.anime; + List get _topLevelNavigationList => _isLogIn == true + ? [ + TopLevelNavigation.discover, + TopLevelNavigation.track, + TopLevelNavigation.social, + TopLevelNavigation.profile, + ] + : [ + TopLevelNavigation.discover, + TopLevelNavigation.track, + ]; + @override void initState() { super.initState(); @@ -126,12 +142,18 @@ class _AnimeTrackerAppScaffoldState extends State { }); }); _mediaTypeSub = userDataRepository.getMediaTypeStream().distinct().listen( - (mediaType) { + (mediaType) { setState(() { _mediaType = mediaType; }); }, ); + _authSub = + authRepository.getAuthedUserStream().distinct().listen((userData) { + setState(() { + _isLogIn = userData != null; + }); + }); } @override @@ -140,41 +162,46 @@ class _AnimeTrackerAppScaffoldState extends State { animeTrackerRouterDelegate.dispose(); _mediaTypeSub.cancel(); + _authSub.cancel(); } @override Widget build(BuildContext context) { globalContext = context; + + if (_isLogIn == null) { + /// user login state is unknown. + return const SizedBox(); + } + return MultiBlocProvider( providers: [ BlocProvider( - create: (context) => - DiscoverBloc( - settingsRepository: context.read(), - mediaRepository: context.read(), - authRepository: context.read(), - animeTrackListRepository: context.read(), - ), + create: (context) => DiscoverBloc( + settingsRepository: context.read(), + mediaRepository: context.read(), + authRepository: context.read(), + animeTrackListRepository: context.read(), + ), ), BlocProvider( - create: (context) => - TrackBloc( - settingsRepository: context.read(), - mediaListRepository: context.read(), - authRepository: context.read(), - ), + create: (context) => TrackBloc( + settingsRepository: context.read(), + mediaListRepository: context.read(), + authRepository: context.read(), + ), ), ], child: Scaffold( body: Router( routerDelegate: animeTrackerRouterDelegate, backButtonDispatcher: RootBackButtonDispatcher()), - floatingActionButton: showFloatingButton - ? _buildTopFloatingActionButton() - : null, + floatingActionButton: + showFloatingButton ? _buildTopFloatingActionButton() : null, bottomNavigationBar: VerticalScaleSwitcher( visible: !needHideNavigationBar, child: _animeTrackerNavigationBar( + navigationList: _topLevelNavigationList, selected: currentNavigation, onNavigateToDestination: (navigation) async { animeTrackerRouterDelegate.navigateToTopLevelPage(navigation); @@ -185,13 +212,14 @@ class _AnimeTrackerAppScaffoldState extends State { ); } - Widget _animeTrackerNavigationBar({required TopLevelNavigation selected, - required Function(TopLevelNavigation) onNavigateToDestination}) { + Widget _animeTrackerNavigationBar( + {required List navigationList, + required TopLevelNavigation selected, + required Function(TopLevelNavigation) onNavigateToDestination}) { final currentIndex = TopLevelNavigation.values.indexOf(selected); return NavigationBar( - destinations: TopLevelNavigation.values - .map((navigation) => - navigation.toBottomNavigationBarItem( + destinations: navigationList + .map((navigation) => navigation.toBottomNavigationBarItem( isSelected: navigation == selected)) .toList(), onDestinationSelected: (index) { @@ -214,9 +242,7 @@ class _AnimeTrackerAppScaffoldState extends State { } }, isExtended: true, - icon: isAnime - ? const Icon(Icons.palette_rounded) - : const Icon(Icons.map), + icon: isAnime ? const Icon(Icons.palette_rounded) : const Icon(Icons.map), label: Text(isAnime ? 'Anime' : 'Manga'), ); } From 7a82819ff8e1f727945835bbff22b8d184a7bc49 Mon Sep 17 00:00:00 2001 From: andannn Date: Tue, 7 Nov 2023 20:42:36 +0900 Subject: [PATCH 04/10] make first page item has no space in detail media page --- .../common/util/global_static_constants.dart | 5 +++ lib/feature/detail_media/detail_media.dart | 45 +++++++++++++------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/lib/core/common/util/global_static_constants.dart b/lib/core/common/util/global_static_constants.dart index 6f13b2f3..03654a86 100644 --- a/lib/core/common/util/global_static_constants.dart +++ b/lib/core/common/util/global_static_constants.dart @@ -10,6 +10,11 @@ mixin Config { static const int profilePageDefaultPerPageCount = 6; static const int activityPageDefaultPerPageCount = 50; + + /// Detail page consts. + static const double detailPagePreviewItemHeight = 133.0; + static const int characterColumnCount = 3; + static const int staffColumnCount = 2; } /// Only for test diff --git a/lib/feature/detail_media/detail_media.dart b/lib/feature/detail_media/detail_media.dart index 30650f42..1b8d6809 100644 --- a/lib/feature/detail_media/detail_media.dart +++ b/lib/feature/detail_media/detail_media.dart @@ -173,7 +173,7 @@ class _DetailAnimePageContent extends StatelessWidget { model.externalLinks, ), ), - const SliverPadding(padding: EdgeInsets.only(top: 16)), + const SliverPadding(padding: EdgeInsets.symmetric(vertical: 16)), ], ), ); @@ -279,10 +279,12 @@ class _DetailAnimePageContent extends StatelessWidget { AFLocalizations.of(context).animeDescription, style: Theme.of(context).textTheme.titleMedium, ), - description != null ? Padding( - padding: const EdgeInsets.all(8.0), - child: HtmlWidget(description), - ) : const SizedBox(), + description != null + ? Padding( + padding: const EdgeInsets.all(8.0), + child: HtmlWidget(description), + ) + : const SizedBox(), ], ), ), @@ -291,6 +293,11 @@ class _DetailAnimePageContent extends StatelessWidget { Widget _buildCharacterSection( BuildContext context, List models) { + final canFillPage = models.length >= Config.characterColumnCount; + const itemHeight = Config.detailPagePreviewItemHeight; + final pageHeight = canFillPage + ? Config.characterColumnCount * itemHeight + : models.length * itemHeight; return VerticalScaleSwitcher( visible: models.isNotEmpty, child: Column( @@ -317,15 +324,16 @@ class _DetailAnimePageContent extends StatelessWidget { ), const SizedBox(height: 8), SizedBox( - height: 400, + height: pageHeight, child: PageView.builder( + controller: PageController(viewportFraction: 0.93), itemCount: (models.length / 3).ceil(), itemBuilder: (BuildContext context, int index) { return Column( mainAxisSize: MainAxisSize.min, children: _createColumItemsPage(context, models: models, - pageCount: 3, + pageItemCount: Config.characterColumnCount, pageIndex: index, onBuildWidget: _buildCharacterAndVoiceActorItem), ); @@ -353,6 +361,11 @@ class _DetailAnimePageContent extends StatelessWidget { Widget _buildStaffsSection( BuildContext context, List staffs) { + final canFillPage = staffs.length >= Config.staffColumnCount; + const itemHeight = Config.detailPagePreviewItemHeight; + final pageHeight = canFillPage + ? Config.staffColumnCount * itemHeight + : staffs.length * itemHeight; return VerticalScaleSwitcher( visible: staffs.isNotEmpty, child: Column( @@ -379,11 +392,12 @@ class _DetailAnimePageContent extends StatelessWidget { ), const SizedBox(height: 8), SizedBox( - height: 266, + height: pageHeight, child: PageView.builder( itemCount: (staffs.length).ceil(), itemBuilder: (BuildContext context, int index) { return PageView.builder( + controller: PageController(viewportFraction: 0.93), itemCount: (staffs.length / 2).ceil(), itemBuilder: (BuildContext context, int index) { return Column( @@ -391,7 +405,7 @@ class _DetailAnimePageContent extends StatelessWidget { children: _createColumItemsPage( context, models: staffs, - pageCount: 2, + pageItemCount: Config.staffColumnCount, pageIndex: index, onBuildWidget: _buildStaffItem, ), @@ -545,22 +559,27 @@ class _DetailAnimePageContent extends StatelessWidget { List _createColumItemsPage( BuildContext context, { required List models, - required int pageCount, + required int pageItemCount, required int pageIndex, required Widget Function(BuildContext, T model) onBuildWidget, }) { final modelList = models.sublist( - pageIndex * pageCount, - min((pageIndex + 1) * pageCount, models.length), + pageIndex * pageItemCount, + min((pageIndex + 1) * pageItemCount, models.length), ); final widgets = []; widgets.addAll( modelList.map((model) => onBuildWidget(context, model)), ); + if (pageIndex == 0) { + /// first page have no need to add space. + return widgets; + } + // ignore: lines_longer_than_80_chars /// when column count is less than pageCount, add empty SizeBox to take the space. - while (widgets.length < pageCount) { + while (widgets.length < pageItemCount) { widgets.add(const Expanded(flex: 1, child: SizedBox())); } return widgets; From 04228dc8ff8a2ece01535597883bee39bd10554a Mon Sep 17 00:00:00 2001 From: andannn Date: Tue, 7 Nov 2023 21:35:55 +0900 Subject: [PATCH 05/10] add login function in track page --- lib/app/app.dart | 6 ++ lib/feature/auth/auth_dialog.dart | 8 +-- lib/feature/media_track/media_track.dart | 78 ++++++++++++++---------- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/lib/app/app.dart b/lib/app/app.dart index bbc2083f..77f11436 100644 --- a/lib/app/app.dart +++ b/lib/app/app.dart @@ -10,6 +10,7 @@ import 'package:aniflow/core/data/media_list_repository.dart'; import 'package:aniflow/core/data/settings_repository.dart'; import 'package:aniflow/core/design_system/theme/colors.dart'; import 'package:aniflow/core/design_system/widget/vertical_animated_scale_switcher.dart'; +import 'package:aniflow/feature/auth/bloc/auth_bloc.dart'; import 'package:aniflow/feature/discover/bloc/discover_bloc.dart'; import 'package:aniflow/feature/media_track/bloc/track_bloc.dart'; import 'package:dynamic_color/dynamic_color.dart'; @@ -191,6 +192,11 @@ class _AnimeTrackerAppScaffoldState extends State { authRepository: context.read(), ), ), + BlocProvider( + create: (context) => AuthBloc( + authRepository: context.read(), + ), + ), ], child: Scaffold( body: Router( diff --git a/lib/feature/auth/auth_dialog.dart b/lib/feature/auth/auth_dialog.dart index e69a6d30..e74f9177 100644 --- a/lib/feature/auth/auth_dialog.dart +++ b/lib/feature/auth/auth_dialog.dart @@ -22,12 +22,8 @@ class AuthDialog extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => - AuthBloc(authRepository: context.read()), - child: const AlertDialog( - content: _AuthDialogContent(), - ), + return const AlertDialog( + content: _AuthDialogContent(), ); } } diff --git a/lib/feature/media_track/media_track.dart b/lib/feature/media_track/media_track.dart index 8424de9a..55481f9f 100644 --- a/lib/feature/media_track/media_track.dart +++ b/lib/feature/media_track/media_track.dart @@ -4,6 +4,7 @@ import 'package:aniflow/core/data/model/anime_list_item_model.dart'; import 'package:aniflow/core/design_system/widget/af_toogle_button.dart'; import 'package:aniflow/core/design_system/widget/loading_indicator.dart'; import 'package:aniflow/core/design_system/widget/media_list_item.dart'; +import 'package:aniflow/feature/auth/bloc/auth_bloc.dart'; import 'package:aniflow/feature/media_track/bloc/track_bloc.dart'; import 'package:aniflow/feature/media_track/bloc/track_ui_state.dart'; import 'package:aniflow/feature/media_track/bloc/user_anime_list_load_state.dart'; @@ -39,17 +40,17 @@ class _AnimeTrackPageContent extends StatelessWidget { @override Widget build(BuildContext context) { return BlocBuilder(builder: (context, state) { - // final isLoading = state.isLoading; - - return RefreshIndicator( - onRefresh: () async { - return context.read().syncUserAnimeList(); - }, - child: CustomScrollView( - slivers: [ - _buildAppBar(context, state), - ..._buildTrackSectionContents(context, state), - ], + return Scaffold( + appBar: _buildAppBar(context, state), + body: RefreshIndicator( + onRefresh: () async { + return context.read().syncUserAnimeList(); + }, + child: CustomScrollView( + slivers: [ + ..._buildTrackSectionContents(context, state), + ], + ), ), ); }); @@ -60,12 +61,10 @@ class _AnimeTrackPageContent extends StatelessWidget { final animeLoadState = state.animeLoadState; if (animeLoadState is MediaStateNoUser) { return [ - _buildNoUserHint(), + _buildNoUserHint(context), ]; } else if (animeLoadState is MediaStateInitState) { - return [ - _buildInitialDummyView(), - ]; + return []; } else { final animeList = (animeLoadState as MediaStateLoaded).followingMediaList; @@ -88,9 +87,14 @@ class _AnimeTrackPageContent extends StatelessWidget { } final showReleasedOnly = state.showReleasedOnly; + + final isAnime = state.currentMediaType == MediaType.anime; return [ - SliverToBoxAdapter( - child: _buildFilterBarSection(context, showReleasedOnly), + SliverVisibility( + visible: isAnime, + sliver: SliverToBoxAdapter( + child: _buildFilterBarSection(context, showReleasedOnly), + ), ), SliverList( delegate: SliverChildBuilderDelegate( @@ -140,12 +144,13 @@ class _AnimeTrackPageContent extends StatelessWidget { ); } - Widget _buildAppBar(BuildContext context, TrackUiState state) { + PreferredSizeWidget _buildAppBar(BuildContext context, TrackUiState state) { final isAnime = state.currentMediaType == MediaType.anime; - return SliverAppBar( + final isLoading = state.isLoading; + return AppBar( title: const Text('Track'), actions: [ - LoadingIndicator(isLoading: state.isLoading), + LoadingIndicator(isLoading: isLoading), const SizedBox(width: 10), isAnime ? Padding( @@ -159,23 +164,32 @@ class _AnimeTrackPageContent extends StatelessWidget { ) : const SizedBox(), ], - pinned: true, automaticallyImplyLeading: false, ); } - Widget _buildNoUserHint() { - return const SliverToBoxAdapter( + Widget _buildNoUserHint(BuildContext context) { + return SliverFillRemaining( child: Center( - child: Text('No user'), - ), - ); - } - - Widget _buildInitialDummyView() { - return const SliverToBoxAdapter( - child: Center( - child: Text('Dummy'), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + 'Track your favorite anime or manga', + style: Theme.of(context).textTheme.headlineSmall, + softWrap: true, + textAlign: TextAlign.center, + ), + const SizedBox(height: 16), + FilledButton.tonal( + onPressed: () { + context.read().add(OnLoginButtonTapped()); + }, + child: const Text('Join now'), + ) + ], + ), ), ); } From cf5ea564616db9c02f67040b8331e68055dc9b9c Mon Sep 17 00:00:00 2001 From: andannn Date: Tue, 7 Nov 2023 22:55:36 +0900 Subject: [PATCH 06/10] add notification model --- lib/core/data/auth_repository.dart | 2 +- lib/core/data/model/activity_model.dart | 4 +- lib/core/data/model/notification_model.dart | 168 ++++++++++++++++++++ lib/core/data/model/user_model.dart | 8 +- lib/core/data/user_info_repository.dart | 2 +- 5 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 lib/core/data/model/notification_model.dart diff --git a/lib/core/data/auth_repository.dart b/lib/core/data/auth_repository.dart index 5fca293b..3f4fee41 100644 --- a/lib/core/data/auth_repository.dart +++ b/lib/core/data/auth_repository.dart @@ -96,7 +96,7 @@ class AuthRepositoryImpl implements AuthRepository { return null; } else { final userEntity = await userDataDao.getUserData(userId); - return UserModel.fromDatabaseModel(userEntity); + return UserModel.fromEntity(userEntity); } }); } diff --git a/lib/core/data/model/activity_model.dart b/lib/core/data/model/activity_model.dart index 300ef85d..d7555ff0 100644 --- a/lib/core/data/model/activity_model.dart +++ b/lib/core/data/model/activity_model.dart @@ -57,7 +57,7 @@ sealed class ActivityModel extends Equatable { likeCount: activity.likeCount ?? 0, isPinned: activity.isPinned.toBoolean(), createdAt: activity.createdAt!, - user: UserModel.fromDatabaseModel(user)!, + user: UserModel.fromEntity(user)!, ); case ActivityType.animeList: @@ -72,7 +72,7 @@ sealed class ActivityModel extends Equatable { likeCount: activity.likeCount ?? 0, isPinned: activity.isPinned.toBoolean(), createdAt: activity.createdAt!, - user: UserModel.fromDatabaseModel(user)!, + user: UserModel.fromEntity(user)!, status: activity.status ?? '', progress: activity.progress ?? '', media: MediaModel.fromDatabaseModel(media!), diff --git a/lib/core/data/model/notification_model.dart b/lib/core/data/model/notification_model.dart new file mode 100644 index 00000000..84bd0adc --- /dev/null +++ b/lib/core/data/model/notification_model.dart @@ -0,0 +1,168 @@ +// ignore_for_file: lines_longer_than_80_chars + +import 'package:aniflow/core/data/model/activity_model.dart'; +import 'package:aniflow/core/data/model/media_model.dart'; +import 'package:aniflow/core/data/model/user_model.dart'; +import 'package:equatable/equatable.dart'; + +sealed class NotificationModel extends Equatable { + const NotificationModel({required this.context, required this.createdAt}); + + final String context; + final int createdAt; + + @override + List get props => [context, createdAt]; + + // static NotificationModel fromDto(AniNotification dto) { + // switch (dto) { + // case ActivityLikeNotificationDto(): + // return ActivityLikeNotification( + // user: UserModel.fromDto(dto.user!), + // activity: ActivityModel(), + // context: jsonEncode(dto.contexts), + // createdAt: dto.createdAt ?? 0, + // ); + // case AiringNotificationDto(): + // return AiringNotification(episode: dto.episode ?? 0, context: dto.contexts ); + // case ActivityReplyNotification(): + // return ActivityReplyNotificationDto.fromJson(jsonMap); + // case ActivityReplyLikeNotification(): + // return ActivityReplyLikeNotificationDto.fromJson(jsonMap); + // case ActivityReplySubscribedNotification(): + // return ActivityReplySubscribedNotificationDto.fromJson(jsonMap); + // case ActivityMessageNotification(): + // return ActivityMessageNotificationDto.fromJson(jsonMap); + // + // case FollowingNotification(): + // return FollowingNotificationDto.fromJson(jsonMap); + // case MediaDataChangeNotification(): + // return MediaDataChangeNotificationDto.fromJson(jsonMap); + // case RelatedMediaAdditionNotification(): + // return RelatedMediaAdditionNotificationDto.fromJson(jsonMap); + // case MediaDeletionNotification(): + // return MediaDeletionNotificationDto.fromJson(jsonMap); + // case MediaMergeNotification(): + // return MediaMergeNotificationDto.fromJson(jsonMap); + // } + // } +} + +class AiringNotification extends NotificationModel { + const AiringNotification({required this.episode, + required super.context, + required super.createdAt, + required this.media}); + + final int episode; + final MediaModel media; + + @override + List get props => [...super.props, episode, media]; +} + +class FollowNotification extends NotificationModel { + const FollowNotification({ + required super.context, + required super.createdAt, + required this.user, + }); + + final UserModel user; + + @override + List get props => [...super.props, user]; +} + +abstract class ActivityNotification extends NotificationModel { + final UserModel user; + final ActivityModel activity; + + const ActivityNotification({required this.user, + required this.activity, + required super.context, + required super.createdAt}); + + @override + List get props => [...super.props, user, activity]; +} + +class ActivityMentionNotification extends ActivityNotification { + const ActivityMentionNotification({required super.user, + required super.activity, + required super.context, + required super.createdAt}); +} + +class ActivityReplyNotification extends ActivityNotification { + const ActivityReplyNotification({required super.user, + required super.activity, + required super.context, + required super.createdAt}); +} + +class ActivityReplyLikeNotification extends ActivityNotification { + const ActivityReplyLikeNotification({required super.user, + required super.activity, + required super.context, + required super.createdAt}); +} + +class ActivityLikeNotification extends ActivityNotification { + const ActivityLikeNotification({required super.user, + required super.activity, + required super.context, + required super.createdAt}); +} + +class ActivityMessageNotification extends ActivityNotification { + const ActivityMessageNotification({required super.user, + required super.activity, + required super.context, + required super.createdAt}); +} + +abstract class MediaNotification extends NotificationModel { + const MediaNotification({ + required super.context, + required super.createdAt, + required this.media, + }); + + final MediaModel media; + + @override + List get props => [...super.props, media]; +} + +class RelatedMediaAdditionNotification extends MediaNotification { + const RelatedMediaAdditionNotification({ + required super.context, + required super.createdAt, + required super.media, + }); +} + +class MediaDataChangeNotification extends MediaNotification { + const MediaDataChangeNotification({ + required super.context, + required super.createdAt, + required super.media, + }); +} + +class MediaMergeNotification extends MediaNotification { + const MediaMergeNotification({ + required super.context, + required super.createdAt, + required super.media, + }); +} + +class MediaDeletionNotification extends MediaNotification { + const MediaDeletionNotification({ + required super.context, + required super.createdAt, + required super.media, + }); +} diff --git a/lib/core/data/model/user_model.dart b/lib/core/data/model/user_model.dart index a4e91b59..7bc66ce3 100644 --- a/lib/core/data/model/user_model.dart +++ b/lib/core/data/model/user_model.dart @@ -1,4 +1,5 @@ import 'package:aniflow/core/database/model/user_entity.dart'; +import 'package:aniflow/core/network/model/user_data_dto.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'user_model.freezed.dart'; @@ -12,7 +13,7 @@ class UserModel with _$UserModel { String? bannerImage, }) = _UserModel; - static UserModel? fromDatabaseModel(UserEntity? model) { + static UserModel? fromEntity(UserEntity? model) { if (model == null) { return null; } else { @@ -24,4 +25,9 @@ class UserModel with _$UserModel { ); } } + + static UserModel fromDto(UserDataDto dto) { + final entity = UserEntity.fromNetworkModel(dto); + return UserModel.fromEntity(entity)!; + } } diff --git a/lib/core/data/user_info_repository.dart b/lib/core/data/user_info_repository.dart index a5de198f..49e77b93 100644 --- a/lib/core/data/user_info_repository.dart +++ b/lib/core/data/user_info_repository.dart @@ -13,6 +13,6 @@ class UserInfoRepositoryImpl extends UserInfoRepository { @override Future getUserDataById(String id) async { final userEntity = await userDao.getUserData(id); - return UserModel.fromDatabaseModel(userEntity)!; + return UserModel.fromEntity(userEntity)!; } } From acf7a846ccbe031aa18c4731c651120b1933f936 Mon Sep 17 00:00:00 2001 From: andannn Date: Wed, 8 Nov 2023 21:31:16 +0900 Subject: [PATCH 07/10] Correct database initialization --- lib/core/database/aniflow_database.dart | 198 +++++++++++------- lib/main.dart | 5 +- .../repository/activity_repository_test.dart | 2 +- .../repository/ani_lsit_repository_test.dart | 2 +- .../repository/favorite_repository_test.dart | 2 +- .../media_list_repository_test.dart | 2 +- .../repository/search_repository_test.dart | 2 +- .../core/database/activity_database_test.dart | 20 +- test/core/database/anime_database_test.dart | 11 +- test/core/database/database_upgrade_test.dart | 32 +++ .../database/user_anime_list_dao_test.dart | 10 +- .../bloc/airing_schedule_bloc_test.dart | 2 +- .../bloc/anime_search_bloc_test.dart | 2 +- 13 files changed, 182 insertions(+), 108 deletions(-) create mode 100644 test/core/database/database_upgrade_test.dart diff --git a/lib/core/database/aniflow_database.dart b/lib/core/database/aniflow_database.dart index 71083754..9b931183 100644 --- a/lib/core/database/aniflow_database.dart +++ b/lib/core/database/aniflow_database.dart @@ -2,12 +2,12 @@ import 'dart:async'; +import 'package:aniflow/core/common/util/logger.dart'; import 'package:aniflow/core/database/dao/activity_dao.dart'; import 'package:aniflow/core/database/dao/favorite_dao.dart'; import 'package:aniflow/core/database/dao/media_dao.dart'; import 'package:aniflow/core/database/dao/media_list_dao.dart'; import 'package:aniflow/core/database/dao/user_data_dao.dart'; -import 'package:path/path.dart'; import 'package:sqflite/sqflite.dart'; const databaseFileName = "anime_data_base.db"; @@ -29,10 +29,15 @@ mixin Tables { static const String favoriteInfoTable = 'favorite_info_table'; static const String mediaRelationCrossRef = 'media_relation_cross_ref_table'; static const String activityTable = 'activity_table'; - static const String activityFilterTypeCrossRef = 'activity_filter_type_cross_ref_table'; + static const String activityFilterTypeCrossRef = + 'activity_filter_type_cross_ref_table'; } +const databaseVersion = 1; + class AniflowDatabase { + static const String _tag = 'AniflowDatabase'; + static AniflowDatabase? _instance; factory AniflowDatabase() => _instance ??= AniflowDatabase._(); @@ -53,15 +58,33 @@ class AniflowDatabase { Database get aniflowDB => _aniflowDB!; - Future initDatabase({String? dbName, bool isTest = false}) async { - if (isTest) { - _aniflowDB = await openDatabase(inMemoryDatabasePath); - } else { - final path = join(await getDatabasesPath(), dbName ?? databaseFileName); - _aniflowDB = await openDatabase(path); - } - - await _createTables(); + Future initDatabase( + {required String path, int version = databaseVersion}) async { + _aniflowDB = await openDatabase( + path, + version: version, + onConfigure: (db) { + // db.execute('PRAGMA foreign_keys = 1'); + logger.d('$_tag onConfigure'); + }, + onCreate: (Database db, int version) async { + await _createTables(db); + logger.d('$_tag onCreate version $version'); + }, + onUpgrade: (Database db, int oldVersion, int newVersion) async { + switch (oldVersion) { + case 1: + await _onUpgradeToVersion2(db); + continue version_2; + version_2: + case 2: + await _onUpgradeToVersion3(db); + } + }, + onOpen: (Database db) async { + logger.d('$_tag onOpen'); + }, + ); } MediaInformationDao getMediaInformationDaoDao() => @@ -75,43 +98,42 @@ class AniflowDatabase { ActivityDao getActivityDao() => _activityDao ??= ActivityDaoImpl(this); - Future _createTables() async { - await _aniflowDB! - .execute('create table if not exists ${Tables.mediaTable} (' - '${MediaTableColumns.id} text primary key,' - '${MediaTableColumns.type} text,' - '${MediaTableColumns.englishTitle} text,' - '${MediaTableColumns.romajiTitle} text,' - '${MediaTableColumns.nativeTitle} text,' - '${MediaTableColumns.coverImage} text,' - '${MediaTableColumns.coverImageColor} text,' - '${MediaTableColumns.description} text,' - '${MediaTableColumns.source} text,' - '${MediaTableColumns.bannerImage} text,' - '${MediaTableColumns.averageScore} integer,' - '${MediaTableColumns.hashtag} text,' - '${MediaTableColumns.trending} integer,' - '${MediaTableColumns.favourites} integer,' - '${MediaTableColumns.trailerId} text,' - '${MediaTableColumns.trailerSite} text,' - '${MediaTableColumns.trailerThumbnail} text,' - '${MediaTableColumns.episodes} integer,' - '${MediaTableColumns.seasonYear} integer,' - '${MediaTableColumns.genres} text,' - '${MediaTableColumns.season} text,' - '${MediaTableColumns.status} text,' - '${MediaTableColumns.timeUntilAiring} integer,' - '${MediaTableColumns.nextAiringEpisode} integer,' - '${MediaTableColumns.popularRanking} integer,' - '${MediaTableColumns.ratedRanking} integer' - ')'); - - await _aniflowDB! - .execute('create table if not exists ${Tables.categoryTable} (' - '${CategoryColumns.category} text primary key' - ')'); - - await _aniflowDB!.execute( + Future _createTables(Database db) async { + final batch = db.batch(); + batch.execute('create table if not exists ${Tables.mediaTable} (' + '${MediaTableColumns.id} text primary key,' + '${MediaTableColumns.type} text,' + '${MediaTableColumns.englishTitle} text,' + '${MediaTableColumns.romajiTitle} text,' + '${MediaTableColumns.nativeTitle} text,' + '${MediaTableColumns.coverImage} text,' + '${MediaTableColumns.coverImageColor} text,' + '${MediaTableColumns.description} text,' + '${MediaTableColumns.source} text,' + '${MediaTableColumns.bannerImage} text,' + '${MediaTableColumns.averageScore} integer,' + '${MediaTableColumns.hashtag} text,' + '${MediaTableColumns.trending} integer,' + '${MediaTableColumns.favourites} integer,' + '${MediaTableColumns.trailerId} text,' + '${MediaTableColumns.trailerSite} text,' + '${MediaTableColumns.trailerThumbnail} text,' + '${MediaTableColumns.episodes} integer,' + '${MediaTableColumns.seasonYear} integer,' + '${MediaTableColumns.genres} text,' + '${MediaTableColumns.season} text,' + '${MediaTableColumns.status} text,' + '${MediaTableColumns.timeUntilAiring} integer,' + '${MediaTableColumns.nextAiringEpisode} integer,' + '${MediaTableColumns.popularRanking} integer,' + '${MediaTableColumns.ratedRanking} integer' + ')'); + + batch.execute('create table if not exists ${Tables.categoryTable} (' + '${CategoryColumns.category} text primary key' + ')'); + + batch.execute( 'create table if not exists ${Tables.animeCategoryCrossRefTable} (' '${MediaCategoryCrossRefColumns.mediaId} text,' '${MediaCategoryCrossRefColumns.categoryId} text,' @@ -121,15 +143,13 @@ class AniflowDatabase { 'foreign key (${MediaCategoryCrossRefColumns.categoryId}) references ${Tables.categoryTable} (${CategoryColumns.category})' ')'); - await _aniflowDB! - .execute('create table if not exists ${Tables.userDataTable} (' - '${UserDataTableColumns.id} text primary key,' - '${UserDataTableColumns.name} text,' - '${UserDataTableColumns.avatarImage} text,' - '${UserDataTableColumns.bannerImage} text)'); + batch.execute('create table if not exists ${Tables.userDataTable} (' + '${UserDataTableColumns.id} text primary key,' + '${UserDataTableColumns.name} text,' + '${UserDataTableColumns.avatarImage} text,' + '${UserDataTableColumns.bannerImage} text)'); - await _aniflowDB!.execute( - 'create table if not exists ${Tables.characterTable} (' + batch.execute('create table if not exists ${Tables.characterTable} (' '${CharacterColumns.id} text primary key,' '${CharacterColumns.voiceActorId} text,' '${CharacterColumns.role} text,' @@ -139,14 +159,13 @@ class AniflowDatabase { 'foreign key (${CharacterColumns.voiceActorId}) references ${Tables.staffTable} (${StaffColumns.id})' ')'); - await _aniflowDB! - .execute('create table if not exists ${Tables.staffTable} (' - '${StaffColumns.id} text primary key,' - '${StaffColumns.image} text,' - '${StaffColumns.nameEnglish} text,' - '${StaffColumns.nameNative} text)'); + batch.execute('create table if not exists ${Tables.staffTable} (' + '${StaffColumns.id} text primary key,' + '${StaffColumns.image} text,' + '${StaffColumns.nameEnglish} text,' + '${StaffColumns.nameNative} text)'); - await _aniflowDB!.execute( + batch.execute( 'create table if not exists ${Tables.mediaCharacterCrossRefTable} (' '${CharacterCrossRefColumns.mediaId} text,' '${CharacterCrossRefColumns.characterId} text,' @@ -156,7 +175,7 @@ class AniflowDatabase { 'foreign key (${CharacterCrossRefColumns.characterId}) references ${Tables.characterTable} (${CharacterColumns.id})' ')'); - await _aniflowDB!.execute( + batch.execute( 'create table if not exists ${Tables.mediaStaffCrossRefTable} (' '${MediaStaffCrossRefColumns.mediaId} text,' '${MediaStaffCrossRefColumns.staffId} text,' @@ -167,8 +186,7 @@ class AniflowDatabase { 'foreign key (${MediaStaffCrossRefColumns.staffId}) references ${Tables.staffTable} (${StaffColumns.id})' ')'); - await _aniflowDB!.execute( - 'create table if not exists ${Tables.mediaListTable} (' + batch.execute('create table if not exists ${Tables.mediaListTable} (' '${MediaListTableColumns.id} text primary key,' '${MediaListTableColumns.userId} text,' '${MediaListTableColumns.mediaId} text,' @@ -180,7 +198,7 @@ class AniflowDatabase { 'foreign key (${MediaListTableColumns.userId}) references ${Tables.userDataTable} (${UserDataTableColumns.id})' ')'); - await _aniflowDB!.execute( + batch.execute( 'create table if not exists ${Tables.airingSchedulesTable} (' '${AiringSchedulesColumns.id} text primary key,' '${AiringSchedulesColumns.mediaId} text,' @@ -190,7 +208,7 @@ class AniflowDatabase { 'foreign key (${AiringSchedulesColumns.mediaId}) references ${Tables.mediaTable} (${MediaTableColumns.id})' ')'); - await _aniflowDB!.execute( + batch.execute( 'create table if not exists ${Tables.mediaExternalLickTable} (' '${MediaExternalLinkColumnValues.id} text primary key,' '${MediaExternalLinkColumnValues.mediaId} text,' @@ -203,8 +221,7 @@ class AniflowDatabase { 'foreign key (${MediaExternalLinkColumnValues.mediaId}) references ${Tables.mediaTable} (${MediaTableColumns.id})' ')'); - await _aniflowDB!.execute( - 'create table if not exists ${Tables.favoriteInfoTable} (' + batch.execute('create table if not exists ${Tables.favoriteInfoTable} (' '${FavoriteInfoTableColumn.id} integer primary key autoincrement,' '${FavoriteInfoTableColumn.favoriteType} text,' '${FavoriteInfoTableColumn.infoId} text,' @@ -212,7 +229,7 @@ class AniflowDatabase { 'unique (${FavoriteInfoTableColumn.favoriteType},${FavoriteInfoTableColumn.infoId},${FavoriteInfoTableColumn.userId})' ')'); - await _aniflowDB!.execute( + batch.execute( 'create table if not exists ${Tables.mediaRelationCrossRef} (' '${MediaRelationCrossRefColumnValues.ownerId} text,' '${MediaRelationCrossRefColumnValues.relationId} text,' @@ -222,8 +239,7 @@ class AniflowDatabase { 'foreign key (${MediaRelationCrossRefColumnValues.relationId}) references ${Tables.mediaTable} (${MediaTableColumns.id})' ')'); - await _aniflowDB!.execute( - 'create table if not exists ${Tables.activityTable} (' + batch.execute('create table if not exists ${Tables.activityTable} (' '${ActivityTableColumns.id} text primary key,' '${ActivityTableColumns.userId} text,' '${ActivityTableColumns.mediaId} text,' @@ -242,13 +258,35 @@ class AniflowDatabase { 'foreign key (${ActivityTableColumns.mediaId}) references ${Tables.mediaTable} (${MediaTableColumns.id})' ')'); - await _aniflowDB!.execute( + batch.execute( 'create table if not exists ${Tables.activityFilterTypeCrossRef} (' - '${ActivityFilterTypeCrossRefColumns.id} integer primary key autoincrement,' - '${ActivityFilterTypeCrossRefColumns.activityId} text,' - '${ActivityFilterTypeCrossRefColumns.category} text,' - 'unique (${ActivityFilterTypeCrossRefColumns.activityId},${ActivityFilterTypeCrossRefColumns.category})' - 'foreign key (${ActivityFilterTypeCrossRefColumns.activityId}) references ${Tables.activityTable} (${ActivityTableColumns.id})' - ')'); + '${ActivityFilterTypeCrossRefColumns.id} integer primary key autoincrement,' + '${ActivityFilterTypeCrossRefColumns.activityId} text,' + '${ActivityFilterTypeCrossRefColumns.category} text,' + 'unique (${ActivityFilterTypeCrossRefColumns.activityId},${ActivityFilterTypeCrossRefColumns.category})' + 'foreign key (${ActivityFilterTypeCrossRefColumns.activityId}) references ${Tables.activityTable} (${ActivityTableColumns.id})' + ')'); + + batch.execute('create table if not exists parent_table (' + 'parent_id text primary key,' + 'name text' + ')'); + + batch.execute('create table if not exists child (' + 'child_id text primary key,' + 'parent_f_key text, ' + 'child_name text, ' + 'foreign key (parent_f_key) references parent_table (parent_id)' + ')'); + + await batch.commit(noResult: true); + } + + Future _onUpgradeToVersion2(Database db) async { + logger.d('$_tag onUpgradeToVersion2'); + } + + Future _onUpgradeToVersion3(Database db) async { + logger.d('$_tag _onUpgradeToVersion3'); } } diff --git a/lib/main.dart b/lib/main.dart index d084cf53..d09522cd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,6 +11,8 @@ import 'package:aniflow/core/database/aniflow_database.dart'; import 'package:aniflow/core/shared_preference/aniflow_preferences.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:path/path.dart'; +import 'package:sqflite_common_ffi/sqflite_ffi.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -19,7 +21,8 @@ void main() async { await AniFlowPreferences().init(); /// init date base used in this app. - await AniflowDatabase().initDatabase(); + await AniflowDatabase() + .initDatabase(path: join(await getDatabasesPath(), databaseFileName)); /// run app after core instance initialized. runApp(MultiRepositoryProvider(providers: [ diff --git a/test/core/data/repository/activity_repository_test.dart b/test/core/data/repository/activity_repository_test.dart index 3e24ee08..358f5385 100644 --- a/test/core/data/repository/activity_repository_test.dart +++ b/test/core/data/repository/activity_repository_test.dart @@ -20,7 +20,7 @@ void main() { databaseFactory = databaseFactoryFfi; SharedPreferences.setMockInitialValues({}); await AniFlowPreferences().init(); - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); isUnitTest = true; }); diff --git a/test/core/data/repository/ani_lsit_repository_test.dart b/test/core/data/repository/ani_lsit_repository_test.dart index a828d489..57b55816 100644 --- a/test/core/data/repository/ani_lsit_repository_test.dart +++ b/test/core/data/repository/ani_lsit_repository_test.dart @@ -22,7 +22,7 @@ void main() { await AniFlowPreferences().init(); await AniFlowPreferences().setCurrentSeasonYear(2023); await AniFlowPreferences().setCurrentSeason(AnimeSeason.summer); - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); aniListRepository = MediaInformationRepositoryImpl(); }); diff --git a/test/core/data/repository/favorite_repository_test.dart b/test/core/data/repository/favorite_repository_test.dart index db9bb127..342212d7 100644 --- a/test/core/data/repository/favorite_repository_test.dart +++ b/test/core/data/repository/favorite_repository_test.dart @@ -16,7 +16,7 @@ void main() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; SharedPreferences.setMockInitialValues({}); - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); }); test('favorite_anime_test', () async { diff --git a/test/core/data/repository/media_list_repository_test.dart b/test/core/data/repository/media_list_repository_test.dart index 9ac6a771..3fc3ed7e 100644 --- a/test/core/data/repository/media_list_repository_test.dart +++ b/test/core/data/repository/media_list_repository_test.dart @@ -24,7 +24,7 @@ void main() { await AniFlowPreferences().init(); await AniFlowPreferences().setCurrentSeasonYear(2023); await AniFlowPreferences().setCurrentSeason(AnimeSeason.summer); - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); repository = MediaListRepositoryImpl(); isUnitTest = true; diff --git a/test/core/data/repository/search_repository_test.dart b/test/core/data/repository/search_repository_test.dart index 05ef442f..bec24e62 100644 --- a/test/core/data/repository/search_repository_test.dart +++ b/test/core/data/repository/search_repository_test.dart @@ -16,7 +16,7 @@ void main() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; SharedPreferences.setMockInitialValues({}); - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); searchRepository = SearchRepositoryImpl(); }); diff --git a/test/core/database/activity_database_test.dart b/test/core/database/activity_database_test.dart index f4b5dfe5..2e4a07ed 100644 --- a/test/core/database/activity_database_test.dart +++ b/test/core/database/activity_database_test.dart @@ -65,14 +65,13 @@ void main() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); activityDao = AniflowDatabase().getActivityDao(); }); tearDown(() async { - await animeDatabase.aniflowDB.delete(Tables.activityTable); - await animeDatabase.aniflowDB.delete(Tables.userDataTable); + await animeDatabase.aniflowDB.close(); }); test('insert_activity_table', () async { @@ -93,5 +92,20 @@ void main() { (ActivityFilterType.all, ActivityScopeCategory.global) .combineJsonKey); }); + + test('get_activities_aaaaaaaaa', () async { + await animeDatabase.aniflowDB.insert("parent_table", { + 'parent_id' : 1, + 'name' : 'parent name' + }); + await animeDatabase.aniflowDB.insert("child", { + 'child_id' : 1, + 'parent_f_key' : 1, + 'child_name' : 'parent name' + }); + + print('${(await animeDatabase.aniflowDB.query('parent_table'))}'); + print('${(await animeDatabase.aniflowDB.query('child'))}'); + }); }); } diff --git a/test/core/database/anime_database_test.dart b/test/core/database/anime_database_test.dart index f6b62523..9d2ad568 100644 --- a/test/core/database/anime_database_test.dart +++ b/test/core/database/anime_database_test.dart @@ -154,18 +154,11 @@ void main() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); }); tearDown(() async { - await animeDatabase.aniflowDB.delete(Tables.mediaTable); - await animeDatabase.aniflowDB.delete(Tables.categoryTable); - await animeDatabase.aniflowDB.delete(Tables.animeCategoryCrossRefTable); - await animeDatabase.aniflowDB.delete(Tables.userDataTable); - await animeDatabase.aniflowDB.delete(Tables.mediaCharacterCrossRefTable); - await animeDatabase.aniflowDB.delete(Tables.characterTable); - await animeDatabase.aniflowDB.delete(Tables.airingSchedulesTable); - await animeDatabase.aniflowDB.delete(Tables.mediaExternalLickTable); + await animeDatabase.aniflowDB.close(); }); test('anime_dao_clear_all', () async { diff --git a/test/core/database/database_upgrade_test.dart b/test/core/database/database_upgrade_test.dart new file mode 100644 index 00000000..ede09ad7 --- /dev/null +++ b/test/core/database/database_upgrade_test.dart @@ -0,0 +1,32 @@ +import 'package:aniflow/core/common/util/logger.dart'; +import 'package:aniflow/core/database/aniflow_database.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:sqflite_common_ffi/sqflite_ffi.dart'; + +void main() { + group('anime_database_test', () { + final animeDatabase = AniflowDatabase(); + + setUp(() async { + sqfliteFfiInit(); + databaseFactory = databaseFactoryFfi; + }); + + tearDown(() async { + await animeDatabase.aniflowDB.close(); + await databaseFactory.deleteDatabase(animeDatabase.aniflowDB.path); + }); + + test('openDatabase_version_1', () async { + await animeDatabase.initDatabase(path: databaseFileName, version: 2); + logger.d(animeDatabase.aniflowDB.path); + }); + + test('openDatabase_version_2', () async { + await animeDatabase.initDatabase(path: databaseFileName, version: 1); + await animeDatabase.aniflowDB.close(); + + await animeDatabase.initDatabase(path: databaseFileName, version: 3); + }); + }); +} diff --git a/test/core/database/user_anime_list_dao_test.dart b/test/core/database/user_anime_list_dao_test.dart index 15b64c84..0c3478e7 100644 --- a/test/core/database/user_anime_list_dao_test.dart +++ b/test/core/database/user_anime_list_dao_test.dart @@ -38,17 +38,11 @@ void main() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); }); tearDown(() async { - await animeDatabase.aniflowDB.delete(Tables.mediaTable); - await animeDatabase.aniflowDB.delete(Tables.categoryTable); - await animeDatabase.aniflowDB.delete(Tables.animeCategoryCrossRefTable); - await animeDatabase.aniflowDB.delete(Tables.userDataTable); - await animeDatabase.aniflowDB.delete(Tables.mediaCharacterCrossRefTable); - await animeDatabase.aniflowDB.delete(Tables.characterTable); - await animeDatabase.aniflowDB.delete(Tables.mediaListTable); + await animeDatabase.aniflowDB.close(); }); test('insert_test', () async { diff --git a/test/feature/airing_schedule/bloc/airing_schedule_bloc_test.dart b/test/feature/airing_schedule/bloc/airing_schedule_bloc_test.dart index 47843b0e..21137418 100644 --- a/test/feature/airing_schedule/bloc/airing_schedule_bloc_test.dart +++ b/test/feature/airing_schedule/bloc/airing_schedule_bloc_test.dart @@ -15,7 +15,7 @@ void main() { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); airingScheduleBloc = AiringScheduleBloc( mediaInfoRepository: MediaInformationRepositoryImpl()); }); diff --git a/test/feature/anime_search/bloc/anime_search_bloc_test.dart b/test/feature/anime_search/bloc/anime_search_bloc_test.dart index 52e11756..94af7da1 100644 --- a/test/feature/anime_search/bloc/anime_search_bloc_test.dart +++ b/test/feature/anime_search/bloc/anime_search_bloc_test.dart @@ -18,7 +18,7 @@ void main() { SharedPreferences.setMockInitialValues({}); await AniFlowPreferences().init(); - await animeDatabase.initDatabase(isTest: true); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); searchPageBloc = SearchPageBloc( searchRepository: SearchRepositoryImpl(), settingsRepository: SettingsRepositoryImpl()); From afd80747fd7158a4ed65a86f1a00496c976a76f0 Mon Sep 17 00:00:00 2001 From: andannn Date: Wed, 8 Nov 2023 21:56:59 +0900 Subject: [PATCH 08/10] fix exception of not found AuthBloc --- lib/feature/auth/auth_dialog.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/feature/auth/auth_dialog.dart b/lib/feature/auth/auth_dialog.dart index e74f9177..e69a6d30 100644 --- a/lib/feature/auth/auth_dialog.dart +++ b/lib/feature/auth/auth_dialog.dart @@ -22,8 +22,12 @@ class AuthDialog extends StatelessWidget { @override Widget build(BuildContext context) { - return const AlertDialog( - content: _AuthDialogContent(), + return BlocProvider( + create: (context) => + AuthBloc(authRepository: context.read()), + child: const AlertDialog( + content: _AuthDialogContent(), + ), ); } } From f10a6314a348e28b877622c71624005d3d24ce5c Mon Sep 17 00:00:00 2001 From: andannn Date: Wed, 8 Nov 2023 22:27:49 +0900 Subject: [PATCH 09/10] add notification mapping test --- .../common/util/global_static_constants.dart | 4 +- lib/core/data/model/activity_model.dart | 39 ++++ lib/core/data/model/notification_model.dart | 209 ++++++++++++------ lib/core/data/notification_repository.dart | 66 ++++++ .../api/activity_page_query_graphql.dart | 45 +--- .../network/api/ani_auth_mution_graphql.dart | 10 +- .../network/api/media_content_graphql.dart | 18 ++ .../network/api/media_page_query_graphql.dart | 18 +- .../api/notification_query_graphql.dart | 130 +++-------- .../network/api/search_query_graphql.dart | 19 +- .../network/api/user_content_graphql.dart | 9 + .../user_favorite_anime_query_graphql.dart | 19 +- .../user_favorite_manga_query_graphql.dart | 19 +- lib/core/network/auth_data_source.dart | 14 +- .../model/activity_like_notification_dto.dart | 12 +- ...ctivity_like_notification_dto.freezed.dart | 101 +++++---- .../activity_like_notification_dto.g.dart | 7 +- .../activity_message_notification_dto.dart | 13 +- ...vity_message_notification_dto.freezed.dart | 101 +++++---- .../activity_message_notification_dto.g.dart | 7 +- .../activity_reply_like_notification_dto.dart | 12 +- ...y_reply_like_notification_dto.freezed.dart | 101 +++++---- ...ctivity_reply_like_notification_dto.g.dart | 7 +- .../activity_reply_notification_dto.dart | 12 +- ...tivity_reply_notification_dto.freezed.dart | 101 +++++---- .../activity_reply_notification_dto.g.dart | 7 +- ...y_reply_subscription_notification_dto.dart | 13 +- ...subscription_notification_dto.freezed.dart | 101 +++++---- ...reply_subscription_notification_dto.g.dart | 7 +- .../model/following_notification_dto.dart | 2 +- .../following_notification_dto.freezed.dart | 57 +++-- .../model/following_notification_dto.g.dart | 7 +- .../media_data_change_notification_dto.dart | 2 +- ..._data_change_notification_dto.freezed.dart | 57 +++-- .../media_data_change_notification_dto.g.dart | 7 +- .../media_deletion_notification_dto.dart | 2 +- ...dia_deletion_notification_dto.freezed.dart | 57 +++-- .../media_deletion_notification_dto.g.dart | 7 +- .../model/media_merge_notification_dto.dart | 3 +- .../media_merge_notification_dto.freezed.dart | 80 ++++--- .../model/media_merge_notification_dto.g.dart | 9 +- lib/core/network/model/notification.dart | 11 +- ...lated_media_addition_notification_dto.dart | 2 +- ...dia_addition_notification_dto.freezed.dart | 57 +++-- ...ted_media_addition_notification_dto.g.dart | 7 +- .../media_list_repository_test.dart | 2 - .../notification_repository_test.dart | 38 ++++ .../core/database/activity_database_test.dart | 15 -- test/core/network/auth_data_source_test.dart | 5 +- .../core/network/model/activity_dto_test.dart | 19 +- .../model/airing_notification_dto_test.dart | 40 ---- .../network/model/notification_dto_test.dart | 154 +++++++++++++ 52 files changed, 1088 insertions(+), 773 deletions(-) create mode 100644 lib/core/data/notification_repository.dart create mode 100644 lib/core/network/api/media_content_graphql.dart create mode 100644 lib/core/network/api/user_content_graphql.dart create mode 100644 test/core/data/repository/notification_repository_test.dart delete mode 100644 test/core/network/model/airing_notification_dto_test.dart create mode 100644 test/core/network/model/notification_dto_test.dart diff --git a/lib/core/common/util/global_static_constants.dart b/lib/core/common/util/global_static_constants.dart index 03654a86..d6c3f3aa 100644 --- a/lib/core/common/util/global_static_constants.dart +++ b/lib/core/common/util/global_static_constants.dart @@ -1,4 +1,3 @@ - // ignore_for_file: lines_longer_than_80_chars mixin Config { @@ -19,4 +18,5 @@ mixin Config { /// Only for test var isUnitTest = false; -String testToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImNlNjM4MGQ2MTY0YjFmYjdhZmUzZjA0NTM0ZTVlNDJlZmM2MDQwNjNhYjAyYjdjOWRmYWUwODVmNTQ4Yjk0YWEzNDZmZDE5MTEyNDU3Njc4In0.eyJhdWQiOiIxNDQwOSIsImp0aSI6ImNlNjM4MGQ2MTY0YjFmYjdhZmUzZjA0NTM0ZTVlNDJlZmM2MDQwNjNhYjAyYjdjOWRmYWUwODVmNTQ4Yjk0YWEzNDZmZDE5MTEyNDU3Njc4IiwiaWF0IjoxNjk4ODI5MDgyLCJuYmYiOjE2OTg4MjkwODIsImV4cCI6MTczMDQ1MTQ4Miwic3ViIjoiNjM3ODM5MyIsInNjb3BlcyI6W119.sVv96g4xST4QnJucV5O3vNOy2hseu8EZGTsOpx8SOC0Zgp1LTAQj585U32QY900IF8VXlikoFvTPWM0cU0QASx7mCnTeG75vMNxUpzTOoZ6cQbVUFKF0NzOVPkWldVt4m7Wn79wrwGa91Oal6Hj5r8TiICzg_vOZb-dTpkWFiAeZ2CEcuw7099_FaBKLNMspMGPwhRh7xdfiLTvMTRLUdPtwz6TQf7lLtsKVx1Qz0LLIuZluEVb5gBu43N5GHPRbj2JwDJQxsZ6nL95QwrA2LOBIasYltr90mShC78gj0eDOM7Hf84Gioekz26-VJTivWxXSS3mklGPq4WAtHVzfEBdkduhRl-GySsGQoQZamDZdyc4ikii_AOlKH6-aPRPVj5KI1ecC4Wiw5pZHGntGoP2m8fJlprGufawpwbjqo-_Ki0qPyJSSYqJgDWekFC2Wm8-IkyZzDsCca8NXo_EkAow-j54rqLldEZrCT1pzxI9YIHUmsheVMkQfA5-5VCS-zL_qW5o0DYM1P8QVyKJGtgCrL83UOABANLSC__SKhXIH4eiD6LI-lCeiVgaiIv6lwzn2PATFvOJeTv0uUJGkhSLELIJlDhDZ88TwwHUzbxNVjXj5OnywAGHYO09SdZNs1YI3ATccTzMq96SWXN9rzY1If7h8XKts-NzX1esINjM'; +const String testToken = + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2In0.eyJhdWQiOiIxNDQwOSIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2IiwiaWF0IjoxNjk4NTY2MzU0LCJuYmYiOjE2OTg1NjYzNTQsImV4cCI6MTczMDE4ODc1NCwic3ViIjoiNjM3ODM5MyIsInNjb3BlcyI6W119.cjnTU0bSGzQnjxbAy-wkzRqiI5r2zAI_XmOX8teX0MZuceDj7qiBQQ6An-p6Ue30LYSI7V5Tw4ocChZn1bRsg6sRFCPAmE8eBbV4XBGjOhlAb9ciqMgTmVeND6bz0uWO1lr3D0fLfmQKPchrZAwb1-aVDhMkI3Ba4bC1VzxfbGPpw3IzbXjbAg1kFStENCvn3fTXTX53ndNGuPlbS6l8tfOlgYSK7dm0le4JrJAEIlm_Om4WYb6ij42sI0WK1pJY5Lzpar-K0KxaubN9poNKXa81PX65DABzywHXrEi8_D7_O_DkIVsKPjU5dAhXUEhmukFkkLDbRgn7np0i8A-wAfTrVq3tLPvUkDoqdyH105mmwXR_nwO3ZqKJtCnolUok289my02qP1yA0uSmq0nJ51ikI3CEnk_H-jCz5OcVAUhN2qNRb3fhx0fNekBBfaUuJqbHr7usgaNAWRu_vQX0LGs7daClKl1k5FBtdrsJGwSkbY13ghKH42pmBVlY-I9oS8ocznuMsVtyo7QfY6oaMv9kZBuelMto7pM28z61S__qo2jsKzr_2I5uAH3avjUY28G8M3r0r3nkkXqMu_BPn3T95LOLTCghtwx2cE4LARBpZ_1t9rYFUzDb05HeARrqWzbhOwbm9c0N5RM8guq6O1q8kAVZFNLTLjK25ycBuiw'; diff --git a/lib/core/data/model/activity_model.dart b/lib/core/data/model/activity_model.dart index d7555ff0..a23332aa 100644 --- a/lib/core/data/model/activity_model.dart +++ b/lib/core/data/model/activity_model.dart @@ -3,6 +3,9 @@ import 'package:aniflow/core/data/model/media_model.dart'; import 'package:aniflow/core/data/model/user_model.dart'; import 'package:aniflow/core/database/model/relations/activity_and_user_relation.dart'; import 'package:aniflow/core/database/util/content_values_util.dart'; +import 'package:aniflow/core/network/model/ani_activity.dart'; +import 'package:aniflow/core/network/model/list_activity_dto.dart'; +import 'package:aniflow/core/network/model/text_activity_dto.dart'; import 'package:equatable/equatable.dart'; sealed class ActivityModel extends Equatable { @@ -81,6 +84,42 @@ sealed class ActivityModel extends Equatable { throw Exception('Invalid type'); } } + + static ActivityModel fromDto(AniActivity dto) { + switch (dto) { + case TextActivityDto(): + return TextActivityModel( + id: dto.id?.toString() ?? '', + text: dto.text ?? '', + replyCount: dto.replyCount ?? 0, + siteUrl: dto.siteUrl ?? '', + isLocked: dto.isLocked ?? false, + isLiked: dto.isLiked ?? false, + likeCount: dto.likeCount ?? 0, + isPinned: dto.isPinned ?? false, + createdAt: dto.createdAt ?? 0, + user: dto.user == null ? UserModel() : UserModel.fromDto(dto.user!), + ); + case ListActivityDto(): + return ListActivityModel( + id: dto.id?.toString() ?? '', + replyCount: dto.replyCount ?? 0, + siteUrl: dto.siteUrl ?? '', + isLocked: dto.isLocked ?? false, + isLiked: dto.isLiked ?? false, + likeCount: dto.likeCount ?? 0, + isPinned: dto.isPinned ?? false, + createdAt: dto.createdAt ?? 0, + user: dto.user == null ? UserModel() : UserModel.fromDto(dto.user!), + status: dto.status ?? '', + progress: dto.progress ?? '', + media: + dto.media == null ? MediaModel() : MediaModel.fromDto(dto.media!), + ); + default: + throw Exception('Invalid type'); + } + } } class ListActivityModel extends ActivityModel { diff --git a/lib/core/data/model/notification_model.dart b/lib/core/data/model/notification_model.dart index 84bd0adc..4c16a202 100644 --- a/lib/core/data/model/notification_model.dart +++ b/lib/core/data/model/notification_model.dart @@ -1,8 +1,22 @@ // ignore_for_file: lines_longer_than_80_chars +import 'dart:convert'; + import 'package:aniflow/core/data/model/activity_model.dart'; import 'package:aniflow/core/data/model/media_model.dart'; import 'package:aniflow/core/data/model/user_model.dart'; +import 'package:aniflow/core/network/model/activity_like_notification_dto.dart'; +import 'package:aniflow/core/network/model/activity_message_notification_dto.dart'; +import 'package:aniflow/core/network/model/activity_reply_like_notification_dto.dart'; +import 'package:aniflow/core/network/model/activity_reply_notification_dto.dart'; +import 'package:aniflow/core/network/model/activity_reply_subscription_notification_dto.dart'; +import 'package:aniflow/core/network/model/airing_notification_dto.dart'; +import 'package:aniflow/core/network/model/following_notification_dto.dart'; +import 'package:aniflow/core/network/model/media_data_change_notification_dto.dart'; +import 'package:aniflow/core/network/model/media_deletion_notification_dto.dart'; +import 'package:aniflow/core/network/model/media_merge_notification_dto.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:aniflow/core/network/model/related_media_addition_notification_dto.dart'; import 'package:equatable/equatable.dart'; sealed class NotificationModel extends Equatable { @@ -14,45 +28,95 @@ sealed class NotificationModel extends Equatable { @override List get props => [context, createdAt]; - // static NotificationModel fromDto(AniNotification dto) { - // switch (dto) { - // case ActivityLikeNotificationDto(): - // return ActivityLikeNotification( - // user: UserModel.fromDto(dto.user!), - // activity: ActivityModel(), - // context: jsonEncode(dto.contexts), - // createdAt: dto.createdAt ?? 0, - // ); - // case AiringNotificationDto(): - // return AiringNotification(episode: dto.episode ?? 0, context: dto.contexts ); - // case ActivityReplyNotification(): - // return ActivityReplyNotificationDto.fromJson(jsonMap); - // case ActivityReplyLikeNotification(): - // return ActivityReplyLikeNotificationDto.fromJson(jsonMap); - // case ActivityReplySubscribedNotification(): - // return ActivityReplySubscribedNotificationDto.fromJson(jsonMap); - // case ActivityMessageNotification(): - // return ActivityMessageNotificationDto.fromJson(jsonMap); - // - // case FollowingNotification(): - // return FollowingNotificationDto.fromJson(jsonMap); - // case MediaDataChangeNotification(): - // return MediaDataChangeNotificationDto.fromJson(jsonMap); - // case RelatedMediaAdditionNotification(): - // return RelatedMediaAdditionNotificationDto.fromJson(jsonMap); - // case MediaDeletionNotification(): - // return MediaDeletionNotificationDto.fromJson(jsonMap); - // case MediaMergeNotification(): - // return MediaMergeNotificationDto.fromJson(jsonMap); - // } - // } + static NotificationModel fromDto(AniNotification dto) { + switch (dto) { + case AiringNotificationDto(): + return AiringNotification( + createdAt: dto.createdAt ?? 0, + episode: dto.episode ?? 0, + media: MediaModel.fromDto(dto.media!), + context: jsonEncode(dto.contexts), + ); + case FollowingNotificationDto(): + return FollowNotification( + user: UserModel.fromDto(dto.user!), + context: dto.context ?? '', + createdAt: dto.createdAt ?? 0, + ); + case ActivityLikeNotificationDto(): + dto.activity; + return ActivityLikeNotification( + user: UserModel.fromDto(dto.user!), + activity: ActivityModel.fromDto(dto.activity!), + context: dto.context ?? '', + createdAt: dto.createdAt ?? 0, + ); + case ActivityReplyNotificationDto(): + return ActivityReplyNotification( + user: UserModel.fromDto(dto.user!), + activity: ActivityModel.fromDto(dto.activity!), + context: dto.context ?? '', + createdAt: dto.createdAt ?? 0, + ); + case ActivityReplyLikeNotificationDto(): + return ActivityReplyLikeNotification( + user: UserModel.fromDto(dto.user!), + activity: ActivityModel.fromDto(dto.activity!), + context: dto.context ?? '', + createdAt: dto.createdAt ?? 0, + ); + case ActivityReplySubscribedNotificationDto(): + return ActivityReplySubscribedNotification( + user: UserModel.fromDto(dto.user!), + activity: ActivityModel.fromDto(dto.activity!), + context: dto.context ?? '', + createdAt: dto.createdAt ?? 0, + ); + case ActivityMessageNotificationDto(): + return ActivityMessageNotification( + user: UserModel.fromDto(dto.user!), + activity: ActivityModel.fromDto(dto.activity!), + context: dto.context ?? '', + createdAt: dto.createdAt ?? 0, + ); + + case MediaDataChangeNotificationDto(): + return MediaDataChangeNotification( + createdAt: dto.createdAt ?? 0, + context: dto.context ?? '', + media: MediaModel.fromDto(dto.media!), + ); + case RelatedMediaAdditionNotificationDto(): + return RelatedMediaAdditionNotification( + createdAt: dto.createdAt ?? 0, + context: dto.context ?? '', + media: MediaModel.fromDto(dto.media!), + ); + case MediaDeletionNotificationDto(): + return MediaDeletionNotification( + createdAt: dto.createdAt ?? 0, + context: dto.context ?? '', + deletedMediaTitle: dto.deletedMediaTitle ?? '', + reason: dto.reason ?? '', + ); + case MediaMergeNotificationDto(): + return MediaMergeNotification( + createdAt: dto.createdAt ?? 0, + context: dto.context ?? '', + media: MediaModel.fromDto(dto.media!), + ); + default: + throw Exception('Invalid type'); + } + } } class AiringNotification extends NotificationModel { - const AiringNotification({required this.episode, - required super.context, - required super.createdAt, - required this.media}); + const AiringNotification( + {required this.episode, + required super.context, + required super.createdAt, + required this.media}); final int episode; final MediaModel media; @@ -78,48 +142,62 @@ abstract class ActivityNotification extends NotificationModel { final UserModel user; final ActivityModel activity; - const ActivityNotification({required this.user, - required this.activity, - required super.context, - required super.createdAt}); + const ActivityNotification( + {required this.user, + required this.activity, + required super.context, + required super.createdAt}); @override List get props => [...super.props, user, activity]; } class ActivityMentionNotification extends ActivityNotification { - const ActivityMentionNotification({required super.user, - required super.activity, - required super.context, - required super.createdAt}); + const ActivityMentionNotification( + {required super.user, + required super.activity, + required super.context, + required super.createdAt}); } class ActivityReplyNotification extends ActivityNotification { - const ActivityReplyNotification({required super.user, - required super.activity, - required super.context, - required super.createdAt}); + const ActivityReplyNotification( + {required super.user, + required super.activity, + required super.context, + required super.createdAt}); } class ActivityReplyLikeNotification extends ActivityNotification { - const ActivityReplyLikeNotification({required super.user, - required super.activity, - required super.context, - required super.createdAt}); + const ActivityReplyLikeNotification( + {required super.user, + required super.activity, + required super.context, + required super.createdAt}); } class ActivityLikeNotification extends ActivityNotification { - const ActivityLikeNotification({required super.user, - required super.activity, - required super.context, - required super.createdAt}); + const ActivityLikeNotification( + {required super.user, + required super.activity, + required super.context, + required super.createdAt}); } class ActivityMessageNotification extends ActivityNotification { - const ActivityMessageNotification({required super.user, - required super.activity, - required super.context, - required super.createdAt}); + const ActivityMessageNotification( + {required super.user, + required super.activity, + required super.context, + required super.createdAt}); +} + +class ActivityReplySubscribedNotification extends ActivityNotification { + const ActivityReplySubscribedNotification( + {required super.user, + required super.activity, + required super.context, + required super.createdAt}); } abstract class MediaNotification extends NotificationModel { @@ -159,10 +237,17 @@ class MediaMergeNotification extends MediaNotification { }); } -class MediaDeletionNotification extends MediaNotification { +class MediaDeletionNotification extends NotificationModel { const MediaDeletionNotification({ required super.context, required super.createdAt, - required super.media, + required this.deletedMediaTitle, + required this.reason, }); + + final String deletedMediaTitle; + final String reason; + + @override + List get props => [...super.props, deletedMediaTitle, reason]; } diff --git a/lib/core/data/notification_repository.dart b/lib/core/data/notification_repository.dart new file mode 100644 index 00000000..b63ae9ea --- /dev/null +++ b/lib/core/data/notification_repository.dart @@ -0,0 +1,66 @@ +import 'package:aniflow/core/common/util/load_page_util.dart'; +import 'package:aniflow/core/data/load_result.dart'; +import 'package:aniflow/core/data/model/notification_model.dart'; +import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/api/notification_query_graphql.dart'; +import 'package:aniflow/core/network/auth_data_source.dart'; + +enum NotificationCategory { + all, + airing, + activity, + follows, + media; +} + +abstract class NotificationRepository { + Future>> loadNotificationsByPage( + {required int page, + required int perPage, + required NotificationCategory category}); +} + +class NotificationRepositoryImpl extends NotificationRepository { + final AuthDataSource dataSource = AuthDataSource(); + + @override + Future>> loadNotificationsByPage( + {required int page, + required int perPage, + required NotificationCategory category}) { + final types = switch (category) { + NotificationCategory.all => NotificationType.values, + NotificationCategory.airing => [ + NotificationType.airing, + ], + NotificationCategory.activity => [ + NotificationType.activityLike, + NotificationType.activityReply, + NotificationType.activityMention, + NotificationType.activityReplyLike, + NotificationType.activityMessage, + ], + NotificationCategory.follows => [ + NotificationType.following, + ], + NotificationCategory.media => [ + NotificationType.mediaDataChange, + NotificationType.relatedMediaAddition, + NotificationType.mediaMerge, + ], + }; + return LoadPageUtil.loadPageWithoutDBCache( + page: page, + perPage: perPage, + onGetNetworkRes: (int page, int perPage) => dataSource.getNotifications( + NotificationQueryParam( + page: page, + perPage: perPage, + type: types, + ), + ), + mapDtoToModel: (dto) => NotificationModel.fromDto(dto), + onInsertEntityToDB: (dto) async {}, + ); + } +} diff --git a/lib/core/network/api/activity_page_query_graphql.dart b/lib/core/network/api/activity_page_query_graphql.dart index 8a96d10e..c04d61e0 100644 --- a/lib/core/network/api/activity_page_query_graphql.dart +++ b/lib/core/network/api/activity_page_query_graphql.dart @@ -1,4 +1,6 @@ import 'package:aniflow/core/common/model/activity_type.dart'; +import 'package:aniflow/core/network/api/media_content_graphql.dart'; +import 'package:aniflow/core/network/api/user_content_graphql.dart'; class ActivityPageQueryParam { final int? userId; @@ -20,6 +22,13 @@ String get activitiesGraphQLString => ''' query (\$page: Int, \$perPage: Int, \$userId: Int, \$type_in: [ActivityType], \$mediaId: Int, \$isFollowing: Boolean, \$hasRepliesOrTypeText: Boolean) { Page(page: \$page, perPage: \$perPage) { activities(userId: \$userId, type_in: \$type_in, mediaId: \$mediaId, isFollowing: \$isFollowing, sort: ID_DESC, hasRepliesOrTypeText: \$hasRepliesOrTypeText) { + $activityUnionContentString + } + } +} +'''; + +String get activityUnionContentString => ''' __typename ... on TextActivity { id @@ -34,13 +43,7 @@ query (\$page: Int, \$perPage: Int, \$userId: Int, \$type_in: [ActivityType], \$ isPinned createdAt user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } ... on ListActivity { @@ -57,34 +60,10 @@ query (\$page: Int, \$perPage: Int, \$userId: Int, \$type_in: [ActivityType], \$ isPinned createdAt user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } media { - id - type - format - status - season - coverImage { - extraLarge - large - medium - color - } - title { - romaji - english - native - } + $mediaContentQueryGraphql } } - } - } -} '''; diff --git a/lib/core/network/api/ani_auth_mution_graphql.dart b/lib/core/network/api/ani_auth_mution_graphql.dart index c0ec8bc3..1a6a7c97 100644 --- a/lib/core/network/api/ani_auth_mution_graphql.dart +++ b/lib/core/network/api/ani_auth_mution_graphql.dart @@ -1,3 +1,5 @@ +import 'package:aniflow/core/network/api/user_content_graphql.dart'; + const String authCheckMotion = ''' mutation MediaListQuery { UpdateUser { @@ -11,13 +13,7 @@ String get userInfoMotionGraphQLString => ''' mutation UpdateUserMutation { UpdateUser { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } '''; diff --git a/lib/core/network/api/media_content_graphql.dart b/lib/core/network/api/media_content_graphql.dart new file mode 100644 index 00000000..cce287d5 --- /dev/null +++ b/lib/core/network/api/media_content_graphql.dart @@ -0,0 +1,18 @@ +String get mediaContentQueryGraphql => ''' + id + type + format + status + season + coverImage { + extraLarge + large + medium + color + } + title { + romaji + english + native + } +'''; diff --git a/lib/core/network/api/media_page_query_graphql.dart b/lib/core/network/api/media_page_query_graphql.dart index ae9a2450..406d41a1 100644 --- a/lib/core/network/api/media_page_query_graphql.dart +++ b/lib/core/network/api/media_page_query_graphql.dart @@ -4,6 +4,7 @@ import 'package:aniflow/core/common/model/anime_season.dart'; import 'package:aniflow/core/common/model/media_sort.dart'; import 'package:aniflow/core/common/model/media_status.dart'; import 'package:aniflow/core/common/model/media_type.dart'; +import 'package:aniflow/core/network/api/media_content_graphql.dart'; import 'package:country_code/country_code.dart'; class AnimePageQueryParam { @@ -90,22 +91,7 @@ String get animeListQueryGraphQLString => ''' query (\$page: Int, \$perPage: Int, \$type: MediaType, \$countryCode: CountryCode, \$seasonYear: Int, \$season: MediaSeason, \$status: MediaStatus, \$sort: [MediaSort], \$format_in: [MediaFormat]) { Page(page: \$page, perPage: \$perPage) { media: media(type: \$type, countryOfOrigin: \$countryCode, seasonYear: \$seasonYear, season: \$season, status: \$status, sort: \$sort, format_in: \$format_in) { - id - type - format - status - season - coverImage { - extraLarge - large - medium - color - } - title { - romaji - english - native - } + $mediaContentQueryGraphql } } } diff --git a/lib/core/network/api/notification_query_graphql.dart b/lib/core/network/api/notification_query_graphql.dart index d5d8d96b..4ca425f6 100644 --- a/lib/core/network/api/notification_query_graphql.dart +++ b/lib/core/network/api/notification_query_graphql.dart @@ -1,4 +1,7 @@ import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/api/activity_page_query_graphql.dart'; +import 'package:aniflow/core/network/api/media_content_graphql.dart'; +import 'package:aniflow/core/network/api/user_content_graphql.dart'; class NotificationQueryParam { final int page; @@ -25,19 +28,7 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { contexts createdAt media { - id - type - coverImage { - extraLarge - large - medium - color - } - title { - romaji - english - native - } + $mediaContentQueryGraphql } } ... on ActivityLikeNotification { @@ -47,14 +38,11 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { context activityId createdAt + activity { + $activityUnionContentString + } user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } ... on ActivityMentionNotification { @@ -64,14 +52,11 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { activityId context createdAt + activity { + $activityUnionContentString + } user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } ... on ActivityMessageNotification { @@ -85,13 +70,7 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { id } user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } ... on ActivityReplySubscribedNotification { @@ -101,14 +80,11 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { activityId context createdAt + activity { + $activityUnionContentString + } user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } ... on ActivityReplyLikeNotification { @@ -118,14 +94,11 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { activityId context createdAt + activity { + $activityUnionContentString + } user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } ... on ActivityReplyNotification { @@ -135,14 +108,11 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { activityId context createdAt + activity { + $activityUnionContentString + } user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } ... on FollowingNotification { @@ -152,13 +122,7 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { context createdAt user { - id - name - avatar { - large - medium - } - bannerImage + $userContentQueryGraphql } } ... on MediaMergeNotification { @@ -170,19 +134,7 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { reason createdAt media { - id - type - coverImage { - extraLarge - large - medium - color - } - title { - romaji - english - native - } + $mediaContentQueryGraphql } } ... on MediaDataChangeNotification { @@ -193,19 +145,7 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { reason createdAt media { - id - type - coverImage { - extraLarge - large - medium - color - } - title { - romaji - english - native - } + $mediaContentQueryGraphql } } ... on MediaDeletionNotification { @@ -223,19 +163,7 @@ query (\$page: Int, \$perPage: Int, \$type_in: [NotificationType]) { context createdAt media { - id - type - coverImage { - extraLarge - large - medium - color - } - title { - romaji - english - native - } + $mediaContentQueryGraphql } } } diff --git a/lib/core/network/api/search_query_graphql.dart b/lib/core/network/api/search_query_graphql.dart index d8a8f3fe..fad3bb1a 100644 --- a/lib/core/network/api/search_query_graphql.dart +++ b/lib/core/network/api/search_query_graphql.dart @@ -1,25 +1,12 @@ +import 'package:aniflow/core/network/api/media_content_graphql.dart'; + String get searchQueryGraphql => ''' query (\$page: Int, \$perPage: Int, \$search: String, \$type: MediaType) { page: Page(page: \$page, perPage: \$perPage) { media(type: \$type, sort: [POPULARITY_DESC], search: \$search) { - id - title { - romaji - english - native - } - episodes - seasonYear - season - status - coverImage { - extraLarge - large - medium - color - } + $mediaContentQueryGraphql } } } diff --git a/lib/core/network/api/user_content_graphql.dart b/lib/core/network/api/user_content_graphql.dart new file mode 100644 index 00000000..de541f58 --- /dev/null +++ b/lib/core/network/api/user_content_graphql.dart @@ -0,0 +1,9 @@ +String get userContentQueryGraphql => ''' + id + name + avatar { + large + medium + } + bannerImage +'''; \ No newline at end of file diff --git a/lib/core/network/api/user_favorite_anime_query_graphql.dart b/lib/core/network/api/user_favorite_anime_query_graphql.dart index 0c021623..6aaae255 100644 --- a/lib/core/network/api/user_favorite_anime_query_graphql.dart +++ b/lib/core/network/api/user_favorite_anime_query_graphql.dart @@ -1,4 +1,6 @@ +import 'package:aniflow/core/network/api/media_content_graphql.dart'; + String get userFavoriteAnimeQueryGraphQl => ''' query(\$UserId: Int, \$page: Int, \$perPage: Int){ @@ -8,22 +10,7 @@ query(\$UserId: Int, \$page: Int, \$perPage: Int){ favourites(page: 1) { anime(page: \$page, perPage: \$perPage) { nodes { - id - type - format - status - season - coverImage { - extraLarge - large - medium - color - } - title { - romaji - english - native - } + $mediaContentQueryGraphql } } } diff --git a/lib/core/network/api/user_favorite_manga_query_graphql.dart b/lib/core/network/api/user_favorite_manga_query_graphql.dart index e9fa86cb..73da9f9e 100644 --- a/lib/core/network/api/user_favorite_manga_query_graphql.dart +++ b/lib/core/network/api/user_favorite_manga_query_graphql.dart @@ -1,4 +1,6 @@ +import 'package:aniflow/core/network/api/media_content_graphql.dart'; + String get userFavoriteMangaQueryGraphQl => ''' query(\$UserId: Int, \$page: Int, \$perPage: Int){ @@ -8,22 +10,7 @@ query(\$UserId: Int, \$page: Int, \$perPage: Int){ favourites(page: 1) { manga(page: \$page, perPage: \$perPage) { nodes { - id - type - format - status - season - coverImage { - extraLarge - large - medium - color - } - title { - romaji - english - native - } + $mediaContentQueryGraphql } } } diff --git a/lib/core/network/auth_data_source.dart b/lib/core/network/auth_data_source.dart index 54b0eccc..d89d6749 100644 --- a/lib/core/network/auth_data_source.dart +++ b/lib/core/network/auth_data_source.dart @@ -104,13 +104,13 @@ class AuthDataSource { try { final response = await AniListDio().dio.post( - AniListDio.aniListUrl, - queryParameters: { - 'query': notificationQueryGraphql, - 'variables': variablesMap, - }, - options: _createQueryOptions(), - ); + AniListDio.aniListUrl, + options: _createQueryOptions(), + data: { + 'query': notificationQueryGraphql, + 'variables': variablesMap, + }, + ); List resultJson = response.data['data']['Page']['notifications']; return resultJson .map((e) => AniNotification.mapToAniNotification(e)) diff --git a/lib/core/network/model/activity_like_notification_dto.dart b/lib/core/network/model/activity_like_notification_dto.dart index b5b04323..b9e80737 100644 --- a/lib/core/network/model/activity_like_notification_dto.dart +++ b/lib/core/network/model/activity_like_notification_dto.dart @@ -1,4 +1,5 @@ import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/ani_activity.dart'; import 'package:aniflow/core/network/model/notification.dart'; import 'package:aniflow/core/network/model/user_data_dto.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -14,11 +15,20 @@ class ActivityLikeNotificationDto extends AniNotification @Default(-1) @JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity, }) = _ActivityLikeNotificationDto; factory ActivityLikeNotificationDto.fromJson(Map json) => _$$_ActivityLikeNotificationDtoFromJson(json); + + static ActivityLikeNotificationDto fromJsonWithActivity( + Map json) { + return ActivityLikeNotificationDto.fromJson(json).copyWith( + activity: AniActivity.mapToAniActivity(json['activity']), + ); + } } diff --git a/lib/core/network/model/activity_like_notification_dto.freezed.dart b/lib/core/network/model/activity_like_notification_dto.freezed.dart index c0755536..569dc512 100644 --- a/lib/core/network/model/activity_like_notification_dto.freezed.dart +++ b/lib/core/network/model/activity_like_notification_dto.freezed.dart @@ -27,12 +27,14 @@ mixin _$ActivityLikeNotificationDto { NotificationType? get type => throw _privateConstructorUsedError; @JsonKey(name: 'userId') int? get userId => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'user') UserDataDto? get user => throw _privateConstructorUsedError; + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -52,9 +54,11 @@ abstract class $ActivityLikeNotificationDtoCopyWith<$Res> { {@JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); $UserDataDtoCopyWith<$Res>? get user; } @@ -76,9 +80,10 @@ class _$ActivityLikeNotificationDtoCopyWithImpl<$Res, Object? id = null, Object? type = freezed, Object? userId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_value.copyWith( id: null == id @@ -93,10 +98,10 @@ class _$ActivityLikeNotificationDtoCopyWithImpl<$Res, ? _value.userId : userId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -105,6 +110,10 @@ class _$ActivityLikeNotificationDtoCopyWithImpl<$Res, ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, ) as $Val); } @@ -134,9 +143,11 @@ abstract class _$$_ActivityLikeNotificationDtoCopyWith<$Res> {@JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); @override $UserDataDtoCopyWith<$Res>? get user; @@ -158,9 +169,10 @@ class __$$_ActivityLikeNotificationDtoCopyWithImpl<$Res> Object? id = null, Object? type = freezed, Object? userId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_$_ActivityLikeNotificationDto( id: null == id @@ -175,10 +187,10 @@ class __$$_ActivityLikeNotificationDtoCopyWithImpl<$Res> ? _value.userId : userId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -187,6 +199,10 @@ class __$$_ActivityLikeNotificationDtoCopyWithImpl<$Res> ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, )); } } @@ -198,10 +214,10 @@ class _$_ActivityLikeNotificationDto implements _ActivityLikeNotificationDto { {@JsonKey(name: 'id') this.id = -1, @JsonKey(name: 'type') this.type, @JsonKey(name: 'userId') this.userId, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'createdAt') this.createdAt, - @JsonKey(name: 'user') this.user}) - : _contexts = contexts; + @JsonKey(name: 'user') this.user, + @JsonKey(includeFromJson: false, includeToJson: false) this.activity}); factory _$_ActivityLikeNotificationDto.fromJson(Map json) => _$$_ActivityLikeNotificationDtoFromJson(json); @@ -215,25 +231,22 @@ class _$_ActivityLikeNotificationDto implements _ActivityLikeNotificationDto { @override @JsonKey(name: 'userId') final int? userId; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @override @JsonKey(name: 'user') final UserDataDto? user; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity; @override String toString() { - return 'ActivityLikeNotificationDto(id: $id, type: $type, userId: $userId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + return 'ActivityLikeNotificationDto(id: $id, type: $type, userId: $userId, context: $context, createdAt: $createdAt, user: $user, activity: $activity)'; } @override @@ -244,16 +257,18 @@ class _$_ActivityLikeNotificationDto implements _ActivityLikeNotificationDto { (identical(other.id, id) || other.id == id) && (identical(other.type, type) || other.type == type) && (identical(other.userId, userId) || other.userId == userId) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt) && - (identical(other.user, user) || other.user == user)); + (identical(other.user, user) || other.user == user) && + (identical(other.activity, activity) || + other.activity == activity)); } @JsonKey(ignore: true) @override - int get hashCode => Object.hash(runtimeType, id, type, userId, - const DeepCollectionEquality().hash(_contexts), createdAt, user); + int get hashCode => Object.hash( + runtimeType, id, type, userId, context, createdAt, user, activity); @JsonKey(ignore: true) @override @@ -273,13 +288,14 @@ class _$_ActivityLikeNotificationDto implements _ActivityLikeNotificationDto { abstract class _ActivityLikeNotificationDto implements ActivityLikeNotificationDto { factory _ActivityLikeNotificationDto( - {@JsonKey(name: 'id') final int id, - @JsonKey(name: 'type') final NotificationType? type, - @JsonKey(name: 'userId') final int? userId, - @JsonKey(name: 'contexts') final List contexts, - @JsonKey(name: 'createdAt') final int? createdAt, - @JsonKey(name: 'user') final UserDataDto? user}) = - _$_ActivityLikeNotificationDto; + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'context') final String? context, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity}) = _$_ActivityLikeNotificationDto; factory _ActivityLikeNotificationDto.fromJson(Map json) = _$_ActivityLikeNotificationDto.fromJson; @@ -294,8 +310,8 @@ abstract class _ActivityLikeNotificationDto @JsonKey(name: 'userId') int? get userId; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; @@ -303,6 +319,9 @@ abstract class _ActivityLikeNotificationDto @JsonKey(name: 'user') UserDataDto? get user; @override + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity; + @override @JsonKey(ignore: true) _$$_ActivityLikeNotificationDtoCopyWith<_$_ActivityLikeNotificationDto> get copyWith => throw _privateConstructorUsedError; diff --git a/lib/core/network/model/activity_like_notification_dto.g.dart b/lib/core/network/model/activity_like_notification_dto.g.dart index 60a3fdf0..e949dc6e 100644 --- a/lib/core/network/model/activity_like_notification_dto.g.dart +++ b/lib/core/network/model/activity_like_notification_dto.g.dart @@ -12,10 +12,7 @@ _$_ActivityLikeNotificationDto _$$_ActivityLikeNotificationDtoFromJson( id: json['id'] as int? ?? -1, type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), userId: json['userId'] as int?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, user: json['user'] == null ? null @@ -28,7 +25,7 @@ Map _$$_ActivityLikeNotificationDtoToJson( 'id': instance.id, 'type': _$NotificationTypeEnumMap[instance.type], 'userId': instance.userId, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, 'user': instance.user, }; diff --git a/lib/core/network/model/activity_message_notification_dto.dart b/lib/core/network/model/activity_message_notification_dto.dart index b137f427..96c66db9 100644 --- a/lib/core/network/model/activity_message_notification_dto.dart +++ b/lib/core/network/model/activity_message_notification_dto.dart @@ -1,10 +1,10 @@ import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/ani_activity.dart'; import 'package:aniflow/core/network/model/notification.dart'; import 'package:aniflow/core/network/model/user_data_dto.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'activity_message_notification_dto.freezed.dart'; - part 'activity_message_notification_dto.g.dart'; @freezed @@ -15,11 +15,20 @@ class ActivityMessageNotificationDto extends AniNotification @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity, }) = _ActivityMessageNotificationDto; factory ActivityMessageNotificationDto.fromJson(Map json) => _$$_ActivityMessageNotificationDtoFromJson(json); + + static ActivityMessageNotificationDto fromJsonWithActivity( + Map json) { + return ActivityMessageNotificationDto.fromJson(json).copyWith( + activity: AniActivity.mapToAniActivity(json['activity']), + ); + } } diff --git a/lib/core/network/model/activity_message_notification_dto.freezed.dart b/lib/core/network/model/activity_message_notification_dto.freezed.dart index 6e8b2a1e..07fc76e1 100644 --- a/lib/core/network/model/activity_message_notification_dto.freezed.dart +++ b/lib/core/network/model/activity_message_notification_dto.freezed.dart @@ -29,12 +29,14 @@ mixin _$ActivityMessageNotificationDto { int? get userId => throw _privateConstructorUsedError; @JsonKey(name: 'activityId') int? get activityId => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'user') UserDataDto? get user => throw _privateConstructorUsedError; + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -55,9 +57,11 @@ abstract class $ActivityMessageNotificationDtoCopyWith<$Res> { @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); $UserDataDtoCopyWith<$Res>? get user; } @@ -80,9 +84,10 @@ class _$ActivityMessageNotificationDtoCopyWithImpl<$Res, Object? type = freezed, Object? userId = freezed, Object? activityId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_value.copyWith( id: null == id @@ -101,10 +106,10 @@ class _$ActivityMessageNotificationDtoCopyWithImpl<$Res, ? _value.activityId : activityId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -113,6 +118,10 @@ class _$ActivityMessageNotificationDtoCopyWithImpl<$Res, ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, ) as $Val); } @@ -143,9 +152,11 @@ abstract class _$$_ActivityMessageNotificationDtoCopyWith<$Res> @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); @override $UserDataDtoCopyWith<$Res>? get user; @@ -168,9 +179,10 @@ class __$$_ActivityMessageNotificationDtoCopyWithImpl<$Res> Object? type = freezed, Object? userId = freezed, Object? activityId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_$_ActivityMessageNotificationDto( id: null == id @@ -189,10 +201,10 @@ class __$$_ActivityMessageNotificationDtoCopyWithImpl<$Res> ? _value.activityId : activityId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -201,6 +213,10 @@ class __$$_ActivityMessageNotificationDtoCopyWithImpl<$Res> ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, )); } } @@ -214,10 +230,10 @@ class _$_ActivityMessageNotificationDto @JsonKey(name: 'type') this.type, @JsonKey(name: 'userId') this.userId, @JsonKey(name: 'activityId') this.activityId, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'createdAt') this.createdAt, - @JsonKey(name: 'user') this.user}) - : _contexts = contexts; + @JsonKey(name: 'user') this.user, + @JsonKey(includeFromJson: false, includeToJson: false) this.activity}); factory _$_ActivityMessageNotificationDto.fromJson( Map json) => @@ -235,25 +251,22 @@ class _$_ActivityMessageNotificationDto @override @JsonKey(name: 'activityId') final int? activityId; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @override @JsonKey(name: 'user') final UserDataDto? user; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity; @override String toString() { - return 'ActivityMessageNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + return 'ActivityMessageNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, context: $context, createdAt: $createdAt, user: $user, activity: $activity)'; } @override @@ -266,16 +279,18 @@ class _$_ActivityMessageNotificationDto (identical(other.userId, userId) || other.userId == userId) && (identical(other.activityId, activityId) || other.activityId == activityId) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt) && - (identical(other.user, user) || other.user == user)); + (identical(other.user, user) || other.user == user) && + (identical(other.activity, activity) || + other.activity == activity)); } @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, id, type, userId, activityId, - const DeepCollectionEquality().hash(_contexts), createdAt, user); + context, createdAt, user, activity); @JsonKey(ignore: true) @override @@ -295,14 +310,15 @@ class _$_ActivityMessageNotificationDto abstract class _ActivityMessageNotificationDto implements ActivityMessageNotificationDto { factory _ActivityMessageNotificationDto( - {@JsonKey(name: 'id') final int id, - @JsonKey(name: 'type') final NotificationType? type, - @JsonKey(name: 'userId') final int? userId, - @JsonKey(name: 'activityId') final int? activityId, - @JsonKey(name: 'contexts') final List contexts, - @JsonKey(name: 'createdAt') final int? createdAt, - @JsonKey(name: 'user') final UserDataDto? user}) = - _$_ActivityMessageNotificationDto; + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'activityId') final int? activityId, + @JsonKey(name: 'context') final String? context, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity}) = _$_ActivityMessageNotificationDto; factory _ActivityMessageNotificationDto.fromJson(Map json) = _$_ActivityMessageNotificationDto.fromJson; @@ -320,8 +336,8 @@ abstract class _ActivityMessageNotificationDto @JsonKey(name: 'activityId') int? get activityId; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; @@ -329,6 +345,9 @@ abstract class _ActivityMessageNotificationDto @JsonKey(name: 'user') UserDataDto? get user; @override + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity; + @override @JsonKey(ignore: true) _$$_ActivityMessageNotificationDtoCopyWith<_$_ActivityMessageNotificationDto> get copyWith => throw _privateConstructorUsedError; diff --git a/lib/core/network/model/activity_message_notification_dto.g.dart b/lib/core/network/model/activity_message_notification_dto.g.dart index e7fec1c9..a2d659db 100644 --- a/lib/core/network/model/activity_message_notification_dto.g.dart +++ b/lib/core/network/model/activity_message_notification_dto.g.dart @@ -13,10 +13,7 @@ _$_ActivityMessageNotificationDto _$$_ActivityMessageNotificationDtoFromJson( type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), userId: json['userId'] as int?, activityId: json['activityId'] as int?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, user: json['user'] == null ? null @@ -30,7 +27,7 @@ Map _$$_ActivityMessageNotificationDtoToJson( 'type': _$NotificationTypeEnumMap[instance.type], 'userId': instance.userId, 'activityId': instance.activityId, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, 'user': instance.user, }; diff --git a/lib/core/network/model/activity_reply_like_notification_dto.dart b/lib/core/network/model/activity_reply_like_notification_dto.dart index ca910afc..90add6c5 100644 --- a/lib/core/network/model/activity_reply_like_notification_dto.dart +++ b/lib/core/network/model/activity_reply_like_notification_dto.dart @@ -1,6 +1,7 @@ // ignore_for_file: lines_longer_than_80_chars import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/ani_activity.dart'; import 'package:aniflow/core/network/model/notification.dart'; import 'package:aniflow/core/network/model/user_data_dto.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -17,11 +18,20 @@ class ActivityReplyLikeNotificationDto extends AniNotification @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity, }) = _ActivityReplyLikeNotificationDto; factory ActivityReplyLikeNotificationDto.fromJson(Map json) => _$$_ActivityReplyLikeNotificationDtoFromJson(json); + + static ActivityReplyLikeNotificationDto fromJsonWithActivity( + Map json) { + return ActivityReplyLikeNotificationDto.fromJson(json).copyWith( + activity: AniActivity.mapToAniActivity(json['activity']), + ); + } } diff --git a/lib/core/network/model/activity_reply_like_notification_dto.freezed.dart b/lib/core/network/model/activity_reply_like_notification_dto.freezed.dart index 6d1e3490..1ea63d31 100644 --- a/lib/core/network/model/activity_reply_like_notification_dto.freezed.dart +++ b/lib/core/network/model/activity_reply_like_notification_dto.freezed.dart @@ -29,12 +29,14 @@ mixin _$ActivityReplyLikeNotificationDto { int? get userId => throw _privateConstructorUsedError; @JsonKey(name: 'activityId') int? get activityId => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'user') UserDataDto? get user => throw _privateConstructorUsedError; + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -55,9 +57,11 @@ abstract class $ActivityReplyLikeNotificationDtoCopyWith<$Res> { @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); $UserDataDtoCopyWith<$Res>? get user; } @@ -80,9 +84,10 @@ class _$ActivityReplyLikeNotificationDtoCopyWithImpl<$Res, Object? type = freezed, Object? userId = freezed, Object? activityId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_value.copyWith( id: null == id @@ -101,10 +106,10 @@ class _$ActivityReplyLikeNotificationDtoCopyWithImpl<$Res, ? _value.activityId : activityId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -113,6 +118,10 @@ class _$ActivityReplyLikeNotificationDtoCopyWithImpl<$Res, ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, ) as $Val); } @@ -143,9 +152,11 @@ abstract class _$$_ActivityReplyLikeNotificationDtoCopyWith<$Res> @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); @override $UserDataDtoCopyWith<$Res>? get user; @@ -168,9 +179,10 @@ class __$$_ActivityReplyLikeNotificationDtoCopyWithImpl<$Res> Object? type = freezed, Object? userId = freezed, Object? activityId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_$_ActivityReplyLikeNotificationDto( id: null == id @@ -189,10 +201,10 @@ class __$$_ActivityReplyLikeNotificationDtoCopyWithImpl<$Res> ? _value.activityId : activityId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -201,6 +213,10 @@ class __$$_ActivityReplyLikeNotificationDtoCopyWithImpl<$Res> ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, )); } } @@ -214,10 +230,10 @@ class _$_ActivityReplyLikeNotificationDto @JsonKey(name: 'type') this.type, @JsonKey(name: 'userId') this.userId, @JsonKey(name: 'activityId') this.activityId, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'createdAt') this.createdAt, - @JsonKey(name: 'user') this.user}) - : _contexts = contexts; + @JsonKey(name: 'user') this.user, + @JsonKey(includeFromJson: false, includeToJson: false) this.activity}); factory _$_ActivityReplyLikeNotificationDto.fromJson( Map json) => @@ -235,25 +251,22 @@ class _$_ActivityReplyLikeNotificationDto @override @JsonKey(name: 'activityId') final int? activityId; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @override @JsonKey(name: 'user') final UserDataDto? user; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity; @override String toString() { - return 'ActivityReplyLikeNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + return 'ActivityReplyLikeNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, context: $context, createdAt: $createdAt, user: $user, activity: $activity)'; } @override @@ -266,16 +279,18 @@ class _$_ActivityReplyLikeNotificationDto (identical(other.userId, userId) || other.userId == userId) && (identical(other.activityId, activityId) || other.activityId == activityId) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt) && - (identical(other.user, user) || other.user == user)); + (identical(other.user, user) || other.user == user) && + (identical(other.activity, activity) || + other.activity == activity)); } @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, id, type, userId, activityId, - const DeepCollectionEquality().hash(_contexts), createdAt, user); + context, createdAt, user, activity); @JsonKey(ignore: true) @override @@ -296,14 +311,15 @@ class _$_ActivityReplyLikeNotificationDto abstract class _ActivityReplyLikeNotificationDto implements ActivityReplyLikeNotificationDto { factory _ActivityReplyLikeNotificationDto( - {@JsonKey(name: 'id') final int id, - @JsonKey(name: 'type') final NotificationType? type, - @JsonKey(name: 'userId') final int? userId, - @JsonKey(name: 'activityId') final int? activityId, - @JsonKey(name: 'contexts') final List contexts, - @JsonKey(name: 'createdAt') final int? createdAt, - @JsonKey(name: 'user') final UserDataDto? user}) = - _$_ActivityReplyLikeNotificationDto; + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'activityId') final int? activityId, + @JsonKey(name: 'context') final String? context, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity}) = _$_ActivityReplyLikeNotificationDto; factory _ActivityReplyLikeNotificationDto.fromJson( Map json) = _$_ActivityReplyLikeNotificationDto.fromJson; @@ -321,8 +337,8 @@ abstract class _ActivityReplyLikeNotificationDto @JsonKey(name: 'activityId') int? get activityId; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; @@ -330,6 +346,9 @@ abstract class _ActivityReplyLikeNotificationDto @JsonKey(name: 'user') UserDataDto? get user; @override + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity; + @override @JsonKey(ignore: true) _$$_ActivityReplyLikeNotificationDtoCopyWith< _$_ActivityReplyLikeNotificationDto> diff --git a/lib/core/network/model/activity_reply_like_notification_dto.g.dart b/lib/core/network/model/activity_reply_like_notification_dto.g.dart index ddc3828d..f8512fe8 100644 --- a/lib/core/network/model/activity_reply_like_notification_dto.g.dart +++ b/lib/core/network/model/activity_reply_like_notification_dto.g.dart @@ -13,10 +13,7 @@ _$_ActivityReplyLikeNotificationDto type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), userId: json['userId'] as int?, activityId: json['activityId'] as int?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, user: json['user'] == null ? null @@ -30,7 +27,7 @@ Map _$$_ActivityReplyLikeNotificationDtoToJson( 'type': _$NotificationTypeEnumMap[instance.type], 'userId': instance.userId, 'activityId': instance.activityId, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, 'user': instance.user, }; diff --git a/lib/core/network/model/activity_reply_notification_dto.dart b/lib/core/network/model/activity_reply_notification_dto.dart index cad5a9d3..27e7a478 100644 --- a/lib/core/network/model/activity_reply_notification_dto.dart +++ b/lib/core/network/model/activity_reply_notification_dto.dart @@ -1,4 +1,5 @@ import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/ani_activity.dart'; import 'package:aniflow/core/network/model/notification.dart'; import 'package:aniflow/core/network/model/user_data_dto.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -15,11 +16,20 @@ class ActivityReplyNotificationDto extends AniNotification @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity, }) = _ActivityReplyNotificationDto; factory ActivityReplyNotificationDto.fromJson(Map json) => _$$_ActivityReplyNotificationDtoFromJson(json); + + static ActivityReplyNotificationDto fromJsonWithActivity( + Map json) { + return ActivityReplyNotificationDto.fromJson(json).copyWith( + activity: AniActivity.mapToAniActivity(json['activity']), + ); + } } diff --git a/lib/core/network/model/activity_reply_notification_dto.freezed.dart b/lib/core/network/model/activity_reply_notification_dto.freezed.dart index 4d6a31a2..173311fe 100644 --- a/lib/core/network/model/activity_reply_notification_dto.freezed.dart +++ b/lib/core/network/model/activity_reply_notification_dto.freezed.dart @@ -29,12 +29,14 @@ mixin _$ActivityReplyNotificationDto { int? get userId => throw _privateConstructorUsedError; @JsonKey(name: 'activityId') int? get activityId => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'user') UserDataDto? get user => throw _privateConstructorUsedError; + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -55,9 +57,11 @@ abstract class $ActivityReplyNotificationDtoCopyWith<$Res> { @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); $UserDataDtoCopyWith<$Res>? get user; } @@ -80,9 +84,10 @@ class _$ActivityReplyNotificationDtoCopyWithImpl<$Res, Object? type = freezed, Object? userId = freezed, Object? activityId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_value.copyWith( id: null == id @@ -101,10 +106,10 @@ class _$ActivityReplyNotificationDtoCopyWithImpl<$Res, ? _value.activityId : activityId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -113,6 +118,10 @@ class _$ActivityReplyNotificationDtoCopyWithImpl<$Res, ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, ) as $Val); } @@ -143,9 +152,11 @@ abstract class _$$_ActivityReplyNotificationDtoCopyWith<$Res> @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); @override $UserDataDtoCopyWith<$Res>? get user; @@ -168,9 +179,10 @@ class __$$_ActivityReplyNotificationDtoCopyWithImpl<$Res> Object? type = freezed, Object? userId = freezed, Object? activityId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_$_ActivityReplyNotificationDto( id: null == id @@ -189,10 +201,10 @@ class __$$_ActivityReplyNotificationDtoCopyWithImpl<$Res> ? _value.activityId : activityId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -201,6 +213,10 @@ class __$$_ActivityReplyNotificationDtoCopyWithImpl<$Res> ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, )); } } @@ -213,10 +229,10 @@ class _$_ActivityReplyNotificationDto implements _ActivityReplyNotificationDto { @JsonKey(name: 'type') this.type, @JsonKey(name: 'userId') this.userId, @JsonKey(name: 'activityId') this.activityId, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'createdAt') this.createdAt, - @JsonKey(name: 'user') this.user}) - : _contexts = contexts; + @JsonKey(name: 'user') this.user, + @JsonKey(includeFromJson: false, includeToJson: false) this.activity}); factory _$_ActivityReplyNotificationDto.fromJson(Map json) => _$$_ActivityReplyNotificationDtoFromJson(json); @@ -233,25 +249,22 @@ class _$_ActivityReplyNotificationDto implements _ActivityReplyNotificationDto { @override @JsonKey(name: 'activityId') final int? activityId; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @override @JsonKey(name: 'user') final UserDataDto? user; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity; @override String toString() { - return 'ActivityReplyNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + return 'ActivityReplyNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, context: $context, createdAt: $createdAt, user: $user, activity: $activity)'; } @override @@ -264,16 +277,18 @@ class _$_ActivityReplyNotificationDto implements _ActivityReplyNotificationDto { (identical(other.userId, userId) || other.userId == userId) && (identical(other.activityId, activityId) || other.activityId == activityId) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt) && - (identical(other.user, user) || other.user == user)); + (identical(other.user, user) || other.user == user) && + (identical(other.activity, activity) || + other.activity == activity)); } @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, id, type, userId, activityId, - const DeepCollectionEquality().hash(_contexts), createdAt, user); + context, createdAt, user, activity); @JsonKey(ignore: true) @override @@ -293,14 +308,15 @@ class _$_ActivityReplyNotificationDto implements _ActivityReplyNotificationDto { abstract class _ActivityReplyNotificationDto implements ActivityReplyNotificationDto { factory _ActivityReplyNotificationDto( - {@JsonKey(name: 'id') final int id, - @JsonKey(name: 'type') final NotificationType? type, - @JsonKey(name: 'userId') final int? userId, - @JsonKey(name: 'activityId') final int? activityId, - @JsonKey(name: 'contexts') final List contexts, - @JsonKey(name: 'createdAt') final int? createdAt, - @JsonKey(name: 'user') final UserDataDto? user}) = - _$_ActivityReplyNotificationDto; + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'activityId') final int? activityId, + @JsonKey(name: 'context') final String? context, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity}) = _$_ActivityReplyNotificationDto; factory _ActivityReplyNotificationDto.fromJson(Map json) = _$_ActivityReplyNotificationDto.fromJson; @@ -318,8 +334,8 @@ abstract class _ActivityReplyNotificationDto @JsonKey(name: 'activityId') int? get activityId; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; @@ -327,6 +343,9 @@ abstract class _ActivityReplyNotificationDto @JsonKey(name: 'user') UserDataDto? get user; @override + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity; + @override @JsonKey(ignore: true) _$$_ActivityReplyNotificationDtoCopyWith<_$_ActivityReplyNotificationDto> get copyWith => throw _privateConstructorUsedError; diff --git a/lib/core/network/model/activity_reply_notification_dto.g.dart b/lib/core/network/model/activity_reply_notification_dto.g.dart index e98f6df2..153df8a5 100644 --- a/lib/core/network/model/activity_reply_notification_dto.g.dart +++ b/lib/core/network/model/activity_reply_notification_dto.g.dart @@ -13,10 +13,7 @@ _$_ActivityReplyNotificationDto _$$_ActivityReplyNotificationDtoFromJson( type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), userId: json['userId'] as int?, activityId: json['activityId'] as int?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, user: json['user'] == null ? null @@ -30,7 +27,7 @@ Map _$$_ActivityReplyNotificationDtoToJson( 'type': _$NotificationTypeEnumMap[instance.type], 'userId': instance.userId, 'activityId': instance.activityId, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, 'user': instance.user, }; diff --git a/lib/core/network/model/activity_reply_subscription_notification_dto.dart b/lib/core/network/model/activity_reply_subscription_notification_dto.dart index 1c237a77..90b33a03 100644 --- a/lib/core/network/model/activity_reply_subscription_notification_dto.dart +++ b/lib/core/network/model/activity_reply_subscription_notification_dto.dart @@ -1,10 +1,10 @@ import 'package:aniflow/core/data/model/notification_type.dart'; +import 'package:aniflow/core/network/model/ani_activity.dart'; import 'package:aniflow/core/network/model/notification.dart'; import 'package:aniflow/core/network/model/user_data_dto.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'activity_reply_subscription_notification_dto.freezed.dart'; - part 'activity_reply_subscription_notification_dto.g.dart'; @freezed @@ -15,12 +15,21 @@ class ActivityReplySubscribedNotificationDto extends AniNotification @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity, }) = _ActivityReplySubscribedNotificationDto; factory ActivityReplySubscribedNotificationDto.fromJson( Map json) => _$$_ActivityReplySubscribedNotificationDtoFromJson(json); + + static ActivityReplySubscribedNotificationDto fromJsonWithActivity( + Map json) { + return ActivityReplySubscribedNotificationDto.fromJson(json).copyWith( + activity: AniActivity.mapToAniActivity(json['activity']), + ); + } } diff --git a/lib/core/network/model/activity_reply_subscription_notification_dto.freezed.dart b/lib/core/network/model/activity_reply_subscription_notification_dto.freezed.dart index 3f0f1767..635df3df 100644 --- a/lib/core/network/model/activity_reply_subscription_notification_dto.freezed.dart +++ b/lib/core/network/model/activity_reply_subscription_notification_dto.freezed.dart @@ -30,12 +30,14 @@ mixin _$ActivityReplySubscribedNotificationDto { int? get userId => throw _privateConstructorUsedError; @JsonKey(name: 'activityId') int? get activityId => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'user') UserDataDto? get user => throw _privateConstructorUsedError; + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -57,9 +59,11 @@ abstract class $ActivityReplySubscribedNotificationDtoCopyWith<$Res> { @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); $UserDataDtoCopyWith<$Res>? get user; } @@ -82,9 +86,10 @@ class _$ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res, Object? type = freezed, Object? userId = freezed, Object? activityId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_value.copyWith( id: null == id @@ -103,10 +108,10 @@ class _$ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res, ? _value.activityId : activityId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -115,6 +120,10 @@ class _$ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res, ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, ) as $Val); } @@ -145,9 +154,11 @@ abstract class _$$_ActivityReplySubscribedNotificationDtoCopyWith<$Res> @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, @JsonKey(name: 'activityId') int? activityId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, - @JsonKey(name: 'user') UserDataDto? user}); + @JsonKey(name: 'user') UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? activity}); @override $UserDataDtoCopyWith<$Res>? get user; @@ -170,9 +181,10 @@ class __$$_ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res> Object? type = freezed, Object? userId = freezed, Object? activityId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, + Object? activity = freezed, }) { return _then(_$_ActivityReplySubscribedNotificationDto( id: null == id @@ -191,10 +203,10 @@ class __$$_ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res> ? _value.activityId : activityId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -203,6 +215,10 @@ class __$$_ActivityReplySubscribedNotificationDtoCopyWithImpl<$Res> ? _value.user : user // ignore: cast_nullable_to_non_nullable as UserDataDto?, + activity: freezed == activity + ? _value.activity + : activity // ignore: cast_nullable_to_non_nullable + as AniActivity?, )); } } @@ -216,10 +232,10 @@ class _$_ActivityReplySubscribedNotificationDto @JsonKey(name: 'type') this.type, @JsonKey(name: 'userId') this.userId, @JsonKey(name: 'activityId') this.activityId, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'createdAt') this.createdAt, - @JsonKey(name: 'user') this.user}) - : _contexts = contexts; + @JsonKey(name: 'user') this.user, + @JsonKey(includeFromJson: false, includeToJson: false) this.activity}); factory _$_ActivityReplySubscribedNotificationDto.fromJson( Map json) => @@ -237,25 +253,22 @@ class _$_ActivityReplySubscribedNotificationDto @override @JsonKey(name: 'activityId') final int? activityId; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @override @JsonKey(name: 'user') final UserDataDto? user; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity; @override String toString() { - return 'ActivityReplySubscribedNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + return 'ActivityReplySubscribedNotificationDto(id: $id, type: $type, userId: $userId, activityId: $activityId, context: $context, createdAt: $createdAt, user: $user, activity: $activity)'; } @override @@ -268,16 +281,18 @@ class _$_ActivityReplySubscribedNotificationDto (identical(other.userId, userId) || other.userId == userId) && (identical(other.activityId, activityId) || other.activityId == activityId) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt) && - (identical(other.user, user) || other.user == user)); + (identical(other.user, user) || other.user == user) && + (identical(other.activity, activity) || + other.activity == activity)); } @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, id, type, userId, activityId, - const DeepCollectionEquality().hash(_contexts), createdAt, user); + context, createdAt, user, activity); @JsonKey(ignore: true) @override @@ -298,14 +313,15 @@ class _$_ActivityReplySubscribedNotificationDto abstract class _ActivityReplySubscribedNotificationDto implements ActivityReplySubscribedNotificationDto { factory _ActivityReplySubscribedNotificationDto( - {@JsonKey(name: 'id') final int id, - @JsonKey(name: 'type') final NotificationType? type, - @JsonKey(name: 'userId') final int? userId, - @JsonKey(name: 'activityId') final int? activityId, - @JsonKey(name: 'contexts') final List contexts, - @JsonKey(name: 'createdAt') final int? createdAt, - @JsonKey(name: 'user') final UserDataDto? user}) = - _$_ActivityReplySubscribedNotificationDto; + {@JsonKey(name: 'id') final int id, + @JsonKey(name: 'type') final NotificationType? type, + @JsonKey(name: 'userId') final int? userId, + @JsonKey(name: 'activityId') final int? activityId, + @JsonKey(name: 'context') final String? context, + @JsonKey(name: 'createdAt') final int? createdAt, + @JsonKey(name: 'user') final UserDataDto? user, + @JsonKey(includeFromJson: false, includeToJson: false) + final AniActivity? activity}) = _$_ActivityReplySubscribedNotificationDto; factory _ActivityReplySubscribedNotificationDto.fromJson( Map json) = @@ -324,8 +340,8 @@ abstract class _ActivityReplySubscribedNotificationDto @JsonKey(name: 'activityId') int? get activityId; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; @@ -333,6 +349,9 @@ abstract class _ActivityReplySubscribedNotificationDto @JsonKey(name: 'user') UserDataDto? get user; @override + @JsonKey(includeFromJson: false, includeToJson: false) + AniActivity? get activity; + @override @JsonKey(ignore: true) _$$_ActivityReplySubscribedNotificationDtoCopyWith< _$_ActivityReplySubscribedNotificationDto> diff --git a/lib/core/network/model/activity_reply_subscription_notification_dto.g.dart b/lib/core/network/model/activity_reply_subscription_notification_dto.g.dart index b4d2e7e9..67f98faa 100644 --- a/lib/core/network/model/activity_reply_subscription_notification_dto.g.dart +++ b/lib/core/network/model/activity_reply_subscription_notification_dto.g.dart @@ -14,10 +14,7 @@ _$_ActivityReplySubscribedNotificationDto type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), userId: json['userId'] as int?, activityId: json['activityId'] as int?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, user: json['user'] == null ? null @@ -31,7 +28,7 @@ Map _$$_ActivityReplySubscribedNotificationDtoToJson( 'type': _$NotificationTypeEnumMap[instance.type], 'userId': instance.userId, 'activityId': instance.activityId, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, 'user': instance.user, }; diff --git a/lib/core/network/model/following_notification_dto.dart b/lib/core/network/model/following_notification_dto.dart index 613417f7..422196e6 100644 --- a/lib/core/network/model/following_notification_dto.dart +++ b/lib/core/network/model/following_notification_dto.dart @@ -14,7 +14,7 @@ class FollowingNotificationDto extends AniNotification @Default(-1) @JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'user') UserDataDto? user, }) = _FollowingNotificationDto; diff --git a/lib/core/network/model/following_notification_dto.freezed.dart b/lib/core/network/model/following_notification_dto.freezed.dart index 30ade0fe..621aefca 100644 --- a/lib/core/network/model/following_notification_dto.freezed.dart +++ b/lib/core/network/model/following_notification_dto.freezed.dart @@ -27,8 +27,8 @@ mixin _$FollowingNotificationDto { NotificationType? get type => throw _privateConstructorUsedError; @JsonKey(name: 'userId') int? get userId => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'user') @@ -50,7 +50,7 @@ abstract class $FollowingNotificationDtoCopyWith<$Res> { {@JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'user') UserDataDto? user}); @@ -74,7 +74,7 @@ class _$FollowingNotificationDtoCopyWithImpl<$Res, Object? id = null, Object? type = freezed, Object? userId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, }) { @@ -91,10 +91,10 @@ class _$FollowingNotificationDtoCopyWithImpl<$Res, ? _value.userId : userId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -132,7 +132,7 @@ abstract class _$$_FollowingNotificationDtoCopyWith<$Res> {@JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'userId') int? userId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'user') UserDataDto? user}); @@ -155,7 +155,7 @@ class __$$_FollowingNotificationDtoCopyWithImpl<$Res> Object? id = null, Object? type = freezed, Object? userId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? user = freezed, }) { @@ -172,10 +172,10 @@ class __$$_FollowingNotificationDtoCopyWithImpl<$Res> ? _value.userId : userId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -195,10 +195,9 @@ class _$_FollowingNotificationDto implements _FollowingNotificationDto { {@JsonKey(name: 'id') this.id = -1, @JsonKey(name: 'type') this.type, @JsonKey(name: 'userId') this.userId, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'createdAt') this.createdAt, - @JsonKey(name: 'user') this.user}) - : _contexts = contexts; + @JsonKey(name: 'user') this.user}); factory _$_FollowingNotificationDto.fromJson(Map json) => _$$_FollowingNotificationDtoFromJson(json); @@ -212,15 +211,9 @@ class _$_FollowingNotificationDto implements _FollowingNotificationDto { @override @JsonKey(name: 'userId') final int? userId; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @@ -230,7 +223,7 @@ class _$_FollowingNotificationDto implements _FollowingNotificationDto { @override String toString() { - return 'FollowingNotificationDto(id: $id, type: $type, userId: $userId, contexts: $contexts, createdAt: $createdAt, user: $user)'; + return 'FollowingNotificationDto(id: $id, type: $type, userId: $userId, context: $context, createdAt: $createdAt, user: $user)'; } @override @@ -241,7 +234,7 @@ class _$_FollowingNotificationDto implements _FollowingNotificationDto { (identical(other.id, id) || other.id == id) && (identical(other.type, type) || other.type == type) && (identical(other.userId, userId) || other.userId == userId) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt) && (identical(other.user, user) || other.user == user)); @@ -249,8 +242,8 @@ class _$_FollowingNotificationDto implements _FollowingNotificationDto { @JsonKey(ignore: true) @override - int get hashCode => Object.hash(runtimeType, id, type, userId, - const DeepCollectionEquality().hash(_contexts), createdAt, user); + int get hashCode => + Object.hash(runtimeType, id, type, userId, context, createdAt, user); @JsonKey(ignore: true) @override @@ -272,7 +265,7 @@ abstract class _FollowingNotificationDto implements FollowingNotificationDto { {@JsonKey(name: 'id') final int id, @JsonKey(name: 'type') final NotificationType? type, @JsonKey(name: 'userId') final int? userId, - @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'context') final String? context, @JsonKey(name: 'createdAt') final int? createdAt, @JsonKey(name: 'user') final UserDataDto? user}) = _$_FollowingNotificationDto; @@ -290,8 +283,8 @@ abstract class _FollowingNotificationDto implements FollowingNotificationDto { @JsonKey(name: 'userId') int? get userId; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; diff --git a/lib/core/network/model/following_notification_dto.g.dart b/lib/core/network/model/following_notification_dto.g.dart index cce3e193..40686e48 100644 --- a/lib/core/network/model/following_notification_dto.g.dart +++ b/lib/core/network/model/following_notification_dto.g.dart @@ -12,10 +12,7 @@ _$_FollowingNotificationDto _$$_FollowingNotificationDtoFromJson( id: json['id'] as int? ?? -1, type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), userId: json['userId'] as int?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, user: json['user'] == null ? null @@ -28,7 +25,7 @@ Map _$$_FollowingNotificationDtoToJson( 'id': instance.id, 'type': _$NotificationTypeEnumMap[instance.type], 'userId': instance.userId, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, 'user': instance.user, }; diff --git a/lib/core/network/model/media_data_change_notification_dto.dart b/lib/core/network/model/media_data_change_notification_dto.dart index c458a7a4..a61b2281 100644 --- a/lib/core/network/model/media_data_change_notification_dto.dart +++ b/lib/core/network/model/media_data_change_notification_dto.dart @@ -14,7 +14,7 @@ class MediaDataChangeNotificationDto extends AniNotification @Default(-1) @JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') int? mediaId, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'reason') String? reason, @JsonKey(name: 'media') MediaDto? media, diff --git a/lib/core/network/model/media_data_change_notification_dto.freezed.dart b/lib/core/network/model/media_data_change_notification_dto.freezed.dart index 0b68e2b3..78cdf010 100644 --- a/lib/core/network/model/media_data_change_notification_dto.freezed.dart +++ b/lib/core/network/model/media_data_change_notification_dto.freezed.dart @@ -27,8 +27,8 @@ mixin _$MediaDataChangeNotificationDto { NotificationType? get type => throw _privateConstructorUsedError; @JsonKey(name: 'mediaId') int? get mediaId => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'reason') @@ -54,7 +54,7 @@ abstract class $MediaDataChangeNotificationDtoCopyWith<$Res> { {@JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') int? mediaId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'reason') String? reason, @JsonKey(name: 'media') MediaDto? media}); @@ -79,7 +79,7 @@ class _$MediaDataChangeNotificationDtoCopyWithImpl<$Res, Object? id = null, Object? type = freezed, Object? mediaId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? reason = freezed, Object? media = freezed, @@ -97,10 +97,10 @@ class _$MediaDataChangeNotificationDtoCopyWithImpl<$Res, ? _value.mediaId : mediaId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -142,7 +142,7 @@ abstract class _$$_MediaDataChangeNotificationDtoCopyWith<$Res> {@JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') int? mediaId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'reason') String? reason, @JsonKey(name: 'media') MediaDto? media}); @@ -167,7 +167,7 @@ class __$$_MediaDataChangeNotificationDtoCopyWithImpl<$Res> Object? id = null, Object? type = freezed, Object? mediaId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? reason = freezed, Object? media = freezed, @@ -185,10 +185,10 @@ class __$$_MediaDataChangeNotificationDtoCopyWithImpl<$Res> ? _value.mediaId : mediaId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -213,11 +213,10 @@ class _$_MediaDataChangeNotificationDto {@JsonKey(name: 'id') this.id = -1, @JsonKey(name: 'type') this.type, @JsonKey(name: 'mediaId') this.mediaId, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'createdAt') this.createdAt, @JsonKey(name: 'reason') this.reason, - @JsonKey(name: 'media') this.media}) - : _contexts = contexts; + @JsonKey(name: 'media') this.media}); factory _$_MediaDataChangeNotificationDto.fromJson( Map json) => @@ -232,15 +231,9 @@ class _$_MediaDataChangeNotificationDto @override @JsonKey(name: 'mediaId') final int? mediaId; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @@ -253,7 +246,7 @@ class _$_MediaDataChangeNotificationDto @override String toString() { - return 'MediaDataChangeNotificationDto(id: $id, type: $type, mediaId: $mediaId, contexts: $contexts, createdAt: $createdAt, reason: $reason, media: $media)'; + return 'MediaDataChangeNotificationDto(id: $id, type: $type, mediaId: $mediaId, context: $context, createdAt: $createdAt, reason: $reason, media: $media)'; } @override @@ -264,7 +257,7 @@ class _$_MediaDataChangeNotificationDto (identical(other.id, id) || other.id == id) && (identical(other.type, type) || other.type == type) && (identical(other.mediaId, mediaId) || other.mediaId == mediaId) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt) && (identical(other.reason, reason) || other.reason == reason) && @@ -273,8 +266,8 @@ class _$_MediaDataChangeNotificationDto @JsonKey(ignore: true) @override - int get hashCode => Object.hash(runtimeType, id, type, mediaId, - const DeepCollectionEquality().hash(_contexts), createdAt, reason, media); + int get hashCode => Object.hash( + runtimeType, id, type, mediaId, context, createdAt, reason, media); @JsonKey(ignore: true) @override @@ -297,7 +290,7 @@ abstract class _MediaDataChangeNotificationDto {@JsonKey(name: 'id') final int id, @JsonKey(name: 'type') final NotificationType? type, @JsonKey(name: 'mediaId') final int? mediaId, - @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'context') final String? context, @JsonKey(name: 'createdAt') final int? createdAt, @JsonKey(name: 'reason') final String? reason, @JsonKey(name: 'media') final MediaDto? media}) = @@ -316,8 +309,8 @@ abstract class _MediaDataChangeNotificationDto @JsonKey(name: 'mediaId') int? get mediaId; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; diff --git a/lib/core/network/model/media_data_change_notification_dto.g.dart b/lib/core/network/model/media_data_change_notification_dto.g.dart index f485f900..4499e388 100644 --- a/lib/core/network/model/media_data_change_notification_dto.g.dart +++ b/lib/core/network/model/media_data_change_notification_dto.g.dart @@ -12,10 +12,7 @@ _$_MediaDataChangeNotificationDto _$$_MediaDataChangeNotificationDtoFromJson( id: json['id'] as int? ?? -1, type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), mediaId: json['mediaId'] as int?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, reason: json['reason'] as String?, media: json['media'] == null @@ -29,7 +26,7 @@ Map _$$_MediaDataChangeNotificationDtoToJson( 'id': instance.id, 'type': _$NotificationTypeEnumMap[instance.type], 'mediaId': instance.mediaId, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, 'reason': instance.reason, 'media': instance.media, diff --git a/lib/core/network/model/media_deletion_notification_dto.dart b/lib/core/network/model/media_deletion_notification_dto.dart index 9fa3c01b..9305e75e 100644 --- a/lib/core/network/model/media_deletion_notification_dto.dart +++ b/lib/core/network/model/media_deletion_notification_dto.dart @@ -14,7 +14,7 @@ class MediaDeletionNotificationDto extends AniNotification @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'deletedMediaTitle') String? deletedMediaTitle, @JsonKey(name: 'reason') String? reason, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, }) = _MediaDeletionNotificationDto; diff --git a/lib/core/network/model/media_deletion_notification_dto.freezed.dart b/lib/core/network/model/media_deletion_notification_dto.freezed.dart index 54a928ef..6d05e518 100644 --- a/lib/core/network/model/media_deletion_notification_dto.freezed.dart +++ b/lib/core/network/model/media_deletion_notification_dto.freezed.dart @@ -29,8 +29,8 @@ mixin _$MediaDeletionNotificationDto { String? get deletedMediaTitle => throw _privateConstructorUsedError; @JsonKey(name: 'reason') String? get reason => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @@ -53,7 +53,7 @@ abstract class $MediaDeletionNotificationDtoCopyWith<$Res> { @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'deletedMediaTitle') String? deletedMediaTitle, @JsonKey(name: 'reason') String? reason, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt}); } @@ -75,7 +75,7 @@ class _$MediaDeletionNotificationDtoCopyWithImpl<$Res, Object? type = freezed, Object? deletedMediaTitle = freezed, Object? reason = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, }) { return _then(_value.copyWith( @@ -95,10 +95,10 @@ class _$MediaDeletionNotificationDtoCopyWithImpl<$Res, ? _value.reason : reason // ignore: cast_nullable_to_non_nullable as String?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -121,7 +121,7 @@ abstract class _$$_MediaDeletionNotificationDtoCopyWith<$Res> @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'deletedMediaTitle') String? deletedMediaTitle, @JsonKey(name: 'reason') String? reason, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt}); } @@ -142,7 +142,7 @@ class __$$_MediaDeletionNotificationDtoCopyWithImpl<$Res> Object? type = freezed, Object? deletedMediaTitle = freezed, Object? reason = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, }) { return _then(_$_MediaDeletionNotificationDto( @@ -162,10 +162,10 @@ class __$$_MediaDeletionNotificationDtoCopyWithImpl<$Res> ? _value.reason : reason // ignore: cast_nullable_to_non_nullable as String?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -182,9 +182,8 @@ class _$_MediaDeletionNotificationDto implements _MediaDeletionNotificationDto { @JsonKey(name: 'type') this.type, @JsonKey(name: 'deletedMediaTitle') this.deletedMediaTitle, @JsonKey(name: 'reason') this.reason, - @JsonKey(name: 'contexts') final List contexts = const [], - @JsonKey(name: 'createdAt') this.createdAt}) - : _contexts = contexts; + @JsonKey(name: 'context') this.context, + @JsonKey(name: 'createdAt') this.createdAt}); factory _$_MediaDeletionNotificationDto.fromJson(Map json) => _$$_MediaDeletionNotificationDtoFromJson(json); @@ -201,22 +200,16 @@ class _$_MediaDeletionNotificationDto implements _MediaDeletionNotificationDto { @override @JsonKey(name: 'reason') final String? reason; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @override String toString() { - return 'MediaDeletionNotificationDto(id: $id, type: $type, deletedMediaTitle: $deletedMediaTitle, reason: $reason, contexts: $contexts, createdAt: $createdAt)'; + return 'MediaDeletionNotificationDto(id: $id, type: $type, deletedMediaTitle: $deletedMediaTitle, reason: $reason, context: $context, createdAt: $createdAt)'; } @override @@ -229,15 +222,15 @@ class _$_MediaDeletionNotificationDto implements _MediaDeletionNotificationDto { (identical(other.deletedMediaTitle, deletedMediaTitle) || other.deletedMediaTitle == deletedMediaTitle) && (identical(other.reason, reason) || other.reason == reason) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt)); } @JsonKey(ignore: true) @override - int get hashCode => Object.hash(runtimeType, id, type, deletedMediaTitle, - reason, const DeepCollectionEquality().hash(_contexts), createdAt); + int get hashCode => Object.hash( + runtimeType, id, type, deletedMediaTitle, reason, context, createdAt); @JsonKey(ignore: true) @override @@ -261,7 +254,7 @@ abstract class _MediaDeletionNotificationDto @JsonKey(name: 'type') final NotificationType? type, @JsonKey(name: 'deletedMediaTitle') final String? deletedMediaTitle, @JsonKey(name: 'reason') final String? reason, - @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'context') final String? context, @JsonKey(name: 'createdAt') final int? createdAt}) = _$_MediaDeletionNotificationDto; @@ -281,8 +274,8 @@ abstract class _MediaDeletionNotificationDto @JsonKey(name: 'reason') String? get reason; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; diff --git a/lib/core/network/model/media_deletion_notification_dto.g.dart b/lib/core/network/model/media_deletion_notification_dto.g.dart index 196fedca..53a244bc 100644 --- a/lib/core/network/model/media_deletion_notification_dto.g.dart +++ b/lib/core/network/model/media_deletion_notification_dto.g.dart @@ -13,10 +13,7 @@ _$_MediaDeletionNotificationDto _$$_MediaDeletionNotificationDtoFromJson( type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), deletedMediaTitle: json['deletedMediaTitle'] as String?, reason: json['reason'] as String?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, ); @@ -27,7 +24,7 @@ Map _$$_MediaDeletionNotificationDtoToJson( 'type': _$NotificationTypeEnumMap[instance.type], 'deletedMediaTitle': instance.deletedMediaTitle, 'reason': instance.reason, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, }; diff --git a/lib/core/network/model/media_merge_notification_dto.dart b/lib/core/network/model/media_merge_notification_dto.dart index 65eafc8a..6b3359c6 100644 --- a/lib/core/network/model/media_merge_notification_dto.dart +++ b/lib/core/network/model/media_merge_notification_dto.dart @@ -15,8 +15,9 @@ class MediaMergeNotificationDto extends AniNotification @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') String? mediaId, @JsonKey(name: 'deletedMediaTitle') List? deletedMediaTitle, + @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'reason') String? reason, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'media') MediaDto? media, }) = _MediaMergeNotificationDto; diff --git a/lib/core/network/model/media_merge_notification_dto.freezed.dart b/lib/core/network/model/media_merge_notification_dto.freezed.dart index 24eca7f3..1c8d92fd 100644 --- a/lib/core/network/model/media_merge_notification_dto.freezed.dart +++ b/lib/core/network/model/media_merge_notification_dto.freezed.dart @@ -29,10 +29,12 @@ mixin _$MediaMergeNotificationDto { String? get mediaId => throw _privateConstructorUsedError; @JsonKey(name: 'deletedMediaTitle') List? get deletedMediaTitle => throw _privateConstructorUsedError; + @JsonKey(name: 'createdAt') + int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'reason') String? get reason => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'media') MediaDto? get media => throw _privateConstructorUsedError; @@ -53,8 +55,9 @@ abstract class $MediaMergeNotificationDtoCopyWith<$Res> { @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') String? mediaId, @JsonKey(name: 'deletedMediaTitle') List? deletedMediaTitle, + @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'reason') String? reason, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'media') MediaDto? media}); $MediaDtoCopyWith<$Res>? get media; @@ -78,8 +81,9 @@ class _$MediaMergeNotificationDtoCopyWithImpl<$Res, Object? type = freezed, Object? mediaId = freezed, Object? deletedMediaTitle = freezed, + Object? createdAt = freezed, Object? reason = freezed, - Object? contexts = null, + Object? context = freezed, Object? media = freezed, }) { return _then(_value.copyWith( @@ -99,14 +103,18 @@ class _$MediaMergeNotificationDtoCopyWithImpl<$Res, ? _value.deletedMediaTitle : deletedMediaTitle // ignore: cast_nullable_to_non_nullable as List?, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, reason: freezed == reason ? _value.reason : reason // ignore: cast_nullable_to_non_nullable as String?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, media: freezed == media ? _value.media : media // ignore: cast_nullable_to_non_nullable @@ -141,8 +149,9 @@ abstract class _$$_MediaMergeNotificationDtoCopyWith<$Res> @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') String? mediaId, @JsonKey(name: 'deletedMediaTitle') List? deletedMediaTitle, + @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'reason') String? reason, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'media') MediaDto? media}); @override @@ -166,8 +175,9 @@ class __$$_MediaMergeNotificationDtoCopyWithImpl<$Res> Object? type = freezed, Object? mediaId = freezed, Object? deletedMediaTitle = freezed, + Object? createdAt = freezed, Object? reason = freezed, - Object? contexts = null, + Object? context = freezed, Object? media = freezed, }) { return _then(_$_MediaMergeNotificationDto( @@ -187,14 +197,18 @@ class __$$_MediaMergeNotificationDtoCopyWithImpl<$Res> ? _value._deletedMediaTitle : deletedMediaTitle // ignore: cast_nullable_to_non_nullable as List?, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as int?, reason: freezed == reason ? _value.reason : reason // ignore: cast_nullable_to_non_nullable as String?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, media: freezed == media ? _value.media : media // ignore: cast_nullable_to_non_nullable @@ -211,11 +225,11 @@ class _$_MediaMergeNotificationDto implements _MediaMergeNotificationDto { @JsonKey(name: 'type') this.type, @JsonKey(name: 'mediaId') this.mediaId, @JsonKey(name: 'deletedMediaTitle') final List? deletedMediaTitle, + @JsonKey(name: 'createdAt') this.createdAt, @JsonKey(name: 'reason') this.reason, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'media') this.media}) - : _deletedMediaTitle = deletedMediaTitle, - _contexts = contexts; + : _deletedMediaTitle = deletedMediaTitle; factory _$_MediaMergeNotificationDto.fromJson(Map json) => _$$_MediaMergeNotificationDtoFromJson(json); @@ -241,25 +255,22 @@ class _$_MediaMergeNotificationDto implements _MediaMergeNotificationDto { return EqualUnmodifiableListView(value); } + @override + @JsonKey(name: 'createdAt') + final int? createdAt; @override @JsonKey(name: 'reason') final String? reason; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'media') final MediaDto? media; @override String toString() { - return 'MediaMergeNotificationDto(id: $id, type: $type, mediaId: $mediaId, deletedMediaTitle: $deletedMediaTitle, reason: $reason, contexts: $contexts, media: $media)'; + return 'MediaMergeNotificationDto(id: $id, type: $type, mediaId: $mediaId, deletedMediaTitle: $deletedMediaTitle, createdAt: $createdAt, reason: $reason, context: $context, media: $media)'; } @override @@ -272,8 +283,10 @@ class _$_MediaMergeNotificationDto implements _MediaMergeNotificationDto { (identical(other.mediaId, mediaId) || other.mediaId == mediaId) && const DeepCollectionEquality() .equals(other._deletedMediaTitle, _deletedMediaTitle) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && (identical(other.reason, reason) || other.reason == reason) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.media, media) || other.media == media)); } @@ -285,8 +298,9 @@ class _$_MediaMergeNotificationDto implements _MediaMergeNotificationDto { type, mediaId, const DeepCollectionEquality().hash(_deletedMediaTitle), + createdAt, reason, - const DeepCollectionEquality().hash(_contexts), + context, media); @JsonKey(ignore: true) @@ -310,8 +324,9 @@ abstract class _MediaMergeNotificationDto implements MediaMergeNotificationDto { @JsonKey(name: 'type') final NotificationType? type, @JsonKey(name: 'mediaId') final String? mediaId, @JsonKey(name: 'deletedMediaTitle') final List? deletedMediaTitle, + @JsonKey(name: 'createdAt') final int? createdAt, @JsonKey(name: 'reason') final String? reason, - @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'context') final String? context, @JsonKey(name: 'media') final MediaDto? media}) = _$_MediaMergeNotificationDto; @@ -331,11 +346,14 @@ abstract class _MediaMergeNotificationDto implements MediaMergeNotificationDto { @JsonKey(name: 'deletedMediaTitle') List? get deletedMediaTitle; @override + @JsonKey(name: 'createdAt') + int? get createdAt; + @override @JsonKey(name: 'reason') String? get reason; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'media') MediaDto? get media; diff --git a/lib/core/network/model/media_merge_notification_dto.g.dart b/lib/core/network/model/media_merge_notification_dto.g.dart index 2d691e01..26ce55fb 100644 --- a/lib/core/network/model/media_merge_notification_dto.g.dart +++ b/lib/core/network/model/media_merge_notification_dto.g.dart @@ -15,11 +15,9 @@ _$_MediaMergeNotificationDto _$$_MediaMergeNotificationDtoFromJson( deletedMediaTitle: (json['deletedMediaTitle'] as List?) ?.map((e) => e as String) .toList(), + createdAt: json['createdAt'] as int?, reason: json['reason'] as String?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, media: json['media'] == null ? null : MediaDto.fromJson(json['media'] as Map), @@ -32,8 +30,9 @@ Map _$$_MediaMergeNotificationDtoToJson( 'type': _$NotificationTypeEnumMap[instance.type], 'mediaId': instance.mediaId, 'deletedMediaTitle': instance.deletedMediaTitle, + 'createdAt': instance.createdAt, 'reason': instance.reason, - 'contexts': instance.contexts, + 'context': instance.context, 'media': instance.media, }; diff --git a/lib/core/network/model/notification.dart b/lib/core/network/model/notification.dart index 154ab35d..e9c9de5c 100644 --- a/lib/core/network/model/notification.dart +++ b/lib/core/network/model/notification.dart @@ -14,7 +14,7 @@ abstract class AniNotification { static AniNotification mapToAniNotification(Map jsonMap) { switch (jsonMap['__typename']) { case 'ActivityLikeNotification': - return ActivityLikeNotificationDto.fromJson(jsonMap); + return ActivityLikeNotificationDto.fromJsonWithActivity(jsonMap); case 'AiringNotification': return AiringNotificationDto.fromJson(jsonMap); case 'FollowingNotification': @@ -28,13 +28,14 @@ abstract class AniNotification { case 'MediaMergeNotification': return MediaMergeNotificationDto.fromJson(jsonMap); case 'ActivityReplyNotification': - return ActivityReplyNotificationDto.fromJson(jsonMap); + return ActivityReplyNotificationDto.fromJsonWithActivity(jsonMap); case 'ActivityReplyLikeNotification': - return ActivityReplyLikeNotificationDto.fromJson(jsonMap); + return ActivityReplyLikeNotificationDto.fromJsonWithActivity(jsonMap); case 'ActivityReplySubscribedNotification': - return ActivityReplySubscribedNotificationDto.fromJson(jsonMap); + return ActivityReplySubscribedNotificationDto.fromJsonWithActivity( + jsonMap); case 'ActivityMessageNotification': - return ActivityMessageNotificationDto.fromJson(jsonMap); + return ActivityMessageNotificationDto.fromJsonWithActivity(jsonMap); } throw Exception('InvalidType'); diff --git a/lib/core/network/model/related_media_addition_notification_dto.dart b/lib/core/network/model/related_media_addition_notification_dto.dart index 9e3c6d0e..42cffdeb 100644 --- a/lib/core/network/model/related_media_addition_notification_dto.dart +++ b/lib/core/network/model/related_media_addition_notification_dto.dart @@ -14,7 +14,7 @@ class RelatedMediaAdditionNotificationDto extends AniNotification @Default(-1) @JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') int? mediaId, - @Default([]) @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'media') MediaDto? media, }) = _RelatedMediaAdditionNotificationDto; diff --git a/lib/core/network/model/related_media_addition_notification_dto.freezed.dart b/lib/core/network/model/related_media_addition_notification_dto.freezed.dart index f7f82844..f0471bca 100644 --- a/lib/core/network/model/related_media_addition_notification_dto.freezed.dart +++ b/lib/core/network/model/related_media_addition_notification_dto.freezed.dart @@ -27,8 +27,8 @@ mixin _$RelatedMediaAdditionNotificationDto { NotificationType? get type => throw _privateConstructorUsedError; @JsonKey(name: 'mediaId') int? get mediaId => throw _privateConstructorUsedError; - @JsonKey(name: 'contexts') - List get contexts => throw _privateConstructorUsedError; + @JsonKey(name: 'context') + String? get context => throw _privateConstructorUsedError; @JsonKey(name: 'createdAt') int? get createdAt => throw _privateConstructorUsedError; @JsonKey(name: 'media') @@ -53,7 +53,7 @@ abstract class $RelatedMediaAdditionNotificationDtoCopyWith<$Res> { {@JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') int? mediaId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'media') MediaDto? media}); @@ -77,7 +77,7 @@ class _$RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res, Object? id = null, Object? type = freezed, Object? mediaId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? media = freezed, }) { @@ -94,10 +94,10 @@ class _$RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res, ? _value.mediaId : mediaId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value.contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -135,7 +135,7 @@ abstract class _$$_RelatedMediaAdditionNotificationDtoCopyWith<$Res> {@JsonKey(name: 'id') int id, @JsonKey(name: 'type') NotificationType? type, @JsonKey(name: 'mediaId') int? mediaId, - @JsonKey(name: 'contexts') List contexts, + @JsonKey(name: 'context') String? context, @JsonKey(name: 'createdAt') int? createdAt, @JsonKey(name: 'media') MediaDto? media}); @@ -159,7 +159,7 @@ class __$$_RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res> Object? id = null, Object? type = freezed, Object? mediaId = freezed, - Object? contexts = null, + Object? context = freezed, Object? createdAt = freezed, Object? media = freezed, }) { @@ -176,10 +176,10 @@ class __$$_RelatedMediaAdditionNotificationDtoCopyWithImpl<$Res> ? _value.mediaId : mediaId // ignore: cast_nullable_to_non_nullable as int?, - contexts: null == contexts - ? _value._contexts - : contexts // ignore: cast_nullable_to_non_nullable - as List, + context: freezed == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as String?, createdAt: freezed == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -200,10 +200,9 @@ class _$_RelatedMediaAdditionNotificationDto {@JsonKey(name: 'id') this.id = -1, @JsonKey(name: 'type') this.type, @JsonKey(name: 'mediaId') this.mediaId, - @JsonKey(name: 'contexts') final List contexts = const [], + @JsonKey(name: 'context') this.context, @JsonKey(name: 'createdAt') this.createdAt, - @JsonKey(name: 'media') this.media}) - : _contexts = contexts; + @JsonKey(name: 'media') this.media}); factory _$_RelatedMediaAdditionNotificationDto.fromJson( Map json) => @@ -218,15 +217,9 @@ class _$_RelatedMediaAdditionNotificationDto @override @JsonKey(name: 'mediaId') final int? mediaId; - final List _contexts; @override - @JsonKey(name: 'contexts') - List get contexts { - if (_contexts is EqualUnmodifiableListView) return _contexts; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_contexts); - } - + @JsonKey(name: 'context') + final String? context; @override @JsonKey(name: 'createdAt') final int? createdAt; @@ -236,7 +229,7 @@ class _$_RelatedMediaAdditionNotificationDto @override String toString() { - return 'RelatedMediaAdditionNotificationDto(id: $id, type: $type, mediaId: $mediaId, contexts: $contexts, createdAt: $createdAt, media: $media)'; + return 'RelatedMediaAdditionNotificationDto(id: $id, type: $type, mediaId: $mediaId, context: $context, createdAt: $createdAt, media: $media)'; } @override @@ -247,7 +240,7 @@ class _$_RelatedMediaAdditionNotificationDto (identical(other.id, id) || other.id == id) && (identical(other.type, type) || other.type == type) && (identical(other.mediaId, mediaId) || other.mediaId == mediaId) && - const DeepCollectionEquality().equals(other._contexts, _contexts) && + (identical(other.context, context) || other.context == context) && (identical(other.createdAt, createdAt) || other.createdAt == createdAt) && (identical(other.media, media) || other.media == media)); @@ -255,8 +248,8 @@ class _$_RelatedMediaAdditionNotificationDto @JsonKey(ignore: true) @override - int get hashCode => Object.hash(runtimeType, id, type, mediaId, - const DeepCollectionEquality().hash(_contexts), createdAt, media); + int get hashCode => + Object.hash(runtimeType, id, type, mediaId, context, createdAt, media); @JsonKey(ignore: true) @override @@ -280,7 +273,7 @@ abstract class _RelatedMediaAdditionNotificationDto {@JsonKey(name: 'id') final int id, @JsonKey(name: 'type') final NotificationType? type, @JsonKey(name: 'mediaId') final int? mediaId, - @JsonKey(name: 'contexts') final List contexts, + @JsonKey(name: 'context') final String? context, @JsonKey(name: 'createdAt') final int? createdAt, @JsonKey(name: 'media') final MediaDto? media}) = _$_RelatedMediaAdditionNotificationDto; @@ -299,8 +292,8 @@ abstract class _RelatedMediaAdditionNotificationDto @JsonKey(name: 'mediaId') int? get mediaId; @override - @JsonKey(name: 'contexts') - List get contexts; + @JsonKey(name: 'context') + String? get context; @override @JsonKey(name: 'createdAt') int? get createdAt; diff --git a/lib/core/network/model/related_media_addition_notification_dto.g.dart b/lib/core/network/model/related_media_addition_notification_dto.g.dart index f8c349e7..1e0aff30 100644 --- a/lib/core/network/model/related_media_addition_notification_dto.g.dart +++ b/lib/core/network/model/related_media_addition_notification_dto.g.dart @@ -13,10 +13,7 @@ _$_RelatedMediaAdditionNotificationDto id: json['id'] as int? ?? -1, type: $enumDecodeNullable(_$NotificationTypeEnumMap, json['type']), mediaId: json['mediaId'] as int?, - contexts: (json['contexts'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + context: json['context'] as String?, createdAt: json['createdAt'] as int?, media: json['media'] == null ? null @@ -29,7 +26,7 @@ Map _$$_RelatedMediaAdditionNotificationDtoToJson( 'id': instance.id, 'type': _$NotificationTypeEnumMap[instance.type], 'mediaId': instance.mediaId, - 'contexts': instance.contexts, + 'context': instance.context, 'createdAt': instance.createdAt, 'media': instance.media, }; diff --git a/test/core/data/repository/media_list_repository_test.dart b/test/core/data/repository/media_list_repository_test.dart index 3fc3ed7e..eec580e3 100644 --- a/test/core/data/repository/media_list_repository_test.dart +++ b/test/core/data/repository/media_list_repository_test.dart @@ -28,8 +28,6 @@ void main() { repository = MediaListRepositoryImpl(); isUnitTest = true; - testToken = - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2In0.eyJhdWQiOiIxNDQwOSIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2IiwiaWF0IjoxNjk4NTY2MzU0LCJuYmYiOjE2OTg1NjYzNTQsImV4cCI6MTczMDE4ODc1NCwic3ViIjoiNjM3ODM5MyIsInNjb3BlcyI6W119.cjnTU0bSGzQnjxbAy-wkzRqiI5r2zAI_XmOX8teX0MZuceDj7qiBQQ6An-p6Ue30LYSI7V5Tw4ocChZn1bRsg6sRFCPAmE8eBbV4XBGjOhlAb9ciqMgTmVeND6bz0uWO1lr3D0fLfmQKPchrZAwb1-aVDhMkI3Ba4bC1VzxfbGPpw3IzbXjbAg1kFStENCvn3fTXTX53ndNGuPlbS6l8tfOlgYSK7dm0le4JrJAEIlm_Om4WYb6ij42sI0WK1pJY5Lzpar-K0KxaubN9poNKXa81PX65DABzywHXrEi8_D7_O_DkIVsKPjU5dAhXUEhmukFkkLDbRgn7np0i8A-wAfTrVq3tLPvUkDoqdyH105mmwXR_nwO3ZqKJtCnolUok289my02qP1yA0uSmq0nJ51ikI3CEnk_H-jCz5OcVAUhN2qNRb3fhx0fNekBBfaUuJqbHr7usgaNAWRu_vQX0LGs7daClKl1k5FBtdrsJGwSkbY13ghKH42pmBVlY-I9oS8ocznuMsVtyo7QfY6oaMv9kZBuelMto7pM28z61S__qo2jsKzr_2I5uAH3avjUY28G8M3r0r3nkkXqMu_BPn3T95LOLTCghtwx2cE4LARBpZ_1t9rYFUzDb05HeARrqWzbhOwbm9c0N5RM8guq6O1q8kAVZFNLTLjK25ycBuiw'; }); tearDown(() async { diff --git a/test/core/data/repository/notification_repository_test.dart b/test/core/data/repository/notification_repository_test.dart new file mode 100644 index 00000000..40a86161 --- /dev/null +++ b/test/core/data/repository/notification_repository_test.dart @@ -0,0 +1,38 @@ +import 'package:aniflow/core/common/util/global_static_constants.dart'; +import 'package:aniflow/core/data/load_result.dart'; +import 'package:aniflow/core/data/model/notification_model.dart'; +import 'package:aniflow/core/data/notification_repository.dart'; +import 'package:aniflow/core/database/aniflow_database.dart'; +import 'package:aniflow/core/shared_preference/aniflow_preferences.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:sqflite_common_ffi/sqflite_ffi.dart'; + +void main() { + group('notification_repository_test', () { + late NotificationRepository repository; + final animeDatabase = AniflowDatabase(); + + setUp(() async { + sqfliteFfiInit(); + databaseFactory = databaseFactoryFfi; + SharedPreferences.setMockInitialValues({}); + isUnitTest = true; + await AniFlowPreferences().init(); + await animeDatabase.initDatabase(path: inMemoryDatabasePath); + + repository = NotificationRepositoryImpl(); + }); + + tearDown(() => animeDatabase.aniflowDB.close()); + + test('notification_page', () async { + final res = await repository.loadNotificationsByPage( + page: 1, + perPage: 50, + category: NotificationCategory.activity, + ); + expect(res.runtimeType, LoadSuccess>); + }); + }); +} diff --git a/test/core/database/activity_database_test.dart b/test/core/database/activity_database_test.dart index 2e4a07ed..9af0f0be 100644 --- a/test/core/database/activity_database_test.dart +++ b/test/core/database/activity_database_test.dart @@ -92,20 +92,5 @@ void main() { (ActivityFilterType.all, ActivityScopeCategory.global) .combineJsonKey); }); - - test('get_activities_aaaaaaaaa', () async { - await animeDatabase.aniflowDB.insert("parent_table", { - 'parent_id' : 1, - 'name' : 'parent name' - }); - await animeDatabase.aniflowDB.insert("child", { - 'child_id' : 1, - 'parent_f_key' : 1, - 'child_name' : 'parent name' - }); - - print('${(await animeDatabase.aniflowDB.query('parent_table'))}'); - print('${(await animeDatabase.aniflowDB.query('child'))}'); - }); }); } diff --git a/test/core/network/auth_data_source_test.dart b/test/core/network/auth_data_source_test.dart index c60333ea..3dafd5b4 100644 --- a/test/core/network/auth_data_source_test.dart +++ b/test/core/network/auth_data_source_test.dart @@ -14,9 +14,8 @@ import 'package:shared_preferences/shared_preferences.dart'; void main() { setUp(() async { isUnitTest = true; - testToken = - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2In0.eyJhdWQiOiIxNDQwOSIsImp0aSI6Ijc4ZWQ1YTk5ZDFkNTU2NDBkMTRkN2E5N2I1YWMyNDc3MjIyODFhYjM2NzE4MmFiN2VjNDg2ZTJjOWQ0MTA2MDZkN2ZlOGZkYzA1YjJlOGQ2IiwiaWF0IjoxNjk4NTY2MzU0LCJuYmYiOjE2OTg1NjYzNTQsImV4cCI6MTczMDE4ODc1NCwic3ViIjoiNjM3ODM5MyIsInNjb3BlcyI6W119.cjnTU0bSGzQnjxbAy-wkzRqiI5r2zAI_XmOX8teX0MZuceDj7qiBQQ6An-p6Ue30LYSI7V5Tw4ocChZn1bRsg6sRFCPAmE8eBbV4XBGjOhlAb9ciqMgTmVeND6bz0uWO1lr3D0fLfmQKPchrZAwb1-aVDhMkI3Ba4bC1VzxfbGPpw3IzbXjbAg1kFStENCvn3fTXTX53ndNGuPlbS6l8tfOlgYSK7dm0le4JrJAEIlm_Om4WYb6ij42sI0WK1pJY5Lzpar-K0KxaubN9poNKXa81PX65DABzywHXrEi8_D7_O_DkIVsKPjU5dAhXUEhmukFkkLDbRgn7np0i8A-wAfTrVq3tLPvUkDoqdyH105mmwXR_nwO3ZqKJtCnolUok289my02qP1yA0uSmq0nJ51ikI3CEnk_H-jCz5OcVAUhN2qNRb3fhx0fNekBBfaUuJqbHr7usgaNAWRu_vQX0LGs7daClKl1k5FBtdrsJGwSkbY13ghKH42pmBVlY-I9oS8ocznuMsVtyo7QfY6oaMv9kZBuelMto7pM28z61S__qo2jsKzr_2I5uAH3avjUY28G8M3r0r3nkkXqMu_BPn3T95LOLTCghtwx2cE4LARBpZ_1t9rYFUzDb05HeARrqWzbhOwbm9c0N5RM8guq6O1q8kAVZFNLTLjK25ycBuiw'; }); + group('auth_data_source_test', () { late AuthDataSource authDataSource; setUp(() async { @@ -42,7 +41,7 @@ void main() { test('notification_query', () async { await authDataSource.getNotifications(NotificationQueryParam( - page: 1, perPage: 2, type: [NotificationType.activityMessage])); + page: 1, perPage: 2, type: [NotificationType.relatedMediaAddition])); }); }); } diff --git a/test/core/network/model/activity_dto_test.dart b/test/core/network/model/activity_dto_test.dart index ac90b824..16e9b493 100644 --- a/test/core/network/model/activity_dto_test.dart +++ b/test/core/network/model/activity_dto_test.dart @@ -22,10 +22,13 @@ void main() { "id": 6378393, "name": "andannn", "avatar": { - "large": "https://s4.anilist.co/file/anilistcdn/user/avatar/large/b6378393-3BsPEhU6Tz5l.png", - "medium": "https://s4.anilist.co/file/anilistcdn/user/avatar/medium/b6378393-3BsPEhU6Tz5l.png" + "large": + "https://s4.anilist.co/file/anilistcdn/user/avatar/large/b6378393-3BsPEhU6Tz5l.png", + "medium": + "https://s4.anilist.co/file/anilistcdn/user/avatar/medium/b6378393-3BsPEhU6Tz5l.png" }, - "bannerImage": "https://s4.anilist.co/file/anilistcdn/user/banner/b6378393-qmyrEYbiA2HR.jpg" + "bannerImage": + "https://s4.anilist.co/file/anilistcdn/user/banner/b6378393-qmyrEYbiA2HR.jpg" } }; final dummyTextActivity = { @@ -45,12 +48,16 @@ void main() { "id": 1, "name": "Josh", "avatar": { - "large": "https://s4.anilist.co/file/anilistcdn/user/avatar/large/b1-PPhlCaTCpmrV.png", - "medium": "https://s4.anilist.co/file/anilistcdn/user/avatar/medium/b1-PPhlCaTCpmrV.png" + "large": + "https://s4.anilist.co/file/anilistcdn/user/avatar/large/b1-PPhlCaTCpmrV.png", + "medium": + "https://s4.anilist.co/file/anilistcdn/user/avatar/medium/b1-PPhlCaTCpmrV.png" }, - "bannerImage": "https://s4.anilist.co/file/anilistcdn/user/banner/n1-Uq15ejQKm1Kg.jpg" + "bannerImage": + "https://s4.anilist.co/file/anilistcdn/user/banner/n1-Uq15ejQKm1Kg.jpg" } }; + test('list_activity_dto', () async { ListActivityDto.fromJson(dummyListActivity); }); diff --git a/test/core/network/model/airing_notification_dto_test.dart b/test/core/network/model/airing_notification_dto_test.dart deleted file mode 100644 index 7fe22e5e..00000000 --- a/test/core/network/model/airing_notification_dto_test.dart +++ /dev/null @@ -1,40 +0,0 @@ -// ignore_for_file: lines_longer_than_80_chars - -import 'package:aniflow/core/network/model/activity_like_notification_dto.dart'; -import 'package:aniflow/core/network/model/airing_notification_dto.dart'; -import 'package:aniflow/core/network/model/notification.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group('notification_test', () { - final airingNotification = { - "__typename": "AiringNotification", - "id": 464758426, - "type": "AIRING", - "animeId": 151970, - "episode": 5, - "contexts": ["Episode ", " of ", " aired."], - "createdAt": 1698566410, - "media": {"id": 151970} - }; - - final likeNotification = { - "__typename": "ActivityLikeNotification", - "id": 457867547, - "userId": 5338139, - "type": "ACTIVITY_LIKE", - "context": " liked your activity.", - "createdAt": 1696629541, - "user": {"id": 5338139} - }; - test('airing_notification', () async { - AiringNotificationDto.fromJson(airingNotification); - }); - test('like_notification', () async { - ActivityLikeNotificationDto.fromJson(likeNotification); - }); - test('resolve_type', () async { - AniNotification.mapToAniNotification(likeNotification); - }); - }); -} diff --git a/test/core/network/model/notification_dto_test.dart b/test/core/network/model/notification_dto_test.dart new file mode 100644 index 00000000..11df34aa --- /dev/null +++ b/test/core/network/model/notification_dto_test.dart @@ -0,0 +1,154 @@ +// ignore_for_file: lines_longer_than_80_chars + +import 'package:aniflow/core/network/model/airing_notification_dto.dart'; +import 'package:aniflow/core/network/model/notification.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('notification_test', () { + final dummyAiringNotification = { + "__typename": "AiringNotification", + "id": 467561733, + "type": "AIRING", + "animeId": 140501, + "episode": 7, + "contexts": ["Episode ", " of ", " aired."], + "createdAt": 1699288203, + "media": { + "id": 140501, + "type": "ANIME", + "coverImage": { + "extraLarge": + "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx140501-pXY8yUDScfHS.jpg", + "large": + "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx140501-pXY8yUDScfHS.jpg", + "medium": + "https://s4.anilist.co/file/anilistcdn/media/anime/cover/small/bx140501-pXY8yUDScfHS.jpg", + "color": "#35bbff" + }, + "title": { + "romaji": "Seiken Gakuin no Maken Tsukai", + "english": "The Demon Sword Master of Excalibur Academy", + "native": "聖剣学院の魔剣使い" + } + } + }; + + final dummyFollowNotification = { + "__typename": "FollowingNotification", + "id": 464823439, + "userId": 6478504, + "type": "FOLLOWING", + "context": " started following you.", + "createdAt": 1698582885, + "user": { + "id": 6478504, + "name": "SubAcc", + "avatar": { + "large": + "https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png", + "medium": + "https://s4.anilist.co/file/anilistcdn/user/avatar/medium/default.png" + }, + "bannerImage": null + } + }; + + final activityNotification = { + "__typename": "ActivityReplyNotification", + "id": 464823653, + "userId": 6478504, + "type": "ACTIVITY_REPLY", + "activityId": 640108268, + "context": " replied to your activity.", + "createdAt": 1698582959, + "activity": { + "__typename": "ListActivity", + "id": 640108268, + "status": "watched episode", + "progress": "4", + "userId": 6378393, + "type": "ANIME_LIST", + "replyCount": 1, + "siteUrl": "https://anilist.co/activity/640108268", + "isLocked": false, + "isLiked": false, + "likeCount": 1, + "isPinned": false, + "createdAt": 1698561143, + "user": null, + "media": null + }, + "user": { + "id": 6478504, + "name": "SubAcc", + "avatar": { + "large": + "https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png", + "medium": + "https://s4.anilist.co/file/anilistcdn/user/avatar/medium/default.png" + }, + "bannerImage": null + } + }; + + final dummyRelatedMediaAdditionNotification = { + "__typename": "RelatedMediaAdditionNotification", + "id": 465097652, + "type": "RELATED_MEDIA_ADDITION", + "mediaId": 170596, + "context": " was recently added to the site.", + "createdAt": 1698626948, + "media": { + "id": 170596, + "type": "MANGA", + "format": "NOVEL", + "status": "NOT_YET_RELEASED", + "season": null, + "coverImage": { + "extraLarge": + "https://s4.anilist.co/file/anilistcdn/media/manga/cover/large/bx170596-qnmbdCiv0ZGv.jpg", + "large": + "https://s4.anilist.co/file/anilistcdn/media/manga/cover/medium/bx170596-qnmbdCiv0ZGv.jpg", + "medium": + "https://s4.anilist.co/file/anilistcdn/media/manga/cover/small/bx170596-qnmbdCiv0ZGv.jpg", + "color": "#f10dbb" + }, + "title": { + "romaji": "[Oshi no Ko]: Ichibanboshi no Spica", + "english": null, + "native": "【推しの子】~一番星のスピカ~" + } + } + }; + test('airing_activity_notification', () async { + final res = AniNotification.mapToAniNotification(dummyAiringNotification) + as AiringNotificationDto; + expect(res.runtimeType.toString().contains('AiringNotification'), + equals(true)); + print(res); + }); + + test('following_notification_notification', () async { + final res = AniNotification.mapToAniNotification(dummyFollowNotification); + expect(res.runtimeType.toString().contains('FollowingNotification'), + equals(true)); + print(res); + }); + + test('activity_reply_notification', () async { + final res = AniNotification.mapToAniNotification(activityNotification); + expect(res.runtimeType.toString().contains('ActivityReplyNotification'), + equals(true)); + print(res); + }); + + test('related_media_addition_notification', () async { + final res = AniNotification.mapToAniNotification( + dummyRelatedMediaAdditionNotification); + expect(res.runtimeType.toString().contains('RelatedMediaAdditionNotification'), + equals(true)); + print(res); + }); + }); +} From 71e8349f909da0a0779ddf402257cb471e31d5d1 Mon Sep 17 00:00:00 2001 From: andannn Date: Thu, 9 Nov 2023 23:21:56 +0900 Subject: [PATCH 10/10] add notification page --- lib/app/local/util/string_resource_util.dart | 103 ++++++++- lib/app/navigation/ani_flow_route_path.dart | 7 + lib/app/navigation/ani_flow_router.dart | 4 + .../common/util/global_static_constants.dart | 1 + lib/core/data/model/notification_model.dart | 4 + .../widget/activity_item_widget.dart | 53 +++-- .../widget/notification_item_widget.dart | 208 ++++++++++++++++++ lib/feature/discover/discover.dart | 13 +- .../notification/bloc/notification_bloc.dart | 24 ++ .../bloc/notification_paging_bloc.dart | 27 +++ .../notification/bloc/notification_state.dart | 11 + .../bloc/notification_state.freezed.dart | 136 ++++++++++++ lib/feature/notification/notification.dart | 179 +++++++++++++++ lib/main.dart | 4 + .../network/model/notification_dto_test.dart | 4 - 15 files changed, 749 insertions(+), 29 deletions(-) create mode 100644 lib/core/design_system/widget/notification_item_widget.dart create mode 100644 lib/feature/notification/bloc/notification_bloc.dart create mode 100644 lib/feature/notification/bloc/notification_paging_bloc.dart create mode 100644 lib/feature/notification/bloc/notification_state.dart create mode 100644 lib/feature/notification/bloc/notification_state.freezed.dart create mode 100644 lib/feature/notification/notification.dart diff --git a/lib/app/local/util/string_resource_util.dart b/lib/app/local/util/string_resource_util.dart index 379984c5..f68271a5 100644 --- a/lib/app/local/util/string_resource_util.dart +++ b/lib/app/local/util/string_resource_util.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:aniflow/app/local/ani_flow_localizations.dart'; import 'package:aniflow/core/common/model/activity_filter_type.dart'; import 'package:aniflow/core/common/model/anime_season.dart'; @@ -5,7 +7,12 @@ import 'package:aniflow/core/common/model/anime_source.dart'; import 'package:aniflow/core/common/model/character_role.dart'; import 'package:aniflow/core/common/model/media_status.dart'; import 'package:aniflow/core/common/util/time_util.dart'; +import 'package:aniflow/core/data/model/activity_model.dart'; import 'package:aniflow/core/data/model/media_model.dart'; +import 'package:aniflow/core/data/model/media_title_modle.dart'; +import 'package:aniflow/core/data/model/notification_model.dart'; +import 'package:aniflow/core/data/notification_repository.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; extension AnimeSourceEx on AnimeSource { @@ -109,9 +116,95 @@ extension AnimeModelEx on MediaModel { } extension ActivityFilterTypeEx on ActivityFilterType { - String label(BuildContext context) => switch(this) { - ActivityFilterType.all => 'All', - ActivityFilterType.text => 'Text', - ActivityFilterType.list => 'List', - }; + String label(BuildContext context) => switch (this) { + ActivityFilterType.all => 'All', + ActivityFilterType.text => 'Text', + ActivityFilterType.list => 'List', + }; +} + +extension NotificationCategoryEx on NotificationCategory { + String label(BuildContext context) => switch (this) { + NotificationCategory.all => 'All', + NotificationCategory.airing => 'Airing', + NotificationCategory.activity => 'Activity', + NotificationCategory.follows => 'Follows', + NotificationCategory.media => 'Media', + }; +} + +extension AiringNotificationEx on AiringNotification { + List createTextSpanList(BuildContext buildContext, + {required VoidCallback onMediaTextClick}) { + final List contextList = jsonDecode(context); + final colorScheme = Theme.of(buildContext).colorScheme; + return [ + TextSpan(text: '${contextList[0]} $episode ${contextList[1]}'), + TextSpan( + text: media.title?.native, + style: TextStyle(color: colorScheme.tertiary), + recognizer: TapGestureRecognizer()..onTap = onMediaTextClick, + ), + TextSpan(text: contextList[2]), + ]; + } +} + +extension FollowNotificationEx on FollowNotification { + List createTextSpanList(BuildContext buildContext, + {required VoidCallback onUserTextClick}) { + final colorScheme = Theme.of(buildContext).colorScheme; + return [ + TextSpan( + text: user.name, + style: TextStyle(color: colorScheme.tertiary), + recognizer: TapGestureRecognizer()..onTap = onUserTextClick, + ), + TextSpan(text: context), + ]; + } +} + +extension ActivityNotificationEx on ActivityNotification { + List createTextSpanList(BuildContext buildContext, + {required VoidCallback onUserTextClick}) { + final colorScheme = Theme.of(buildContext).colorScheme; + return [ + TextSpan( + text: user.name, + style: TextStyle(color: colorScheme.tertiary), + recognizer: TapGestureRecognizer()..onTap = onUserTextClick, + ), + TextSpan(text: context), + ]; + } +} + +extension MediaNotificationEx on MediaNotification { + List createTextSpanList(BuildContext buildContext, + {required VoidCallback onUserTextClick}) { + final colorScheme = Theme.of(buildContext).colorScheme; + return [ + TextSpan( + text: media.title?.native, + style: TextStyle(color: colorScheme.tertiary), + recognizer: TapGestureRecognizer()..onTap = onUserTextClick, + ), + TextSpan(text: context), + ]; + } +} +extension ListActivityModelEx on ListActivityModel { + List createTextSpanList(BuildContext buildContext, + {required VoidCallback onMediaClick}) { + final colorScheme = Theme.of(buildContext).colorScheme; + return [ + TextSpan(text: '${status.toString()} $progress of '), + TextSpan( + text: media.title!.getLocalTitle(buildContext), + style: TextStyle(color: colorScheme.tertiary), + recognizer: TapGestureRecognizer()..onTap = onMediaClick, + ), + ]; + } } diff --git a/lib/app/navigation/ani_flow_route_path.dart b/lib/app/navigation/ani_flow_route_path.dart index d52791a0..33a45dea 100644 --- a/lib/app/navigation/ani_flow_route_path.dart +++ b/lib/app/navigation/ani_flow_route_path.dart @@ -7,6 +7,7 @@ import 'package:aniflow/feature/detail_media/detail_media.dart'; import 'package:aniflow/feature/discover/discover.dart'; import 'package:aniflow/feature/media_page/media_page.dart'; import 'package:aniflow/feature/media_track/media_track.dart'; +import 'package:aniflow/feature/notification/notification.dart'; import 'package:aniflow/feature/profile/profile.dart'; import 'package:aniflow/feature/social/social.dart'; import 'package:aniflow/feature/staff_page/staff_page.dart'; @@ -97,6 +98,10 @@ class AiringScheduleRoutePath extends AniFlowRoutePath { const AiringScheduleRoutePath() : super(isFullScreen: true); } +class NotificationRoutePath extends AniFlowRoutePath { + const NotificationRoutePath() : super(isFullScreen: true); +} + extension AniFlowRoutePathEx on AniFlowRoutePath { Page generatePage() { switch (this) { @@ -134,6 +139,8 @@ extension AniFlowRoutePathEx on AniFlowRoutePath { return const AiringSchedule(key: ValueKey('AiringSchedule')); case SearchRoutePath(): return const SearchPage(key: ValueKey('SearchPage')); + case NotificationRoutePath(): + return const NotificationPage(key: ValueKey('NotificationPage')); default: return const MaterialPage(child: SizedBox()); } diff --git a/lib/app/navigation/ani_flow_router.dart b/lib/app/navigation/ani_flow_router.dart index dadbad2f..66809a5d 100644 --- a/lib/app/navigation/ani_flow_router.dart +++ b/lib/app/navigation/ani_flow_router.dart @@ -99,6 +99,10 @@ class AFRouterDelegate extends RouterDelegate _pushAsSingleton(const SearchRoutePath()); } + void navigateToNotification() { + _pushAsSingleton(const NotificationRoutePath()); + } + void navigateToUserProfile(String userId) { _pushAsSingleton(UserProfileRoutePath(userId)); } diff --git a/lib/core/common/util/global_static_constants.dart b/lib/core/common/util/global_static_constants.dart index d6c3f3aa..7bec9e6f 100644 --- a/lib/core/common/util/global_static_constants.dart +++ b/lib/core/common/util/global_static_constants.dart @@ -9,6 +9,7 @@ mixin Config { static const int profilePageDefaultPerPageCount = 6; static const int activityPageDefaultPerPageCount = 50; + static const int notificationPageDefaultPerPageCount = 25; /// Detail page consts. static const double detailPagePreviewItemHeight = 133.0; diff --git a/lib/core/data/model/notification_model.dart b/lib/core/data/model/notification_model.dart index 4c16a202..c313fbbc 100644 --- a/lib/core/data/model/notification_model.dart +++ b/lib/core/data/model/notification_model.dart @@ -85,6 +85,7 @@ sealed class NotificationModel extends Equatable { createdAt: dto.createdAt ?? 0, context: dto.context ?? '', media: MediaModel.fromDto(dto.media!), + reason: dto.reason ?? '', ); case RelatedMediaAdditionNotificationDto(): return RelatedMediaAdditionNotification( @@ -226,7 +227,10 @@ class MediaDataChangeNotification extends MediaNotification { required super.context, required super.createdAt, required super.media, + required this.reason, }); + + final String reason; } class MediaMergeNotification extends MediaNotification { diff --git a/lib/core/design_system/widget/activity_item_widget.dart b/lib/core/design_system/widget/activity_item_widget.dart index 877105f9..5da05e09 100644 --- a/lib/core/design_system/widget/activity_item_widget.dart +++ b/lib/core/design_system/widget/activity_item_widget.dart @@ -1,5 +1,5 @@ +import 'package:aniflow/app/local/util/string_resource_util.dart'; import 'package:aniflow/core/data/model/activity_model.dart'; -import 'package:aniflow/core/data/model/media_title_modle.dart'; import 'package:aniflow/core/design_system/widget/af_network_image.dart'; import 'package:aniflow/core/design_system/widget/avatar_icon.dart'; import 'package:aniflow/core/design_system/widget/short_num_label_icon_button.dart'; @@ -7,11 +7,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_widget_from_html/flutter_widget_from_html.dart'; class ActivityItem extends StatelessWidget { - const ActivityItem( - {required this.model, - super.key, - this.onMediaClick, - this.onUserIconClick}); + const ActivityItem({required this.model, + super.key, + this.onMediaClick, + this.onUserIconClick}); final ActivityModel model; final Function(String mediaId)? onMediaClick; @@ -29,8 +28,12 @@ class ActivityItem extends StatelessWidget { } Widget _buildListActivity(BuildContext context, ListActivityModel activity) { - final colorScheme = Theme.of(context).colorScheme; - final textTheme = Theme.of(context).textTheme; + final colorScheme = Theme + .of(context) + .colorScheme; + final textTheme = Theme + .of(context) + .textTheme; return Container( constraints: const BoxConstraints(minHeight: 120), child: Card( @@ -68,11 +71,17 @@ class ActivityItem extends StatelessWidget { .copyWith(color: colorScheme.primary), ), const SizedBox(height: 8), - Text( - // ignore: lines_longer_than_80_chars - '${activity.status.toString()} ${activity.progress} of ${activity.media.title!.getLocalTitle(context)}', - style: textTheme.bodyMedium! - .copyWith(color: colorScheme.onSurfaceVariant), + RichText( + text: TextSpan( + style: textTheme.bodyMedium! + .copyWith(color: colorScheme.onSurfaceVariant), + children: activity.createTextSpanList( + context, + onMediaClick: () { + onMediaClick?.call(activity.media.id); + }, + ), + ), ), const SizedBox(height: 8), SizedBox( @@ -112,8 +121,12 @@ class ActivityItem extends StatelessWidget { } Widget _buildTextActivity(BuildContext context, TextActivityModel activity) { - final colorScheme = Theme.of(context).colorScheme; - final textTheme = Theme.of(context).textTheme; + final colorScheme = Theme + .of(context) + .colorScheme; + final textTheme = Theme + .of(context) + .textTheme; return Card( elevation: 0, color: colorScheme.surfaceVariant, @@ -167,10 +180,14 @@ class ActivityItem extends StatelessWidget { ); } - Widget _buildReplyLikeStateSection( - BuildContext context, bool isLike, int likeCount, int repliedCount) { + Widget _buildReplyLikeStateSection(BuildContext context, bool isLike, + int likeCount, int repliedCount) { final defaultColor = - Theme.of(context).colorScheme.onSurfaceVariant.withOpacity(0.8); + Theme + .of(context) + .colorScheme + .onSurfaceVariant + .withOpacity(0.8); return Row( mainAxisSize: MainAxisSize.min, children: [ diff --git a/lib/core/design_system/widget/notification_item_widget.dart b/lib/core/design_system/widget/notification_item_widget.dart new file mode 100644 index 00000000..7b2d5437 --- /dev/null +++ b/lib/core/design_system/widget/notification_item_widget.dart @@ -0,0 +1,208 @@ +import 'package:aniflow/app/local/util/string_resource_util.dart'; +import 'package:aniflow/core/data/model/notification_model.dart'; +import 'package:aniflow/core/design_system/widget/af_network_image.dart'; +import 'package:flutter/material.dart'; + +class NotificationItem extends StatelessWidget { + const NotificationItem( + {required this.model, + required this.onCoverImageClick, + required this.onNotificationClick, + super.key}); + + final NotificationModel model; + final VoidCallback onCoverImageClick; + final VoidCallback onNotificationClick; + + ColorScheme _colorScheme(BuildContext context) => + Theme.of(context).colorScheme; + + TextStyle? _contentTextStyle(BuildContext context) => Theme.of(context) + .textTheme + .labelLarge! + .copyWith(color: _colorScheme(context).onSurfaceVariant); + + @override + Widget build(BuildContext context) { + final notification = model; + + Widget buildContentRow() => switch (notification) { + AiringNotification() => + _buildAiringNotificationContent(context, notification), + FollowNotification() => + _buildFollowNotificationContent(context, notification), + ActivityNotification() => + _buildActivityNotificationContent(context, notification), + MediaNotification() => + _buildMediaNotificationContent(context, notification), + MediaDeletionNotification() => + Text(notification.runtimeType.toString()), + }; + + String getCoverImageUrl() => switch (notification) { + AiringNotification() => notification.media.coverImage, + FollowNotification() => notification.user.avatar, + ActivityNotification() => notification.user.avatar, + MediaNotification() => notification.media.coverImage, + MediaDeletionNotification() => '' + }; + + return Card( + elevation: 0, + color: Theme.of(context).colorScheme.surfaceVariant, + clipBehavior: Clip.antiAlias, + child: InkWell( + onTap: onNotificationClick, + child: IntrinsicHeight( + child: Row( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SizedBox( + // compile error if no set this height. + // ignore: lines_longer_than_80_chars + // this height value will no take effect because we have set the IntrinsicHeight + height: 1, + width: 85, + child: InkWell( + onTap: onCoverImageClick, + child: AFNetworkImage( + imageUrl: getCoverImageUrl(), + ), + ), + ), + const SizedBox(width: 12), + Expanded( + flex: 1, + child: Container( + constraints: const BoxConstraints(minHeight: 85), + child: Align( + alignment: Alignment.centerLeft, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 4.0), + child: buildContentRow(), + ), + ), + ), + ), + const SizedBox(width: 12), + ], + ), + ), + ), + ); + } + + Widget _buildAiringNotificationContent( + BuildContext context, AiringNotification notification) { + return RichText( + text: TextSpan( + style: _contentTextStyle(context), + children: notification.createTextSpanList( + context, + onMediaTextClick: onCoverImageClick, + ), + ), + ); + } + + Widget _buildFollowNotificationContent( + BuildContext context, FollowNotification notification) { + return RichText( + text: TextSpan( + style: _contentTextStyle(context), + children: notification.createTextSpanList( + context, + onUserTextClick: onCoverImageClick, + ), + ), + ); + } + + Widget _buildActivityNotificationContent( + BuildContext context, ActivityNotification notification) { + return RichText( + text: TextSpan( + style: _contentTextStyle(context), + children: notification.createTextSpanList( + context, + onUserTextClick: onCoverImageClick, + ), + ), + ); + } + + Widget _buildMediaNotificationContent( + BuildContext context, MediaNotification notification) { + Widget createContentText() { + return RichText( + text: TextSpan( + style: _contentTextStyle(context), + children: notification.createTextSpanList( + context, + onUserTextClick: onCoverImageClick, + ), + ), + ); + } + + if (notification is MediaDataChangeNotification) { + return Column( + children: [ + createContentText(), + _ShowReasonButton(reason: notification.reason) + ], + ); + } else { + return createContentText(); + } + } +} + +class _ShowReasonButton extends StatefulWidget { + const _ShowReasonButton({required this.reason}); + + final String reason; + + @override + State<_ShowReasonButton> createState() => _ShowReasonButtonState(); +} + +class _ShowReasonButtonState extends State<_ShowReasonButton> { + var isShowing = false; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const SizedBox(height: 8), + isShowing + ? Text(widget.reason, style: Theme.of(context).textTheme.labelSmall) + : const SizedBox(), + Row( + children: [ + InkWell( + customBorder: const StadiumBorder(), + onTap: () { + setState(() { + isShowing = !isShowing; + }); + }, + child: Padding( + padding: const EdgeInsets.all(4.0), + child: Text( + isShowing ? 'Hide reason..' : 'Show reason..', + style: TextStyle( + color: Theme.of(context).primaryColor, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + ], + ), + ], + ); + } +} diff --git a/lib/feature/discover/discover.dart b/lib/feature/discover/discover.dart index 66dc64a7..6259c0cf 100644 --- a/lib/feature/discover/discover.dart +++ b/lib/feature/discover/discover.dart @@ -56,9 +56,18 @@ class DiscoverScreen extends StatelessWidget { LoadingIndicator(isLoading: isLoading), IconButton( onPressed: () { - AFRouterDelegate.of(context).navigateToSearch(); + AFRouterDelegate.of(context).navigateToNotification(); }, - icon: const Icon(Icons.search_rounded), + icon: const Icon(Icons.notifications_none), + ), + Padding( + padding: const EdgeInsets.only(right: 12.0), + child: IconButton( + onPressed: () { + AFRouterDelegate.of(context).navigateToSearch(); + }, + icon: const Icon(Icons.search_rounded), + ), ), Padding( padding: const EdgeInsets.only(right: 12.0), diff --git a/lib/feature/notification/bloc/notification_bloc.dart b/lib/feature/notification/bloc/notification_bloc.dart new file mode 100644 index 00000000..5a17e8d5 --- /dev/null +++ b/lib/feature/notification/bloc/notification_bloc.dart @@ -0,0 +1,24 @@ +import 'dart:async'; + +import 'package:aniflow/core/data/notification_repository.dart'; +import 'package:aniflow/feature/notification/bloc/notification_state.dart'; +import 'package:bloc/bloc.dart'; + +sealed class NotificationEvent {} + +class OnNotificationChanged extends NotificationEvent { + OnNotificationChanged({required this.category}); + + final NotificationCategory category; +} + +class NotificationBloc extends Bloc { + NotificationBloc() : super(NotificationState()) { + on(_onNotificationChanged); + } + + FutureOr _onNotificationChanged( + OnNotificationChanged event, Emitter emit) { + emit(state.copyWith(category: event.category)); + } +} diff --git a/lib/feature/notification/bloc/notification_paging_bloc.dart b/lib/feature/notification/bloc/notification_paging_bloc.dart new file mode 100644 index 00000000..6f83bc63 --- /dev/null +++ b/lib/feature/notification/bloc/notification_paging_bloc.dart @@ -0,0 +1,27 @@ +import 'package:aniflow/core/common/util/global_static_constants.dart'; +import 'package:aniflow/core/data/load_result.dart'; +import 'package:aniflow/core/data/model/notification_model.dart'; +import 'package:aniflow/core/data/notification_repository.dart'; +import 'package:aniflow/feature/common/page_loading_state.dart'; +import 'package:aniflow/feature/common/paging_bloc.dart'; + +class NotificationPagingBloc extends PagingBloc { + NotificationPagingBloc({ + required NotificationRepository repository, + required NotificationCategory category, + }) : _repository = repository, + _category = category, + super(const PageInit(data: [])); + + final NotificationRepository _repository; + final NotificationCategory _category; + + @override + Future>> loadPage( + {required int page, bool isRefresh = false}) { + return _repository.loadNotificationsByPage( + page: page, + perPage: Config.notificationPageDefaultPerPageCount, + category: _category); + } +} diff --git a/lib/feature/notification/bloc/notification_state.dart b/lib/feature/notification/bloc/notification_state.dart new file mode 100644 index 00000000..2b5698f6 --- /dev/null +++ b/lib/feature/notification/bloc/notification_state.dart @@ -0,0 +1,11 @@ +import 'package:aniflow/core/data/notification_repository.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'notification_state.freezed.dart'; + +@freezed +class NotificationState with _$NotificationState { + factory NotificationState({ + @Default(NotificationCategory.all) NotificationCategory category, + }) = _NotificationState; +} diff --git a/lib/feature/notification/bloc/notification_state.freezed.dart b/lib/feature/notification/bloc/notification_state.freezed.dart new file mode 100644 index 00000000..93f46826 --- /dev/null +++ b/lib/feature/notification/bloc/notification_state.freezed.dart @@ -0,0 +1,136 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'notification_state.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$NotificationState { + NotificationCategory get category => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $NotificationStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $NotificationStateCopyWith<$Res> { + factory $NotificationStateCopyWith( + NotificationState value, $Res Function(NotificationState) then) = + _$NotificationStateCopyWithImpl<$Res, NotificationState>; + @useResult + $Res call({NotificationCategory category}); +} + +/// @nodoc +class _$NotificationStateCopyWithImpl<$Res, $Val extends NotificationState> + implements $NotificationStateCopyWith<$Res> { + _$NotificationStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? category = null, + }) { + return _then(_value.copyWith( + category: null == category + ? _value.category + : category // ignore: cast_nullable_to_non_nullable + as NotificationCategory, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_NotificationStateCopyWith<$Res> + implements $NotificationStateCopyWith<$Res> { + factory _$$_NotificationStateCopyWith(_$_NotificationState value, + $Res Function(_$_NotificationState) then) = + __$$_NotificationStateCopyWithImpl<$Res>; + @override + @useResult + $Res call({NotificationCategory category}); +} + +/// @nodoc +class __$$_NotificationStateCopyWithImpl<$Res> + extends _$NotificationStateCopyWithImpl<$Res, _$_NotificationState> + implements _$$_NotificationStateCopyWith<$Res> { + __$$_NotificationStateCopyWithImpl( + _$_NotificationState _value, $Res Function(_$_NotificationState) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? category = null, + }) { + return _then(_$_NotificationState( + category: null == category + ? _value.category + : category // ignore: cast_nullable_to_non_nullable + as NotificationCategory, + )); + } +} + +/// @nodoc + +class _$_NotificationState implements _NotificationState { + _$_NotificationState({this.category = NotificationCategory.all}); + + @override + @JsonKey() + final NotificationCategory category; + + @override + String toString() { + return 'NotificationState(category: $category)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_NotificationState && + (identical(other.category, category) || + other.category == category)); + } + + @override + int get hashCode => Object.hash(runtimeType, category); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_NotificationStateCopyWith<_$_NotificationState> get copyWith => + __$$_NotificationStateCopyWithImpl<_$_NotificationState>( + this, _$identity); +} + +abstract class _NotificationState implements NotificationState { + factory _NotificationState({final NotificationCategory category}) = + _$_NotificationState; + + @override + NotificationCategory get category; + @override + @JsonKey(ignore: true) + _$$_NotificationStateCopyWith<_$_NotificationState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/feature/notification/notification.dart b/lib/feature/notification/notification.dart new file mode 100644 index 00000000..f12eeb5b --- /dev/null +++ b/lib/feature/notification/notification.dart @@ -0,0 +1,179 @@ +import 'package:aniflow/app/local/util/string_resource_util.dart'; +import 'package:aniflow/app/navigation/ani_flow_router.dart'; +import 'package:aniflow/core/data/model/notification_model.dart'; +import 'package:aniflow/core/data/notification_repository.dart'; +import 'package:aniflow/core/design_system/widget/notification_item_widget.dart'; +import 'package:aniflow/core/design_system/widget/popup_menu_anchor.dart'; +import 'package:aniflow/feature/common/page_loading_state.dart'; +import 'package:aniflow/feature/common/paging_bloc.dart'; +import 'package:aniflow/feature/common/paging_content_widget.dart'; +import 'package:aniflow/feature/notification/bloc/notification_bloc.dart'; +import 'package:aniflow/feature/notification/bloc/notification_paging_bloc.dart'; +import 'package:aniflow/feature/notification/bloc/notification_state.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class NotificationPage extends Page { + const NotificationPage({super.key}); + + @override + Route createRoute(BuildContext context) { + return NotificationPageRoute(settings: this); + } +} + +class NotificationPageRoute extends PageRoute + with MaterialRouteTransitionMixin { + NotificationPageRoute({super.settings}) : super(allowSnapshotting: false); + + @override + Widget buildContent(BuildContext context) { + return BlocProvider( + create: (BuildContext context) => NotificationBloc(), + child: const _NotificationPageContent(), + ); + } + + @override + bool get maintainState => true; +} + +class _NotificationPageContent extends StatelessWidget { + const _NotificationPageContent(); + + @override + Widget build(BuildContext context) { + return BlocBuilder( + builder: (BuildContext context, state) { + final category = state.category; + + return Scaffold( + appBar: AppBar( + title: const Text('Notification'), + actions: [ + PopupMenuAnchor( + menuItems: NotificationCategory.values, + builder: (context, controller, child) { + return TextButton.icon( + onPressed: () { + if (controller.isOpen) { + controller.close(); + } else { + controller.open(); + } + }, + icon: const Icon(Icons.filter_alt), + label: Text( + category.label(context), + ), + ); + }, + menuItemBuilder: (context, item) { + return MenuItemButton( + child: Container( + constraints: const BoxConstraints(minWidth: 80), + child: Text(item.label(context)), + ), + onPressed: () { + context + .read() + .add(OnNotificationChanged(category: item)); + }, + ); + }, + ), + const SizedBox(width: 12), + ], + ), + body: Column( + children: [ + Expanded( + child: _NotificationPagingBlocProvider( + key: ValueKey('${category}_paging'), + category: category, + ), + ), + ], + ), + ); + }, + ); + } +} + +class _NotificationPagingBlocProvider extends StatelessWidget { + const _NotificationPagingBlocProvider({required this.category, super.key}); + + final NotificationCategory category; + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (BuildContext context) => NotificationPagingBloc( + category: category, + repository: context.read(), + ), + child: const _NotificationPagingContent()); + } +} + +class _NotificationPagingContent extends StatelessWidget { + const _NotificationPagingContent(); + + @override + Widget build(BuildContext context) { + return BlocBuilder>>( + builder: (BuildContext context, state) { + return PagingContent( + onBuildItem: _buildNotificationItem, + pagingState: state, + onRequestNewPage: () { + context + .read() + .add(OnRequestLoadPageEvent()); + }, + onRetryLoadPage: () { + context.read().add(OnRetryLoadPageEvent()); + }, + ); + }, + ); + } + + Widget _buildNotificationItem(BuildContext context, NotificationModel model) { + final navigator = AFRouterDelegate.of(context); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 1), + child: NotificationItem( + model: model, + onCoverImageClick: () { + switch (model) { + case AiringNotification(): + navigator.navigateToDetailMedia(model.media.id); + case FollowNotification(): + navigator.navigateToUserProfile(model.user.id); + case ActivityNotification(): + navigator.navigateToUserProfile(model.user.id); + case MediaNotification(): + navigator.navigateToDetailMedia(model.media.id); + case MediaDeletionNotification(): + // Do nothing. + } + }, + onNotificationClick: () { + switch (model) { + case AiringNotification(): + navigator.navigateToDetailMedia(model.media.id); + case MediaNotification(): + navigator.navigateToDetailMedia(model.media.id); + case MediaDeletionNotification(): + case FollowNotification(): + case ActivityNotification(): + // Do nothing. + } + }, + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index d09522cd..070f1461 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:aniflow/core/data/auth_repository.dart'; import 'package:aniflow/core/data/favorite_repository.dart'; import 'package:aniflow/core/data/media_information_repository.dart'; import 'package:aniflow/core/data/media_list_repository.dart'; +import 'package:aniflow/core/data/notification_repository.dart'; import 'package:aniflow/core/data/search_repository.dart'; import 'package:aniflow/core/data/settings_repository.dart'; import 'package:aniflow/core/data/user_info_repository.dart'; @@ -50,5 +51,8 @@ void main() async { RepositoryProvider( create: (context) => UserInfoRepositoryImpl(), ), + RepositoryProvider( + create: (context) => NotificationRepositoryImpl(), + ), ], child: const AnimeTrackerApp())); } diff --git a/test/core/network/model/notification_dto_test.dart b/test/core/network/model/notification_dto_test.dart index 11df34aa..dd58a5ef 100644 --- a/test/core/network/model/notification_dto_test.dart +++ b/test/core/network/model/notification_dto_test.dart @@ -126,21 +126,18 @@ void main() { as AiringNotificationDto; expect(res.runtimeType.toString().contains('AiringNotification'), equals(true)); - print(res); }); test('following_notification_notification', () async { final res = AniNotification.mapToAniNotification(dummyFollowNotification); expect(res.runtimeType.toString().contains('FollowingNotification'), equals(true)); - print(res); }); test('activity_reply_notification', () async { final res = AniNotification.mapToAniNotification(activityNotification); expect(res.runtimeType.toString().contains('ActivityReplyNotification'), equals(true)); - print(res); }); test('related_media_addition_notification', () async { @@ -148,7 +145,6 @@ void main() { dummyRelatedMediaAdditionNotification); expect(res.runtimeType.toString().contains('RelatedMediaAdditionNotification'), equals(true)); - print(res); }); }); }