Skip to content

Commit b34864f

Browse files
Merge pull request #20 from QuickBlox/0.4.0
0.4.0 - Updated QuickBlox dependencies to latest versions. - Added support for Mac Catalyst. - Enhanced AI features with latest updates. - Ensured compatibility with iOS 18. - Bug fixes and code refactoring.
2 parents 44f8f84 + 6d684d4 commit b34864f

File tree

76 files changed

+2005
-994
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2005
-994
lines changed

Package.resolved

Lines changed: 0 additions & 41 deletions
This file was deleted.

Package.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// swift-tools-version: 5.7
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

4+
45
import PackageDescription
56

67
let package = Package(
@@ -16,10 +17,10 @@ let package = Package(
1617
targets: ["QuickBloxUIKit", "QuickBloxData", "QuickBloxDomain"]),
1718
],
1819
dependencies: [
19-
.package(url: "https://github.com/QuickBlox/ios-quickblox-sdk", .upToNextMajor(from: "2.19.0")),
20-
.package(url: "https://github.com/QuickBlox/ios-ai-answer-assistant.git", .upToNextMajor(from: "2.0.0")),
21-
.package(url: "https://github.com/QuickBlox/ios-ai-translate.git", .upToNextMajor(from: "2.0.0")),
22-
.package(url: "https://github.com/QuickBlox/ios-ai-rephrase.git", .upToNextMajor(from: "2.0.0"))
20+
.package(url: "https://github.com/QuickBlox/ios-quickblox-sdk", .upToNextMajor(from: "2.21.0")),
21+
.package(url: "https://github.com/QuickBlox/ios-ai-answer-assistant.git", .upToNextMajor(from: "2.1.0")),
22+
.package(url: "https://github.com/QuickBlox/ios-ai-translate.git", .upToNextMajor(from: "2.1.0")),
23+
.package(url: "https://github.com/QuickBlox/ios-ai-rephrase.git", .upToNextMajor(from: "2.1.0"))
2324
],
2425
targets: [
2526
.target(
@@ -51,5 +52,13 @@ let package = Package(
5152
"QuickBloxData",
5253
"QuickBloxLog"],
5354
resources: [.process("Resources")]),
55+
.testTarget(
56+
name: "QuickBloxUIKitIntegrationTests",
57+
dependencies: ["QuickBloxUIKit",
58+
"QuickBloxData",
59+
"QuickBloxLog",
60+
.product(name: "Quickblox",
61+
package: "ios-quickblox-sdk")],
62+
resources: [.process("Resources")]),
5463
]
5564
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// RemoteAnswerAssistMessageDTO.swift
3+
// QuickBloxUIKit
4+
//
5+
// Created by Injoit on 16.05.2024.
6+
// Copyright © 2023 QuickBlox. All rights reserved.
7+
//
8+
9+
import QuickBloxDomain
10+
import Foundation
11+
12+
/// This is a DTO model for interactions with the Answer Assist Message models in remote storage.
13+
public struct RemoteAnswerAssistMessageDTO {
14+
var id = ""
15+
var smartChatAssistantId = ""
16+
var message = ""
17+
var history: [RemoteAnswerAssistHistoryMessageDTO] = []
18+
}
19+
20+
/// This is a DTO model for interactions with the Answer Assist History Message models in remote storage.
21+
public struct RemoteAnswerAssistHistoryMessageDTO {
22+
var id = ""
23+
var role: AIMessageRole = .user
24+
var message = ""
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// RemoteTranslateMessageDTO.swift
3+
// QuickBloxUIKit
4+
//
5+
// Created by Injoit on 16.05.2024.
6+
// Copyright © 2023 QuickBlox. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct RemoteTranslateMessageDTO {
12+
var id = ""
13+
var smartChatAssistantId = ""
14+
var message = ""
15+
var languageCode = ""
16+
}

Sources/QuickBloxData/Exception/DataSourceException.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public enum DataSourceException: Error, Equatable {
1919

2020
/// Would be thrown when an operation is attempted on an record that does not exist in the data source.
2121
case notFound(description:String = "")
22+
23+
/// Would be thrown when attempting to access and without authentication credentials to do so.
24+
case unauthorised(description:String = "")
2225
}
2326

2427
extension DataSourceException: LocalizedError {
@@ -32,6 +35,8 @@ extension DataSourceException: LocalizedError {
3235
description = ("Already exist.", reason)
3336
case .notFound(let reason):
3437
description = ("Not found.", reason)
38+
case .unauthorised(let reason):
39+
description = ("Unauthorised.", reason)
3540
}
3641

3742
return description.info + "" + description.reason

Sources/QuickBloxData/Mapper/Error+RepositoryException.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extension Error {
3232
return RepositoryException.alreadyExist(description: info)
3333
case .notFound(description: let info):
3434
return RepositoryException.notFound(description: info)
35+
case .unauthorised(description: let description):
36+
return RepositoryException.unauthorised(description)
3537
}
3638
}
3739

Sources/QuickBloxData/RepositoriesFabric.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ public class RepositoriesFabric {
4343
static public var permissions: PermissionsRepository {
4444
PermissionsRepository(repo: Service.permissions)
4545
}
46+
47+
static public var ai: AIRepository {
48+
AIRepository(remote: Service.remote)
49+
}
4650
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// AIRepository.swift
3+
// QuickBloxUIKit
4+
//
5+
// Created by Injoit on 16.05.2024.
6+
// Copyright © 2023 QuickBlox. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import QuickBloxDomain
11+
12+
/// This is a class that implements the ``AIRepositoryProtocol`` protocol and contains methods and properties that allow it to interact with the ``AnswerAssistMessage`` items.
13+
public class AIRepository {
14+
private let remote: RemoteDataSourceProtocol
15+
16+
public init(remote: RemoteDataSourceProtocol) {
17+
self.remote = remote
18+
}
19+
}
20+
21+
extension AIRepository: AIRepositoryProtocol {
22+
23+
public func answerAssist(message entity: AnswerAssistMessage) async throws -> String {
24+
do {
25+
return try await remote.answerAssist(message: RemoteAnswerAssistMessageDTO(entity))
26+
} catch {
27+
throw try error.repositoryException
28+
}
29+
}
30+
31+
public func translate(message entity: TranslateMessage) async throws -> String {
32+
do {
33+
return try await remote.translate(message: RemoteTranslateMessageDTO(entity))
34+
} catch {
35+
throw try error.repositoryException
36+
}
37+
}
38+
}
39+
40+
private extension RemoteAnswerAssistMessageDTO {
41+
init(_ value: AnswerAssistMessage) {
42+
id = value.id
43+
smartChatAssistantId = value.smartChatAssistantId
44+
message = value.message
45+
history = value.history.compactMap({ RemoteAnswerAssistHistoryMessageDTO($0) })
46+
}
47+
}
48+
49+
private extension RemoteAnswerAssistHistoryMessageDTO {
50+
init(_ value: AnswerAssistHistoryMessage) {
51+
id = value.id
52+
role = value.role
53+
message = value.message
54+
}
55+
}
56+
57+
private extension RemoteTranslateMessageDTO {
58+
init(_ value: TranslateMessage) {
59+
id = value.id
60+
message = value.message
61+
smartChatAssistantId = value.smartChatAssistantId
62+
languageCode = value.languageCode
63+
}
64+
}

Sources/QuickBloxData/Repository/UsersRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ extension UsersRepository: UsersRepositoryProtocol {
116116

117117
public func get(usersFromRemote fullName: String) async throws -> [User] {
118118
do {
119-
let pagination = Pagination(skip: 0, limit: 30)
119+
let pagination = Pagination(skip: 0, limit: 100)
120120
let withFullName = RemoteUsersDTO(name:fullName, pagination: pagination)
121121
let data = try await remote.get(users: withFullName)
122122
return data.users.map { User($0) }
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// AnswerAssistMessage.swift
3+
// QuickBloxUIKit
4+
//
5+
// Created by Injoit on 16.05.2024.
6+
// Copyright © 2023 QuickBlox. All rights reserved.
7+
//
8+
9+
import QuickBloxDomain
10+
import Foundation
11+
12+
/// Contain methods and properties that describe an Answer Assist Message.
13+
///
14+
/// This is an active model that conforms to the ``AnswerAssistMessageEntity`` protocol.
15+
public struct AnswerAssistMessage: AnswerAssistMessageEntity {
16+
public typealias AnswerAssistHistoryMessageItem = AnswerAssistHistoryMessage
17+
public var id: String = UUID().uuidString
18+
public var smartChatAssistantId: String
19+
public var message: String
20+
public var history: [AnswerAssistHistoryMessage]
21+
22+
public init(message: String,
23+
history: [AnswerAssistHistoryMessage],
24+
smartChatAssistantId: String) {
25+
self.smartChatAssistantId = smartChatAssistantId
26+
self.message = message
27+
self.history = history
28+
}
29+
}
30+
31+
public extension AnswerAssistMessage {
32+
init<T: AnswerAssistMessageEntity>(_ value: T) {
33+
self.init(message: value.message,
34+
history: value.history.map({ AnswerAssistHistoryMessage($0) }),
35+
smartChatAssistantId: value.smartChatAssistantId)
36+
}
37+
}
38+
39+
/// Contain methods and properties that describe an Answer Assist History Message.
40+
///
41+
/// This is an active model that conforms to the ``AnswerAssistHistoryMessageEntity`` protocol.
42+
public struct AnswerAssistHistoryMessage: AnswerAssistHistoryMessageEntity {
43+
public var id: String = UUID().uuidString
44+
public var role: AIMessageRole
45+
public var message: String
46+
47+
public init(role: AIMessageRole,
48+
message: String) {
49+
self.role = role
50+
self.message = message
51+
}
52+
}
53+
54+
public extension AnswerAssistHistoryMessage {
55+
init<T: AnswerAssistHistoryMessageEntity>(_ value: T) {
56+
self.init(role: value.role,
57+
message: value.message)
58+
}
59+
}
60+
61+
public extension AnswerAssistHistoryMessage {
62+
init<T: MessageEntity>(_ value: T) {
63+
self.init(role: value.isOwnedByCurrentUser ? .user : .assistant,
64+
message: value.text)
65+
}
66+
}

0 commit comments

Comments
 (0)