Skip to content

Commit

Permalink
Calling .leave request when unsubscribing (#180)
Browse files Browse the repository at this point in the history
fix(presence): calling .leave request in missing cases
  • Loading branch information
jguz-pubnub authored Jun 18, 2024
1 parent 2eedd48 commit 9868745
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
9 changes: 7 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
name: swift
scm: github.com/pubnub/swift
version: "7.3.0"
version: "7.3.1"
schema: 1
changelog:
- date: 2024-06-18
version: 7.3.1
changes:
- type: bug
text: "Calling .leave request in missing cases."
- date: 2024-06-12
version: 7.3.0
changes:
Expand Down Expand Up @@ -554,7 +559,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: PubNub
location: https://github.com/pubnub/swift/archive/refs/tags/7.3.0.zip
location: https://github.com/pubnub/swift/archive/refs/tags/7.3.1.zip
supported-platforms:
supported-operating-systems:
macOS:
Expand Down
16 changes: 8 additions & 8 deletions PubNub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3847,7 +3847,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 7.3.0;
MARKETING_VERSION = 7.3.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -3898,7 +3898,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 7.3.0;
MARKETING_VERSION = 7.3.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -4006,7 +4006,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 7.3.0;
MARKETING_VERSION = 7.3.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -4059,7 +4059,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 7.3.0;
MARKETING_VERSION = 7.3.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -4180,7 +4180,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 7.3.0;
MARKETING_VERSION = 7.3.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -4232,7 +4232,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 7.3.0;
MARKETING_VERSION = 7.3.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -4712,7 +4712,7 @@
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 7.3.0;
MARKETING_VERSION = 7.3.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++14";
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
Expand Down Expand Up @@ -4754,7 +4754,7 @@
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 7.3.0;
MARKETING_VERSION = 7.3.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++14";
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
Expand Down
2 changes: 1 addition & 1 deletion PubNubSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PubNubSwift'
s.version = '7.3.0'
s.version = '7.3.1'
s.homepage = 'https://github.com/pubnub/swift'
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
s.authors = { 'PubNub, Inc.' => '[email protected]' }
Expand Down
19 changes: 11 additions & 8 deletions Sources/PubNub/EventEngine/Presence/PresenceTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class PresenceTransition: TransitionProtocol {
case .joined:
return configuration.heartbeatInterval > 0
case .left:
return !(state is Presence.HeartbeatInactive)
return true
case .heartbeatSuccess:
return state is Presence.Heartbeating
case .heartbeatFailed:
return state is Presence.Heartbeating
case .timesUp:
return state is Presence.HeartbeatCooldown
case .leftAll:
return !(state is Presence.HeartbeatInactive)
return true
case .disconnect:
return !(state is Presence.HeartbeatInactive)
case .reconnect:
Expand Down Expand Up @@ -120,19 +120,22 @@ fileprivate extension PresenceTransition {
channels: leaving.channels,
groups: leaving.groups
)
let invocations = configuration.supressLeaveEvents ? [] : [
EffectInvocation.regular(Presence.Invocation.leave(
channels: leaving.channels,
groups: leaving.groups
))
]

if state is Presence.HeartbeatStopped {
return TransitionResult(
state: Presence.HeartbeatStopped(input: newInput),
invocations: []
invocations: invocations
)
} else {
let leaveInvocation = EffectInvocation.regular(Presence.Invocation.leave(
channels: leaving.channels,
groups: leaving.groups
))
return TransitionResult(
state: newInput.isEmpty ? Presence.HeartbeatInactive() : Presence.Heartbeating(input: newInput),
invocations: configuration.supressLeaveEvents ? [] : [leaveInvocation]
invocations: invocations
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/Helpers/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public enum Constant {

static let pubnubSwiftSDKName: String = "PubNubSwift"

static let pubnubSwiftSDKVersion: String = "7.3.0"
static let pubnubSwiftSDKVersion: String = "7.3.1"

static let appBundleId: String = {
if let info = Bundle.main.infoDictionary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,12 @@ class PresenceTransitionTests: XCTestCase {
let expectedState = Presence.HeartbeatStopped(
input: PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])
)
let expectedInvocations: [EffectInvocation<Presence.Invocation>] = [
.regular(.leave(channels: ["c3"], groups: ["g3"])),
]

XCTAssertTrue(results.state.isEqual(to: expectedState))
XCTAssertTrue(results.invocations.isEmpty)
XCTAssertTrue(results.invocations.elementsEqual(expectedInvocations))
}

func testPresence_LeftEventForCooldownState() {
Expand Down Expand Up @@ -294,6 +297,23 @@ class PresenceTransitionTests: XCTestCase {
XCTAssertTrue(results.invocations.elementsEqual(expectedInvocations))
}

func testPresence_LeftAllForHeartbeatStoppedState() {
let input = PresenceInput(
channels: ["c1", "c2"],
groups: ["g1", "g2"]
)
let results = transition.transition(
from: Presence.HeartbeatStopped(input: input),
event: .leftAll
)
let expectedInvocations: [EffectInvocation<Presence.Invocation>] = [
.regular(.leave(channels: ["c1", "c2"], groups: ["g1", "g2"]))
]

XCTAssertTrue(results.state.isEqual(to: Presence.HeartbeatInactive()))
XCTAssertTrue(results.invocations.elementsEqual(expectedInvocations))
}

func testPresence_LeftAllForCooldownState() {
let input = PresenceInput(
channels: ["c1", "c2"],
Expand Down

0 comments on commit 9868745

Please sign in to comment.