Skip to content

Commit

Permalink
Fix tests related with Channel/ThreadChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Dec 13, 2024
1 parent 301eac7 commit 36b10e0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
14 changes: 7 additions & 7 deletions PubNubSwiftChatSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
3D2CA2482C621876008D2284 /* MessageActionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D2CA2472C621876008D2284 /* MessageActionType.swift */; };
3D334BD02C8EE9E500F8793C /* PubNub.PushService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D334BCF2C8EE9E500F8793C /* PubNub.PushService.swift */; };
3D334BD22C8EEAA800F8793C /* PubNub.PushEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D334BD12C8EEAA800F8793C /* PubNub.PushEnvironment.swift */; };
3D79EB842D0C39C100F7AB56 /* PubNubChat in Frameworks */ = {isa = PBXBuildFile; productRef = 3D79EB832D0C39C100F7AB56 /* PubNubChat */; };
3D60C28C2D0CDC0A00C17981 /* PubNubChat in Frameworks */ = {isa = PBXBuildFile; productRef = 3D60C28B2D0CDC0A00C17981 /* PubNubChat */; };
3D79EB862D0C40ED00F7AB56 /* PubNubChat.PubNubError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D79EB852D0C40ED00F7AB56 /* PubNubChat.PubNubError.swift */; };
3D7BBF6F2C8893D400FBA623 /* ChatAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D7BBF6E2C8893D400FBA623 /* ChatAdapter.swift */; };
3D83621A2CC7B35200A21B9A /* MessageDraftChangeListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D8362192CC7B35200A21B9A /* MessageDraftChangeListener.swift */; };
Expand Down Expand Up @@ -192,7 +192,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3D79EB842D0C39C100F7AB56 /* PubNubChat in Frameworks */,
3D60C28C2D0CDC0A00C17981 /* PubNubChat in Frameworks */,
3DCF7DFC2CD0FFCC00889326 /* PubNubSDK in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -401,7 +401,7 @@
name = PubNubSwiftChatSDK;
packageProductDependencies = (
3DCF7DFB2CD0FFCC00889326 /* PubNubSDK */,
3D79EB832D0C39C100F7AB56 /* PubNubChat */,
3D60C28B2D0CDC0A00C17981 /* PubNubChat */,
);
productName = PubNubChatSDK;
productReference = 3DB73A072C4FE13C007FE249 /* PubNubSwiftChatSDK.framework */;
Expand Down Expand Up @@ -455,7 +455,7 @@
mainGroup = 3DB739FD2C4FE13B007FE249;
packageReferences = (
3DCF7DFA2CD0FFCC00889326 /* XCRemoteSwiftPackageReference "swift" */,
3D79EB822D0C39C100F7AB56 /* XCRemoteSwiftPackageReference "kmp-chat" */,
3D60C28A2D0CDC0A00C17981 /* XCRemoteSwiftPackageReference "kmp-chat" */,
);
productRefGroup = 3DB73A082C4FE13C007FE249 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -881,7 +881,7 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
3D79EB822D0C39C100F7AB56 /* XCRemoteSwiftPackageReference "kmp-chat" */ = {
3D60C28A2D0CDC0A00C17981 /* XCRemoteSwiftPackageReference "kmp-chat" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pubnub/kmp-chat";
requirement = {
Expand All @@ -900,9 +900,9 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
3D79EB832D0C39C100F7AB56 /* PubNubChat */ = {
3D60C28B2D0CDC0A00C17981 /* PubNubChat */ = {
isa = XCSwiftPackageProductDependency;
package = 3D79EB822D0C39C100F7AB56 /* XCRemoteSwiftPackageReference "kmp-chat" */;
package = 3D60C28A2D0CDC0A00C17981 /* XCRemoteSwiftPackageReference "kmp-chat" */;
productName = PubNubChat;
};
3DCF7DFB2CD0FFCC00889326 /* PubNubSDK */ = {
Expand Down
20 changes: 9 additions & 11 deletions Sources/Entities/BaseChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ final class BaseChannel<C: PubNubChat.Channel_, M: PubNubChat.Message>: Channel
}
}

func startTyping(completion: ((Swift.Result<Void, Error>) -> Void)?) {
channel.startTyping().async(caller: self) { (result: FutureResult<BaseChannel, PubNubChat.KotlinUnit>) in
func startTyping(completion: ((Swift.Result<Timetoken?, Error>) -> Void)?) {
channel.startTyping().async(caller: self) { (result: FutureResult<BaseChannel, PubNubChat.PNPublishResult?>) in
switch result.result {
case .success:
completion?(.success(()))
case let .success(publishRes):
completion?(.success(publishRes?.timetoken.asTimetoken()))
case let .failure(error):
completion?(.failure(error))
}
}
}

func stopTyping(completion: ((Swift.Result<Void, Error>) -> Void)?) {
channel.stopTyping().async(caller: self) { (result: FutureResult<BaseChannel, PubNubChat.KotlinUnit>) in
func stopTyping(completion: ((Swift.Result<Timetoken?, Error>) -> Void)?) {
channel.stopTyping().async(caller: self) { (result: FutureResult<BaseChannel, PubNubChat.PNPublishResult?>) in
switch result.result {
case .success:
completion?(.success(()))
case let .success(publishRes):
completion?(.success(publishRes?.timetoken.asTimetoken()))
case let .failure(error):
completion?(.failure(error))
}
Expand Down Expand Up @@ -274,9 +274,7 @@ final class BaseChannel<C: PubNubChat.Channel_, M: PubNubChat.Message>: Channel
case let .success(response):
completion?(.success(
(
memberships: response.members.compactMap {
$0 as? PubNubChat.Membership
}.map {
memberships: response.members.map {
MembershipImpl(membership: $0)
},
page: PubNubHashedPageBase(
Expand Down
8 changes: 4 additions & 4 deletions Sources/Entities/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ public protocol Channel {
///
/// - Parameters:
/// - completion: The async `Result` of the method call
/// - **Success**: A `Void` indicating a success
/// - **Success**: A `Timetoken` indicating the action timestamp
/// - **Failure**: An `Error` describing the failure
func startTyping(
completion: ((Swift.Result<Void, Error>) -> Void)?
completion: ((Swift.Result<Timetoken?, Error>) -> Void)?
)

/// Deactivates a typing indicator on a given channel.
///
/// - Parameters:
/// - completion: The async `Result` of the method call
/// - **Success**: A `Void` indicating a success
/// - **Success**: A `Timetoken` indicating the action timestamp
/// - **Failure**: An `Error` describing the failure
func stopTyping(
completion: ((Swift.Result<Void, Error>) -> Void)?
completion: ((Swift.Result<Timetoken?, Error>) -> Void)?
)

/// Enables continuous tracking of typing activity within the ``Channel``.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Entities/ChannelImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ extension ChannelImpl: Channel {
)
}

public func startTyping(completion: ((Swift.Result<Void, Error>) -> Void)? = nil) {
public func startTyping(completion: ((Swift.Result<Timetoken?, Error>) -> Void)? = nil) {
target.startTyping(
completion: completion
)
}

public func stopTyping(completion: ((Swift.Result<Void, Error>) -> Void)? = nil) {
public func stopTyping(completion: ((Swift.Result<Timetoken?, Error>) -> Void)? = nil) {
target.stopTyping(
completion: completion
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Entities/ThreadChannelImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ extension ThreadChannelImpl: ThreadChannel {
)
}

public func startTyping(completion: ((Swift.Result<Void, Error>) -> Void)? = nil) {
public func startTyping(completion: ((Swift.Result<Timetoken?, Error>) -> Void)? = nil) {
target.startTyping(
completion: completion
)
}

public func stopTyping(completion: ((Swift.Result<Void, Error>) -> Void)? = nil) {
public func stopTyping(completion: ((Swift.Result<Timetoken?, Error>) -> Void)? = nil) {
target.stopTyping(
completion: completion
)
Expand Down
6 changes: 6 additions & 0 deletions Sources/Extensions/Timetoken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ extension Timetoken {
KotlinLong(value: Int64(self))
}
}

extension Int64 {
func asTimetoken() -> Timetoken {
Timetoken(self)
}
}
8 changes: 3 additions & 5 deletions Tests/ChannelIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,9 @@ class ChannelIntegrationTests: PubNubSwiftChatSDKIntegrationTests {
}

func testChannel_StopTyping() throws {
XCTAssertNotNil(
try awaitResultValue {
channel.stopTyping(completion: $0)
}
)
try awaitResultValue {
channel.stopTyping(completion: $0)
}
}

func testChannel_WhoIsPresent() throws {
Expand Down

0 comments on commit 36b10e0

Please sign in to comment.