Skip to content

Commit

Permalink
PubNub Swift Chat SDK 0.9.3 release (#12)
Browse files Browse the repository at this point in the history
refactor(project): run `swiftformat` to uplift the codebase
fix(custom-payloads): add missing initialization for `reactionsActionName` property
fix(channel): add missing `completion:` parameter when sending a text
  • Loading branch information
jguz-pubnub authored Dec 18, 2024
1 parent 8898769 commit 9b666a0
Show file tree
Hide file tree
Showing 27 changed files with 258 additions and 230 deletions.
13 changes: 11 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
---
name: swift-chat-sdk
scm: github.com/pubnub/swift-chat-sdk
version: "0.9.2"
version: "0.9.3"
schema: 1
changelog:
- date: 2024-12-18
version: 0.9.3
changes:
- type: bug
text: "Add missing initialization for `reactionsActionName` property."
- type: bug
text: "Add missing `completion:` parameter when sending a text."
- type: improvement
text: "Run `swiftformat` to uplift the codebase."
- date: 2024-12-17
version: 0.9.2
changes:
Expand Down Expand Up @@ -68,7 +77,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: PubNubSwiftChatSDK
location: https://github.com/pubnub/swift-chat-sdk/archive/refs/tags/0.9.2-dev.zip
location: https://github.com/pubnub/swift-chat-sdk/archive/refs/tags/0.9.3-dev.zip
supported-platforms:
supported-operating-systems:
iOS:
Expand Down
4 changes: 2 additions & 2 deletions PubNubSwiftChatSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.9.2;
MARKETING_VERSION = 0.9.3;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS";
Expand Down Expand Up @@ -782,7 +782,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.9.2;
MARKETING_VERSION = 0.9.3;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS";
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
1. Create or open your project inside Xcode.
2. Navigate to **File -> Add Package Dependencies**.
3. Search for `https://github.com/pubnub/swift-chat-sdk`
4. From the **Dependency Rule** drop-down list, select **Exact**. In the version input field, type `0.9.2-dev`
4. From the **Dependency Rule** drop-down list, select **Exact**. In the version input field, type `0.9.3-dev`
5. Click the **Add Package** button.

For more information see Apple's guide on [Adding Package Dependencies to Your App](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app)
Expand Down
1 change: 0 additions & 1 deletion Sources/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import Foundation
import PubNubSDK
import Combine

/// A protocol that defines the basic structure and behavior for a chat.
///
Expand Down
1 change: 1 addition & 0 deletions Sources/ChatConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class CustomPayloads {
self.getMessageResponseBody = getMessageResponseBody
self.editMessageActionName = editMessageActionName
self.deleteMessageActionName = deleteMessageActionName
self.reactionsActionName = reactionsActionName
}

func transform() -> PubNubChat.CustomPayloads {
Expand Down
20 changes: 11 additions & 9 deletions Sources/ChatImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,17 @@ extension ChatImpl: Chat {
).async(caller: self) { (result: FutureResult<ChatImpl, PubNubChat.MarkAllMessageAsReadResponse>) in
switch result.result {
case let .success(response):
completion?(.success((
memberships: response.memberships.compactMap {
MembershipImpl(membership: $0)
},
page: PubNubHashedPageBase(
start: response.next?.pageHash,
end: response.prev?.pageHash,
totalCount: Int(response.total)
))
completion?(.success(
(
memberships: response.memberships.compactMap {
MembershipImpl(membership: $0)
},
page: PubNubHashedPageBase(
start: response.next?.pageHash,
end: response.prev?.pageHash,
totalCount: Int(response.total)
)
)
))
case let .failure(error):
completion?(.failure(error))
Expand Down
9 changes: 8 additions & 1 deletion Sources/Entities/BaseChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,14 @@ final class BaseChannel<C: PubNubChat.Channel_, M: PubNubChat.Message>: Channel
quotedMessage: quotedMessage?.target.message,
files: files?.compactMap { $0.transform() },
usersToMention: usersToMention
)
).async(caller: self) { (result: FutureResult<BaseChannel, PubNubChat.PNPublishResult>) in
switch result.result {
case let .success(response):
completion?(.success(Timetoken(response.timetoken)))
case let .failure(error):
completion?(.failure(error))
}
}
}

func invite(user: ChatType.ChatUserType, completion: ((Swift.Result<MembershipImpl, Error>) -> Void)?) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Entities/ChannelImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ extension ChannelImpl: Channel {
usePost: Bool = false,
ttl: Int? = nil,
quotedMessage: MessageImpl? = nil,
files: [InputFile]?,
files: [InputFile]? = nil,
usersToMention: [String]? = nil,
completion: ((Swift.Result<Timetoken, Error>) -> Void)? = nil
) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Entities/ThreadChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//

import Foundation
import PubNubSDK
import PubNubChat
import PubNubSDK

/// Represents an object that refers to a single thread (channel) in a chat.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/Entities/ThreadMessageImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public final class ThreadMessageImpl {
}
}

extension ThreadMessageImpl {
public func asMessage() -> MessageImpl {
public extension ThreadMessageImpl {
func asMessage() -> MessageImpl {
MessageImpl(message: target.message)
}
}
Expand Down
4 changes: 1 addition & 3 deletions Sources/Extensions/PubNubChat.PubNubError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@
import Foundation
import PubNubChat

extension PubNubChat.PubNubError: Error {

}
extension PubNubChat.PubNubError: Error {}
44 changes: 22 additions & 22 deletions Sources/MessageDraft/MessageDraft.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//

import Foundation
import PubNubSDK
import PubNubChat
import PubNubSDK

/// An object that refers to a single message that has not been published yet.
public protocol MessageDraft {
Expand Down Expand Up @@ -123,20 +123,20 @@ public enum UserSuggestionSource {
func transform() -> PubNubChat.MessageDraftUserSuggestionSource {
switch self {
case .global:
return .global
.global
case .channel:
return .channel
.channel
}
}

static func from(source: PubNubChat.MessageDraftUserSuggestionSource) -> UserSuggestionSource {
switch source {
case .global:
return .global
.global
case .channel:
return .channel
.channel
default:
return .global
.global
}
}
}
Expand All @@ -150,34 +150,34 @@ public enum MessageElement: Equatable {

static func from(element: PubNubChat.MessageElement) -> MessageElement? {
if let plainTextElement = element as? PubNubChat.MessageElementPlainText {
return .plainText(text: plainTextElement.text)
.plainText(text: plainTextElement.text)
} else if let linkElement = element as? PubNubChat.MessageElementLink, let target = MentionTarget.from(target: linkElement.target) {
return .link(text: linkElement.text, target: target)
.link(text: linkElement.text, target: target)
} else {
return nil
nil
}
}

func isLink() -> Bool {
switch self {
case .plainText:
return false
false
case .link:
return true
true
}
}

func transform() -> PubNubChat.MessageElement {
switch self {
case let .plainText(text):
return MessageElementPlainText(text: text)
MessageElementPlainText(text: text)
case let .link(text, target):
return MessageElementLink(text: text, target: target.transform())
MessageElementLink(text: text, target: target.transform())
}
}
}

public extension Array where Element == MessageElement {
public extension [MessageElement] {
/// Returns `true` if the underlying Array contains any mention (user/channel)
func containsAnyMention() -> Bool {
reduce(into: false) { accumulatedResult, currentElement in
Expand All @@ -198,23 +198,23 @@ public enum MentionTarget: Equatable {
func transform() -> PubNubChat.MentionTarget {
switch self {
case let .channel(channelId):
return MentionTargetChannel(channelId: channelId)
MentionTargetChannel(channelId: channelId)
case let .user(userId):
return MentionTargetUser(userId: userId)
MentionTargetUser(userId: userId)
case let .url(url):
return MentionTargetUrl(url: url)
MentionTargetUrl(url: url)
}
}

static func from(target: PubNubChat.MentionTarget) -> MentionTarget? {
if let channelTarget = target as? PubNubChat.MentionTargetChannel {
return .channel(channelId: channelTarget.channelId)
.channel(channelId: channelTarget.channelId)
} else if let userTarget = target as? PubNubChat.MentionTargetUser {
return .user(userId: userTarget.userId)
.user(userId: userTarget.userId)
} else if let urlTarget = target as? PubNubChat.MentionTargetUrl {
return .url(url: urlTarget.url)
.url(url: urlTarget.url)
} else {
return nil
nil
}
}
}
Expand Down Expand Up @@ -254,7 +254,7 @@ public struct SuggestedMention {
}
}

public extension Array where Element == SuggestedMention {
public extension [SuggestedMention] {
/// Utility function for filtering suggestions for a specific position in the message draft text.
///
/// - Parameter position: The cursor position in the message draft text
Expand Down
13 changes: 6 additions & 7 deletions Sources/MessageDraft/MessageDraftChangeListener.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MessageDraftStateListener.swift
// MessageDraftChangeListener.swift
//
// Copyright (c) PubNub Inc.
// All rights reserved.
Expand All @@ -14,7 +14,6 @@ import PubNubChat
/// A listener that can be used with ``MessageDraft/addChangeListener(_:)`` to listen for changes to the message draft
/// text and get current mention suggestions.
public protocol MessageDraftChangeListener: AnyObject {

/// Called when there is a change in the message elements or suggested mentions.
///
/// - Parameters:
Expand All @@ -27,11 +26,11 @@ public protocol MessageDraftChangeListener: AnyObject {
///
/// This class allows you to handle delegate events by passing a closure, reducing the need to implement the ``MessageDraftChangeListener`` protocol.
/// This is useful when you want to quickly handle messages without writing additional boilerplate code.
final public class ClosureMessageDraftChangeListener: MessageDraftChangeListener {
let onChangeClosure: (([MessageElement], any FutureObject<[SuggestedMention]>) -> Void)
public final class ClosureMessageDraftChangeListener: MessageDraftChangeListener {
let onChangeClosure: ([MessageElement], any FutureObject<[SuggestedMention]>) -> Void

init(onChange: @escaping ([MessageElement], any FutureObject<[SuggestedMention]>) -> Void) {
self.onChangeClosure = onChange
onChangeClosure = onChange
}

public func onChange(messageElements: [MessageElement], suggestedMentions: any FutureObject<[SuggestedMention]>) {
Expand Down Expand Up @@ -60,13 +59,13 @@ class SuggestedMentionsFuture: FutureObject {
}

func async(completion: @escaping (Swift.Result<[SuggestedMention], Error>) -> Void) {
future.async(caller: self, callback: { (result: FutureResult<SuggestedMentionsFuture, [PubNubChat.SuggestedMention]>) in
future.async(caller: self) { (result: FutureResult<SuggestedMentionsFuture, [PubNubChat.SuggestedMention]>) in
switch result.result {
case let .success(suggestedMentions):
completion(.success(suggestedMentions.compactMap { SuggestedMention.from(mention: $0) }))
case let .failure(error):
completion(.failure(error))
}
})
}
}
}
2 changes: 1 addition & 1 deletion Sources/MessageDraft/MessageDraftImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//

import Foundation
import PubNubSDK
import PubNubChat
import PubNubSDK

/// A concrete implementation of the ``MessageDraft`` protocol.
///
Expand Down
2 changes: 1 addition & 1 deletion Sources/Miscellaneous/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

import Foundation

let pubNubSwiftChatSDKVersion: String = "0.9.2"
let pubNubSwiftChatSDKVersion: String = "0.9.3"
2 changes: 1 addition & 1 deletion Sources/Miscellaneous/ErrorConstants.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Constants.swift
// ErrorConstants.swift
//
// Copyright (c) PubNub Inc.
// All rights reserved.
Expand Down
10 changes: 5 additions & 5 deletions Sources/Models/InputFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct InputFile {
public var source: PubNub.FileUploadContent

/// Initializes a new instance of ``InputFile`` with the provided details.
///
///
/// - Parameters:
/// - name: The name of the file
/// - type: The type or MIME type of the file (e.g., "image/jpeg", "application/pdf")
Expand Down Expand Up @@ -63,19 +63,19 @@ public struct InputFile {
static func from(input: PubNubChat.InputFile) -> InputFile? {
switch input.source {
case let source as PubNubChat.FileUploadContent:
return InputFile(
InputFile(
name: input.name,
type: input.type,
source: .file(url: source.url)
)
case let source as PubNubChat.DataUploadContent:
return InputFile(
InputFile(
name: input.name,
type: input.type,
source: .data(source.data, contentType: source.contentType)
)
case let source as PubNubChat.StreamUploadContent:
return InputFile(
InputFile(
name: input.name,
type: input.type,
source: .stream(
Expand All @@ -85,7 +85,7 @@ public struct InputFile {
)
)
default:
return nil
nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/Models/QuotedMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct QuotedMessage {
public var userId: String

/// Initializes a new instance of ``QuotedMessage`` with the provided details.
///
///
/// - Parameters:
/// - timetoken: Timetoken of the orginal message that you quote
/// - text: Original message content
Expand Down
Loading

0 comments on commit 9b666a0

Please sign in to comment.