Skip to content

Commit 9868745

Browse files
authored
Calling .leave request when unsubscribing (#180)
fix(presence): calling .leave request in missing cases
1 parent 2eedd48 commit 9868745

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

.pubnub.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
---
22
name: swift
33
scm: github.com/pubnub/swift
4-
version: "7.3.0"
4+
version: "7.3.1"
55
schema: 1
66
changelog:
7+
- date: 2024-06-18
8+
version: 7.3.1
9+
changes:
10+
- type: bug
11+
text: "Calling .leave request in missing cases."
712
- date: 2024-06-12
813
version: 7.3.0
914
changes:
@@ -554,7 +559,7 @@ sdks:
554559
- distribution-type: source
555560
distribution-repository: GitHub release
556561
package-name: PubNub
557-
location: https://github.com/pubnub/swift/archive/refs/tags/7.3.0.zip
562+
location: https://github.com/pubnub/swift/archive/refs/tags/7.3.1.zip
558563
supported-platforms:
559564
supported-operating-systems:
560565
macOS:

PubNub.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,7 +3847,7 @@
38473847
"@loader_path/Frameworks",
38483848
);
38493849
MACOSX_DEPLOYMENT_TARGET = 10.15;
3850-
MARKETING_VERSION = 7.3.0;
3850+
MARKETING_VERSION = 7.3.1;
38513851
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
38523852
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
38533853
MTL_FAST_MATH = YES;
@@ -3898,7 +3898,7 @@
38983898
"@loader_path/Frameworks",
38993899
);
39003900
MACOSX_DEPLOYMENT_TARGET = 10.15;
3901-
MARKETING_VERSION = 7.3.0;
3901+
MARKETING_VERSION = 7.3.1;
39023902
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
39033903
MTL_ENABLE_DEBUG_INFO = NO;
39043904
MTL_FAST_MATH = YES;
@@ -4006,7 +4006,7 @@
40064006
"@loader_path/Frameworks",
40074007
);
40084008
MACOSX_DEPLOYMENT_TARGET = 10.15;
4009-
MARKETING_VERSION = 7.3.0;
4009+
MARKETING_VERSION = 7.3.1;
40104010
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
40114011
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
40124012
MTL_FAST_MATH = YES;
@@ -4059,7 +4059,7 @@
40594059
"@loader_path/Frameworks",
40604060
);
40614061
MACOSX_DEPLOYMENT_TARGET = 10.15;
4062-
MARKETING_VERSION = 7.3.0;
4062+
MARKETING_VERSION = 7.3.1;
40634063
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
40644064
MTL_ENABLE_DEBUG_INFO = NO;
40654065
MTL_FAST_MATH = YES;
@@ -4180,7 +4180,7 @@
41804180
"@loader_path/Frameworks",
41814181
);
41824182
MACOSX_DEPLOYMENT_TARGET = 10.15;
4183-
MARKETING_VERSION = 7.3.0;
4183+
MARKETING_VERSION = 7.3.1;
41844184
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
41854185
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
41864186
MTL_FAST_MATH = YES;
@@ -4232,7 +4232,7 @@
42324232
"@loader_path/Frameworks",
42334233
);
42344234
MACOSX_DEPLOYMENT_TARGET = 10.15;
4235-
MARKETING_VERSION = 7.3.0;
4235+
MARKETING_VERSION = 7.3.1;
42364236
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++17";
42374237
MTL_ENABLE_DEBUG_INFO = NO;
42384238
MTL_FAST_MATH = YES;
@@ -4712,7 +4712,7 @@
47124712
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
47134713
);
47144714
MACOSX_DEPLOYMENT_TARGET = 10.15;
4715-
MARKETING_VERSION = 7.3.0;
4715+
MARKETING_VERSION = 7.3.1;
47164716
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++14";
47174717
OTHER_CFLAGS = "$(inherited)";
47184718
OTHER_LDFLAGS = "$(inherited)";
@@ -4754,7 +4754,7 @@
47544754
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
47554755
);
47564756
MACOSX_DEPLOYMENT_TARGET = 10.15;
4757-
MARKETING_VERSION = 7.3.0;
4757+
MARKETING_VERSION = 7.3.1;
47584758
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++14";
47594759
OTHER_CFLAGS = "$(inherited)";
47604760
OTHER_LDFLAGS = "$(inherited)";

PubNubSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'PubNubSwift'
3-
s.version = '7.3.0'
3+
s.version = '7.3.1'
44
s.homepage = 'https://github.com/pubnub/swift'
55
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
66
s.authors = { 'PubNub, Inc.' => '[email protected]' }

Sources/PubNub/EventEngine/Presence/PresenceTransition.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ class PresenceTransition: TransitionProtocol {
2626
case .joined:
2727
return configuration.heartbeatInterval > 0
2828
case .left:
29-
return !(state is Presence.HeartbeatInactive)
29+
return true
3030
case .heartbeatSuccess:
3131
return state is Presence.Heartbeating
3232
case .heartbeatFailed:
3333
return state is Presence.Heartbeating
3434
case .timesUp:
3535
return state is Presence.HeartbeatCooldown
3636
case .leftAll:
37-
return !(state is Presence.HeartbeatInactive)
37+
return true
3838
case .disconnect:
3939
return !(state is Presence.HeartbeatInactive)
4040
case .reconnect:
@@ -120,19 +120,22 @@ fileprivate extension PresenceTransition {
120120
channels: leaving.channels,
121121
groups: leaving.groups
122122
)
123+
let invocations = configuration.supressLeaveEvents ? [] : [
124+
EffectInvocation.regular(Presence.Invocation.leave(
125+
channels: leaving.channels,
126+
groups: leaving.groups
127+
))
128+
]
129+
123130
if state is Presence.HeartbeatStopped {
124131
return TransitionResult(
125132
state: Presence.HeartbeatStopped(input: newInput),
126-
invocations: []
133+
invocations: invocations
127134
)
128135
} else {
129-
let leaveInvocation = EffectInvocation.regular(Presence.Invocation.leave(
130-
channels: leaving.channels,
131-
groups: leaving.groups
132-
))
133136
return TransitionResult(
134137
state: newInput.isEmpty ? Presence.HeartbeatInactive() : Presence.Heartbeating(input: newInput),
135-
invocations: configuration.supressLeaveEvents ? [] : [leaveInvocation]
138+
invocations: invocations
136139
)
137140
}
138141
}

Sources/PubNub/Helpers/Constants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public enum Constant {
5757

5858
static let pubnubSwiftSDKName: String = "PubNubSwift"
5959

60-
static let pubnubSwiftSDKVersion: String = "7.3.0"
60+
static let pubnubSwiftSDKVersion: String = "7.3.1"
6161

6262
static let appBundleId: String = {
6363
if let info = Bundle.main.infoDictionary,

Tests/PubNubTests/EventEngine/Presence/PresenceTransitionTests.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ class PresenceTransitionTests: XCTestCase {
200200
let expectedState = Presence.HeartbeatStopped(
201201
input: PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])
202202
)
203+
let expectedInvocations: [EffectInvocation<Presence.Invocation>] = [
204+
.regular(.leave(channels: ["c3"], groups: ["g3"])),
205+
]
203206

204207
XCTAssertTrue(results.state.isEqual(to: expectedState))
205-
XCTAssertTrue(results.invocations.isEmpty)
208+
XCTAssertTrue(results.invocations.elementsEqual(expectedInvocations))
206209
}
207210

208211
func testPresence_LeftEventForCooldownState() {
@@ -294,6 +297,23 @@ class PresenceTransitionTests: XCTestCase {
294297
XCTAssertTrue(results.invocations.elementsEqual(expectedInvocations))
295298
}
296299

300+
func testPresence_LeftAllForHeartbeatStoppedState() {
301+
let input = PresenceInput(
302+
channels: ["c1", "c2"],
303+
groups: ["g1", "g2"]
304+
)
305+
let results = transition.transition(
306+
from: Presence.HeartbeatStopped(input: input),
307+
event: .leftAll
308+
)
309+
let expectedInvocations: [EffectInvocation<Presence.Invocation>] = [
310+
.regular(.leave(channels: ["c1", "c2"], groups: ["g1", "g2"]))
311+
]
312+
313+
XCTAssertTrue(results.state.isEqual(to: Presence.HeartbeatInactive()))
314+
XCTAssertTrue(results.invocations.elementsEqual(expectedInvocations))
315+
}
316+
297317
func testPresence_LeftAllForCooldownState() {
298318
let input = PresenceInput(
299319
channels: ["c1", "c2"],

0 commit comments

Comments
 (0)