Skip to content

Commit

Permalink
未知の通知でもパースエラーを吐かないように
Browse files Browse the repository at this point in the history
  • Loading branch information
shiosyakeyakini-info committed Oct 18, 2024
1 parent 8d0a0d5 commit e31e54c
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ analyzer:
exclude:
- "**/*.freezed.dart"
- "**/*.g.dart"
- "example/misskey_dart_flutter_app_example/**"
- "example/misskey_dart_flutter_app_example/**"
errors:
invalid_annotation_target: false
1 change: 1 addition & 0 deletions lib/src/data/i/i_notifications_request.g.dart

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

1 change: 1 addition & 0 deletions lib/src/data/i/i_notifications_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class INotificationsResponse with _$INotificationsResponse {
const factory INotificationsResponse({
required String id,
@DateTimeConverter() required DateTime createdAt,
@JsonKey(unknownEnumValue: NotificationType.unknown)
required NotificationType type,
String? noteId,
String? followRequestId,
Expand Down
8 changes: 7 additions & 1 deletion lib/src/data/i/i_notifications_response.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mixin _$INotificationsResponse {
String get id => throw _privateConstructorUsedError;
@DateTimeConverter()
DateTime get createdAt => throw _privateConstructorUsedError;
@JsonKey(unknownEnumValue: NotificationType.unknown)
NotificationType get type => throw _privateConstructorUsedError;
String? get noteId => throw _privateConstructorUsedError;
String? get followRequestId => throw _privateConstructorUsedError;
Expand Down Expand Up @@ -59,6 +60,7 @@ abstract class $INotificationsResponseCopyWith<$Res> {
$Res call(
{String id,
@DateTimeConverter() DateTime createdAt,
@JsonKey(unknownEnumValue: NotificationType.unknown)
NotificationType type,
String? noteId,
String? followRequestId,
Expand Down Expand Up @@ -245,6 +247,7 @@ abstract class _$$INotificationsResponseImplCopyWith<$Res>
$Res call(
{String id,
@DateTimeConverter() DateTime createdAt,
@JsonKey(unknownEnumValue: NotificationType.unknown)
NotificationType type,
String? noteId,
String? followRequestId,
Expand Down Expand Up @@ -391,7 +394,7 @@ class _$INotificationsResponseImpl implements _INotificationsResponse {
const _$INotificationsResponseImpl(
{required this.id,
@DateTimeConverter() required this.createdAt,
required this.type,
@JsonKey(unknownEnumValue: NotificationType.unknown) required this.type,
this.noteId,
this.followRequestId,
this.reaction,
Expand All @@ -418,6 +421,7 @@ class _$INotificationsResponseImpl implements _INotificationsResponse {
@DateTimeConverter()
final DateTime createdAt;
@override
@JsonKey(unknownEnumValue: NotificationType.unknown)
final NotificationType type;
@override
final String? noteId;
Expand Down Expand Up @@ -534,6 +538,7 @@ abstract class _INotificationsResponse implements INotificationsResponse {
const factory _INotificationsResponse(
{required final String id,
@DateTimeConverter() required final DateTime createdAt,
@JsonKey(unknownEnumValue: NotificationType.unknown)
required final NotificationType type,
final String? noteId,
final String? followRequestId,
Expand Down Expand Up @@ -561,6 +566,7 @@ abstract class _INotificationsResponse implements INotificationsResponse {
@DateTimeConverter()
DateTime get createdAt;
@override
@JsonKey(unknownEnumValue: NotificationType.unknown)
NotificationType get type;
@override
String? get noteId;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/data/i/i_notifications_response.g.dart

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

1 change: 1 addition & 0 deletions lib/src/data/streaming/note_updated_event.g.dart

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

1 change: 1 addition & 0 deletions lib/src/data/streaming/streaming_response.g.dart

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

5 changes: 4 additions & 1 deletion lib/src/enums/broadcast_event_type.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:collection/collection.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

enum BroadcastEventType {
emojiAdded,
emojiUpdated,
emojiDeleted,
announcementCreated,
unknown,
}

class BroadcastEventTypeJsonConverter
Expand All @@ -13,7 +15,8 @@ class BroadcastEventTypeJsonConverter

@override
BroadcastEventType? fromJson(String json) =>
BroadcastEventType.values.firstWhere((e) => e.name == json);
BroadcastEventType.values.firstWhereOrNull((e) => e.name == json) ??
BroadcastEventType.unknown;

@override
String toJson(BroadcastEventType? object) => object?.name ?? "";
Expand Down
6 changes: 5 additions & 1 deletion lib/src/enums/channel_event_type.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

enum ChannelEventType {
Expand Down Expand Up @@ -38,6 +39,8 @@ enum ChannelEventType {
driveFileCreated,
readAntenna,
receiveFollowRequest,

unknown,
}

class ChannelEventTypeJsonConverter
Expand All @@ -46,7 +49,8 @@ class ChannelEventTypeJsonConverter

@override
ChannelEventType? fromJson(String json) =>
ChannelEventType.values.firstWhere((e) => e.name == json);
ChannelEventType.values.firstWhereOrNull((e) => e.name == json) ??
ChannelEventType.unknown;

@override
String toJson(ChannelEventType? object) => object?.name ?? "";
Expand Down
5 changes: 4 additions & 1 deletion lib/src/enums/note_updated_event_type.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

enum NoteUpdatedEventType {
Expand All @@ -6,6 +7,7 @@ enum NoteUpdatedEventType {
deleted,
pollVoted,
updated,
unknown,
}

class NoteUpdatedEventTypeJsonConverter
Expand All @@ -14,7 +16,8 @@ class NoteUpdatedEventTypeJsonConverter

@override
NoteUpdatedEventType? fromJson(String json) =>
NoteUpdatedEventType.values.firstWhere((e) => e.name == json);
NoteUpdatedEventType.values.firstWhereOrNull((e) => e.name == json) ??
NoteUpdatedEventType.unknown;

@override
String toJson(NoteUpdatedEventType? object) => object?.name ?? "";
Expand Down
1 change: 1 addition & 0 deletions lib/src/enums/notification_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ enum NotificationType {
roleAssigned,
exportCompleted,
login,
unknown,
}
5 changes: 4 additions & 1 deletion lib/src/enums/streaming_response_type.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

enum StreamingResponseType {
Expand All @@ -7,6 +8,7 @@ enum StreamingResponseType {
emojiUpdated,
emojiDeleted,
announcementCreated,
unknown,
}

class StreamingResponseTypeJsonConverter
Expand All @@ -15,7 +17,8 @@ class StreamingResponseTypeJsonConverter

@override
StreamingResponseType? fromJson(String json) =>
StreamingResponseType.values.firstWhere((e) => e.name == json);
StreamingResponseType.values.firstWhereOrNull((e) => e.name == json) ??
StreamingResponseType.unknown;

@override
String toJson(StreamingResponseType? object) => object?.name ?? "";
Expand Down

0 comments on commit e31e54c

Please sign in to comment.