Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
Reuse mixins
  • Loading branch information
r52 committed Aug 15, 2023
1 parent 2231c4e commit 30241f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/mangadex/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class MangaDexModel {
return false;
}

return _token!.expired;
return _token!.isExpired();
});
}

Expand Down
8 changes: 4 additions & 4 deletions lib/mangadex/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ class ReadChapterSet with ShortLivedData {

// Deprecated old style login types
@freezed
class OldToken with _$OldToken {
class OldToken with _$OldToken, ShortLivedData {
OldToken._();

static const int expiryTime = 600; // seconds (10 minutes)
Expand All @@ -938,10 +938,10 @@ class OldToken with _$OldToken {
factory OldToken.fromJson(Map<String, dynamic> json) =>
_$OldTokenFromJson(json);

final DateTime expiresAt =
@override
final DateTime expiry =
DateTime.now().add(const Duration(seconds: expiryTime));

Duration get timeUntilExpiry => expiresAt.difference(DateTime.now());
bool get expired => (DateTime.now().compareTo(expiresAt) >= 0);
Duration get timeUntilExpiry => expiry.difference(DateTime.now());
bool get isValid => (session.isNotEmpty && refresh.isNotEmpty);
}

0 comments on commit 30241f7

Please sign in to comment.