Skip to content

Commit

Permalink
feat(subscribe): add subscription list changed status
Browse files Browse the repository at this point in the history
  • Loading branch information
parfeon committed Feb 8, 2024
1 parent 03b5201 commit d5465f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dx/subscribe/event_engine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ impl SubscribeState {
input: SubscriptionInput::new(channels, channel_groups),
cursor: cursor.clone(),
}),
None,
Some(vec![EmitStatus(ConnectionStatus::SubscriptionChanged {
channels: channels.clone(),
channel_groups: channel_groups.clone(),
})]),
))
}
Self::ReceiveFailed { cursor, .. } => Some(self.transition_to(
Expand Down Expand Up @@ -290,7 +293,10 @@ impl SubscribeState {
input: SubscriptionInput::new(channels, channel_groups),
cursor: restore_cursor.clone(),
}),
None,
Some(vec![EmitStatus(ConnectionStatus::SubscriptionChanged {
channels: channels.clone(),
channel_groups: channel_groups.clone(),
})]),
)),
Self::ReceiveFailed { .. } => Some(self.transition_to(
Some(Self::Handshaking {
Expand Down
24 changes: 24 additions & 0 deletions src/dx/subscribe/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ pub enum ConnectionStatus {

/// Unexpected disconnection.
DisconnectedUnexpectedly(PubNubError),

/// List of channels and groups changed in subscription.
SubscriptionChanged {
/// List of channels used in subscription.
///
/// Channels can be:
/// - regular channels
/// - channel metadata `id`s
/// - user metadata `id`s
channels: Option<Vec<String>>,

/// List of channel groups used in subscription.
channel_groups: Option<Vec<String>>,
},
}

/// Presence update information.
Expand Down Expand Up @@ -733,6 +747,16 @@ impl Debug for ConnectionStatus {
ConnectionStatus::DisconnectedUnexpectedly(err) => {
write!(f, "DisconnectedUnexpectedly({err:?})")
}
Self::SubscriptionChanged {
channels,
channel_groups,
} => {
write!(
f,
"SubscriptionChanged {{ channels: {channels:?}, \
channel_groups: {channel_groups:?} }}"
)
}
}
}
}
Expand Down

0 comments on commit d5465f9

Please sign in to comment.