Skip to content

Commit

Permalink
wip 24
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Feb 13, 2024
1 parent 2ef1334 commit 734f78e
Showing 1 changed file with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,43 +154,42 @@ class EventEngineSubscriptionSessionStrategy: SubscriptionSessionStrategy {
groups: [PubNubChannel],
presenceGroupsOnly: [PubNubChannel]
) {
// Gets the current list of subscribed channels and channel groups
// Retrieve the current list of subscribed channels and channel groups
let currentChannelsAndGroups = subscribeEngine.state.input
// Returns the result of updating channel and channel group list
// Provides the outcome after updating the list of channels and channel groups
let removingResult = currentChannelsAndGroups.removing(
channels: channels,
presenceChannelsOnly: presenceChannelsOnly,
groups: groups,
presenceGroupsOnly: presenceGroupsOnly
channels: channels,presenceChannelsOnly: presenceChannelsOnly,
groups: groups, presenceGroupsOnly: presenceGroupsOnly
)
let newChannelsAndGroups = removingResult.newInput

if newChannelsAndGroups != currentChannelsAndGroups {
if configuration.maintainPresenceState {
presenceStateContainer.removeState(forChannels: removingResult.removedChannels.map { $0.id })
}
// Dispatch local event first to guarantee the expected order of events.
// An event indicating unsubscribing from channels and channel groups
// should be emitted before an event related to disconnecting
// from the Subscribe loop, assuming you unsubscribed from all channels
// and channel groups
notify {
$0.emit(subscribe: .subscriptionChanged(
.unsubscribed(
channels: removingResult.removedChannels,
groups: removingResult.removedGroups
))
)
}
sendSubscribeEvent(event: .subscriptionChanged(
channels: newChannelsAndGroups.allSubscribedChannelNames,
groups: newChannelsAndGroups.allSubscribedGroupNames
))
sendPresenceEvent(event: .left(
channels: removingResult.removedChannels.map { $0.id },
groups: removingResult.removedGroups.map { $0.id }
))
// Exits if there are no differences for channels or channel groups
guard removingResult.newInput != currentChannelsAndGroups else {
return
}
if configuration.maintainPresenceState {
presenceStateContainer.removeState(forChannels: removingResult.removedChannels.map { $0.id })
}
// Dispatch local event first to guarantee the expected order of events.
// An event indicating unsubscribing from channels and channel groups
// should be emitted before an event related to disconnecting
// from the Subscribe loop, assuming you unsubscribed from all channels
// and channel groups
notify {
$0.emit(subscribe: .subscriptionChanged(
.unsubscribed(
channels: removingResult.removedChannels,
groups: removingResult.removedGroups
))
)
}
sendSubscribeEvent(event: .subscriptionChanged(
channels: removingResult.newInput.allSubscribedChannelNames,
groups: removingResult.newInput.allSubscribedGroupNames
))
sendPresenceEvent(event: .left(
channels: removingResult.removedChannels.map { $0.id },
groups: removingResult.removedGroups.map { $0.id }
))
}

func reconnect(at cursor: SubscribeCursor?) {
Expand Down

0 comments on commit 734f78e

Please sign in to comment.