Skip to content

Commit

Permalink
Merge pull request #9 from QuickBlox/Release-0.1.5
Browse files Browse the repository at this point in the history
Release QuickBlox UIKit 0.1.5
  • Loading branch information
VladimirNybozhinsky authored Aug 29, 2023
2 parents d889190 + b781109 commit 5f717d9
Show file tree
Hide file tree
Showing 68 changed files with 2,308 additions and 580 deletions.
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"version" : "1.0.1"
}
},
{
"identity" : "ios-ai-translate",
"kind" : "remoteSourceControl",
"location" : "https://github.com/QuickBlox/ios-ai-translate.git",
"state" : {
"revision" : "3a224bec51097629589fcc0a33dbc4b81feb95d6",
"version" : "1.0.0"
}
},
{
"identity" : "ios-quickblox-sdk",
"kind" : "remoteSourceControl",
Expand Down
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/QuickBlox/ios-quickblox-sdk", .upToNextMajor(from: "2.19.0")),
.package(url: "https://github.com/QuickBlox/ios-ai-answer-assistant.git", .upToNextMajor(from: "1.0.0"))
.package(url: "https://github.com/QuickBlox/ios-ai-answer-assistant.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/QuickBlox/ios-ai-translate.git", .upToNextMajor(from: "1.0.0"))
],
targets: [
.target(
Expand All @@ -35,7 +36,9 @@ let package = Package(
.product(name: "Quickblox",
package: "ios-quickblox-sdk"),
.product(name: "QBAIAnswerAssistant",
package: "ios-ai-answer-assistant")]),
package: "ios-ai-answer-assistant"),
.product(name: "QBAITranslate",
package: "ios-ai-translate")]),
.target(
name: "QuickBloxLog",
dependencies: []),
Expand Down
322 changes: 241 additions & 81 deletions README.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Sources/QuickBloxData/DTO/Dialog/LocalDialogDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ public struct LocalDialogDTO: Equatable, Identifiable, Hashable {
var lastMessageDateSent = Date(timeIntervalSince1970: 0.0)
var lastMessageUserId: String = ""
var unreadMessagesCount: Int = 0
var decrementCounter: Bool = false
}

extension LocalDialogDTO: Dated {
var date: Date {
return updatedAt
}


}
4 changes: 2 additions & 2 deletions Sources/QuickBloxData/Event/RemoteEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


public enum RemoteEvent {
case create(_ dialogId: String)
case create(_ dialogId: String, byUser: Bool, message: RemoteMessageDTO)
case update(_ dialogId: String)
case leave(_ dialogId: String, byUser: Bool)
case removed(_ dialogId: String)
Expand All @@ -23,7 +23,7 @@ public enum RemoteEvent {
if message.type == .event {
switch message.eventType {
case .create:
self = .create(message.dialogId)
self = .create(message.dialogId, byUser: message.isOwnedByCurrentUser, message: message)
case .update:
self = .update(message.dialogId)
case .leave:
Expand Down
5 changes: 5 additions & 0 deletions Sources/QuickBloxData/RepositoriesFabric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class RepositoriesFabric {
static let remote = RemoteDataSource()
static let local = LocalDataSource()
static let localFiles = LocalFilesDataSource()
static let permissions = PermissionsSource()
}

static public var dialogs: DialogsRepository {
Expand All @@ -38,4 +39,8 @@ public class RepositoriesFabric {
static public var connection: ConnectionRepository {
ConnectionRepository(remote: Service.remote)
}

static public var permissions: PermissionsRepository {
PermissionsRepository(repo: Service.permissions)
}
}
7 changes: 4 additions & 3 deletions Sources/QuickBloxData/Repository/DialogsRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ extension DialogsRepository: DialogsRepositoryProtocol {
await remote.eventPublisher
.compactMap { event in
switch event {
case .create(withId: let dialogId): return .create(dialogId)
case .update(witthDialogId: let dialogId): return .update(dialogId)
case .leave( let dialogId, let isCurrentUser ):
case .create(let dialogId, let isCurrent, let message): return .create(dialogId, byUser: isCurrent, message: Message(message))
case .update(withDialogId: let dialogId): return .update(dialogId)
case .leave( let dialogId, let isCurrentUser):
return .leave(dialogId, byUser: isCurrentUser)
case .removed(let dialogId):
return .removed(dialogId)
Expand Down Expand Up @@ -247,6 +247,7 @@ private extension LocalDialogDTO {
lastMessageUserId = value.lastMessage.userId

unreadMessagesCount = value.unreadMessagesCount
decrementCounter = value.decrementCounter
isOwnedByCurrentUser = value.isOwnedByCurrentUser
}
}
Expand Down
38 changes: 38 additions & 0 deletions Sources/QuickBloxData/Repository/PermissionsRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// PermissionsRepository.swift
// QuickBloxUIKit
//
// Created by Injoit on 25.08.2023.
// Copyright © 2023 QuickBlox. All rights reserved.
//

import QuickBloxDomain
import AVFoundation

public class PermissionsRepository {
private var repo: PermissionsRepositoryProtocol!

init(repo: PermissionsRepositoryProtocol) {
self.repo = repo
}

private init() { }
}

extension PermissionsRepository: PermissionsRepositoryProtocol {
public func openSettings() async throws {
do {
try await repo.openSettings()
} catch {
throw try error.repositoryException
}
}

public func get(permissionTo mediaType: AVMediaType) async throws -> Bool {
do {
return try await repo.get(permissionTo: mediaType)
} catch {
throw try error.repositoryException
}
}
}
5 changes: 4 additions & 1 deletion Sources/QuickBloxData/Source/Entity/Dialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public struct Dialog: DialogEntity {
userId: "")
public var messages: [Message] = []
public var unreadMessagesCount: Int
public var decrementCounter: Bool = false

public init(id: String = "",
type: DialogType,
Expand All @@ -43,7 +44,8 @@ public struct Dialog: DialogEntity {
text: "",
userId: ""),
messages: [Message] = [],
unreadMessagesCount: Int = 0) {
unreadMessagesCount: Int = 0,
decrementCounter: Bool = false) {
self.id = id
self.type = type
self.name = name
Expand All @@ -55,6 +57,7 @@ public struct Dialog: DialogEntity {
self.lastMessage = lastMessage
self.messages = messages
self.unreadMessagesCount = unreadMessagesCount
self.decrementCounter = decrementCounter
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/QuickBloxData/Source/Entity/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public struct Message: MessageEntity {
///
/// > Note: Returns an empty string by default
public var text: String = ""
public var translatedText: String = ""

public var userId: String = ""
public var isOwnedByCurrentUser = false
Expand Down Expand Up @@ -49,6 +50,7 @@ public extension Message {
self.init(id: value.id,
dialogId: value.dialogId,
text: value.text,
translatedText: value.translatedText,
userId: value.userId,
date: value.date,
isOwnedByCurrentUser: value.isOwnedByCurrentUser,
Expand Down
4 changes: 3 additions & 1 deletion Sources/QuickBloxData/Source/Local/LocalDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ extension LocalDataSource {

dialog.updatedAt = dto.updatedAt

if dto.unreadMessagesCount != 0 {
if dto.decrementCounter == true {
dialog.unreadMessagesCount -= 1
} else if dto.unreadMessagesCount != 0 {
dialog.unreadMessagesCount = dto.unreadMessagesCount
}

Expand Down
57 changes: 57 additions & 0 deletions Sources/QuickBloxData/Source/Local/PermissionsSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// PermissionsSource.swift
// QuickBloxUIKit
//
// Created by Injoit on 25.08.2023.
// Copyright © 2023 QuickBlox. All rights reserved.
//

import QuickBloxDomain
import AVFoundation
import UIKit

class PermissionsSource {

}

//MARK: PermissionsRepositoryProtocol
extension PermissionsSource: PermissionsRepositoryProtocol {
func openSettings() async throws {
if let url = await URL(string: UIApplication.openSettingsURLString) {
await UIApplication.shared.open(url, options: [:])
}
}

func get(permissionTo mediaType: AVMediaType) async throws -> Bool {
switch mediaType {
case .audio: return try await PermissionsSource.requestPermissionTo(.audio)
case .video: return try await PermissionsSource.requestPermissionTo(.video)
default: return false
}
}
}

private extension PermissionsSource {

static func requestPermissionTo(_ mediaType: AVMediaType) async throws -> Bool {
switch mediaType {
case .audio:
return try await withCheckedThrowingContinuation { continuation in
AVAudioSession.sharedInstance().requestRecordPermission({ granted in
DispatchQueue.main.async(execute: {
continuation.resume(returning: granted)
})
})
}
case .video:
return try await withCheckedThrowingContinuation { continuation in
AVCaptureDevice.requestAccess(for: .video, completionHandler: {granted in
DispatchQueue.main.async {
continuation.resume(returning: granted)
}
})
}
default: return false
}
}
}
Loading

0 comments on commit 5f717d9

Please sign in to comment.