From ad8099e0591dce330aa4154bc38733cf7173d66f Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Fri, 4 Aug 2023 08:41:29 +0400 Subject: [PATCH] Update subscription state --- lib/src/client/state.dart | 2 +- lib/src/subscription/subscription_state.dart | 35 ++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/src/client/state.dart b/lib/src/client/state.dart index ffc0722..8488ae8 100644 --- a/lib/src/client/state.dart +++ b/lib/src/client/state.dart @@ -485,7 +485,7 @@ abstract base class _$SpinifyStateBase { Map toJson() => { 'type': type, - 'timestamp': timestamp.microsecondsSinceEpoch, + 'timestamp': timestamp.toUtc().toIso8601String(), if (url != null) 'url': url, }; } diff --git a/lib/src/subscription/subscription_state.dart b/lib/src/subscription/subscription_state.dart index 265ac34..e04971b 100644 --- a/lib/src/subscription/subscription_state.dart +++ b/lib/src/subscription/subscription_state.dart @@ -50,7 +50,7 @@ sealed class SpinifySubscriptionState extends _$SpinifySubscriptionStateBase { /// Unsubscribed state /// -/// {@nodoc} +/// {@macro subscription_state} /// {@category Subscription} /// {@category Entity} final class SpinifySubscriptionState$Unsubscribed @@ -99,6 +99,13 @@ final class SpinifySubscriptionState$Unsubscribed }) => unsubscribed(this); + @override + Map toJson() => { + ...super.toJson(), + 'code': code, + 'reason': reason, + }; + @override int get hashCode => Object.hash(0, timestamp, since); @@ -110,7 +117,8 @@ final class SpinifySubscriptionState$Unsubscribed } /// Subscribing state -/// {@nodoc} +/// +/// {@macro subscription_state} /// {@category Subscription} /// {@category Entity} final class SpinifySubscriptionState$Subscribing @@ -162,7 +170,8 @@ final class SpinifySubscriptionState$Subscribing } /// Subscribed state -/// {@nodoc} +/// +/// {@macro subscription_state} /// {@category Subscription} /// {@category Entity} final class SpinifySubscriptionState$Subscribed extends SpinifySubscriptionState @@ -207,6 +216,12 @@ final class SpinifySubscriptionState$Subscribed extends SpinifySubscriptionState }) => subscribed(this); + @override + Map toJson() => { + ...super.toJson(), + if (ttl != null) 'ttl': ttl?.toUtc().toIso8601String(), + }; + @override int get hashCode => Object.hash(2, timestamp, since, recoverable, ttl); @@ -299,4 +314,18 @@ abstract base class _$SpinifySubscriptionStateBase { subscribing: subscribing ?? (_) => null, subscribed: subscribed ?? (_) => null, ); + + Map toJson() => { + 'type': type, + 'timestamp': timestamp.toUtc().toIso8601String(), + if (since != null) + 'since': switch (since) { + (:fixnum.Int64 offset, :String epoch) => { + 'offset': offset, + 'epoch': epoch, + }, + _ => null, + }, + 'recoverable': recoverable, + }; }