diff --git a/lib/src/model/channel_event.dart b/lib/src/model/channel_event.dart index 448a972..17410b6 100644 --- a/lib/src/model/channel_event.dart +++ b/lib/src/model/channel_event.dart @@ -439,7 +439,7 @@ final class SpinifySubscribe extends SpinifyChannelEvent { final bool positioned; /// Data attached to subscription. - final List data; + final List? data; @override bool get isConnect => false; @@ -519,7 +519,7 @@ final class SpinifyConnect extends SpinifyChannelEvent { final String? node; /// Payload of connected push. - final List data; + final List? data; @override bool get isConnect => true; diff --git a/lib/src/model/subscription_state.dart b/lib/src/model/subscription_state.dart index 5d07d06..596c1b3 100644 --- a/lib/src/model/subscription_state.dart +++ b/lib/src/model/subscription_state.dart @@ -31,6 +31,7 @@ sealed class SpinifySubscriptionState extends _$SpinifySubscriptionStateBase { /// Subscribed /// {@macro subscription_state} factory SpinifySubscriptionState.subscribed({ + required List? data, DateTime? timestamp, }) = SpinifySubscriptionState$Subscribed; } @@ -142,9 +143,13 @@ final class SpinifySubscriptionState$Subscribed extends SpinifySubscriptionState { /// {@macro subscription_state} SpinifySubscriptionState$Subscribed({ + required this.data, DateTime? timestamp, }) : super(timestamp: timestamp ?? DateTime.now()); + /// Data + final List? data; + @override String get type => 'subscribed'; diff --git a/lib/src/protobuf/protobuf_codec.dart b/lib/src/protobuf/protobuf_codec.dart index 87296c8..a481162 100644 --- a/lib/src/protobuf/protobuf_codec.dart +++ b/lib/src/protobuf/protobuf_codec.dart @@ -219,9 +219,9 @@ final class ProtobufReplyDecoder extends Converter { event = SpinifyPublication( timestamp: DateTime.now(), channel: channel, - data: push.pub.data, + data: push.pub.hasData() ? push.pub.data : const [], info: _decodeClientInfo(push.pub.info), - offset: push.pub.offset, + offset: push.pub.hasOffset() ? push.pub.offset : null, tags: push.pub.tags, ); } else if (push.hasJoin()) { @@ -254,7 +254,7 @@ final class ProtobufReplyDecoder extends Converter { timestamp: DateTime.now(), channel: channel, recoverable: push.subscribe.recoverable, - data: push.subscribe.data, + data: push.subscribe.hasData() ? push.subscribe.data : null, positioned: push.subscribe.positioned, since: ( offset: push.subscribe.offset, @@ -289,7 +289,7 @@ final class ProtobufReplyDecoder extends Converter { version: push.connect.version, expires: expBool, ttl: ttlDT, - data: push.connect.data, + data: push.connect.hasData() ? push.connect.data : null, node: push.connect.node, pingInterval: pingInterval, sendPong: push.connect.pong == true, @@ -390,7 +390,7 @@ final class ProtobufReplyDecoder extends Converter { // have the "channel" field - I should fill it in manually // by copying the channel from the SubscribeRequest channel: '', - data: pub.data, + data: pub.hasData() ? pub.data : const [], info: _decodeClientInfo(pub.info), offset: pub.offset, tags: pub.tags, @@ -435,7 +435,7 @@ final class ProtobufReplyDecoder extends Converter { version: connect.version, expires: expBool, ttl: ttlDT, - data: connect.data, + data: connect.hasData() ? connect.data : null, subs: switch (connect.subs) { Map map when map.isNotEmpty => { @@ -494,7 +494,7 @@ final class ProtobufReplyDecoder extends Converter { // have the "channel" field - I should fill it in manually // by copying the channel from the SubscribeRequest channel: '', - data: pub.data, + data: pub.hasData() ? pub.data : const [], info: _decodeClientInfo(pub.info), offset: pub.offset, tags: pub.tags, @@ -506,7 +506,7 @@ final class ProtobufReplyDecoder extends Converter { return SpinifyRPCResult( id: id, timestamp: now, - data: rpc.data, + data: rpc.hasData() ? rpc.data : const [], ); } else if (reply.hasRefresh()) { final refresh = reply.refresh; diff --git a/lib/src/spinify_impl.dart b/lib/src/spinify_impl.dart index 748d5d3..9cb8177 100644 --- a/lib/src/spinify_impl.dart +++ b/lib/src/spinify_impl.dart @@ -432,7 +432,7 @@ base mixin SpinifySubscriptionMixin on SpinifyBase, SpinifyCommandMixin { ..epoch = event.since.epoch ..offset = event.since.offset ..onEvent(event) - ..setState(SpinifySubscriptionState.subscribed()); + ..setState(SpinifySubscriptionState.subscribed(data: event.data)); } else if (event is SpinifyUnsubscribe) { // Remove server subscription from the registry on unsubscribe event. _serverSubscriptionRegistry.remove(event.channel) @@ -492,7 +492,7 @@ base mixin SpinifySubscriptionMixin on SpinifyBase, SpinifyCommandMixin { ..recoverable = value.recoverable ..epoch = value.since.epoch ..offset = value.since.offset - ..setState(SpinifySubscriptionState.subscribed()); + ..setState(SpinifySubscriptionState.subscribed(data: value.data)); // Notify about new publications. for (var publication in value.publications) { // If publication has wrong channel, fix it.