Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubNub Swift Chat SDK 0.9.3 release #12

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/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