Skip to content

Commit

Permalink
Update subscription state
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Aug 4, 2023
1 parent 7f7fd71 commit ad8099e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/src/client/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ abstract base class _$SpinifyStateBase {

Map<String, Object?> toJson() => <String, Object?>{
'type': type,
'timestamp': timestamp.microsecondsSinceEpoch,
'timestamp': timestamp.toUtc().toIso8601String(),
if (url != null) 'url': url,
};
}
35 changes: 32 additions & 3 deletions lib/src/subscription/subscription_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sealed class SpinifySubscriptionState extends _$SpinifySubscriptionStateBase {

/// Unsubscribed state
///
/// {@nodoc}
/// {@macro subscription_state}
/// {@category Subscription}
/// {@category Entity}
final class SpinifySubscriptionState$Unsubscribed
Expand Down Expand Up @@ -99,6 +99,13 @@ final class SpinifySubscriptionState$Unsubscribed
}) =>
unsubscribed(this);

@override
Map<String, Object?> toJson() => <String, Object?>{
...super.toJson(),
'code': code,
'reason': reason,
};

@override
int get hashCode => Object.hash(0, timestamp, since);

Expand All @@ -110,7 +117,8 @@ final class SpinifySubscriptionState$Unsubscribed
}

/// Subscribing state
/// {@nodoc}
///
/// {@macro subscription_state}
/// {@category Subscription}
/// {@category Entity}
final class SpinifySubscriptionState$Subscribing
Expand Down Expand Up @@ -162,7 +170,8 @@ final class SpinifySubscriptionState$Subscribing
}

/// Subscribed state
/// {@nodoc}
///
/// {@macro subscription_state}
/// {@category Subscription}
/// {@category Entity}
final class SpinifySubscriptionState$Subscribed extends SpinifySubscriptionState
Expand Down Expand Up @@ -207,6 +216,12 @@ final class SpinifySubscriptionState$Subscribed extends SpinifySubscriptionState
}) =>
subscribed(this);

@override
Map<String, Object?> toJson() => <String, Object?>{
...super.toJson(),
if (ttl != null) 'ttl': ttl?.toUtc().toIso8601String(),
};

@override
int get hashCode => Object.hash(2, timestamp, since, recoverable, ttl);

Expand Down Expand Up @@ -299,4 +314,18 @@ abstract base class _$SpinifySubscriptionStateBase {
subscribing: subscribing ?? (_) => null,
subscribed: subscribed ?? (_) => null,
);

Map<String, Object?> toJson() => <String, Object?>{
'type': type,
'timestamp': timestamp.toUtc().toIso8601String(),
if (since != null)
'since': switch (since) {
(:fixnum.Int64 offset, :String epoch) => <String, Object>{
'offset': offset,
'epoch': epoch,
},
_ => null,
},
'recoverable': recoverable,
};
}

0 comments on commit ad8099e

Please sign in to comment.