Skip to content

Commit

Permalink
Merge pull request #10 from QuickBlox/Release-0.1.6
Browse files Browse the repository at this point in the history
Release 0.1.6
  • Loading branch information
VladimirNybozhinsky authored Aug 31, 2023
2 parents 5f717d9 + 63ed1c8 commit 6ae794a
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 20 deletions.
1 change: 1 addition & 0 deletions Sources/QuickBloxData/DTO/File/LocalFileDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public struct LocalFileDTO: DataStringConvertible {
public var type: FileType = .file
public var data: Data = Data()
public var path: FilePath = FilePath()
public var uid: String = ""
}
1 change: 1 addition & 0 deletions Sources/QuickBloxData/DTO/File/RemoteFileDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public struct RemoteFileDTO: DataStringConvertible {
public var type: FileType = .file
public var data: Data = Data()
public var path: FilePath = FilePath()
public var uid: String = ""

public var `public`: Bool = false
}
1 change: 1 addition & 0 deletions Sources/QuickBloxData/DTO/Message/LocalMessageDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ public struct LocalFileInfoDTO: Equatable, Identifiable, Hashable {
var ext: FileExtension = .json
var name: String = ""
var path: FilePath = FilePath()
public var uid: String = ""
}
1 change: 1 addition & 0 deletions Sources/QuickBloxData/DTO/Message/RemoteMessageDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public struct RemoteFileInfoDTO: Equatable {
var name = ""
var type = ""
var path = ""
var uid = ""
}
8 changes: 6 additions & 2 deletions Sources/QuickBloxData/Repository/FilesRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private extension LocalFileDTO {
type = value.type
data = value.data
path = value.path
uid = value.uid
}
}

Expand All @@ -85,7 +86,8 @@ private extension File {
info = FileInfo(id: value.id,
ext: value.ext,
name: value.name,
path: value.path)
path: value.path,
uid: value.uid)
data = value.data
}
}
Expand All @@ -96,7 +98,8 @@ private extension File {
info = FileInfo(id: value.id,
ext: value.ext,
name: value.name,
path: value.path)
path: value.path,
uid: value.uid)
data = value.data
}
}
Expand All @@ -109,5 +112,6 @@ private extension LocalFileDTO {
type = value.info.type
path = value.info.path
data = value.data
uid = value.info.uid
}
}
6 changes: 5 additions & 1 deletion Sources/QuickBloxData/Repository/MessagesRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extension LocalMessageDTO {
fileInfo?.name = new.name
fileInfo?.ext = new.ext
fileInfo?.path = new.path
fileInfo?.uid = new.uid
}
}
}
Expand All @@ -68,7 +69,8 @@ private extension RemoteMessageDTO {
id: file.id,
name: file.name,
type: file.ext.type.rawValue,
path: file.path.remote
path: file.path.remote,
uid: file.uid
))
}
}
Expand Down Expand Up @@ -105,6 +107,7 @@ extension Message {
name: filesInfo.name)
}
fileInfo?.path.remote = filesInfo.path
fileInfo?.uid = filesInfo.uid
}
}

Expand All @@ -126,6 +129,7 @@ extension Message {
ext: info.ext,
name: info.name)
fileInfo?.path = info.path
fileInfo?.uid = info.uid
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/QuickBloxData/Source/Entity/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public struct FileInfo: FileInfoEntity {
public var name: String
public var type: FileType
public var path: FilePath
public var uid: String

public init(id: String,
ext: FileExtension,
Expand All @@ -44,6 +45,7 @@ public struct FileInfo: FileInfoEntity {
}
type = ext.type
path = FilePath()
uid = ""
}
}

Expand All @@ -52,7 +54,8 @@ public extension FileInfo {
self.init(id: value.id,
ext: value.ext,
name: value.name,
path: FilePath(value.path))
path: FilePath(value.path),
uid: value.uid)
}
}

Expand Down
36 changes: 28 additions & 8 deletions Sources/QuickBloxData/Source/Remote/RemoteDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ extension RemoteDataSource {
system.dateSent = Date()

system.recipientID = QBSession.current.currentUserID
// await stream.process(system)

for id in dto.participantsIds {
system.recipientID = UInt(id) ?? 0
Expand Down Expand Up @@ -893,6 +892,7 @@ extension RemoteDataSource {

let fileName = blob.name ?? "file"
let fileId = String(blob.id)
let fileUID = blob.uid ?? ""

var fileExtension: FileExtension
if let extStr = fileName.components(separatedBy: ".").last,
Expand All @@ -916,7 +916,8 @@ extension RemoteDataSource {
name: fileName,
type: fileExtension.type,
data: dto.data,
path: filePath)
path: filePath,
uid: fileUID)
} catch let nsError as NSError {
throw try nsError.convertToRemoteException()
} catch {
Expand Down Expand Up @@ -974,6 +975,7 @@ extension RemoteDataSource {
uploaded.name = fileName
uploaded.type = fileExtension.type
uploaded.path = filePath
uploaded.uid = uuid
return uploaded
} catch let nsError as NSError {
throw try nsError.convertToRemoteException()
Expand All @@ -982,6 +984,10 @@ extension RemoteDataSource {
}
} else {
var uploaded = try await get(fileWithPath: dto.id)
if uploaded.name.contains("json"), uploaded.ext != .json {
uploaded.name = uploaded.name.replacingOccurrences(of: "json",
with: uploaded.ext.rawValue)
}
if dto.name.contains(dto.ext.rawValue) {
let fileName = dto.name.replacingOccurrences(of: dto.ext.rawValue,
with: "")
Expand Down Expand Up @@ -1425,7 +1431,8 @@ private extension QBRequest {
name: fileName,
type: fileExt.type,
data: data,
path: filePath)
path: filePath,
uid: uuid ?? "")
}

static func delete(file id: UInt) async throws {
Expand Down Expand Up @@ -1645,7 +1652,9 @@ extension QBChatMessage {
}

attachments = value.filesInfo.compactMap {
return QBChatAttachment($0)
var attachment = QBChatAttachment($0)
attachment["uid"] = $0.uid
return attachment
}

delayed = value.delayed
Expand All @@ -1658,15 +1667,26 @@ extension QBChatMessage {

private extension RemoteFileInfoDTO {
init (_ value: QBChatAttachment) throws {
guard let id = value.id else {
let info = "\(String(describing: QBChatAttachment.self)) id is missing"
throw MapperException.incorrectData(description: info)
if let id = value.id {
self.id = id
} else {
if let urlPath = value.url, let url = URL(string: urlPath) {
self.id = url.lastPathComponent
}
if let uid = value.customParameters?["uid"] {
self.id = uid
}
if let contentType = value["content-type"] {
type = contentType
}
}
self.id = id

name = value.name ?? ""
type = value.type ?? ""
path = value.url ?? ""
if let uid = value.customParameters?["uid"] {
self.uid = uid
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions Sources/QuickBloxDomain/Entity/FileEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public protocol FileInfoEntity: Entity {
var name: String { get set }
var type: FileType { get set }
var path: PathItem { get set }
var uid: String { get set }

init(id: String, ext: FileExtension, name: String)
}
Expand All @@ -36,12 +37,13 @@ extension FileInfoEntity {
public init(id: String,
ext: FileExtension,
name: String,
path: PathItem) {
path: PathItem,
uid: String) {
self.init(id: id, ext: ext, name: name)
self.name = name
self.name = name
self.type = ext.type
self.path = path
self.uid = uid
}
}

Expand Down
11 changes: 7 additions & 4 deletions Sources/QuickBloxUIKit/SwiftUIView/Dialog/GroupDialogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ public struct GroupDialogView<ViewModel: DialogViewModelProtocol>: View {
if action == .play {
viewModel.playAudio(data, action: action)
tappedMessage = message
} else {
} else if action == .stop {
viewModel.stopPlayng()
tappedMessage = nil
} else if action == .save {
self.fileUrl = url
isFileExporterPresented = true
}
}
}, onAIFeature: { type, message in
Expand Down Expand Up @@ -188,9 +191,9 @@ public struct GroupDialogView<ViewModel: DialogViewModelProtocol>: View {
viewModel.sendStopTyping()
viewModel.stopPlayng()
isInfoPresented = true
}))
.sheet(isPresented: $isFileExporterPresented) {
}))

.sheet(isPresented: $isFileExporterPresented) {
if let fileUrl = fileUrl {
ActivityViewController(activityItems: [fileUrl.lastPathComponent , fileUrl])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public struct InboundAudioMessageRow<MessageItem: MessageEntity>: View {
}
.fixedSize(horizontal: false, vertical: true)
.id(message.id)
.contextMenu {
Button {
save()
} label: {
Label("Save", systemImage: "folder")
}
}
}

private func play() {
Expand All @@ -106,6 +113,11 @@ public struct InboundAudioMessageRow<MessageItem: MessageEntity>: View {
onTap(.play, data, url)
}
}

private func save() {
guard let url = fileTuple?.url, let data = fileTuple?.data else { return }
onTap(.save, data, url)
}
}

import QuickBloxData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ public struct OutboundAudioMessageRow<MessageItem: MessageEntity>: View {
}
.fixedSize(horizontal: false, vertical: true)
.id(message.id)

.contextMenu {
Button {
save()
} label: {
Label("Save", systemImage: "folder")
}
}
}

private func play() {
Expand All @@ -100,6 +106,11 @@ public struct OutboundAudioMessageRow<MessageItem: MessageEntity>: View {
onTap(.play, data, url)
}
}

private func save() {
guard let url = fileTuple?.url, let data = fileTuple?.data else { return }
onTap(.save, data, url)
}
}

import QuickBloxData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ public struct PrivateDialogView<ViewModel: DialogViewModelProtocol>: View {
if action == .play {
viewModel.playAudio(data, action: action)
tappedMessage = message
} else {
} else if action == .stop {
viewModel.stopPlayng()
tappedMessage = nil
} else if action == .save {
self.fileUrl = url
isFileExporterPresented = true
}
}
}, onAIFeature: { type, message in
Expand Down
1 change: 1 addition & 0 deletions Sources/QuickBloxUIKit/ViewModel/DialogsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ open class DialogsViewModel: DialogsListProtocol {
if dialogId == self?.selectedItem?.id {
self?.selectedItem = nil
}
self?.dialogToBeDeleted = nil
}
.store(in: &cancellables)

Expand Down

0 comments on commit 6ae794a

Please sign in to comment.