Skip to content

Commit

Permalink
Add getters to sub state
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Jul 28, 2023
1 parent b7bdcf1 commit d640c43
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/src/subscription/client_subscription_impl.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'dart:async';

import 'package:centrifuge_dart/centrifuge.dart';
import 'package:centrifuge_dart/src/subscription/subscription.dart';
import 'package:centrifuge_dart/src/subscription/subscription_config.dart';
import 'package:centrifuge_dart/src/subscription/subscription_state.dart';
import 'package:centrifuge_dart/src/subscription/subscription_states_stream.dart';
import 'package:centrifuge_dart/src/transport/transport_interface.dart';
import 'package:centrifuge_dart/src/util/event_queue.dart';
Expand Down Expand Up @@ -238,6 +235,7 @@ base mixin CentrifugeClientSubscriptionSubscribeMixin
/// {@nodoc}
@override
Future<void> unsubscribe() async {
if (state.isUnsubscribed) return;
// TODO(plugfox): implement
}

Expand Down
36 changes: 36 additions & 0 deletions lib/src/subscription/subscription_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ final class CentrifugeSubscriptionState$Unsubscribed
/// Unsubscribe reason.
final String reason;

@override
bool get isUnsubscribed => true;

@override
bool get isSubscribing => false;

@override
bool get isSubscribed => false;

@override
R map<R>({
required CentrifugeSubscriptionStateMatch<R,
Expand Down Expand Up @@ -101,6 +110,15 @@ final class CentrifugeSubscriptionState$Subscribing
({fixnum.Int64 offset, String epoch})? since,
}) : super(timestamp ?? DateTime.now(), since);

@override
bool get isUnsubscribed => false;

@override
bool get isSubscribing => true;

@override
bool get isSubscribed => false;

@override
R map<R>({
required CentrifugeSubscriptionStateMatch<R,
Expand Down Expand Up @@ -145,6 +163,15 @@ final class CentrifugeSubscriptionState$Subscribed
/// Time to live in seconds.
final DateTime? ttl;

@override
bool get isUnsubscribed => false;

@override
bool get isSubscribing => false;

@override
bool get isSubscribed => true;

@override
R map<R>({
required CentrifugeSubscriptionStateMatch<R,
Expand Down Expand Up @@ -189,6 +216,15 @@ abstract base class _$CentrifugeSubscriptionStateBase {
/// Stream Position
final ({fixnum.Int64 offset, String epoch})? since;

/// Whether channel is unsubscribed.
abstract final bool isUnsubscribed;

/// Whether channel is subscribing.
abstract final bool isSubscribing;

/// Whether channel is subscribed.
abstract final bool isSubscribed;

/// Pattern matching for [CentrifugeSubscriptionState].
R map<R>({
required CentrifugeSubscriptionStateMatch<R,
Expand Down

0 comments on commit d640c43

Please sign in to comment.