Skip to content

Commit 9ee7f9a

Browse files
committed
PubNub Swift Chat SDK 0.10.3 release
fix(membership): Fix the error when retrieving the unread messages count on the Membership instance
1 parent c5b7919 commit 9ee7f9a

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Sources/Entities/Membership.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ public protocol Membership {
8585
///
8686
/// - Parameters:
8787
/// - completion: The async `Result` of the method call
88-
/// - **Success**: The number of unread messages on the membership's channel
88+
/// - **Success**: The number of unread messages on the membership's channel or `nil` when ``lastReadMessageTimetoken`` is also `nil`
8989
/// - **Failure**: An `Error` describing the failure
9090
func getUnreadMessagesCount(
91-
completion: ((Swift.Result<UInt64, Error>) -> Void)?
91+
completion: ((Swift.Result<UInt64?, Error>) -> Void)?
9292
)
9393

9494
/// You can receive updates when specific user-channel Membership object(s) are added, edited, or removed.

Sources/Entities/MembershipImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ extension MembershipImpl: Membership {
124124
}
125125
}
126126

127-
public func getUnreadMessagesCount(completion: ((Swift.Result<UInt64, Error>) -> Void)? = nil) {
128-
membership.getUnreadMessagesCount().async(caller: self) { (result: FutureResult<MembershipImpl, UInt64>) in
127+
public func getUnreadMessagesCount(completion: ((Swift.Result<UInt64?, Error>) -> Void)? = nil) {
128+
membership.getUnreadMessagesCount().async(caller: self) { (result: FutureResult<MembershipImpl, UInt64?>) in
129129
switch result.result {
130130
case let .success(messagesCount):
131131
completion?(.success(messagesCount))

Tests/MembershipIntegrationTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ final class MembershipTests: PubNubSwiftChatSDKIntegrationTests {
106106
)
107107
}
108108

109+
func testMembership_GetUnreadMessagesCountForEmptyChannel() throws {
110+
let someMembership = MembershipImpl(
111+
chat: chat,
112+
channel: channel,
113+
user: UserImpl(chat: chat, id: randomString())
114+
)
115+
XCTAssertNil(
116+
try awaitResultValue {
117+
someMembership.getUnreadMessagesCount(completion: $0)
118+
}
119+
)
120+
}
121+
109122
func testMembership_StreamUpdates() throws {
110123
let expectation = expectation(description: "MembershipStreamUpdates")
111124
expectation.assertForOverFulfill = true

0 commit comments

Comments
 (0)