Skip to content

Commit

Permalink
Fixes according to review
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Jan 31, 2025
1 parent 2c8d26b commit af4e593
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ disabled_rules:
- type_name
- function_body_length
- function_parameter_count
- type_body_length
included:
- Sources/
excluded:
- Tests/
opt_in_rules:
- force_unwrapping
Expand Down
1 change: 0 additions & 1 deletion Sources/Entities/BaseChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Foundation
import PubNubChat
import PubNubSDK

// swiftlint:disable:next type_body_length
final class BaseChannel<C: PubNubChat.Channel_, M: PubNubChat.Message>: Channel {
var chat: ChatImpl { ChatAdapter.map(chat: channel.chat).chat }
var id: String { channel.id }
Expand Down
4 changes: 2 additions & 2 deletions Sources/Entities/ThreadChannel+AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public extension ThreadChannel {
/// Pins a selected thread message to the thread channel.
///
/// - Parameter message: A message you want to pin to the selected thread channel
/// - Returns: An updated `TheadChannel`
/// - Returns: An updated `ThreadChannel`
func pinMessageToParentChannel(message: ChatType.ChatThreadMessageType) async throws -> ChatType.ChatChannelType {
try await withCheckedThrowingContinuation { continuation in
pinMessageToParentChannel(message: message) {
Expand All @@ -34,7 +34,7 @@ public extension ThreadChannel {

/// Unpins the previously pinned thread message from the thread channel.
///
/// - Returns: An updated `TheadChannel`
/// - Returns: An updated `ThreadChannel`
func unpinMessageFromParentChannel() async throws -> ChatType.ChatChannelType {
try await withCheckedThrowingContinuation { continuation in
unpinMessageFromParentChannel {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Entities/ThreadChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public protocol ThreadChannel: Channel {
/// - Parameters:
/// - message: A message you want to pin to the selected thread channel
/// - completion: The async `Result` of the method call
/// - **Success**: An updated `TheadChannel`
/// - **Success**: An updated `ThreadChannel`
/// - **Failure**: An `Error` describing the failure
func pinMessageToParentChannel(
message: ChatType.ChatThreadMessageType,
Expand All @@ -38,7 +38,7 @@ public protocol ThreadChannel: Channel {
///
/// - Parameters:
/// - completion: The async `Result` of the method call
/// - **Success**: An updated `TheadChannel`
/// - **Success**: An updated `ThreadChannel`
/// - **Failure**: An `Error` describing the failure
func unpinMessageFromParentChannel(
completion: ((Swift.Result<ChatType.ChatChannelType, Error>) -> Void)?
Expand Down
2 changes: 1 addition & 1 deletion Sources/Entities/ThreadMessage+AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public extension ThreadMessage {
/// * `pinnedMessageTimetoken`: The timetoken marking when the message was pinned
/// * `pinnedMessageChannelID`: The ID of the channel where the message was pinned (either the parent channel or a thread channel)
///
/// - Parameters: The updated Channel after the message is unpinned
/// - Returns: The updated Channel after the message is unpinned
@discardableResult
func unpinFromParentChannel() async throws -> ChatType.ChatChannelType {
try await withCheckedThrowingContinuation { continuation in
Expand Down
2 changes: 1 addition & 1 deletion Sources/Entities/User+AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public extension User {
/// Deletes the user. If soft deletion is enabled, the user's data is retained but marked as inactive.
///
/// - Parameter soft: If true, the user is soft deleted, retaining their data but making them inactive
/// - Returns: For hard delete, the method returns `nil`. Otherwise, an updated ``User`` instance with the status field set to `"deleted"`
/// - Returns: Returns `nil` if the user was hard-deleted. Otherwise, an updated ``User`` instance with the status field set to `"deleted"`
func delete(soft: Bool = false) async throws -> ChatType.ChatUserType? {
try await withCheckedThrowingContinuation { continuation in
delete(soft: soft) {
Expand Down
20 changes: 10 additions & 10 deletions Tests/AsyncAwait/ChannelAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ class ChannelIntegrationTests: BaseAsyncIntegrationTestCase {
let newChannel = try await newChat.createChannel(
id: randomString()
)
let inputFile = try InputFile(
let inputFile = InputFile(
name: "TxtFile",
type: "text/plain",
source: .data(XCTUnwrap("Lorem ipsum".data(using: .utf8)), contentType: "text/plain")
source: .data(Data("Lorem ipsum".utf8), contentType: "text/plain")
)

try await newChannel.sendText(text: "Text", files: [inputFile])
Expand Down Expand Up @@ -437,10 +437,10 @@ class ChannelIntegrationTests: BaseAsyncIntegrationTestCase {
let newChannel = try await newChat.createChannel(
id: randomString()
)
let inputFile = try InputFile(
let inputFile = InputFile(
name: "TxtFile",
type: "text/plain",
source: .data(XCTUnwrap("Lorem ipsum".data(using: .utf8)), contentType: "text/plain")
source: .data(Data("Lorem ipsum".utf8), contentType: "text/plain")
)

try await newChannel.sendText(text: "Text", files: [inputFile])
Expand Down Expand Up @@ -471,12 +471,10 @@ class ChannelIntegrationTests: BaseAsyncIntegrationTestCase {
}

let presenceStreamTask = Task {
for await userIdentifiers in channel.streamPresence() {
if !userIdentifiers.isEmpty {
XCTAssertEqual(userIdentifiers.count, 1)
XCTAssertEqual(userIdentifiers.first, chat.currentUser.id)
expectation.fulfill()
}
for await userIdentifiers in channel.streamPresence() where !userIdentifiers.isEmpty {
XCTAssertEqual(userIdentifiers.count, 1)
XCTAssertEqual(userIdentifiers.first, chat.currentUser.id)
expectation.fulfill()
}
}

Expand Down Expand Up @@ -542,4 +540,6 @@ class ChannelIntegrationTests: BaseAsyncIntegrationTestCase {
_ = try? await message?.delete()
}
}

// swiftlint:disable:next file_length
}
2 changes: 2 additions & 0 deletions Tests/AsyncAwait/ChatAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,6 @@ class ChatAsyncIntegrationTests: BaseAsyncIntegrationTestCase {
try await chat.mutedUsersManager.unmuteUser(userId: userToMute)
XCTAssertTrue(chat.mutedUsersManager.mutedUsers.isEmpty)
}

// swiftlint:disable:next file_length
}
7 changes: 4 additions & 3 deletions Tests/AsyncAwait/ThreadMessageAsyncIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ class ThreadMessageaAsyncIntegrationTests: BaseAsyncIntegrationTestCase {

let task = Task {
for await receivedMessages in ThreadMessageImpl.streamUpdatesOn(messages: [unwrappedMessage]) {
XCTAssertTrue(receivedMessages.first!.hasUserReaction(reaction: "myReaction"))
XCTAssertEqual(receivedMessages.first!.channelId, unwrappedMessage.channelId)
XCTAssertEqual(receivedMessages.first!.userId, unwrappedMessage.userId)
let message = try XCTUnwrap(receivedMessages.first)
XCTAssertTrue(message.hasUserReaction(reaction: "myReaction"))
XCTAssertEqual(message.channelId, unwrappedMessage.channelId)
XCTAssertEqual(message.userId, unwrappedMessage.userId)
expectation.fulfill()
}
}
Expand Down
10 changes: 6 additions & 4 deletions Tests/ChannelIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,10 @@ class ChannelIntegrationTests: BaseClosureIntegrationTestCase {
completion: $0
)
}
let inputFile = try InputFile(
let inputFile = InputFile(
name: "TxtFile",
type: "text/plain",
source: .data(XCTUnwrap("Lorem ipsum".data(using: .utf8)), contentType: "text/plain")
source: .data(Data("Lorem ipsum".utf8), contentType: "text/plain")
)

try awaitResultValue(timeout: 10) {
Expand Down Expand Up @@ -732,10 +732,10 @@ class ChannelIntegrationTests: BaseClosureIntegrationTestCase {
completion: $0
)
}
let inputFile = try InputFile(
let inputFile = InputFile(
name: "TxtFile",
type: "text/plain",
source: .data(XCTUnwrap("Lorem ipsum".data(using: .utf8)), contentType: "text/plain")
source: .data(Data("Lorem ipsum".utf8), contentType: "text/plain")
)

try awaitResultValue(timeout: 30) {
Expand Down Expand Up @@ -891,4 +891,6 @@ class ChannelIntegrationTests: BaseClosureIntegrationTestCase {
try awaitResult { message?.delete(completion: $0) }
}
}

// swiftlint:disable:next file_length
}
2 changes: 2 additions & 0 deletions Tests/ChatIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -991,4 +991,6 @@ class ChatIntegrationTests: BaseClosureIntegrationTestCase {
chat.mutedUsersManager.mutedUsers.isEmpty
)
}

// swiftlint:disable:next file_length
}
4 changes: 2 additions & 2 deletions Tests/Common/IntegrationTestCaseConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ enum IntegrationTestCaseConfiguration {
}

return PubNubConfiguration(
publishKey: dictionary["publishKey"]!,
subscribeKey: dictionary["subscribeKey"]!,
publishKey: dictionary["publishKey"] ?? "",
subscribeKey: dictionary["subscribeKey"] ?? "",
userId: RandomStringGenerator().randomString()
)
}
Expand Down
6 changes: 5 additions & 1 deletion Tests/Common/RandomStringGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import Foundation
final class RandomStringGenerator {
func randomString(length: Int = 6) -> String {
String((0 ..< max(1, min(length, 6))).map { _ in
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".randomElement()!
if let character = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".randomElement() {
return character
} else {
preconditionFailure("Empty collection. Aborting")
}
})
}
}
2 changes: 2 additions & 0 deletions Tests/MessageIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,6 @@ final class MessageIntegrationTests: BaseClosureIntegrationTestCase {

XCTAssertTrue(restoredMessage.actions?.isEmpty ?? false)
}

// swiftlint:disable:next file_length
}

0 comments on commit af4e593

Please sign in to comment.